Beruflich Dokumente
Kultur Dokumente
CONTENTS:
SINGLE-LEVEL OCCURS Clauses Processing data Stored in an ARRAY Using an OCCURS Clause for Table Handling Use the SEARCH statement for Table and Array Processing The SEARCHVARYING Option for processing PARALLEL Tables The SEARCH ALL Statements MULTIPLE LEVEL OCCURS Clause
Defining a Subscript:
01 ARRAY-1 VALUE ZERO. 05 TOTALS OCCURS 50 TIMES PIC 9(5). can also be written as:
01 ARRAY-1.
05 TOTALS OCCURS 50 TIMES PIC 9(5) VALUE ZERO.
01 MONTH-NAMES. 05 STRING-1 PIC X(36) VALUE JANFEBMARAPRMAYJUNJULAUGSEPOCTNOVDEC 05 MONTH REDEFINES STRING-1 OCCURS 12 TIMES PIC XXX.
redefines STRING-1 and enables each three-character abbreviation for months 1 through 12 to be accessed separately using a subscript.. establishes a 36-position constant that contains a three-character abbreviation for each of the 12 months of the year In either case. MONTH (SUB) contains a three-character month abbreviation.
Sales tax rates occasionally change- each time there is a change to a tax rate in a county, all input records for that county would need to be changed Recording the sales tax rate for each input record means extra keying. If 100 records all pertain to a single county, we would be entering the same sales tax rate 1000 times additional labor and added risk of input errors.
SEARCH identifier-1 [ AT END imperative-statement1] WHEN condition1 ] imperative-statement2 ..... CONTINUE [END-SEARCH]
============================================ SET X1 TO 1 SEARCH TABLE-ENTRIES AT END MOVE 0 TO WS-SALES-TAX WHEN ZIP-IN = WS-ZIPXODE(X1) COMPUTE WS-SALES-TAX ROUNDED = WS-TAX-RATE (X1) * UNIT-PRICE-IN * QTY-IN END-SEARCH. =================================================
USE OF THE SEARCH STATEMENT FOR TABLE AND ARRAY PROCESSING conttinued
MOVE WS-SALES-TAX TO DL-SALES-TAX. COMPUTE DL-TOTAL = UNIT-PRICE-IN * QTY-IN + WS-SALES-TAX. WRITE BILLING-REC FROM DETAIL-LINE AFTER ADVANCING 2 LINES.
The identifier used with the SEARCH verb is the table entry name specified on the OCCURS level, not on the 01 level. The WHEN clause indicates what action is to be taken when the condition specified is actually met With the SEARCH statement, the AT END clause specifies what should be done if the table has been completely searched and no matched is found. It is strongly recommended that always use this optional clause, without it, the no match condition will simply cause the program to continue with the next sentence.
The SEARCH statement will perform a table look-up, TABLE-ENTRIES, the identifier used with the OCCURS and INDEXED BY clauses, is the item designated with the SEARCH as well. 01 SALES-TAX-TABLE will not be used with the SEARCH. The table will be searched and the index automatically incremented until the condition specified is satisfied or until AT END is met. The AT END indicates that the table has been completely searched without the condition being met; that is, no match has been found between an input field (search argument) and a table entry (table argument).
Move 1 to the X1 index Add 1 to the X1 index Subtract 1 from the X1 index
This two-dimensional array is established as follows: 1. The arrays will have 7 rows as indicated by the first OCCURS clause. 2. Within this array, each row will have 24 columns, as indicated by the second OCCURS clause. 3. Each of the elements in this 7 x 24 array will be large enough to hold three integers, as indicated by the subordinate entry.
01 TEMPERATURE-ARRAY. 05 DAY-IN-WEEK OCCURS 7 TIMES. 10 HOURS OCCURS 24 TIMES PIC S9(3). To access any of the element , we use the data-name on the lowest OCCURS level or any data-name subordinate to it. Either TEMP (in coding 1) or HOUR (coding 2) could be used to access the elements of the array.
COMPUTE WEEKLY-AVERAGE= TOTAL/168 WRITE PRINT-REC FROM OUT-REC AFTER ADVANCING 2 LINES.
END