Menu
CoddyTech

PIC 9 Numbers

Part of the First Programs section of Coddy's COBOL Programming journey. Lesson 7 of 19.

A PIC 9 field holds digits. PIC 9(3) holds three of them, so any whole number from 0 to 999:

01 SCORE PIC 9(3) VALUE 42.

A numeric VALUE has no quotes. DISPLAY prints every digit of the field, leading zeros included, so SCORE prints 042.

Only PIC 9 fields take part in arithmetic. A PIC X field holding "42" is text, the same as a name.

PIC 9(3) and PIC 999 mean the same picture: the number in brackets repeats the symbol.

challenge icon

Challenge

Easy

Declare YEAR as PIC 9(4) with the value 1959 and STEPS as PIC 9(5) with the value 250. Display each on its own line.

Try it yourself

       IDENTIFICATION DIVISION.
       PROGRAM-ID. NUMBERS.
       DATA DIVISION.
       WORKING-STORAGE SECTION.
       *> Declare YEAR and STEPS here
       PROCEDURE DIVISION.
           *> Display them here
           STOP RUN.

All lessons in First Programs