Arrays or Table real use in COBOL is to store temporary data that to use later in your application program. The table need a clear definition in COBOL before you start using it. In the definition you need to give size or dimensions of the table as per your requirement.

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

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

How to Define a Table or Array
Some people define the array in the ‘COPY’ book. Other programmers use both definitions and usage in the same program.
Definition for the 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 to your table element.
01 Sub1 PIC 9(01) value 1.
You need a definition of the subscript. It is initialized with ‘1’.
Move field-1(sub1) TO WS_FIELD.
The internal meaning is:
MOVE field-1(1) TO WS_FIELD.
You must be logged in to post a comment.