STRING Statement COBOL

The STRING statement concatenates the partial or complete contents of one or more data items into a single data item.

STRING Statement

literal-1 and literal-2 may be any figurative constant except those that begin with the word ALL. When figurative constants are used in a STRING statement, they behave as single character nonnumeric literals.

All literals must be nonnumeric literals, and the explicit or implicit usage of each identifier, except identifier-4, must be DISPLAY.

identifier-3 must not be reference modified; it must not represent an edited data item; and it must not be described with the JUSTIFIED clause.

identifier-4 must represent an elementary numeric integer data item of sufficient size to contain a value equal to the size plus 1 of the area referenced by identifier-3. The symbol P may not be used in the PICTURE character-string of identifier-4.

When identifier-1 or identifier-2 is an elementary numeric data item, it must be described as an integer without the symbol P in its PICTURE character-string.

identifier-1 or literal-1 represents the sending item. identifier-3 in the INTO phrase represents the receiving item.

When the STRING statement is executed, characters from literal-1 or from the contents of the data item referenced by identifier-1 are transferred to the data item referenced by identifier-3 in accordance with the rules for alphanumeric to alphanumeric moves, except that no space filling is provided.

When characters are transferred to the data item referenced by identifier-3, the moves behave as though the characters were moved one at a time from the source into the character position of the data item referenced by identifier-3 designated by the value associated with identifier-4, and then identifier-4 was increased by one prior to the move of the next character. The value associated with identifier-4 is changed during execution of the STRING statement according to the rules set forth in the POINTER phrase description.

At the end of the execution of the STRING statement, only the portion of the data item referenced by identifier-3 that was referenced during the execution of the STRING statement is changed. All other portions of the data item referenced by identifier-3 contain data that was present before this execution of the STRING statement.

DELIMITED Phrase

DELIMITED Phrase

If the DELIMITED phrase is specified without the SIZE phrase, the contents of the data item referenced by identifier-1 or the value of literal-1 are transferred to the receiving data item in the sequence specified in the STRING statement beginning with the leftmost character and continuing from left to right until the end of the sending data item is reached, or the end of the receiving data item is reached, or until the character (or characters) specified by literal-2, or by the content of the data item referenced by identifier-2 is encountered. The character (or characters) specified by literal-2 or by the data item referenced by identifier-2 is not transferred.

If the DELIMITED phrase is specified with the SIZE phrase, the entire contents of literal-1 or the contents of the data item referenced by identifier-1 are transferred, in the sequence specified in the STRING statement, to the data item referenced by identifier-3 until all data has been transferred or the end of the data item referenced by identifier-3 has been reached.

POINTER Phrase

WITH POINTERidentifier-4

If the POINTER phrase is specified, the data item referenced by identifier-4 must have a positive value at the time execution of the STRING statement begins.

If the POINTER phrase is not specified, the effect is as if the user had specified identifier-4 referencing a data item with an initial value of 1.

OVERFLOW and NOT OVERFLOW Phrases

ON OVERFLOWimperative –statement -1

NOT ON OVERFLOWimperative-statement-2

Before each move of a character from the current sending item to the receiving item, if the value associated with the data item referenced by identifier-4 is either less than one or exceeds the number of character positions in the receiving item, an overflow condition exists.

If an overflow condition arises, no (further) data is transferred from the sending item to the receiving item, the NOT ON OVERFLOW phrase, if present, is ignored, and control is transferred either to the end of the STRING statement, or, if the ON OVERFLOW phrase is present, to imperative-statement-1 . In the latter case, execution continues according to the rules for each statement specified in imperative-statement-1. If a procedure branching or conditional statement that causes explicit transfer of control is encountered, control is transferred in accordance with the rules for that statement; otherwise, upon completion of the execution of imperative-statement-1, control is transferred to the end of the STRING statement.

If the STRING statement executes without an overflow condition arising, the ON OVERFLOW phrase, if present, is ignored and control is transferred either to the end of the STRING statement, or, if the NOT ON OVERFLOW phrase is present, to imperative-statement-2. In the latter case, execution continues according to the rules for each statement specified in imperative-statement-2. If a procedure branching or conditional statement that causes explicit transfer of control is encountered, control is transferred in accordance with the rules for that statement; otherwise, upon completion of the execution of imperative-statement-2, control is transferred to the end of the STRING statement.

STRING Statement Examples


All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

COBOL Topics