Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

What is the Extract statement? Please give me some sample code.?

Former Member
0 Likes
427

What is the Extract statement? Please give me some sample code.?

2 REPLIES 2
Read only

Former Member
0 Likes
386

Hello ,

Once you have declared the possible record types as field groups and defined their structure, you can fill the extract dataset using the following statements: EXTRACT . When the first EXTRACT statement occurs in a program, the system creates the extract dataset and adds the first extract record to it. In each subsequent EXTRACT statement, the new extract record is added to the dataset EXTRACT HEADER. When you extract the data, the record is filled with the current values of the corresponding fields. As soon as the system has processed the first EXTRACT statement for a field group , the structure of the corresponding extract record in the extract dataset is fixed. You can no longer insert new fields into the field groups and HEADER. If you try to modify one of the field groups afterwards and use it in another EXTRACT statement, a runtime error occurs. By processing EXTRACT statements several times using different field groups, you fill the extract dataset with records of different length and structure. Since you can modify field groups dynamically up to their first usage in an EXTRACT statement, extract datasets provide the advantage that you need not determine the structure at the beginning of the program.

Sample program:

REPORT ZSPFLI LINE-SIZE 132 LINE-COUNT 65(3)

NO STANDARD PAGE HEADING.

TABLES:SPFLI,SCARR, SFLIGHT, SBOOK.

SELECT-OPTIONS: MYCARRID FOR SPFLI-CARRID.

FIELD-GROUPS: HEADER, SPFLI_FG, SFLIGHT_FG, SBOOK_FG.

INSERT:

SPFLI-CARRID

SPFLI-CONNID

SFLIGHT-FLDATE

SBOOK-BOOKID

INTO HEADER,

SPFLI-CARRID

SPFLI-CONNID

SPFLI-CITYFROM

SPFLI-AIRPFROM

SPFLI-CITYTO

SPFLI-AIRPTO

SPFLI-DEPTIME

SCARR-CARRNAME

INTO SPFLI_FG,

SFLIGHT-FLDATE

SFLIGHT-SEATSMAX

SFLIGHT-SEATSOCC

SFLIGHT-PRICE

INTO SFLIGHT_FG,

SBOOK-BOOKID

SBOOK-CUSTOMID

SBOOK-CUSTTYPE

SBOOK-SMOKER

INTO SBOOK_FG.

SELECT * FROM SPFLI WHERE CARRID IN MYCARRID.

SELECT SINGLE * FROM SCARR WHERE CARRID = SPFLI-CARRID.

EXTRACT SPFLI_FG.

SELECT * FROM SFLIGHT

WHERE CARRID = SPFLI-CARRID AND CONNID = SPFLI-CONNID.

EXTRACT SFLIGHT_FG.

SELECT * FROM SBOOK

WHERE CARRID = SFLIGHT-CARRID AND

CONNID = SFLIGHT-CONNID AND FLDATE = SFLIGHT-FLDATE.

EXTRACT SBOOK_FG.

CLEAR SBOOK.

ENDSELECT.

CLEAR SFLIGHT.

ENDSELECT.

CLEAR SPFLI.

ENDSELECT.

SORT.

LOOP.

AT SPFLI_FG.

FORMAT COLOR COL_HEADING.

WRITE: / SCARR-CARRNAME,

SPFLI-CONNID, SPFLI-CITYFROM,

SPFLI-AIRPFROM, SPFLI-CITYTO, SPFLI-AIRPTO, SPFLI-DEPTIME.

FORMAT COLOR OFF.

ENDAT.

AT SFLIGHT_FG.

WRITE: /15 SFLIGHT-FLDATE, SFLIGHT-PRICE, SFLIGHT-SEATSMAX,

SFLIGHT-SEATSOCC.

ENDAT.

AT SBOOK_FG.

WRITE: /30 SBOOK-BOOKID, SBOOK-CUSTOMID,

SBOOK-CUSTTYPE, SBOOK-SMOKER.

ENDAT.

ENDLOOP.

Read only

Former Member