Previous Topic: What You Can DoNext Topic: Obtaining Sort-key Values


Demonstration

Objective

The following report lists the quarterly gain or loss for each of four stores. The annual gain or loss, by store, is printed across the bottom of the report.

Procedure

Complete Code

col. 2
▼
IN 80 F 320 PS(TAPE)
REC STORE        1  3  2
REC INCOME       4                 GROUP AA 8.4
REC QTR          1  8  2  DP=2     ELMNT AA
REC EXPEND      36                 GROUP BB 8.4
REC AMT          1  8  2  DP=2     ELMNT BB
010 GAIN-OR-LOSS.4  DP=2                    $Quarterly income
010 INDEX 1
010 TOTAL 0
010 STORE-TOTAL.4                     $Annual income
010 COUNT 1
013 PROFIT/LOSS REPORT ── yyyy
0151*010 STORE  SZ=5       HH 'STORE'
0151*020 GAIN-OR-LOSS.INDEX SZ=11 F3 HH 'QUARTERLY' 'GAIN/LOSS'
0152*001 ' '
0161*0200GAIN-OR-LOSS.INDEX SZ=11 F3
0162*010-'STORE TOTAL SUMMARY:'
0163*010 'STORE 1:'
0163*015 STORE-TOTAL.1  SZ=11 F3  $Current value of the first occurrence
0163*020 'STORE 10:'
0163*025 STORE-TOTAL.2  SZ=11 F3  $Current value of the second occurrence
0163*030 'STORE 11:'
0163*035 STORE-TOTAL.3  SZ=11 F3  $Current value of the third occurrence
0163*050 'STORE 20:'
0163*055 STORE-TOTAL.4  SZ=11 F3  $Current value of the fourth occurrence
017100 COMPUTE QTR.INDEX - AMT.INDEX  GAIN-OR-LOSS.INDEX
017    COMPUTE TOTAL + GAIN-OR-LOSS.INDEX  TOTAL
017    RELS (1)
017175 IF INDEX EQ 4  200
017    INDEX + 1  INDEX
017    IF INDEX LE 4 100
017200 MOVE 1 TO INDEX
017    MOVE TOTAL TO STORE-TOTAL.COUNT
017    COUNT + 1  COUNT
017    RELS (2)
017    TOTAL - TOTAL  TOTAL
017    DROP

Result

REPORT NO. 01          PROFIT/LOSS REPORT ── yyyy           mm/dd/yyPAGE     1                                               QUARTERLY              STORE                            GAIN/LOSS                   1                              19,900.21                   1                              10,788.50                   1                              53,899.98                   1                              19,895.00                  10                                   0.21                  10                               1,388.41                  10                                  99.98                  10                               2,895.76                  11                               5,099.79-                  11                              34,788.50                  11                              17,900.00                  11                              19,895.00                  21                              44,900.21                  21                              10,211.50-                  21                             123,899.98                  21                              70,104.50-                                                 264,835.95 -     STORE TOTAL SUMMARY:             STORE 1:               104,484    STORE 10:              4,384  STORE 11:          67,484  STORE 20:          88,485