Compaq COBOL AAQ2G1FTK User Manual

Page 151

Advertising
background image

Using the STRING, UNSTRING, and INSPECT Statements

5.1 Concatenating Data Using the STRING Statement

The ON OVERFLOW phrase cannot distinguish the overflow caused by a bad
initial value in the pointer from the overflow caused by a receiving item that is
too short. Only a separate test preceding the STRING statement can distinguish
between the two.

Additionally, even if an overflow condition does not exist, you can use the NOT
ON OVERFLOW phrase to branch to or execute other sections of code.

Example 5–2 illustrates the overflow condition.

Example 5–2 Sample Overflow Condition

DATA DIVISION.

.
.
.

01 FIELD1 PIC XXX VALUE "ABC".
01 FIELD2 PIC XXXX.
PROCEDURE DIVISION.

.
.
.

1.

STRING FIELD1 QUOTE DELIMITED BY SIZE INTO FIELD2

ON OVERFLOW DISPLAY "overflow at 1".

2.

STRING FIELD1 FIELD1 DELIMITED BY SIZE INTO FIELD2

ON OVERFLOW DISPLAY "overflow at 2".

3.

STRING FIELD1 FIELD1 DELIMITED BY "C" INTO FIELD2

ON OVERFLOW DISPLAY "overflow at 3".

4.

STRING FIELD1 FIELD1 FIELD1 FIELD1

DELIMITED BY "B" INTO FIELD2 ON OVERFLOW DISPLAY "overflow at 4".

5.

STRING FIELD1 FIELD1 "D" DELIMITED BY "C"

INTO FIELD2 ON OVERFLOW DISPLAY "overflow at 5".

6.

MOVE 2 TO P.

MOVE ALL QUOTES TO FIELD2.

STRING FIELD1 "AC" DELIMITED BY "C"

INTO FIELD2 WITH POINTER P ON OVERFLOW DISPLAY "overflow at 6".

The STRING statement numbers in Example 5–2 point to the line number results
shown in Table 5–1.

Table 5–1 Results of Sample Overflow Statements

Value of FIELD2 After the
STRING Operation

Overflow?

1. ABC

"

No

2. ABCA

Yes

3. ABAB

No

4. AAAA

No

5. ABAB

Yes

6.

"

ABA

No

Using the STRING, UNSTRING, and INSPECT Statements 5–5

Advertising