Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Concatenate string by its length COBOL

Tags:

cobol

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?

like image 944
Dinesh Avatar asked Dec 20 '12 06:12

Dinesh


People also ask

What is delimited by size in Cobol?

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.

How do I remove duplicate characters in a string in Cobol?

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.

How do I find a character in a string in Cobol?

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'


1 Answers

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?                            <
like image 193
NealB Avatar answered Sep 22 '22 16:09

NealB