Entering content frame

Formatting Data During Reading Locate the document in its SAP Library structure

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.

  WRITE: / wa_spfli-carrid,
           'from', (15) wa_spfli-cityfrom,
           'to',   (15) wa_spfli-cityto.


  SELECT * FROM sflight INTO wa_sflight
                        WHERE carrid = wa_spfli-carrid
                          AND connid = wa_spfli-connid
                        ORDER BY fldate.

    WRITE: / 'Date:', wa_sflight-fldate.
    WRITE: 20 'Book-ID', 40 'Smoker', 50 'Class'.

    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.


    WRITE: 'Number of bookings:  ', (3) cnt,
         / 'Total luggage weight:', (3) sum, wa_sbook-wunit.




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.


Leaving content frame