Edited pictures in COBOL
MOVE into an edited picture is how COBOL formats numbers for people.
IDENTIFICATION DIVISION.
PROGRAM-ID. EDITED-PICTURES.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 RAW-TOTAL PIC 9(5)V99 VALUE 1234.5.
01 PRICE-OUT PIC $$$,$$9.99.
01 STOCK-RAW PIC 9(4) VALUE 87.
01 STOCK-OUT PIC Z,ZZ9.
PROCEDURE DIVISION.
*> MOVE into an edited picture formats the digits for people.
MOVE RAW-TOTAL TO PRICE-OUT
MOVE STOCK-RAW TO STOCK-OUT
DISPLAY "Invoice total: " PRICE-OUT
DISPLAY "On the shelf: " STOCK-OUT
STOP RUN.
How it works
$$$,$$9.99floats a dollar sign against the first digit and inserts the comma.Z,ZZ9replaces leading zeros with spaces so 87 prints as bare 87.- The
MOVEdoes the formatting;DISPLAYjust prints the edited field.
Keywords and builtins used here
DATADISPLAYDIVISIONIDENTIFICATIONMOVEPROCEDURESECTIONSTOP
The run, in numbers
- Lines
- 15
- Characters to type
- 449
- Tokens
- 54
- Three-star pace
- 35 tpm
At the three-star pace of 35 tokens a minute, this run takes about 93 seconds.
Step 2 of 3 in Pictures, step 5 of 27 in Language basics.