RECORD-POSITION

The RECORD-POSITION construct allows you to refer to a data item by creating a numeric literal representing the location of the data item within a record.

General Format

RECORD-POSITION OF data-name

Syntax Rules

  1. data-name must refer to a data item with a level number of 01 through 50 or 77. data-name may be qualified, but may not be subscripted or reference modified.
  2. The RECORD-POSITION phrase is allowed anywhere a numeric literal data item may appear.

General Rules

  1. The RECORD-POSITION phrase creates a numeric literal whose value is the character position of data-name within its record, as follows:
    • If data-name is a level 01 or 77 data item, then the value is 1.
    • Otherwise, the value is the character position of the start of data-name within its containing level 01 group item. Character positions start numbering at 1.
  2. If data-name refers to a table item, the value is computed from the first occurrence of that item.
  3. The format of the resulting literal is the same as a PIC 9(9) DISPLAY data item.

Code Examples

If you assume the following group item:

01  GROUP-1.
    03  ELEM-1  PIC X(10).
    03  ELEM-2  PIC X(10).
    03  GROUP-2.
        05  ELEM-3
            OCCURS 10 TIMES  PIC X(10).
        05  ELEM-4  PIC X(10).

then, the following procedure division code:

DISPLAY RECORD-POSITION OF ELEM-1, CONVERT, LEFT
DISPLAY RECORD-POSITION OF ELEM-2, CONVERT, LEFT
DISPLAY RECORD-POSITION OF ELEM-3, CONVERT, LEFT
DISPLAY RECORD-POSITION OF ELEM-4, CONVERT, LEFT

would produce the following output:

1
11
21
121

The RECORD-POSITION construct is particularly useful with the DATA-COLUMNS property of the list box and grid controls. For example, in a list box control, you might have a line that reads:

data-columns - (1, 13, 24, 33 )

changing the line to:

data-columns = ( 
    record-position of data-key-1, 
    record-position of data-city, 
    record-position of data-state, 
    record-position of data-amount )

makes it easier to understand. With this syntax, changes to the record format do not need to be echoed in the data-columns format, so this is also easier to maintain.