How to resolve the algorithm String concatenation step by step in the COBOL programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm String concatenation step by step in the COBOL programming language

Table of Contents

Problem Statement

Create a string variable equal to any text value. Create another string variable whose value is the original variable concatenated with another string literal. To illustrate the operation, show the content of the variables.

Let's start with the solution:

Step by Step solution about How to resolve the algorithm String concatenation step by step in the COBOL programming language

Source code in the cobol programming language

       IDENTIFICATION DIVISION.
       PROGRAM-ID. Concat.

       DATA DIVISION.
       WORKING-STORAGE SECTION.
       01  Str  PIC X(7) VALUE "Hello, ".
       01  Str2 PIC X(15).

       PROCEDURE DIVISION.
           DISPLAY "Str  : " Str
           STRING Str " World!" DELIMITED BY SIZE INTO Str2
           DISPLAY "Str2 : " Str2

           GOBACK
           .


       ...
       PROCEDURE DIVISION.
           DISPLAY "Str  : " Str
           MOVE FUNCTION CONCATENATE(Str, " World!") TO Str2
           DISPLAY "Str2 : " Str2

           GOBACK
           .


*      *> Using a '&'.
       01  Long-Str-Val     PIC X(200) VALUE "Lorem ipsum dolor sit "
           & "amet, consectetuer adipiscing elit, sed diam nonummy "
           & "nibh euismod tincidunt ut laoreet dolore magna aliquam "
           & "erat volutpat.".

*      *> Using a '-' in column 7. Note the first two literals have no
*      *> closing quotes.
       01  Another-Long-Str PIC X(200) VALUE " Ut wisi enim ad minim 
      -    "veniam, quis nostrud exerci tation ullamcorper suscipit
      -    "lobortis nisl ut aliquip ex ea commodo consequat".


  

You may also check:How to resolve the algorithm Text processing/2 step by step in the AutoHotkey programming language
You may also check:How to resolve the algorithm Matrix multiplication step by step in the OxygenBasic programming language
You may also check:How to resolve the algorithm Old lady swallowed a fly step by step in the Batch File programming language
You may also check:How to resolve the algorithm Power set step by step in the J programming language
You may also check:How to resolve the algorithm Greatest common divisor step by step in the min programming language