Menu
CoddyTech

Inserting Characters

Part of the Data and Numbers section of Coddy's COBOL Programming journey. Lesson 12 of 23.

Three more symbols put a character between the digits: / a slash, B a space and 0 a zero. Each takes a position of its own in the edited field.

A date kept as 8 digits prints with slashes:

01 DATE-OUT PIC 99/99/9999.
    MOVE 23112026 TO DATE-OUT.
    *> 23/11/2026

B spaces out long numbers so they are easier to read:

01 PHONE-OUT PIC 999B999B9999.
    MOVE 5551234567 TO PHONE-OUT.
    *> 555 123 4567

0 adds zeros on the right, to show amounts kept in thousands: ZZ9000 prints 25 as 25000.

B also works in a text picture: XXBXX prints ABCD as AB CD.

challenge icon

Challenge

Easy

A date arrives as 8 digits, day first: 23112026. Read it into DATE-IN, then display Date: 23/11/2026 through an edited field DATE-OUT that you declare.

Example input, one line per ACCEPT: 23112026.

Try it yourself

       IDENTIFICATION DIVISION.
       PROGRAM-ID. DATES.
       DATA DIVISION.
       WORKING-STORAGE SECTION.
       01 DATE-IN PIC 9(8).
       *> Declare DATE-OUT here
       PROCEDURE DIVISION.
           ACCEPT DATE-IN.
           *> Move it into DATE-OUT and display it
           STOP RUN.
quiz iconTest yourself

This lesson includes a short quiz. Start the lesson to answer it and track your progress.

All lessons in Data and Numbers