Intrinsic functions in COBOL
FUNCTION calls compute a value right where a field would sit.
IDENTIFICATION DIVISION.
PROGRAM-ID. INTRINSIC-FUNCTIONS.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 RAW-ORDER PIC X(14) VALUE "twelve anchors".
01 LOUD-ORDER PIC X(14).
01 PRICE-TEXT PIC X(6) VALUE "417.25".
01 PRICE-NUM PIC 9(3)V99.
01 PRICE-SHOW PIC ZZ9.99.
PROCEDURE DIVISION.
*> FUNCTION calls compute a value right where a field would sit.
MOVE FUNCTION UPPER-CASE(RAW-ORDER) TO LOUD-ORDER
COMPUTE PRICE-NUM = FUNCTION NUMVAL(PRICE-TEXT)
MOVE PRICE-NUM TO PRICE-SHOW
DISPLAY LOUD-ORDER " at " PRICE-SHOW
STOP RUN.
How it works
FUNCTION UPPER-CASE(RAW-ORDER)shouts the order inside aMOVE.FUNCTION NUMVAL(PRICE-TEXT)turns display text into a numberCOMPUTEcan use.- The edited
ZZ9.99picture puts the decimal point back for printing.
Keywords and builtins used here
COMPUTEDATADISPLAYDIVISIONIDENTIFICATIONMOVENUMVALPROCEDURESECTIONSTOP
The run, in numbers
- Lines
- 16
- Characters to type
- 526
- Tokens
- 68
- Three-star pace
- 35 tpm
At the three-star pace of 35 tokens a minute, this run takes about 117 seconds.
Step 1 of 3 in Functions & calls, step 22 of 27 in Language basics.