Easytrieve END-PROC — Closing Procedure Modules

PROC opens a module; END-PROC closes it and hands control back to whoever PERFORMed it. Without END-PROC, your source loses structure—the compiler may swallow the next procedure into the wrong body or fail with unterminated procedure diagnostics. END-PROC is not optional decoration; it is the return instruction that makes modular Easytrieve work. This tutorial explains return flow after PERFORM, nested END-PROC ordering, early EXIT versus normal fall-through, differences from END-IF and other END keywords, and what maintainers should verify when merging PROC blocks from legacy programs. Beginners who internalize END-PROC pairing write PROC modules that compile on first pass and behave predictably under nested calls.

Progress0 of 0 lessons

What END-PROC Does

When runtime execution reaches END-PROC, Easytrieve pops the implicit return point saved when PERFORM entered the module and continues with the next executable statement after that PERFORM. If no PERFORM is active—such as when the report writer invoked BEFORE-LINE automatically—END-PROC returns to the report engine at the appropriate event continuation point. END-PROC does not undo MOVE or arithmetic already executed; side effects on shared fields persist after return.

text
1
2
3
4
5
6
7
8
IF BONUS-CODE EQ 'S' PERFORM SPECIAL-BONUS END-IF MOVE RESULT-AMT TO OUTPUT-FIELD SPECIAL-BONUS. PROC RESULT-AMT = GROSS * 1.20 END-PROC

After SPECIAL-BONUS runs, END-PROC returns to the line after END-IF—not inside the IF block. RESULT-AMT retains the calculated value for MOVE to OUTPUT-FIELD. If END-PROC were missing, the MOVE might be interpreted as part of SPECIAL-BONUS, skipping it on PERFORM paths that never enter the module explicitly.

END-PROC and Nested PERFORM

Nested calls stack return addresses in order. Outer PERFORM enters PROCA; inner PERFORM inside PROCA enters PROCB. PROCB's END-PROC returns to the statement after inner PERFORM still inside PROCA. PROCA's END-PROC then returns to the statement after outer PERFORM in JOB logic. Broadcom forbids recursion—PROCB cannot PERFORM PROCA—but arbitrary nesting depth within that constraint is allowed. Document deep chains for maintainability; flatten when nesting exceeds three levels without clear benefit.

text
1
2
3
4
5
6
7
8
9
10
11
12
13
PERFORM PROCA PROCA. PROC IF REGION EQ 'NE' PERFORM PROCB ELSE TAX-RATE = 0.05 END-IF END-PROC PROCB. PROC TAX-RATE = 0.08 END-PROC

Execution order for REGION NE: enter PROCA, enter PROCB, END-PROC from PROCB back into PROCA, END-PROC from PROCA back to JOB after first PERFORM. TAX-RATE holds 0.08 when PROCB ran.

EXIT Versus END-PROC

EXIT terminates the current procedure invocation early—skipping remaining statements in that PROC body for this call—but does not replace END-PROC in source. The module definition still requires END-PROC after all statements including those following conditional EXIT paths in the grammar. Screen BEFORE-SCREEN examples use EXIT when EOF on GET prevents further setup; control leaves the procedure without running lines below EXIT, then END-PROC still marks module end in the source structure. Confusing EXIT with END-PROC causes missing terminator errors because EXIT is runtime flow, END-PROC is structural close.

END-PROC compared to related keywords
KeywordRolePairs with
END-PROCClose procedure modulePROC / proc-name. PROC
END-IFClose IF blockIF condition
EXITLeave current PROC invocation earlyStill needs END-PROC in source
MENDClose macro definitionMACRO prototype
END-PROC (report)Close report hook moduleBEFORE-LINE. PROC etc.

Missing or Misplaced END-PROC

Typical compile symptoms include undefined procedure on PERFORM that looks correct—because the prior module never closed and swallowed the label—and messages about invalid statement in procedure context. When merging legacy sources, search for proc-name. PROC and confirm each has END-PROC before the next label at the same indentation level. Report PROCs packed without END-PROC between BEFORE-LINE and AFTER-BREAK merge two hooks into one invalid module. Modern editors with bracket matching help; on green screens, maintain a checklist per module.

Recovery checklist

  1. Locate the PROC line without a matching END-PROC in listing or source.
  2. Insert END-PROC immediately before the next procedure label or activity boundary.
  3. Recompile and verify PERFORM cross-reference entries appear for each user label.
  4. Run a small test job exercising each PERFORM path including nested branches.

Multiple PROCs in Sequence

Activities often define many modules back to back—each closed by its own END-PROC. Order among user PROCs at the end of a JOB usually does not affect PERFORM because invocation is by label, not sequential fall-through. Do not rely on fall-through from one PROC into another; always PERFORM explicitly. Report PROCs are different: their order relative to the REPORT block is fixed by special-name semantics, not arbitrary reordering.

text
1
2
3
4
5
6
7
8
9
10
11
PROC-A. PROC COUNT-A = COUNT-A + 1 END-PROC PROC-B. PROC COUNT-B = COUNT-B + 1 END-PROC PROC-C. PROC TOTAL = COUNT-A + COUNT-B END-PROC

END-PROC in Report and Screen Context

Report writer hooks use END-PROC identically to user modules. BEFORE-BREAK. PROC accumulates subtotals; END-PROC returns to break processing. Screen INITIATION. PROC opens files once; END-PROC returns to SCREEN setup. Restrictions on statements inside specific hooks apply regardless of END-PROC—invalid GOTO SCREEN in BEFORE-SCREEN fails even with correct END-PROC placement. TERMINATION PROCs run once at SCREEN or report end; END-PROC still required to delimit the source module.

Side Effects After END-PROC

Fields modified inside a PROC remain modified after END-PROC unless the caller overwrites them. Design modules to document which fields they read as input and which they write as output. Avoid hidden changes to unrelated globals—maintenance programmers trace PERFORM expecting local effect. RESET fields on DEFINE reinitialize on implied JOB loops or screen cycles independent of END-PROC; know your field RESET attributes when mixing PROC logic with report iteration.

Common END-PROC Mistakes

  • Omitting END-PROC after the last statement in a module.
  • Using END-IF where END-PROC is required to close the PROC.
  • Placing END-PROC inside an IF block so outer PROC never closes in source grammar.
  • Assuming END-PROC resets counters or clears fields automatically.
  • Believing EXIT removes the need for END-PROC at module level.
  • Duplicating END-PROC twice for one PROC—second may close nothing and confuse structure.

Explain It Like I'm Five

END-PROC is writing done at the bottom of your recipe card. When you finish the steps, you put the card back where the caller can find the next instruction. If you forget to write done, the next recipe might get glued onto the same page and nobody knows where one ends and the next begins. END-PROC is that done mark so the kitchen knows the chocolate cake steps finished and it is safe to start the next task.

Exercises

  1. Fix a sample source snippet missing END-PROC before a second PROC label.
  2. Trace nested PERFORM with three modules and list END-PROC return order on paper.
  3. Add EXIT on EOF inside BEFORE-SCREEN. PROC and confirm END-PROC still present after the module body.
  4. Document input and output fields for one PROC before and after END-PROC return.
  5. Explain to a peer why END-IF cannot replace END-PROC on a procedure module.

Quiz

Test Your Knowledge

1. END-PROC returns control to:

  • The statement after the PERFORM that invoked the PROC
  • The top of the JOB
  • JCL catalog
  • Library section only

2. Every user PROC must have:

  • Matching END-PROC
  • Only END-IF
  • STOP RUN inside
  • A REPORT block

3. In nested PERFORM, inner END-PROC returns to:

  • The statement after the inner PERFORM
  • The outer JOB INPUT
  • END-PROC of outer PROC directly
  • Compile phase

4. END-PROC is different from END because:

  • END-PROC closes procedures; END may close other constructs per context
  • They are identical keywords
  • END replaces END-PROC in reports
  • END-PROC runs only at EOF

5. Report PROC BEFORE-LINE must end with:

  • END-PROC
  • END-REPORT
  • CLOSE file
  • FINISH only
Published
Read time14 min
AuthorMainframeMaster
Reviewed by MainframeMaster teamVerified: Broadcom Easytrieve Report Generator 11.6 END-PROC procedure terminationSources: Broadcom Easytrieve 11.6 Language Reference END-PROC, PROC, EXITApplies to: Easytrieve END-PROC and procedure return flow