Compaq COBOL AAQ2G1FTK User Manual

Page 153

Advertising
background image

Using the STRING, UNSTRING, and INSPECT Statements

5.2 Separating Data Using the UNSTRING Statement

The compiler-generated code performs the UNSTRING operation by scanning
across FIELD1, the sending item, from left to right. When the number of
characters scanned equals the number of characters in the receiving item, the
scanned characters are moved into that item and the next group of characters is
scanned for the next receiving item.

If each of the receiving items in the preceding example (FIELD2A, FIELD2B, and
FIELD2C) is 5 characters long, and FIELD1 is 15 characters long, FIELD1 is
scanned until the number of characters scanned equals the size of FIELD2A ( 5 ).
Those first five characters are moved to FIELD2A, and scanning is resumed at
the sixth character position in FIELD1. Next, FIELD1 is scanned from character
position 6, until the number of scanned characters equals the size of FIELD2B
(five). The sixth through the tenth characters are then moved to FIELD2B,
and the scanner is set to the next (eleventh) character position in FIELD1. For
the last move in this example, characters 11 to 15 of FIELD1 are moved into
FIELD2C.

Each data movement acts as an individual MOVE statement, the sending item
of which is an alphanumeric item equal in size to the receiving item. If the
receiving item is numeric, the move operation converts the data to numeric form.
For example, consider what would happen if the items under discussion had the
data descriptions and were manipulating the values shown in Table 5–2.

Table 5–2 Values Moved into the Receiving Items Based on the Sending Item

Value

FIELD1
PIC X(15)
VALUE IS:

FIELD2A
PIC X(5)

FIELD2B
PIC S9(5)
LEADING
SEPARATE

FIELD2C
PIC S999V99

ABCDE1234512345

ABCDE

+12345

3450{

XXXXX0000100123

XXXXX

+00001

1230{

FIELD2A is an alphanumeric item. Therefore, the statement simply conducts an
elementary nonnumeric move with the first five characters.

FIELD2B, however, has a leading separate sign that is not included in its size.
Thus, the compiler moves only five numeric characters and generates a positive
sign ( + ) in the separate sign position.

FIELD2C has an implied decimal point with two character positions to the right
of it, plus an overpunched sign on the low-order digit. The sending item should
supply five numeric digits. However, because the sending item is alphanumeric,
the compiler treats it as an unsigned integer; it truncates the two high-order
digits and supplies two zero digits for the decimal positions. Furthermore, it
supplies a positive overpunch sign, making the low-order digit a +0 (ASCII { ).
There is no way to have the UNSTRING statement recognize a sign character or
a decimal point in the sending item in a single statement.

If the sending item is shorter than the sum of the sizes of the receiving items,
the compiler ignores the remaining receiving items. If the compiler reaches the
end of the sending item before it reaches the end of one of the receiving items,
it moves the scanned characters into that receiving item. It either left-justifies
and fills the remaining character positions with spaces for alphanumeric data, or
else it decimal point-aligns and zero-fills the remaining character positions for
numeric data.

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

Advertising