Built-in functions compute values inside expressions—format dates for titles, take absolute differences, test field content, or read system information. Unlike MOVE or IF standing alone, functions nest inside assignment and condition lines. This cheat sheet groups functions by category with typical usage patterns and notes on Report Generator versus Easytrieve Plus availability. Names vary by release; pilot compile on your LPAR before embedding in production. When a function is missing, use category tutorial fallback patterns (overlay, INDEX, PROC). Cross-link to function-categories index and per-category pages for depth beyond this quick table.
Functions take arguments in parentheses. Arguments may be fields, literals, or nested expressions. Result type must fit target field in assignment. Mismatch causes compile diagnostics or truncation. Some functions are niladic—no arguments—like current date helpers referencing system context.
12345WS-TODAY = DATE-FUNCTION() IF ABS(VAR-A - VAR-B) GT TOLERANCE DISPLAY 'VARIANCE' END-IF WS-EDITED = EDIT(NUM-FIELD, 'ZZ,ZZ9.99')
String functions manipulate alphanumeric fields—length, trim, scan, substring where available. Classic Easytrieve without rich builtins uses DEFINE overlay subfields and INDEX loops; modern Plus catalogs add more direct calls. Always check length limits—eight-character targets truncate.
| Function / pattern | Purpose |
|---|---|
| INDEX / scan loops | Find character position in string |
| Overlay subfields | Reference portion of field without copy |
| TRIM / pad helpers | Remove spaces or pad to length (Plus) |
| SUBSTR / segment | Extract substring when in catalog |
Date functions support report headers, age calculations, and period filters. SYSDATE system field often supplements functions for current date. Packed and display date formats need consistent masks—document internal format in comments. Calendar edge cases (leap year, month-end) deserve unit tests on test LPAR.
| Item | Purpose |
|---|---|
| SYSDATE / SYSTIME | System date and time fields (not functions but paired use) |
| Date extraction | Year, month, day from date field |
| Date arithmetic | Add days or months per catalog macros/functions |
| %DATECALC macro | Macro alternative on some releases |
| Function | Purpose |
|---|---|
| ABS | Absolute value |
| MAX / MIN | Larger or smaller of values |
| MOD / remainder patterns | Division remainder for grouping |
| SQRT / power | Advanced math where documented (Plus) |
Conversion changes representation—numeric to character, packed to zoned. Formatting applies EDIT masks for human-readable output without changing stored value semantics. Report LINE masks overlap formatting functions—choose one consistent approach per program.
| Pattern | Purpose |
|---|---|
| EDIT(field, mask) | Picture edit for display |
| Numeric to alpha | Convert for concatenated messages |
| Alpha to numeric | Parse digits when validated first |
| Pattern | Purpose |
|---|---|
| Numeric test | Verify field contains digits |
| Alpha test | Verify alphabetic content |
| SPACES test | Blank field detection in IF |
| Item | Purpose |
|---|---|
| File status helpers | Query open or EOF state per release |
| SYSUSERID / environment | Job user context for audit footers |
| RUN date / time | Batch run timestamp in headers |
Report writer may expose functions for page number, line count, or break level in TITLE and LINE expressions—consult report functions tutorial. Mixing report functions with batch FILE logic in same PROC requires knowing when report engine context is active.
| Category | Tutorial path |
|---|---|
| String | /functions/string |
| Date | /functions/date |
| Numeric | /functions/numeric |
| Math | /functions/math |
| Conversion | /functions/conversion |
| Formatting | /functions/formatting |
| Testing | /functions/testing |
| File | /functions/file |
| System | /functions/system |
| Report | /functions/report |
Functions are mini-calculators inside your sentence. Instead of writing ten steps to get today's date on the report, a date function gives you the date in one piece. The cheat sheet lists which calculators exist for strings, numbers, and dates—your school may have a smaller calculator than another school, so try on your computer before the big test.
1. Built-in functions are used inside:
2. Date functions typically help with:
3. Function availability depends on:
4. When no substring function exists, classic pattern uses:
5. ABS and MAX belong to: