typestar

PICTURE clauses in COBOL

The PIC clause is the type system: 9 for digits, X for anything, V and S invisible.

IDENTIFICATION DIVISION.
PROGRAM-ID. PIC-CLAUSES.
DATA DIVISION.
WORKING-STORAGE SECTION.
*> The PICTURE clause is the type system: 9 digit, X any, V decimal.
01 CREW-COUNT   PIC 99      VALUE 12.
01 BERTH-CODE   PIC X(4)    VALUE "C-7A".
01 RATION-KG    PIC 9(2)V99 VALUE 42.75.
01 DEPTH-M      PIC S9(3)   VALUE -180.
PROCEDURE DIVISION.
    DISPLAY "Crew: " CREW-COUNT
    DISPLAY "Berth: " BERTH-CODE
    DISPLAY "Rations: " RATION-KG " held as bare digits"
    DISPLAY "Depth: " DEPTH-M " (the sign rides in the last digit)"
    STOP RUN.

How it works

  1. PIC 99 and PIC X(4) size a counter and a code, by repetition or a count in parentheses.
  2. PIC 9(2)V99 scales 42.75 with an implied decimal point stored nowhere.
  3. PIC S9(3) keeps a sign, carried inside the last digit rather than shown.

Keywords and builtins used here

The run, in numbers

Lines
15
Characters to type
523
Tokens
59
Three-star pace
35 tpm

At the three-star pace of 35 tokens a minute, this run takes about 101 seconds.

Type this snippet

Step 1 of 3 in Pictures, step 4 of 27 in Language basics.

← Previous Next →