CUCO study materials
CUCO study resources

CUCO: Tables, Arrays, and Subprograms

CUCO · Work through your exam, one topic at a time.

All guide sections

Tables, Arrays, and Subprograms

This domain tests fixed and variable-length tables, the difference between subscripts and indexes, serial versus binary search, and the CALL interface between programs. Items often ask why SEARCH ALL returned the wrong entry or why a caller's field did not change.

Defining tables

OCCURS n TIMES defines a table; ASCENDING KEY and DESCENDING KEY declare the search key; INDEXED BY names an index. OCCURS DEPENDING ON makes the number of occurrences variable, but the maximum size is fixed at compile time, and the data item controlling the count must be defined before use. Tables are initialized by VALUE clauses on subordinate items or by INITIALIZE. A REDEFINES can overlay a table on a flat record area.

Subscripts and indexes

A subscript is an integer data item used in parentheses, such as WS-I (1). An index is an internal value created by INDEXED BY and manipulated with SET; it is not an ordinary number. SEARCH performs a serial scan and can test any condition; SEARCH ALL performs a binary search, requires an INDEXED BY table with an ASCENDING or DESCENDING KEY, and can test only equality. The table must already be in key order.

CALL and LINKAGE

CALL 'PROG' USING A B passes parameters. BY REFERENCE, the default, passes an address so the subprogram can change the caller's field. BY CONTENT passes a copy and protects the caller. BY VALUE passes a value for interoperability. The subprogram declares matching items in LINKAGE SECTION and lists them in PROCEDURE DIVISION USING. IS INITIAL resets WORKING-STORAGE on each call; CANCEL releases the program's state; RECURSIVE requires LOCAL-STORAGE for per-call data.

Worked example. A table is loaded in descending order but declared ASCENDING KEY IS WS-KEY INDEXED BY WS-IDX. A SEARCH ALL for WS-KEY = 500 may miss the entry because binary search assumes ascending order. Reordering the data ascending, or using a serial SEARCH, corrects it. The syntax was legal, so the compiler reported no error; the defect is data-order dependent.

Traps

  • Mixing an index and a subscript without SET or conversion.
  • Using SEARCH ALL with a non-equality condition or an unsorted table.
  • Assuming OCCURS DEPENDING ON changes the allocated maximum size.
  • Passing BY CONTENT and expecting the caller's field to be updated.
  • Mismatched parameter counts or LINKAGE layouts between caller and subprogram.