Easytrieve EXIT Control Flow

Control flow usually falls through statement by statement, but sometimes the remaining path should not run—end of file on GET in BEFORE-SCREEN, validation failure in a long PROC, error branch that must skip twenty setup lines. EXIT ends the current procedure invocation early: statements below EXIT in that PROC body are skipped for this PERFORM call, and control returns to the caller after the procedure module completes its return semantics. EXIT does not replace END-PROC in source; the module definition still closes with END-PROC after all possible paths including those below conditional EXIT. Beginners confuse EXIT with END-PROC, STOP, STOP RUN, and GOTO—each changes flow differently. STOP RUN terminates the program; GOTO jumps to a label; EXIT leaves one PROC call. This control-flow page teaches when early exit improves readability, BEFORE-SCREEN and sort BEFORE patterns, combining EXIT with IF, interaction with loops via PERFORM, contrast with RETURN in other contexts, and testing all PERFORM paths so skipped tail code never held required cleanup that must move before EXIT or into caller.

Progress0 of 0 lessons

EXIT in the Control Flow Model

PERFORM transfers control into PROC module. Normal path executes all statements until implicit return at END-PROC boundary. EXIT shortcut jumps to return without executing intervening statements. Caller resumes after PERFORM. Multiple PERFORM paths may hit different EXIT points or fall through full body. Flow diagram shows EXIT as branch leaving PROC box early back to caller.

Flow keywords compared
KeywordScopeControl flow effect
EXITCurrent PROC invocationSkip to procedure return
END-PROCModule definitionStructural close; return if invoked
GOTO labelActivity containing labelJump to label
STOP RUNProgramTerminate run
RETURNContext-specificSee RETURN page—screen/CALL contexts

BEFORE-SCREEN EOF Pattern

Screen cycle GET from master file: IF EOF, set message, EXIT—skip field MOVE and cursor setup that require valid record. Control returns to screen engine; END-PROC still ends module in source. Without EXIT, MOVE from empty buffer corrupts screen or abends. Same pattern in BEFORE procedures when prescreen determines record unusable—EXIT after error MESSAGE instead of running SELECT tail.

text
1
2
3
4
5
6
7
8
9
BEFORE-SCREEN. PROC GET MASTER IF EOF MASTER MSG = 'NO MORE RECORDS' EXIT END-IF MOVE NAME TO SCR-NAME MOVE BAL TO SCR-BAL END-PROC

IF ... EXIT Guard Clauses

Guard clause style: IF invalid-condition, EXIT, END-IF at PROC top—main logic below assumes preconditions met. Reduces nesting versus IF valid ... large block END-IF. Limit stacked guard EXITs to three; beyond that use CASE or PERFORM sub-procs. Each guard EXIT must represent mutually exclusive failure mode documented in proc header comment.

EXIT Versus END-PROC in Source

Runtime EXIT skips statements; compile-time module still needs END-PROC after all statements including unreachable-on-EXIT tail if present in source. Tail after EXIT may hold shared cleanup—if cleanup must always run, place before EXIT or in caller after PERFORM. Confusing EXIT with END-PROC causes missing terminator compile errors when developer deletes END-PROC thinking EXIT closed module.

EXIT Inside Loops via PERFORM

DO WHILE loop PERFORM SEARCH-PROC; inside SEARCH-PROC, EXIT when found—returns to loop body after PERFORM, loop continues unless caller sets FOUND and WHILE condition stops. EXIT does not break DO loop directly. Pattern: PERFORM sets FOUND Y, loop condition includes FOUND EQ N, or GOTO after END-DO in caller when PERFORM reports success via flag field.

EXIT and SELECT in Sort BEFORE

Invalid record: EXIT without SELECT excludes from sort output and skips remaining BEFORE logic. Valid record: SELECT at end. IF error EXIT early avoids accidental SELECT in fall-through tail. Order IF validation, EXIT, processing, SELECT documents inclusion pipeline clearly.

When Not to Use EXIT

  • Short PROC with one IF—use ELSE instead of EXIT.
  • Cleanup must run on all paths—use IF structure or caller finally pattern.
  • Replacing END-PROC—invalid; module must close.
  • Cross-activity jump—use GOTO within activity rules not EXIT from wrong PROC context.

Testing EXIT Paths

  1. PERFORM path hitting EXIT—confirm tail statements did not run.
  2. PERFORM path not hitting EXIT—full body executes.
  3. Caller state valid after EXIT return.
  4. EOF and error guards trigger EXIT in screen test.
  5. No resource leak when EXIT skips CLOSE—CLOSE must be elsewhere if needed.

Explain It Like I'm Five

EXIT is leaving the recipe early when you realize you are out of eggs. You stop reading the rest of that recipe card and go back to whoever asked you to cook. The recipe card still has an END at the bottom on the paper—you just did not do every step this time. You need another way to finish dinner if steps after EXIT were important.

Exercises

  1. Write BEFORE-SCREEN PROC with GET EOF EXIT pattern.
  2. Refactor nested IF to guard EXIT at PROC top.
  3. Diagram PERFORM/EXIT return to caller loop.
  4. List difference EXIT END-PROC GOTO STOP RUN.
  5. Move required cleanup before EXIT in flawed example.

Quiz

Test Your Knowledge

1. EXIT in a PROC:

  • Ends current procedure invocation early
  • Replaces END-PROC in source
  • Closes all files
  • Same as STOP RUN

2. After EXIT in PROC control returns:

  • To statement after PERFORM
  • To top of JOB
  • To JCL
  • Nowhere—program ends

3. EXIT versus END-PROC:

  • EXIT is runtime early leave; END-PROC closes module definition
  • Identical
  • EXIT is compile only
  • END-PROC is runtime only

4. BEFORE-SCREEN GET EOF often uses EXIT to:

  • Skip rest of screen setup when no record
  • Open files
  • Print report
  • Run SORT

5. EXIT does not replace:

  • END-IF, END-DO, or END-CASE terminators
  • PERFORM
  • MOVE
  • IF
Published
Read time14 min
AuthorMainframeMaster
Reviewed by MainframeMaster teamVerified: Broadcom Easytrieve 11.6 EXIT procedure early terminationSources: Broadcom Easytrieve 11.6 EXIT, PROC, Screen ProceduresApplies to: Easytrieve EXIT control flow