Use one of these three methods to put values in a table: Load the table dynamically.

  • Initialize the table.
  • Assign values when you define the table.

Load the Table Dynamically

If the initial values of your table are different with each execution of your program, then the table can be defined without initial values, and the changed values can be read into the table before your program refers to the table. To load a table, use The PERFORM . . . VARYING statement, either subscripting or indexing. When reading data to load your table:

  • Make sure that the data does not exceed the space allocated for the table.
  • If the data must be in sequence, check the sequence.
  • If the data contains the subscript that determines its position in the table, check the subscript for a valid range.

When testing for the end of a table, use a named value giving the item count, rather than using a literal. Then, if you make the table bigger, you need to change only one value, instead of all references to a literal.

Initialize the Table

You can load your table with a value during execution with the INITIALIZE statement. You can move:

  • Spaces into alphabetic, alphanumeric, and alphanumeric-edited items
  • Zeros into numeric and numeric-edited items
  • A particular value.

You can use INITIALIZE to move another value into each table element. For example, to fill a table with Nines (9)s,


You cannot use INITIALIZE for a variable-length table (one that was defined using OCCURS DEPENDING ON).

Assign Values When You Define the Table

If your table contains stable values (for example a table that contains the days and months of the year), it is useful to set specific values your table holds when you define it. Define static values in the Working-Storage Section in one of three ways:

  • Describe the table storage area by simply arranging subordinate data description entries, specifying the initial value of each subordinate entry in a VALUE clause. Then code a REDEFINES entry to describe the table as a record that contains a repeating subordinate entry, defined with an OCCURS clause. This technique is practical only for small tables. To initialize larger tables, use MOVE, PERFORM, or INITIALIZE statements, as described above.
  • Code a level-01 record and assign to it, through the VALUE clause, the contents of the whole table. Then, in a subordinate level data item, use an OCCURS clause to define the individual table items. For example,

Assign Values When You Define the Table

  • A VALUE clause can also be present on a group item which contains an OCCURS clause with the DEPENDING ON option. In this case, each subordinate structure that contains the DEPENDING ON option is initialized using the maximum number of occurrences. If the table is defined with the DEPENDING ON option, all the elements are initialized using the maximum defined value of the DEPENDING ON object. In both cases, if the ODO object has a VALUE clause, it is logically initialized after the ODO subject has been initialized. Consider the following example:

Assign Values When You Define the Table

It causes Y(l) to be initialized to A, Y(2) to B,... Y(5) to E, and finally the object of the ODO (X) is initialized to 3. Any subsequent reference to TABLE-THREE (such as DISPLAY) would refer to the first three elements, Y(1) through Y(3).

  • You can use the VALUE clause on a table element to initialize the element to the indicated value. Consider the following code:


It causes all the X elements (I through 5) to be initialized to AA, all the Y elements (1 through 5) to be initialized to 19, and all the Z elements (1 through 5) to be initialized to BB. T-OBJ is then set to 3.

All rights reserved © 2020 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

IBM Mainframe Topics