Easytrieve END Statements (Scope Terminators)

One of the first things beginners look for in Easytrieve is a general-purpose END statement, the way some languages use a single END to close any block. Easytrieve does not work that way, and it is important to say so plainly: there is no standalone END keyword in the language. Instead, Easytrieve provides a small family of hyphenated scope terminators, each named after the exact block it closes - END-IF for a conditional, END-DO for a loop, END-PROC for a procedure, and END-CASE for a CASE structure. This design is deliberate. Because each terminator names its block, the source reads clearly even when blocks are deeply nested, and the compiler can immediately flag a loop that was opened but never closed or an IF whose END-IF went missing. This page gathers the END family in one place so you can see how they relate, learn the one-to-one pairing rule that governs all of them, and understand the equally important fact that activities (JOB and SORT) are not closed by any terminator at all - they end when the next activity starts or when STOP runs. If you arrived here searching for "Easytrieve END statement", this is the page that explains what actually exists, why, and how to use each terminator correctly. We cover the format of every terminator, a comparison table, worked examples that show correct pairing, the STOP alternative for ending activities and the whole run, and the pairing mistakes that cause the most compile errors for newcomers.

Progress0 of 0 lessons

There Is No Bare END - Use the Right Terminator

Every block-opening statement in Easytrieve has a matching terminator, and you must use the one that belongs to that block. Writing a lone END will not compile. The table below lists each terminator, the statement it pairs with, and what happens when control reaches it. Learning these pairs is the whole skill: once you know which terminator closes which block, structured Easytrieve code becomes straightforward.

Easytrieve scope terminators and their partners
TerminatorCloses the block opened byEffect when reached
END-IFIF (with optional ELSE-IF / ELSE)Ends the decision; execution continues below
END-DODO WHILE / DO UNTILMarks the loop bottom; branches back to the test
END-PROCPROC (procedure)Returns control to the statement after PERFORM
END-CASECASEEnds the multi-way selection block

Note there is no END-JOB or END-SORT: activities are bounded differently, as explained further down. And ELSE-IF and ELSE never take their own terminator - the single END-IF closes the entire IF structure no matter how many branches it has.

END-IF: Closing a Decision

END-IF terminates the logic associated with the previous IF statement. Exactly one END-IF is required per IF, and it closes any ELSE-IF and ELSE branches too. After END-IF, processing continues regardless of which branch ran.

text
1
2
3
4
5
6
7
8
IF PAY-GROSS NOT NUMERIC DISPLAY EMP# ' PERSONNEL RECORD IS DAMAGED' GOTO JOB ELSE-IF PAY-GROSS > 500.00 XMAS-BONUS = PAY-GROSS * 1.03 ELSE XMAS-BONUS = PAY-GROSS * 1.05 END-IF

The one END-IF at the bottom closes the IF, the ELSE-IF, and the ELSE all at once. This is why multi-band decisions in Easytrieve stay tidy - there is never a stack of terminators to match.

END-DO: Closing a Loop

END-DO terminates the body of the loop associated with a DO WHILE or DO UNTIL statement. When control reaches END-DO it branches back to re-evaluate the loop condition. An END-DO must be specified after each DO statement and its associated statements; nested loops each need their own.

text
1
2
3
4
5
6
DO WHILE COUNT-1 LT 10 COUNT-1 = COUNT-1 + 1 DO WHILE COUNT-2 < 10 COUNT-2 = COUNT-2 + 1 END-DO END-DO

The inner END-DO closes the inner loop and the outer END-DO closes the outer loop. Matching them by indentation is the easiest way to be sure each loop is closed at the right point.

END-PROC: Closing a Procedure

END-PROC delimits the statements in a procedure defined by a PROC statement. A procedure is a named group of statements you invoke with PERFORM. When execution reaches END-PROC, control returns to the statement following the PERFORM that called it.

text
1
2
3
4
FINISH-PROC. PROC DISPLAY 'TOTAL $ SPENT IN BONUS ' + 'MONEY ====> ' TOT-XMAS-BONUS END-PROC

Every PROC must have an END-PROC. The procedure name and the PROC keyword open the block; END-PROC closes it and sends control back to the caller.

END-CASE: Closing a Selection

A CASE structure chooses one path from many based on the value of a field. END-CASE marks the end of that multi-way selection, in the same way END-IF ends a two-way decision. If you use CASE, you close it with END-CASE, not with END-IF.

text
1
2
3
4
5
6
7
8
CASE REGION-CODE CASE 'N' PERFORM PROCESS-NORTH CASE 'S' PERFORM PROCESS-SOUTH OTHERWISE PERFORM PROCESS-OTHER END-CASE

Ending Activities: STOP, Not a Terminator

Activities are the exception. A JOB or SORT activity has no closing keyword. It ends automatically when the next JOB or SORT activity begins, or when a STOP statement runs. This surprises people who expect an END-JOB. STOP ends the current activity, still running any FINISH procedure attached to it, and then moves on to the next activity if one exists. STOP EXECUTE is stronger: it ends all activities immediately without continuing to the next one.

Ending blocks versus ending activities and the run
What you want to endWhat you code
An IF decisionEND-IF
A DO loopEND-DO
A procedureEND-PROC
A CASE selectionEND-CASE
The current JOB/SORT activitySTOP (or start the next activity)
The entire program immediatelySTOP EXECUTE

Common END Mistakes

  • Writing a bare END - it does not exist; use the specific hyphenated terminator.
  • Closing a loop with END-IF or a decision with END-DO - the terminator must match its block.
  • Looking for END-JOB - activities end at the next activity or at STOP instead.
  • Adding an END-IF after every ELSE-IF - one END-IF closes the whole IF chain.
  • Forgetting an inner END-DO or END-IF in nested logic, so an outer terminator gets mispaired.
  • Confusing END-PROC with RETURN - END-PROC closes the procedure body; the return happens there automatically.

Explain It Like I'm Five

Think of each kind of block as a different box with its own lid. A loop box has a lid called END-DO. A yes/no box has a lid called END-IF. A helper-task box has a lid called END-PROC. You have to put the right lid on the right box - you cannot use one magic lid for everything, and there is no plain lid just called END. And the big work sessions (the activities) do not get a lid at all; they finish when the next session starts or when someone says STOP.

Exercises

  1. List the four hyphenated terminators and the statement each one closes.
  2. Explain why writing a bare END will not compile.
  3. Write a nested IF inside a DO loop and mark which terminator closes which block.
  4. State how a JOB activity ends and name the two ways to trigger it.
  5. Describe the difference between STOP and STOP EXECUTE in one sentence each.

Quiz

Test Your Knowledge

1. Is there a standalone END statement in Easytrieve?

  • No - Easytrieve uses hyphenated terminators like END-IF, END-DO, and END-PROC
  • Yes - END ends the whole program
  • Yes - END closes any open block
  • Yes - END is the same as STOP

2. Which terminator closes a DO WHILE or DO UNTIL loop?

  • END-DO
  • END-LOOP
  • END-IF
  • END-WHILE

3. Which terminator marks the end of a procedure?

  • END-PROC
  • END-SUB
  • RETURN
  • STOP

4. How do you end a JOB or SORT activity - is there an END-JOB?

  • There is no END-JOB; an activity ends at the next JOB/SORT or at STOP
  • END-JOB closes it
  • END closes it
  • END-ACTIVITY closes it

5. What is the effect of a missing END-IF?

  • A compile error - the IF block is never properly closed
  • The program runs but ignores the IF
  • Nothing - END-IF is optional
  • It becomes a loop

Related Pages

Published
Read time15 min
AuthorMainframeMaster
Reviewed by MainframeMaster teamVerified: Broadcom Easytrieve Report Generator 11.6 statements index (END-IF, END-DO, END-PROC)Sources: Broadcom Easytrieve 11.6 Language Reference Statements index; END-PROC Statement; IF/ELSE/END-IF; DO UNTIL and DO WHILEApplies to: Easytrieve END-* scope terminators