Master Mainframe Technologies - COBOL, JCL, DB2, VSAM, CICS & More
ABEND Codes SQLCODEs File Status Interview Prep Contact
← Back to Data Division
Data Division | Beginner | COBOL

Numeric PIC Clauses

Problem Description

Demonstrate different numeric PIC clauses: 9, S, V, P.

Expected Output

Understanding numeric data types

Hints

9=digit, S=sign, V=implied decimal, P=scaling.

Solution

IDENTIFICATION DIVISION. PROGRAM-ID. NUMTYPES. DATA DIVISION. WORKING-STORAGE SECTION. * Basic numeric - 5 digits 01 WS-NUM1 PIC 9(5) VALUE 12345. * Signed numeric - can be negative 01 WS-NUM2 PIC S9(5) VALUE -12345. * Implied decimal - 99V99 means 99.99 01 WS-DECIMAL PIC 9(3)V99 VALUE 123.45. * Scaling - P represents decimal positions 01 WS-SCALED PIC 9(3)PP VALUE 12300. * Display versions 01 WS-DISP1 PIC Z(4)9. 01 WS-DISP2 PIC -(5)9. 01 WS-DISP3 PIC ZZ9.99. PROCEDURE DIVISION. DISPLAY "BASIC: " WS-NUM1. DISPLAY "SIGNED: " WS-NUM2. DISPLAY "DECIMAL: " WS-DECIMAL. MOVE WS-NUM1 TO WS-DISP1. DISPLAY "EDITED: " WS-DISP1. MOVE WS-NUM2 TO WS-DISP2. DISPLAY "SIGNED: " WS-DISP2. MOVE WS-DECIMAL TO WS-DISP3. DISPLAY "DECIMAL: " WS-DISP3. STOP RUN.

Explanation:

PIC 9=numeric digit, S=sign, V=implied decimal point, P=decimal scaling.