Key Takeaways: Intrinsic Functions
-
All intrinsic functions require the FUNCTION keyword unless
FUNCTION ALL INTRINSICis declared in the REPOSITORY paragraph. Functions are pure — they return values without modifying arguments. -
String functions (LENGTH, UPPER-CASE, LOWER-CASE, TRIM, REVERSE) are essential for data cleansing and case-insensitive comparisons. LENGTH returns allocated size, not content length — use TRIM first for content length.
-
NUMVAL and NUMVAL-C convert alphanumeric to numeric but abend on invalid input. Always use TEST-NUMVAL or TEST-NUMVAL-C first for defensive validation.
-
Statistical functions (MEAN, MEDIAN, VARIANCE, STANDARD-DEVIATION, MIN, MAX, RANGE, SUM) are built-in capabilities that most other procedural languages lack. They eliminate hand-coded accumulator patterns.
-
ORD-MAX and ORD-MIN return positions, not values — essential when you need to know WHICH element is highest/lowest, not just the value.
-
The ALL subscript with statistical functions processes every declared table entry. For partially loaded tables, this produces incorrect results. Use explicit loops for partial tables.
-
Date functions (CURRENT-DATE, INTEGER-OF-DATE, DATE-OF-INTEGER) enable correct date arithmetic without hand-coded calendar logic. They handle leap years, month lengths, and century boundaries correctly.
-
Financial functions (PRESENT-VALUE, ANNUITY) directly support loan, investment, and insurance calculations. ANNUITY returns a ratio — multiply by principal to get the periodic payment.
-
Functions can be nested for powerful patterns:
FUNCTION UPPER-CASE(FUNCTION TRIM(ws-input TRAILING))combines trimming and case conversion in a single expression. -
Legacy != Obsolete: COBOL's intrinsic function library, expanded in 1989, 2002, and 2014, provides domain-specific capabilities that rival or exceed many modern languages for business computing.