Need to concatenate 4 strings to a destination variable in cobol.
Like,
01 WS-S1 X(10) VALUE "HI ".
01 WS-S2 X(10) VALUE "HOW ".
01 WS-S3 X(10) VALUE "ARE ".
01 WS-S4 X(10) VALUE "YOU?".
to a resultant string
"HI HOW ARE YOU?"
Can anyone please help me out?
DELIMITED BY phrase specifies the content of source string to be transferred. DELIMITED BY [SPACES, Data item or literal] -> Transfers the data till sepcificed delimeter found DELIMITED BY SIZE, Transfers complete string.
PROCEDURE DIVISION. PERFORM VARYING WS-I FROM 1 BY 1 UNTIL WS-I > FUNCTION LENGTH(WS-STR) IF WS-STR(WS-I:1) = '*' THEN CONTINUE ELSE MOVE WS-STR(WS-I:1) TO WS-LETTER(WS-J) ADD 1 TO WS-J ADD 1 TO WS-CNT END-IF END-PERFORM DISPLAY WS-CHAR STOP RUN.
We do this using 'UNSTRING' operation. To find out the pattern in a particular string using 'INSPECT' To replace a particular character or a group of alphabets with other character or group of alphabets respectively using 'INSPECT'
Here is a working example of the STRING verb that does what you are looking for:
IDENTIFICATION DIVISION.
PROGRAM-ID. EXAMPLE.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 WS-S1 PIC X(10) VALUE 'HI '.
01 WS-S2 PIC X(10) VALUE 'HOW '.
01 WS-S3 PIC X(10) VALUE 'ARE '.
01 WS-S4 PIC X(10) VALUE 'YOU?'.
01 WS-CONCAT PIC X(43) VALUE SPACES.
PROCEDURE DIVISION.
MAIN-PARAGRAPH.
STRING WS-S1 DELIMITED BY SPACE
' ' DELIMITED BY SIZE
WS-S2 DELIMITED BY SPACE
' ' DELIMITED BY SIZE
WS-S3 DELIMITED BY SPACE
' ' DELIMITED BY SIZE
WS-S4 DELIMITED BY SPACE
INTO WS-CONCAT
END-STRING
DISPLAY '>' WS-CONCAT '<'
GOBACK
.
Output is:
>HI HOW ARE YOU? <
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With