COBOL: How to Create a VB Array

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.

COBOL VB arrays

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)

flowchart for dynamic array
How VB Arrays or Tables used in COBOL program

Sample Logic to Create Array

    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

  1. OCCURS clause
  2. Depending ON
  3. KEY

#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.

You May Also Like

#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.

Related Posts

Author: Srini

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