How can I index through a COBOL defined multi-dimensional table with VISION:Results?

Document ID : KB000021386
Last Modified Date : 14/02/2018
Show Technical Document Details

Without using TABLE or ARRAY features only one subscript can be used at a time. When multiple subscripts reference a field outside of the TABLE or ARRAY definition only the last subscript is honored.

This is one example showing how to index through a multi-dimensional COBOL layout:

OPTION STRUCTURED2
 FILE INFILE F 164 STATUS INSTAT LENGTH RECLEN
        INREC  164
 FILE XFILE DUMMY
 
 WORKAREA
     WS_GRP_CD           2
     WS_RSN_CD           5
     WS_ADJ_AMT         12  NU  2   VALUE 0
     WS_LN_ADJ_AMT      12  NU  2   VALUE 0
     WS_UOS              9  NU  2   VALUE 0
 
 WORKAREA
        $COBOL
        01 GRP-DATA.
          12 GRP-TABLE OCCURS 5 TIMES
                           INDEXED BY GRP-TBL-NDX.
            13 ADJ-GRP-CD               PIC XX.
            13 RSN-TABLE OCCURS 6 TIMES
                           INDEXED BY RSN-TBL-NDX.
               15 LN-REASON-CD          PIC X(05).
               15 LN-ADJ-AMT            PIC S9(11)V99.
               15 LN-UOS                PIC 9(07)V99.
        $ECOBOL
 
 INX = 0
 READ INFILE
 IF INSTAT EQ 'E' STOP ENDIF
 
 DOWHILE INSTAT NE 'E'
   MOVE INREC TO GRP_DATA(INX) LENGTH RECLEN
   READ INFILE
   INX = INX + RECLEN
 ENDDO
 
 INY = 1   ; USE INY AS COUNTER RATHER THAN INDEX
 INX = 1   ; USE INX AS COUNTER RATHER THAN INDEX
 INZ = 0
 WS_LN_ADJ_AMT = 0
 
 
 DOWHILE INY LE 5 AND ADJ_GRP_CD (INZ) GT ' '
 
   INW = INZ
 
   DOWHILE INX LE 6 AND LN_REASON_CD (INW) GT ' '
        WS_GRP_CD    = ADJ_GRP_CD (INZ)
        WS_RSN_CD    = LN_REASON_CD (INW)
        WS_ADJ_AMT   = LN_ADJ_AMT (INW)
        WS_UOS       = LN_UOS (INW)
 
        LIST INW INX INY INZ
             WS_GRP_CD   WS_RSN_CD WS_ADJ_AMT  WS_UOS
 
        WS_LN_ADJ_AMT = WS_LN_ADJ_AMT + LN_ADJ_AMT (INW)
 
        INX = INX + 1
        INW = INW + 27
    ENDDO
 
    INX = 1
    INY = INY + 1
    INZ = INW + 2
 ENDDO
 
 STOP
 
These are the resulting values:
 
  INW  INX  INY  INZ  WS_GRP_CD  WS_RSN_CD  WS_ADJ_AMT   WS_UOS
   0    1    1     0      AA       REA01      9999.05     11.05
  27    2    1     0      AA       REA02      8888.05     22.05
  54    3    1     0      AA       REA03      7777.05     33.05
  81    4    1     0      AA       REA04      6666.05     44.05
 108    5    1     0      AA       REA05      5555.05     55.05
 135    6    1     0      AA       REA06      4444.05     66.05
 164    1    2   164      BB       REB01     19999.05    911.05
 191    2    2   164      BB       REB02     18888.05    922.05
 218    3    2   164      BB       REB03     17777.05    933.05
 245    4    2   164      BB       REB04     16666.05    944.05
 272    5    2   164      BB       REB05     15555.05    955.05
 299    6    2   164      BB       REB06     14444.05    966.05
 328    1    3   328      CC       REC01     29999.05    811.05
 355    2    3   328      CC       REC02     28888.05    822.05
 382    3    3   328      CC       REC03     27777.05    833.05
 409    4    3   328      CC       REC04     26666.05    844.05
 436    5    3   328      CC       REC05     25555.05    855.05
 463    6    3   328      CC       REC06     24444.05    866.05
 492    1    4   492      DD       RED01     39999.05    711.05
 519    2    4   492      DD       RED02     38888.05    722.05
 546    3    4   492      DD       RED03     37777.05    733.05
 573    4    4   492      DD       RED04     36666.05    744.05
 600    5    4   492      DD       RED05     35555.05    755.05
 627    6    4   492      DD       RED06     34444.05    766.05
 656    1    5   656      EE       REE01     49999.05    611.05
 683    2    5   656      EE       REE02     48888.05    622.05
 710    3    5   656      EE       REE03     47777.05    633.05
 737    4    5   656      EE       REE04     46666.05    644.05
 764    5    5   656      EE       REE05     45555.05    655.05
 791    6    5   656      EE       REE06     44444.05    666.05
 **************************************************************