ContentsIndexPreviousNext

Code Examples

Format 4:

The following definitions will be used in the examples:

01  SOURCE-TABLE OCCURS 20 TIMES    PIC S9(9)V99.
01  DEST-TABLE OCCURS 20 TIMES      PIC S9(9)V99.

01  ROLL-UP-TABLE.
    03  TOTALS OCCURS 10 TIMES.
        05  REPORT-SUM
            OCCURS 20 TIMES         PIC S9(9)V99.
77  CTR                             PIC 99.

To add all the elements of SOURCE-TABLE to DEST-TABLE:

ADD TABLE SOURCE-TABLE TO DEST-TABLE

To add the first five elements of SOURCE-TABLE to the last five elements of DEST-TABLE:

ADD TABLE SOURCE-TABLE TO DEST-TABLE
     FROM INDEX 1 TO 5
     DESTINATION INDEX 16

To add all the REPORT-SUM elements in the last TOTALS row to the row "above" it (second to last row):

ADD TABLE REPORT-SUM(10) TO REPORT-SUM(9)

To perform the same operation using a PERFORM loop you would have to write the following code:

PERFORM VARYING CTR FROM 1 BY 1 UNTIL CTR > 20
    ADD REPORT-SUM(10, CTR) TO REPORT-SUM(9, CTR)
END-PERFORM