Variable-length arrays (Tables) stores variable-length records. In many financial projects, customer information is a variable-length record. To read customer record you need VB array (dynamic array) defined in the COBOL program.
I have explained the syntax you need to create VB array. In COBOL, the alternate name for an Array is Table.
You May Also Like: How to Create VB Files in COBOL
COBOL: How to Call Dynamic Array (VB Array)
Sample Logic to Create Array
01 PRICE-TABLE. 05 PRICE-GROUP OCCURS 1 TO 100 TIMES DEPENDING ON PT-ENTRY-COUNT ASCENDING KEY IS ITEM-NUMBER INDEXED BY PRICE-TABLE-INDEX. 10 ITEM-NUMBER PIC 9(3). 10 ITEM-PRICE PIC S99V99. 05 PT-ENTRY-COUNT PIC S9(3).
4 Key Clauses in VB Array
- OCCURS clause
- Depending ON
- INDEXED BY
#1). Why OCCURS Clause you need
Size of the table you can give in the OCCURS clause. Remember, the values start with ‘0’ and maximum any. You may ask a question about what is maximum. It depends on your OS configuration.
#2). Why DEPENDING ON Clause you need
Variable that you assign in the DEPENDING ON clause stores the input record-length. Remember, update this variable with record length in your program.
#3). Why ASCENDING KEY Clause you need
Key clause sorts data in the array in ascending order. Remember, Key and Index are different. if you confused about differences, you can read my post: Key Vs Index Top Differences.
#4). Why INDEXED BY Clause you need
To Store internally the received records in an array you need INDEXED BY Clause. Precisely, INDEXING and Sorting not the same.