Menu
CoddyTech

STRING

Part of the Tables and Text section of Coddy's COBOL Programming journey. Lesson 11 of 19.

STRING joins pieces into one field. Each piece says where it ends:

STRING FIRST-NAME DELIMITED BY SPACE
    " " DELIMITED BY SIZE
    LAST-NAME DELIMITED BY SPACE
    INTO FULL-NAME
END-STRING.

DELIMITED BY SPACE takes a field up to its first space, which drops its padding. DELIMITED BY SIZE takes the whole piece, spaces included.

STRING writes only the characters it joins; the rest of the receiving field keeps what it held. MOVE SPACES to it first, or give it VALUE SPACES.

MOVE ALL "X" TO OUT.
STRING "ab" DELIMITED BY SIZE
    INTO OUT. *> abXXXXXXXX

When the pieces do not fit, STRING stops at the end of the field and runs ON OVERFLOW.

WITH POINTER P starts writing at position P and leaves P after the last character written, so the next STRING carries on from there.

STRING WORD DELIMITED BY SPACE
    INTO OUT WITH POINTER P
END-STRING.
challenge icon

Challenge

Easy

The program reads FIRST-NAME and LAST-NAME. Join them into FULL-NAME with STRING, last name first: Lovelace, Ada.

Example input, one line per ACCEPT: Ada, Lovelace.

Try it yourself

       IDENTIFICATION DIVISION.
       PROGRAM-ID. FULLNM.
       DATA DIVISION.
       WORKING-STORAGE SECTION.
       01 FIRST-NAME PIC X(15).
       01 LAST-NAME PIC X(15).
       01 FULL-NAME PIC X(32) VALUE SPACES.
       PROCEDURE DIVISION.
           ACCEPT FIRST-NAME.
           ACCEPT LAST-NAME.
           *> Build FULL-NAME here
           DISPLAY FULL-NAME.
           STOP RUN.

All lessons in Tables and Text