codegurukool.com · Free coding tutorials & online compiler

Home › COBOL Tutorial › COBOL edited pictures

COBOL edited pictures

Format numbers for reports.

An edited picture formats a number when you MOVE it: Z hides leading zeros, , and . insert separators, and 9 always shows a digit. Edited fields are for printing only, not for further arithmetic.

Example code

       IDENTIFICATION DIVISION.
       PROGRAM-ID. EDIT.
       DATA DIVISION.
       WORKING-STORAGE SECTION.
       01 AMT PIC 9(5)V99 VALUE 1234.5.
       01 ED  PIC ZZ,ZZ9.99.
       01 PCT PIC 9V99 VALUE 0.5.
       01 ED2 PIC 9.99.
       PROCEDURE DIVISION.
           MOVE AMT TO ED.
           DISPLAY FUNCTION TRIM(ED).
           MOVE PCT TO ED2.
           DISPLAY ED2.
           STOP RUN.

Run this code in the online editor

← COBOL ROUNDED and SIZE ERRORCOBOL IF...ELSE →