The most direct method of formatting data is to use the corresponding options of the SELECT statement. With this method, you must program the database access yourself. In addition, you must program a selection screen to offer the user the possibility of restricting the set of data to be read. Note that using nested SELECT loops is exceedingly inefficient. You should therefore place your data in blocks into internal tables or extracts, and process it from there.
REPORT demo_data_process_read.
DATA: sum TYPE i, cnt TYPE i, wa_spfli TYPE spfli, wa_sflight TYPE sflight, wa_sbook TYPE sbook.
SELECT * FROM spfli INTO wa_spfli ORDER BY cityfrom cityto connid.
SKIP. WRITE: / wa_spfli-carrid, wa_spfli-connid, 'from', (15) wa_spfli-cityfrom, 'to', (15) wa_spfli-cityto. ULINE.
SELECT * FROM sflight INTO wa_sflight WHERE carrid = wa_spfli-carrid AND connid = wa_spfli-connid ORDER BY fldate.
SKIP. WRITE: / 'Date:', wa_sflight-fldate. WRITE: 20 'Book-ID', 40 'Smoker', 50 'Class'. ULINE.
sum = 0. cnt = 0. SELECT * FROM sbook INTO wa_sbook WHERE carrid = wa_sflight-carrid AND connid = wa_sflight-connid AND fldate = wa_sflight-fldate ORDER BY class smoker bookid.
WRITE: / wa_sbook-bookid UNDER 'Book-ID', wa_sbook-smoker UNDER 'Smoker', wa_sbook-class UNDER 'Class'.
sum = sum + wa_sbook-luggweight. cnt = cnt + 1.
ENDSELECT.
ULINE. WRITE: 'Number of bookings: ', (3) cnt, / 'Total luggage weight:', (3) sum, wa_sbook-wunit.
ENDSELECT.
ENDSELECT.
This program creates the same list as in the Example of Formatted Data . It uses the ORDER BY addition in the SELECT statement to sort the data.