PIC X Fields
Part of the First Programs section of Coddy's COBOL Programming journey. Lesson 6 of 19.
Programs keep data in fields. Fields are declared in the DATA DIVISION, in its WORKING-STORAGE SECTION:
DATA DIVISION.
WORKING-STORAGE SECTION.
01 CITY PIC X(10).01 is the level number, CITY the name and PIC X(10) the picture: 10 characters of any kind. A field always has its full size, so CITY holds 10 characters.
VALUE gives a field its starting content. Shorter text is filled with spaces on the right:
01 CITY PIC X(10) VALUE "Paris".A field named in DISPLAY prints its content. Several items on one DISPLAY print side by side:
DISPLAY "[" CITY "]". *> [Paris ]Names use letters, digits and hyphens, like CUSTOMER-NAME, and cannot be a COBOL word such as DISPLAY.
Challenge
EasyDeclare a field GREETING of 12 characters with the value Good evening, then display it.
Try it yourself
IDENTIFICATION DIVISION.
PROGRAM-ID. FIELD.
DATA DIVISION.
WORKING-STORAGE SECTION.
*> Declare GREETING here
PROCEDURE DIVISION.
*> Display GREETING here
STOP RUN.