codegurukool.com · Free coding tutorials & online compiler

Home › COBOL Tutorial › COBOL variables and PICTURE

COBOL variables and PICTURE

Every item has a level number and a PIC.

A variable is declared with a level number (01 for a top-level item), a name and a PIC (picture). PIC X(5) holds 5 characters, PIC 99 two digits, and V marks an implied decimal point: PIC 9(3)V99 holds three digits, then two decimals. The V takes no space, so a plain DISPLAY shows no point. VALUE sets the starting value. Text fields are padded with spaces, so FUNCTION TRIM removes them.

Example code

       IDENTIFICATION DIVISION.
       PROGRAM-ID. DATA1.
       DATA DIVISION.
       WORKING-STORAGE SECTION.
       01 WS-NAME  PIC X(5)    VALUE "Ada".
       01 WS-AGE   PIC 99      VALUE 7.
       01 WS-PRICE PIC 9(3)V99 VALUE 12.5.
       PROCEDURE DIVISION.
           DISPLAY FUNCTION TRIM(WS-NAME).
           DISPLAY WS-AGE.
           DISPLAY WS-PRICE.
           STOP RUN.

Run this code in the online editor

← COBOL DISPLAYCOBOL MOVE →