Previous Topic: ParametersNext Topic: CHANGED


Example 1

This example syntax changes the character string '706' starting at position 62 to '859'.

CHANGE(62,EQ,C'706',C'859')

Example 2

This example syntax changes the halfword field-name field values of X'0010' to X'00A0'.

CHANGE(FIELD-NAME,EQ,X'0010',X'00A0')

If field-name was defined as a packed field of any length, up to 31 digits, only values of a P'16' would be changed to a P'160'. No data shifting would take place.

UPDATE,
  CHANGE(FIELD-NAME,EQ,P'16',P'160')

Example 3

This example syntax changes the first occurrence of the string '706' to '859' starting at position 62 and ending at position 112.

UPDATE,
  CHANGE(62,50,EQ,C'706',C'859')

Example 4

This example syntax changes all occurrences of the string 'STREET' to the string 'ST'. For each CHANGE, the data to the right of the from-data is shifted left four bytes. If the record length allows for the new record length, the length is adjusted accordingly, and the record is written with the shorter length. If the record length does not allow for a smaller record, the PADCHAR keyword value, in this example, space, initializes the four un-initialized bytes.

UPDATE,
  CHANGE(1,0,C'STREET',C'ST',ALL),PADCHAR(C' ')

Example 5

When changing packed data to signed packed data, the current sign of the packed data is maintained. In the following example, both packed values, x'1C' and x'1F' are changed to x'5C' and x'5F' respectively.

UPDATE,
  CHANGE(62,EQ,P'1',P'+5')

The same results could be obtained by using the signed one-byte packed field, field-name, at position 62.

UPDATE,
  CHANGE(SIGNED-PACKED-FIELD,EQ,N'1',N'+5')

Example 6

In the next example, each record is scanned for the value 'TOTALS'. When it is located, at record position 45, it is changed to 'COUNTS' in the output file and the values at record locations 52, 55 and 57 change to '110', '120' and '130' respectively.

COPY,
  IF(1,0,EQ,C'TOTALS),
    CHANGE(+0,EQ,C'TOTALS',C'COUNTS'),
    CHANGE(+7,3,C'110'),
    CHANGE(+11,3,C'120'),
    CHANGE(+14,3,C'130')

Note: If the CHANGE keyword does not find the value 'TOTALS' within the scan-length the subsequent CHANGES would overwrite the values found at locations 8, 12 and 15, respectively.