Compaq AAQ2G1FTK Marine Radio User Manual


 
Using the STRING, UNSTRING, and INSPECT Statements
5.1 Concatenating Data Using the STRING Statement
Remember, the remainder of the receiving item is not space-filled, as with a
MOVE statement. If ADDRESS-LINE is to be printed on a mailing label, for
example, the STRING statement should be preceded by the statement:
MOVE SPACES TO ADDRESS-LINE.
This statement guarantees a space-fill to the right of the concatenated result.
Alternatively, the last item concatenated by the STRING statement can be an
item previously set to SPACES. This sending item must either be moved under
control of a delimiter other than SPACE or use the value of POINTER and
reference modification.
5.1.3 Using the POINTER Phrase
Although the STRING statement normally starts scanning at the leftmost
position of the receiving item, the POINTER phrase makes it possible to start
scanning at another point within the item. The scanning, however, continues left
to right. Consider the following example:
MOVE 5 TO P.
STRING FIELD1A FIELD1B DELIMITED BY SIZE
INTO FIELD2 WITH POINTER P.
The value of P determines the starting character position in the receiving item.
In this example, the 5 in P causes the program to move the first character of
FIELD1A into character position 5 of FIELD2 (the leftmost character position of
the receiving item is character position 1), and leave positions 1 to 4 unchanged.
When the STRING operation is complete, P points to one character position
beyond the last character replaced in the receiving item. If FIELD1A and
FIELD1B are both four characters long, P contains a value of 13 (5+4+4) when
the operation is complete (assuming that FIELD2 is at least 13 characters long).
5.1.4 Using the OVERFLOW Phrase
When the SIZE option of the DELIMITED BY phrase controls the STRING
operation, and the pointer value is either known or the POINTER phrase is not
used, you can add the PICTURE sizes of sending items together at program
development time to see if the receiving item is large enough to hold the sending
items. However, if the DELIMITED BY phrase contains a literal or an identifier,
or if the pointer value is not predictable, it can be difficult to tell whether or not
the size of the receiving item will be large enough at run time. If the size of the
receiving item is not large enough, an overflow can occur.
An overflow occurs when the receiving item is full and the program is either
about to move a character from a sending item or is considering a new sending
item. Overflow can also occur if, during the initialization of the statement, the
pointer contains a value that is either less than 1 or greater than the length of
the receiving item. In this case, the program moves no data to the receiving item
and terminates the operation immediately.
The ON OVERFLOW phrase at the end of the STRING statement tests for an
overflow condition:
STRING FIELD1A FIELD1B DELIMITED BY "C"
INTO FIELD2 WITH POINTER PNTR
ON OVERFLOW GO TO 200-STRING-OVERFLOW.
5–4 Using the STRING, UNSTRING, and INSPECT Statements