Procedures are how Easytrieve programmers modularize logic without leaving the language. Instead of copying the same validation block into ten IF branches, you code it once in a PROC and invoke it with PERFORM. Broadcom supports user PROCs at the end of JOB, PROGRAM, SCREEN, and SORT activities, plus special report PROCs tied to report writer events. Beginners who understand PROC placement, END-PROC rules, and the no-recursion limit write programs that compile cleanly and survive maintenance years later.
Repetitive tasks—tax calculation, status validation, error messaging—appear in nearly every batch program. Copy-pasting logic creates drift: one branch gets fixed, another does not. PROCs centralize the task. PERFORM branches to the module; END-PROC returns to the next statement after PERFORM. Structured Easytrieve mirrors structured COBOL or modern functions, but uses Broadcom's PROC and PERFORM keywords.
A user procedure starts with a label, the keyword PROC on the same or following line, one or more statements, and END-PROC. The label on PERFORM must match proc-name exactly. Broadcom allows proc-name. PROC on one line or proc-name followed by PROC on the next line with proper delimiters.
12345678910111213IF CODE EQ 1 PERFORM CODE1-RTN ELSE PERFORM CODE2-RTN END-IF CODE1-RTN. PROC ORDER-FLAG = 'NO' END-PROC CODE2-RTN. PROC ORDER-FLAG = 'YES' END-PROC
When CODE equals 1, PERFORM CODE1-RTN runs the first procedure and sets ORDER-FLAG to NO. Otherwise CODE2-RTN sets YES. Control always returns to the statement after END-IF because END-PROC hands back to the caller PERFORM.
PERFORM is an unconditional branch to a procedure unless you wrap it in IF logic yourself. When Easytrieve hits PERFORM SPECIAL-BONUS, it jumps to that PROC, executes every statement until END-PROC, then continues with the next executable line after the PERFORM that called it. Nested PERFORM inside a PROC works the same way: inner END-PROC returns to the inner PERFORM's caller, then outer END-PROC returns to the original job logic.
123456789101112131415JOB INPUT PERSNL IF PAY-GROSS LT 300.99 PERFORM SPECIAL-BONUS ELSE PERFORM STANDARD-BONUS END-IF PRINT MYREPORT SPECIAL-BONUS. PROC XMAS-BONUS = PAY-GROSS * 1.20 END-PROC STANDARD-BONUS. PROC XMAS-BONUS = PAY-GROSS * 1.05 END-PROC
| Type | Naming | How invoked |
|---|---|---|
| Job/user PROC | Your label (e.g. CALC-TAX) | PERFORM proc-name |
| Report PROC | REPORT-INPUT, BEFORE-LINE, AFTER-BREAK, TERMINATION | Automatically by report writer at event points |
| Screen PROC | INITIATION, BEFORE-SCREEN, AFTER-SCREEN, TERMINATION | Automatically during SCREEN activity flow |
| START/FINISH job PROCs | START, FINISH when used | Implied JOB flow at activity start or EOF |
Procedures are local to the activity in which they are coded. A PERFORM in JOB PAYROLL cannot reach a PROC defined at the end of a different JOB activity. Job PROCs sit after executable JOB statements and before REPORT subactivities. Report PROCs must immediately follow the REPORT they belong to—not mixed with job PROCs from the same activity. Violating placement produces compile errors about undefined procedures or invalid statement order.
Broadcom explicitly warns that recursion is not permitted. Procedure A may PERFORM B, and B may PERFORM C, but neither B nor C may PERFORM A again directly or indirectly. Attempted recursion yields unpredictable results because the runtime does not maintain a safe call stack for infinite recursion. If you need repeated iteration, use JOB's implied loop, DO WHILE, or GOTO JOB—not PERFORM calling itself.
123456789101112131415IF DEPT EQ '911' PERFORM PROCA END-IF PROCA. PROC IF STATE EQ 'NY' PERFORM PROCB ELSE TAX = GROSS * 0.05 END-IF END-PROC PROCB. PROC TAX = GROSS * 0.10 END-PROC
This nested pattern is valid: PROCA calls PROCB when STATE is NY. PROCB never calls PROCA back, so recursion rules are satisfied.
Report PROCs hook into the report writer lifecycle. REPORT-INPUT runs for each selected record before detail printing—you may filter further with SELECT inside the PROC. BEFORE-BREAK and AFTER-BREAK surround control break processing. BEFORE-LINE and AFTER-LINE bracket each detail line. ENDPAGE fires at page boundaries. TERMINATION runs at report end for grand totals or distribution messages. Each uses the same PROC / END-PROC envelope but is triggered by the product, not by your PERFORM statement.
Most statements are allowed in user PROCs, but Broadcom limits certain I/O statements when PROCs run during SORT or REPORT processing. GET and PUT may be restricted in those contexts because the sort and report engines own record flow. Check your release documentation before placing file I/O inside report PROCs. When unsure, keep file reads in JOB logic and use report PROCs for formatting, masking, and last-chance SELECT tests.
A PROC is a recipe card for one small cooking step, like how to frost a cupcake. PERFORM means read that card now, do what it says, then come back to the main recipe. END-PROC is the bottom of the card that tells you to return to the big cookbook. You can read a card that says open another card, but you cannot tell a card to open itself forever—that would never finish baking.
1. A user PROC is invoked with:
2. Every PROC must end with:
3. Procedures are local to:
4. Recursion in Easytrieve PROCs is:
5. Report PROCs such as BEFORE-LINE appear: