codegurukool.com · Free coding tutorials & online compiler

Home › COBOL Tutorial › COBOL intrinsic functions

COBOL intrinsic functions

Built-in helpers with FUNCTION.

Call built-in functions with the word FUNCTION: UPPER-CASE, LOWER-CASE, REVERSE, TRIM, LENGTH, MAX, MIN, SQRT. Move a numeric result into a PIC field to control how it prints.

Example code

       IDENTIFICATION DIVISION.
       PROGRAM-ID. FUNCS.
       DATA DIVISION.
       WORKING-STORAGE SECTION.
       01 TXT PIC X(10) VALUE "cobol".
       01 N   PIC 99.
       PROCEDURE DIVISION.
           DISPLAY FUNCTION TRIM(FUNCTION UPPER-CASE(TXT)).
           MOVE FUNCTION LENGTH(FUNCTION TRIM(TXT)) TO N.
           DISPLAY N.
           MOVE FUNCTION MAX(3 9 4) TO N.
           DISPLAY N.
           DISPLAY FUNCTION TRIM(FUNCTION REVERSE(FUNCTION TRIM(TXT))).
           MOVE FUNCTION SQRT(16) TO N.
           DISPLAY N.
           STOP RUN.

Run this code in the online editor

← COBOL group items and recordsCOBOL file handling →