Using the string, unstring, and inspect statements – Compaq COBOL AAQ2G1FTK User Manual
Page 147
5
Using the STRING, UNSTRING, and INSPECT
Statements
The STRING, UNSTRING, and INSPECT statements give your Compaq COBOL
programs the following capabilities:
•
Concatenating data using the STRING statement (Section 5.1)
•
Separating data using the UNSTRING statement (Section 5.2)
•
Examining and replacing characters using the INSPECT statement
(Section 5.3)
5.1 Concatenating Data Using the STRING Statement
The STRING statement concatenates the contents of one or more sending items
into a single receiving item.
The statement has many forms; the simplest is equivalent in function to a
nonnumeric MOVE statement. Consider the following example:
STRING FIELD1 DELIMITED BY SIZE INTO FIELD2.
If the two items are the same size, or if the sending item (FIELD1) is larger, the
statement is equivalent to the following statement:
MOVE FIELD1 TO FIELD2.
If the sending item of the string is shorter than the receiving item, the compiler
does not replace unused positions in the receiving item with spaces. Thus, the
STRING statement can leave some portion of the receiving item unchanged.
The receiving item of the string must be an elementary alphanumeric item with
no JUSTIFIED clause or editing characters in its description. Thus, the data
movement of the STRING statement always fills the receiving item with the
sending item from left to right and with no editing insertions.
5.1.1 Multiple Sending Items
The STRING statement can concatenate a series of sending items into one
receiving item. Consider the following example:
STRING FIELD1A FIELD1B FIELD1C DELIMITED BY SIZE
INTO FIELD2.
In this sample STRING statement, FIELD1A, FIELD1B, and FIELD1C are all
sending items. The compiler moves them to the receiving item (FIELD2) in the
order in which they appear in the statement, from left to right, resulting in the
concatenation of their values.
Using the STRING, UNSTRING, and INSPECT Statements 5–1