Multiple choice technology mainframe

3.How do you define a table/array in COBOL using INDEX?

  1. 01 ARRAYS. 05 ARRAY2 PIC X(6) OCCURS 20 TIMES INDEXED BY WS-INDEX

  2. 01 ARRAY2 PIC X(6) OCCURS 20 TIMES INDEXED BY WS-INDEX

  3. 01 ARRAYS. 05 ARRAY1 PIC X(9) OCCURS INDEX BY 10 TIMES

  4. 01 ARRAYS. 88 ARRAY2 PIC X(6) OCCURS 20 TIMES INDEXED BY WS-INDEX

Reveal answer Fill a bubble to check yourself
A Correct answer
Explanation

In COBOL, the OCCURS clause cannot be defined at the 01 level (ruling out the second option) or with level 88 condition names (ruling out the fourth). The third option uses incorrect syntax order. The first option correctly defines the table at level 05 with INDEXED BY.

AI explanation

To define a table/array in COBOL using an index, you can use the OCCURS clause along with an INDEXED BY phrase.

Option A) 01 ARRAYS. 05 ARRAY2 PIC X(6) OCCURS 20 TIMES INDEXED BY WS-INDEX - This option is correct. It defines a table/array named ARRAY2 with a length of 6 characters, occurring 20 times. It also includes the INDEXED BY phrase, which associates an index (WS-INDEX) with the array.

Option B) 01 ARRAY2 PIC X(6) OCCURS 20 TIMES INDEXED BY WS-INDEX - This option is incorrect. It defines a single occurrence of ARRAY2 without the necessary parent group (ARRAYS) and does not include an INDEXED BY phrase.

Option C) 01 ARRAYS. 05 ARRAY1 PIC X(9) OCCURS INDEX BY 10 TIMES - This option is incorrect. It defines a table/array named ARRAY1 with a length of 9 characters, but it does not include the OCCURS clause or the INDEXED BY phrase.

Option D) 01 ARRAYS. 88 ARRAY2 PIC X(6) OCCURS 20 TIMES INDEXED BY WS-INDEX - This option is incorrect. It uses the 88 level, which is typically used for condition names, rather than the OCCURS clause for defining a table/array.

The correct answer is A) 01 ARRAYS. 05 ARRAY2 PIC X(6) OCCURS 20 TIMES INDEXED BY WS-INDEX. This option correctly defines a table/array with the OCCURS clause and includes the INDEXED BY phrase to associate an index with the array.