REPORT ZS016AssignmentB .
TABLES: SFLIGHT,SPFLI.
*Define the structure of internal table
TYPES: BEGIN OF INT_TABLE_TYPE,
CARRID LIKE SFLIGHT-CARRID,
CONNID LIKE SFLIGHT-CONNID,
FLDATE LIKE SFLIGHT-FLDATE,
CITYFROM LIKE SPFLI-CITYFROM,
CITYTO LIKE SPFLI-CITYTO,
PRICE LIKE SFLIGHT-PRICE,
SEATSMAX LIKE
SFLIGHT-SEATSMAX,
seatspct TYPE P DECIMALS 2,
SEATSOCC LIKE
SFLIGHT-SEATSOCC,
END OF INT_TABLE_TYPE.
*declare your table statistics variables
DATA:
carrid LIKE sflight-carrid,
connid LIKE sflight-connid,
ROW_COUNTER TYPE I,
REC_COUNTER TYPE I,
average_price LIKE
sflight-price,
total_price LIKE
sflight-price,
average_seatspct TYPE P
DECIMALS 2.
*internal table declare
DATA: itab1 TYPE STANDARD TABLE OF INT_TABLE_TYPE WITH HEADER
LINE.
*===================================
*add a selection range for flight dates.
SELECT-OPTIONS: S_CARRID FOR SFLIGHT-CARRID.
*separate the two selection options on the screen.
SELECTION-SCREEN ULINE.
*add a selection radio button for occupied percentage
DATA:
prct like itab1-seatspct.
parameters:
95% radiobutton group prct,
97% radiobutton group prct,
99% radiobutton group prct
default 'X'.
if 95% = 'X'.
prct = '95'.
elseif 97% = 'X'.
prct = '97'.
else.
prct = '99'.
endif.
*===================
*select data (inner join)
SELECT * FROM SFLIGHT
INNER JOIN SPFLI
ON SFLIGHT~CARRID
= SPFLI~CARRID
AND
SFLIGHT~CONNID = SPFLI~CONNID
INTO
CORRESPONDING FIELDS OF TABLE ITAB1
ORDER BY
sflight~connid.
*place the number into the variable row_counter
DESCRIBE TABLE ITAB1 LINES ROW_COUNTER.
ROW_COUNTER = ROW_COUNTER + 1.
*calculate the seats occupied percentage
LOOP AT itab1.
ITAB1-seatspct =
itab1-seatsocc * '100' / itab1-seatsmax.
MODIFY itab1.
*create subtotals while we're at it
TOTAL_PRICE = TOTAL_PRICE +
itab1-PRICE.
ENDLOOP.
*re-count the rows now in the table
DESCRIBE TABLE itab1 LINES ROW_COUNTER.
*delete records where the occupation percentage < seats_pt
DELETE ITAB1 WHERE seatspct < prct.
*sort the table by price into descending order
SORT itab1 BY carrid ASCENDING.
*the data is loaded in we can loop through itab1
LOOP AT itab1.
*1----------REPORT HEADER
AT FIRST.
SKIP 2.
*write column headers
WRITE: /12 'Connid',
20 'Fldate',
40 'City-From',
60 'City-To',
90 'Price',
110 'Occupy %'.
SKIP.
ENDAT.
*2-------1st record in EACH CARRIER ID (GROUP HEADERS)
AT NEW CARRID.
ULINE.
WRITE: / 'Carrier
ID:',itab1-CARRID.
ULINE.
ENDAT.
* write the data for each line n the group
WRITE: /12 itab1-CONNID,
20
itab1-FLDATE,
40
itab1-CityFrom,
60
itab1-CityTo,
80
itab1-PRICE,
100
itab1-seatspct.
*maintain stats for group footer
REC_COUNTER = REC_COUNTER + 1.
*3----------after the last item in each group (footer)
AT END OF CARRID.
* calculate statistics for the group
SUM.
average_price = itab1-PRICE /
rec_counter.
average_seatspct =
itab1-seatspct / rec_counter.
*write the group footer to the report
SKIP 1.
WRITE: /40 'Average price of',
(2) itab1-CARRID,
'flights',
'---->'.
WRITE: 80 average_price,
100 average_seatspct.
SKIP 2.
WRITE: /40 'Total Number of
Flight ---->'.
WRITE: 105 rec_counter.
*clear the group statistics
CLEAR: AVERAGE_PRICE,
REC_COUNTER.
ENDAT.
*4----------THE END OF THE REPORT (report footer)
ENDLOOP.
SKIP 5.
WRITE 'End of report.'.