Using the STRING, UNSTRING, and INSPECT Statements
5.2 Separating Data Using the UNSTRING Statement
The compiler then counts the number of characters between the last contiguous
asterisk in the first scan and the next asterisk in the second scan, and places the
count in COUNT2B. The data between the delimiters of the second scan is moved
into FIELD2B.
The third scan begins at the first character after the last contiguous asterisk
in the second scan. Any data between the delimiters of this scan is moved to
FIELD2C.
The COUNT phrase should be used only where it is needed. In this example,
the length of the string moved to FIELD2C is not needed, so no COUNT phrase
follows it.
If the receiving item is shorter than the value placed in the count item, the code
truncates the sending string. If the number of integer positions in a numeric item
is smaller than the value placed into the count item, high-order numeric digits
have been lost. If a delimiter match is found on the first character examined, a
zero is placed in the count item.
The COUNT phrase can be used only in conjunction with the DELIMITED BY
phrase.
5.2.4 Saving UNSTRING Delimiters Using the DELIMITER Phrase
The DELIMITER phrase causes the actual character or characters that delimited
the sending item to be stored in a user-supplied data area. This phrase is most
useful when:
•
The UNSTRING statement contains a delimiter list.
•
Any one of the delimiters in the list might have delimited the item.
•
Program logic flow depends on the delimiter match found.
By using the DELIMITER and COUNT phrases, you can make the flow of
program logic dependent on both the size of the sending string and the delimiter
terminating the string.
To use the DELIMITER phrase, follow the receiving item name with the words
DELIMITER IN and an identifier. The compiler generates code that places the
delimiter character in the area named by the identifier. Consider the following
sample UNSTRING statement:
UNSTRING FIELD1 DELIMITED BY ","
OR TAB
OR ALL SPACE
OR CR
INTO FIELD2A DELIMITER IN DELIMA
FIELD2B DELIMITER IN DELIMB
FIELD2C.
After moving the first sending string to FIELD2A, the character (or characters)
that delimited that string is placed in DELIMA. In this example, DELIMA
contains either a comma, a tab, a carriage return, or any number of spaces.
Because the delimiter string is moved under the rules of the elementary
nonnumeric MOVE statement, the compiler truncates or space-fills with left
or right justification.
The second sending string is then moved to FIELD2B and its delimiting character
is placed into DELIMB.
Using the STRING, UNSTRING, and INSPECT Statements 5–13
Содержание COBOL AAQ2G1FTK
Страница 22: ......
Страница 30: ......
Страница 94: ......
Страница 110: ......
Страница 146: ......
Страница 180: ......
Страница 194: ...Processing Files and Records 6 1 Defi...
Страница 300: ......
Страница 490: ......
Страница 516: ......
Страница 517: ......
Страница 530: ......
Страница 534: ......
Страница 590: ......
Страница 620: ......