String Statement
String Statement Example
Scenario1 - Concatenate two strings separated by space.
Code -
----+----1----+----2----+----3----+----4----+----5----+
IDENTIFICATION DIVISION.
PROGRAM-ID. STRINGE.
AUTHOR. MTH.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 WS-OUTPUT PIC X(70).
PROCEDURE DIVISION.
STRING "Mainframestechhelp" DELIMITED BY SIZE,
SPACE,
"is a Mainframe Community" DELIMITED BY SIZE
INTO WS-OUTPUT
ON OVERFLOW DISPLAY "Error occured"
NOT ON OVERFLOW DISPLAY "Result: " WS-OUTPUT
END-STRING.
STOP RUN.
Output -
Result: Mainframestechhelp is a Mainframe Community
Explaining Example -
In the above example:
- Two strings are concatenated by separating a space between them and storing them in the WS-OUTPUT variable.
Scenario2 - Concatenate two strings separated by space using WORKING-STORAGE variables.
Code -
----+----1----+----2----+----3----+----4----+----5----+
IDENTIFICATION DIVISION.
PROGRAM-ID. STRINGE.
AUTHOR. MTH.
DATA DIVISION.
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.
STOP RUN.
Output -
Result: MAINFRAMESTECHHELP IS A MAINFRAME COMMUNITY
Explaining Example -
In the above example:
- WS-INP1 and WS-INP2 are concatenated by separating a space between them and storing them in the WS-OUTPUT variable. Because of no overflow, NOT ON OVERFLOW gets executed, and the result is displayed