Input arrives dirty. Dates are February 30. Account numbers point at closed customers. Amounts disagree with control totals. Every Easytrieve program must decide what to do: reject the record, flag it on an exception report, or stop the job. Without a validation framework, each developer writes slightly different IF tests, error messages, and counters—operations cannot compare runs, and auditors find inconsistent rules. The validation framework pattern centralizes checks in Library PROCs with standard RETURN-CODE fields, error code tables, and optional error output files. Screen programs layer declarative ROW validation on top; batch programs PERFORM the same PROCs after JOB INPUT reads. Beginners often validate too late—after UPDATE—or too early—before required fields are populated from chained reads. This page teaches framework structure, error code design, batch versus online integration, soft versus hard failures, testing with bad data, and how the pattern pairs with the error-handling and reusable report framework patterns in this tutorial section.
| Component | Role | Example |
|---|---|---|
| STATUS / RETURN-CODE field | Single outcome per check | ZERO = OK, nonzero = error code |
| VALIDATE-xxx PROCs | Encapsulate one rule or rule set | VALIDATE-DATE, VALIDATE-KEY |
| Error message table | Map code to operator text | V012 = Invalid date format |
| ERROR-FILE output | Persist rejects with context | Copy input record plus code |
| Counters | Summarize run in TERM PROC | ERR-COUNT, READ-COUNT |
Pick one working storage field—VAL-STATUS, RETURN-CODE, or CHECK-RESULT—and use it everywhere. Every validation PROC sets it to zero on success or a positive numeric code on failure. Callers test IF VAL-STATUS NE ZERO before UPDATE. Never overload multiple meanings into one code without documentation; reserve ranges: 1–99 format errors, 100–199 referential errors, 200+ business rule violations. Document the table in a shared comment member operations can search. Matching codes across batch and screen programs lets the same training materials explain rejects whether they appear on a terminal or in an error file.
12345678VALIDATE-DATE. PROC MOVE ZERO TO VAL-STATUS IF IN-DATE LT '19000101' OR IN-DATE GT '20991231' MOVE 12 TO VAL-STATUS EXIT END-IF * Additional calendar logic (month/day) sets code 13, 14, ... END-PROC
123456789101112JOB INPUT TRANS-FILE PERFORM VALIDATE-RECORD IF VAL-STATUS NE ZERO PERFORM WRITE-ERROR-RECORD ADD 1 TO ERR-COUNT ELSE PERFORM UPDATE-MASTER ADD 1 TO OK-COUNT END-IF END-JOB
VALIDATE-RECORD internally PERFORMs field-level PROCs—date, amount sign, key existence via READ on reference file—and stops at first failure or accumulates multiple codes depending on framework policy. Fail-fast is simpler for beginners; accumulate-all suits regulatory listings showing every error on one record. WRITE-ERROR-RECORD moves input buffer, VAL-STATUS, and message text to ERROR-FILE layout defined in Library FILE section.
ROW field definitions use VALUE lists, NUMERIC, MUSTENTER, and ERROR message clauses. Easytrieve catches invalid keystrokes before AFTER-SCREEN runs. This layer handles format—digits only, allowed Y/N—not whether the account exists on the master file.
AFTER-SCREEN PERFORMs the same VALIDATE-ACCOUNT PROC batch uses. On failure MOVE message from error table to screen MSG field and GOTO SCREEN. Framework ensures message text matches batch error file text for the same VAL-STATUS code—operators recognize one vocabulary.
123456789AFTER-SCREEN. PROC PERFORM VALIDATE-ACCOUNT IF VAL-STATUS NE ZERO PERFORM GET-MSG-FOR-CODE MOVE MSG-TEXT TO SCR-ERROR-LINE GOTO SCREEN END-IF PERFORM UPDATE-MASTER END-PROC
Store codes and messages in a static table loaded at INIT or hard-coded in GET-MSG-FOR-CODE CASE structure. For large message sets use a small reference file and SEARCH or sequential READ in GET-MSG-FOR-CODE. Table driven frameworks let non-programmers update messages in a flat file if your change process allows. Keep codes stable across releases; add new codes at unused numbers rather than renumbering—historical error files remain interpretable.
| Range | Category | Sample |
|---|---|---|
| 1–19 | Format / type | 11 non-numeric amount |
| 20–39 | Date / time | 23 invalid calendar date |
| 40–59 | Reference / lookup | 41 account not found |
| 60–79 | Cross-field rules | 62 end date before start |
| 80–99 | Control totals | 80 batch out of balance |
Soft failure writes the record to ERROR-FILE and continues processing—typical for large batch loads where a few bad rows should not stop millions of good ones. Hard failure sets a JOB-ABORT flag, DISPLAY or writes a severe message, and STOPs when control totals fail or reference files are missing. Framework documents which PROCs use which severity. VALIDATE-CONTROL-TOTAL might be hard; VALIDATE-ZIP-CODE might be soft. Mixing severities without documentation causes overnight jobs to stop when operations expected only an error file.
Small PROCs compose into VALIDATE-RECORD. VALIDATE-DATE knows nothing about accounts. VALIDATE-ACCOUNT READs master and sets code 41. VALIDATE-AMOUNT checks sign and decimal rules. VALIDATE-RECORD sequences PERFORMs and optionally short-circuits on first error. Composition beats monolithic thousand-line PROCs you cannot unit test. Naming convention VALIDATE-entity and CHECK-entity helps new developers find the right routine in the Library index.
Validation sets VAL-STATUS; error-handling pattern decides DISPLAY versus ERROR-FILE versus STOP. Keep validation PROCs free of STOP—they only set status. A separate HANDLE-VALIDATION-ERROR PROC increments counters, writes files, and evaluates JOB-ABORT threshold such as IF ERR-COUNT GT 100 STOP. Separation lets screen programs HANDLE without STOP while batch uses STOP on threshold breach.
Before homework goes in the teacher's basket, someone checks each page: name written, numbers in the right boxes, answers not blank. The validation framework is that checker team with the same red stamp for each mistake—stamp 12 always means bad date. Batch homework goes in a reject pile; screen homework gets handed back to you to fix before it counts. Same stamps, same rules, different place the paper goes.
1. A validation framework centralizes:
2. Declarative screen VALUE clauses handle:
3. Batch record validation typically runs:
4. Error codes in a framework are usually:
5. Failed validation should not: