STRING
STRING {identifier-1 or literal-1} DELIMITED BY {identifier-2 or literal-2 or SIZE}...
INTO {identifier-3}
ON OVERFLOW [statements]
NOT ON OVERFLOW [statements]
END-STRING
|
STRING will move a series of strings into a destination string (from left to right without space filling).
If the destination string is not large enough to hold all the source strings then this can be detected and
acted on by the ON OVERFLOW condition. The DELIMITED word specifies the source string characters to be used:
01 W-DAY PIC XXX VALUE 'MON'.
01 W-MONTH PIC XXX VALUE '5 '.
01 W-YEAR PIC XXXX VALUE '2000;'.
:
STRING W-DAY DELIMITED BY SIZE
'/' DELIMITED BY SIZE
W-MONTH DELIMITED BY SPACES
'/' DELIMITED BY SIZE
W-YEAR DELIMITED BY ';'
INTO DATE-STRING
END-STRING
The item DATE-STRING will contain "MON/5/2000".
UNSTRING
UNSTRING {identifier-1 or literal-1} DELIMITED BY {identifier-2 or literal-2 or SIZE}...
INTO {identifier-3 COUNT IN identifier-4}...
TALLYING IN {identifier-5}
ON OVERFLOW [statements]
NOT ON OVERFLOW [statements]
END-UNSTRING
|
UNSTRING allows you to break up a string into small strings placed into new items:
01 W-LONG-STRING PIC X(50) VALUE 'Name;Address;Post Code'.
:
UNSTRING W-LONG-STRING DELIMITED BY ';'
INTO W-NAME COUNT IN CHARS-NAME
W-ADDRESS COUNT IN CHARS-ADDR
W-POST-CODE COUNT IN CHARS-PCODE
TALLYING IN NUM-STRINGS-OUT
END-UNSTRING
Here then string 'Name' will be placed into W-NAME, containing 4 characters, thus CHARS-NAME will contain
the value of 4. Likewise for W-ADDRESS ('Address') CHARS-ADDR (7) etc... Notice how the ; character has
been lost. Any character, including spaces can be used as a delimiter. TALLYING IN will count the number
of items that were filled by the UNSTRING operation, in this case NUM-STRINGS-OUT will contain the value 3.
Lastly, the ON OVERFLOW detects when each target of the UNSTRING operation has been used but there remains
unused characters in the source string, e.g. if W-LONG-STRING contained 'Name;Address;Post Code;Country'.
INSPECT
INSPECT {identifier-1} REPLACING CHARACTERS BY {identifier-2 or literal-1}
{BEFORE or AFTER} [INITIAL {identifier-3 or literal-2}]
{ALL or LEADING or FIRST} {identifier-4 or literal-3}
BY {identifier-5 or literal-4} {BEFORE or AFTER} INITIAL {identifier-6 or literal-5}
|
This form of INSPECT allows you to change characters within a string using the various options above.
INSPECT {identifier-1} TALLYING {identifier-2}
{BEFORE or AFTER} [INITIAL {identifier-3 or literal-2}]
{ALL or LEADING or FIRST} {identifier-4 or literal-3}
BY {identifier-5 or literal-4} {BEFORE or AFTER} INITIAL {identifier-6 or literal-5}
|
Here the source string is inspected and a tally of the number of characters defined (using the
subsequent options) is held in {identifier-2}.