ACCEPT a Number
Part of the First Programs section of Coddy's COBOL Programming journey. Lesson 12 of 19.
ACCEPT into a PIC 9 field reads the line as a number and lines it up on the right: typing 7 into a PIC 9(3) stores 007.
01 AGE PIC 9(3).
ACCEPT AGE.The field can then take part in arithmetic, unlike a PIC X field.
This is GnuCOBOL, the compiler in this course, and a line that is not a number, like abc, stores zeros. IBM's compiler copies the line as typed, so input on a mainframe carries every digit: 007. Section 3 shows how a program checks its input first.
Challenge
EasyRead a number into AGE and display Age: followed by it.
Example input, one line per ACCEPT: 30.
Try it yourself
IDENTIFICATION DIVISION.
PROGRAM-ID. AGES.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 AGE PIC 9(3).
PROCEDURE DIVISION.
*> Read AGE and display it
STOP RUN.