Theory behind usage of COBOL multi dimensional Arrays

Arrays or Table real use in COBOL is to store temporary data that to use later in your application program.  Table need a clear definition in COBOL before you start using it. In the definition you need to give size or dimensions of table as per your requirement.
Table Vs Array
COBOL uses the term Table. But it has similarities like an array

Table Vs Array

What is a Table

Multiple occurrences of similar data item you can call it as a Table. The items in a Table starts with ‘1’ and goes to maximum of Size. In a Table each element is subordinate to another element.
table in COBOL

What is an Array

An array is similar to table. Here, you can store multiple occurrences similar data items. The only difference is in an Array, the items start with ‘0’ and goes to ‘n-1’ maximum items. Arrays does not have any relation between one element to other. The first item you can refer as i(0), i(1) and so on.
arrays definition

How to Define a Table or Array

Some people define the array in ‘COPY’ book. Other programmers use both definition and usage in the same program. Definition for multi dimension array is as follows:
01  Table occurs 10 times.
      03  field-1      pic x(03).
      03  sub-table  pic 9(5) occurs 5 times.
      03  field-2      pic 9(03).
The OCCURS clause will be used to define the size of a Table. You can define a subscript to refer your table element.
01 Sub1   PIC 9(01) value 1.
You need a definition for subscript. It is initialized with ‘1’.
Move field-1(sub1) TO WS_FIELD.
The internal meaning is:
MOVE field-1(1) TO WS_FIELD.

Also Read


Author: Srini

Experienced software developer. Skills in Development, Coding, Testing and Debugging. Good Data analytic skills (Data Warehousing and BI). Also skills in Mainframe.