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/2026B spaces out long numbers so they are easier to read:
01 PHONE-OUT PIC 999B999B9999.
MOVE 5551234567 TO PHONE-OUT.
*> 555 123 45670 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
EasyA 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.
This lesson includes a short quiz. Start the lesson to answer it and track your progress.