In a periodic sales and commissions report, the salesmen are listed in order of decreasing sales volume. The "top salesman" is the first one listed in the report. This example uses statement DO EXIT to terminate the extraction process after the name of the top salesman in department 50x has been extracted.
Figure 195 DO EXIT Statement Example
EXECUTE 'DD'
ON DATA
ALWAYS
DO BLOCK 'READ'
DO TERMINATE RESULT OK USER_CODE 444
EXECUTE 'READ'
ON_FILE 'ACTG.SALES.MNTHLY(SORTDOWN)' ON_PARM MODE PG
WHEN FLINE 1 TLINE 999 FCOL 13 TCOL 14 SEARCH '50'
DO EXTRACT 'TOP_SALE' LEVEL 0 LINE +0 FCOL 20 TCOL 39
DO PRINT DATA 'TOP SALESMAN = %%TOP_SALE'
DO EXIT
Input file "ACTG.SALES.MNTHLY(SORTDOWN)" contains the following lines:
1 MONTHLY SALES REPORT
EMPLOYEE DPT SALES PERIOD DOLLAR
NUMBER NUM EMPLOYEE NAME FROM TO VOLUME
---------------------------------------
000187 507 MURPHY CHRISTOPHER 01/01/00 31/01/00 284,817
000132 505 BRADY GREG 01/01/00 31/01/00 281,224
The output of this rule is: TOP SALESMAN = MURPHY CHRISTOPHER
The DO EXIT statement is often used to terminate the current block when a specified condition occurs or the needed information is found.
In the example above, block READ is terminated after "50" is located in columns 13-14 and the desired information has been extracted and printed. This avoids looking through the entire file when information is needed from only one line.
Parent Topic |