Compaq AAQ2G1FTK Marine Radio User Manual


 
Using the STRING, UNSTRING, and INSPECT Statements
5.2 Separating Data Using the UNSTRING Statement
Consider the following statement with reference to the corresponding PICTURE
character-strings and values in Table 5–3:
UNSTRING FIELD1 INTO FIELD2A FIELD2B.
FIELD2A is a 3-character alphanumeric item. It receives the first three
characters of FIELD1 (ABC) in every operation. FIELD2B, however, runs
out of characters every time before filling, as Table 5–3 illustrates.
Table 5–3 Handling a Short Sending Item
FIELD1
PIC X(6)
VALUE IS:
FIELD2B
PICTURE IS:
FIELD2B
Value After UNSTRING Operation
ABCDEF XXXXX DEF
S99999 0024F
ABC246 S9V999 600{
S9999 LEADING SEPARATE +0246
5.2.2 Controlling Moved Data Using the DELIMITED BY Phrase
The size of the data to be moved can be controlled by a delimiter, rather than by
the size of the receiving item. The DELIMITED BY phrase supplies the delimiter
characters.
UNSTRING delimiters can be literals, figurative constants (including ALL
literal), or identifiers (identifiers can even be subscripted data names). This
section describes the use of these three types of delimiters. Subsequent sections
cover multiple delimiters, the COUNT phrase, and the DELIMITER phrase.
Consider the following sample UNSTRING statement with the figurative constant
SPACE as a delimiter:
UNSTRING FIELD1 DELIMITED BY SPACE
INTO FIELD2.
In this example, the compiler scans the sending item (FIELD1), searching
for a space character. If it encounters a space, it moves all of the scanned
(nonspace) characters that precede that space to the receiving item (FIELD2). If
it finds no space character, it moves the entire sending item. When the compiler
has determined the size of the sending item, it moves the contents of that item
following the rules for the MOVE statement, truncating or zero-filling as required.
Table 5–4 shows the results of the following UNSTRING operation that uses a
literal asterisk delimiter:
UNSTRING FIELD1 DELIMITED BY "*"
INTO FIELD2.
5–8 Using the STRING, UNSTRING, and INSPECT Statements