Intrinsic functions
| Syntax | |
| Date functions | |
| Numeric 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).
Next: COBOL idioms and clean code
Article author: Arthur Isaev