Skip to content
Variables and DISPLAY
step 1/5

Reading — step 1 of 5

Learn

~1 min readStructure and Output

Variables go in WORKING-STORAGE SECTION of the DATA DIVISION. Each variable has a level number (the depth — 01 is top-level) and a PICTURE (PIC) that defines its type/size:

       IDENTIFICATION DIVISION.
       PROGRAM-ID. DEMO.
       DATA DIVISION.
       WORKING-STORAGE SECTION.
       01 NAME    PIC X(20).
       01 AGE     PIC 9(3).
       01 SALARY  PIC 9(7)V99.
       PROCEDURE DIVISION.
           MOVE "Ada" TO NAME.
           MOVE 36 TO AGE.
           DISPLAY NAME.
           DISPLAY AGE.
           STOP RUN.

PIC syntax:

  • X(n) — n alphanumeric characters
  • 9(n) — n digits
  • V99 — implicit decimal point with 2 places after
  • S9(5) — signed integer of 5 digits

Reading stdin:

       ACCEPT N.        *> reads a line into N

ACCEPT parses the input based on the variable's PIC. For numeric PIC it converts to integer.

Assignment is MOVE source TO target. Arithmetic uses verbs: ADD, SUBTRACT, MULTIPLY, DIVIDE, or COMPUTE.

Discussion

Ask a question, share an insight, or help someone who’s stuck.

Sign in to post a comment or reply.

Loading…