STRING Statement


  • STRING statement concatenates two or more strings or literals into a single string and places them into a result variable.
  • It enables the creation of a single string from multiple stings separated by delimiter.
  • One STRING statement does the same task that a series of MOVE statements does.
  • STRING requires a minimum of two variables or literals to concatenate.
  • It is applicable only to alphabetic and alpha-numeric items and not applicable to numeric items.

Syntax -

1----+----2----+----3----+----4----+----5----+
  STRING source-item-1 [DELIMITED BY delimiter-1]
      [source-item-2 DELIMITED BY delimiter-2] [...]
      INTO destination-item
      [ON OVERFLOW statements-block-1]
      [NOT ON OVERFLOW statement-block-2]
      [END-STRING].
Note! All statements coded in [ ] are optional.

Parameters -

  • source-item - Specifies the variables that we want to concatenate.
  • DELIMITED BY - Specifies the character to place at the end of the source item. If SIZE is used, it'll consider the entire variable.
  • destination-item - Specifies the data item where the result will be placed after concatenation.
  • ON OVERFLOW statements-block-1 - Specifies the statements block executed when ON OVERFLOW occurs.
  • NOT ON OVERFLOW statement-block-2 - Specifies the statements block executed when the STRING operation is successful.
  • END-STRING - Explicit scope terminator for the STRING statement.

Practical Example -


Scenario - Concatenate two strings separated by space.

Code -

----+----1----+----2----+----3----+----4----+----5
       ...
       WORKING-STORAGE SECTION.
       01 WS-VAR.
          05 WS-INP1    PIC X(18)
		                VALUE 'MAINFRAMESTECHHELP'.
          05 WS-INP2    PIC X(40)
                        VALUE 'IS A MAINFRAME COMMUNITY'.
          05 WS-OUTPUT  PIC X(70).
       ...
       PROCEDURE DIVISION.
           STRING WS-INP1 DELIMITED BY SIZE, 
                  SPACE,
                  WS-INP2 DELIMITED BY SIZE
             INTO WS-OUTPUT
                  ON OVERFLOW DISPLAY "Error occured"
              NOT ON OVERFLOW DISPLAY "Result: " WS-OUTPUT
           END-STRING.
           ...

Output -

Result: MAINFRAMESTECHHELP IS A MAINFRAME COMMUNITY