Intrinsic functions

Syntax

Intrinsic functions are read-only values you call like variables. FUNCTION names the function, and arguments go in parentheses. They work anywhere a data item works:

COMPUTE WS-LEN = FUNCTION LENGTH(WS-NAME). MOVE FUNCTION CURRENT-DATE TO WS-STAMP.

Date functions

CURRENT-DATE returns a 21-character timestamp: year, month, day, time, and timezone. INTEGER-OF-DATE converts a YYYYMMDD integer to a day number, which makes date subtraction trivial:

COMPUTE WS-DAYS = FUNCTION INTEGER-OF-DATE(WS-TO) - FUNCTION INTEGER-OF-DATE(WS-FROM).

Numeric functions

NUMVAL converts text to a number, and NUMVAL-C handles currency symbols and commas. TRIM removes leading and trailing spaces, and MOD gives the remainder:

COMPUTE WS-N = FUNCTION NUMVAL(WS-TEXT). COMPUTE WS-REM = FUNCTION MOD(WS-A, WS-B).

The code on this page was run with GnuCOBOL 3.2.0 on Alpine Linux 3.24.3 (x86_64) in a Docker container.

Article author: Arthur Isaev

Banner image