Formatting Data Using Extracts 

You can use a single extract to store entries from more than one database table, since the records in an extract can have different structures.

Assume the following program is linked to the logical database F1S.

REPORT DEMO.

NODES: SPFLI, SFLIGHT, SBOOK.

FIELD-GROUPS: HEADER, FLIGHT_INFO, FLIGHT_BOOKING.

INSERT:
  SPFLI-CITYFROM SPFLI-CITYTO
  SPFLI-CONNID SFLIGHT-FLDATE
  SBOOK-CLASS SBOOK-SMOKER SBOOK-BOOKID INTO HEADER,
  SPFLI-CARRID                          INTO FLIGHT_INFO,
  SBOOK-LUGGWEIGHT SBOOK-WUNIT          INTO FLIGHT_BOOKING.

START-OF-SELECTION.

GET SPFLI.
  EXTRACT FLIGHT_INFO.

GET SFLIGHT.

GET SBOOK.
  EXTRACT FLIGHT_BOOKING.

END-OF-SELECTION.

  SORT.

  LOOP.
    AT FLIGHT_INFO.
      SKIP.
      WRITE: / SPFLI-CARRID,
               SPFLI-CONNID,
               'from', (15) SPFLI-CITYFROM,
               'to',   (15) SPFLI-CITYTO.
      ULINE.
    ENDAT.
    AT NEW SFLIGHT-FLDATE.
        SKIP.
        WRITE: / 'Date:', SFLIGHT-FLDATE.
        WRITE: 20 'Book-ID', 40 'Smoker', 50 'Class'.
        ULINE.
    ENDAT.
    AT FLIGHT_BOOKING.
        WRITE: / SBOOK-BOOKID UNDER 'Book-ID',
                 SBOOK-SMOKER UNDER 'Smoker',
                 SBOOK-CLASS  UNDER 'Class'.
    ENDAT.
    AT END OF SFLIGHT-FLDATE.
      ULINE.
      WRITE: 'Number of bookings:  ', (3) CNT(SBOOK-BOOKID),
           / 'Total luggage weight:',
              SUM(SBOOK-LUGGWEIGHT), SBOOK-WUNIT.
    ENDAT.
  ENDLOOP.

This program creates the same list as in the Example of Formatted Data.

The system creates three field groups and fills them with several fields. It then fills the extract in the EXTRACT statements in the GET events. Note that there is no EXTRACT statement for GET SFLIGHT, since the required field SFLIGHT_FLDATE is part of the HEADER field group and thus automatically extracted for each subordinate event GET SBOOK.

After retrieving the data, the system terminates the creation of the dataset when the SORT statement occurs, and sorts the dataset by the HEADER sort key. In the LOOP-ENDLOOP block, it writes the sorted extract dataset to the output list, using various AT ... ENDAT blocks and the fields CNT(...) and SUM(...).