COBOL: How to Create a VB Array

Variable-length arrays (Tables) stores variable-length records. That means record length varies. The best example is NAME In customer information is a variable-length record. To read a customer record you need VB array (dynamic array) in your program.


COBOL: How to Create a VB  Array
COBOL: How to Create a VB Array

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.

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

Advertisements

4 Key Clauses in VB Array.

  1. OCCURS clause.
  2. Depending ON.
  3. KEY.
  4. INDEXED BY.

4 Interview Questions on VB Files.

The two questions are on OCCURS and Depending on clauses.

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. The MAX number depends on your project.

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.