Easytrieve Procedures Overview

Procedures are Easytrieve's primary modularization unit—named blocks you call instead of copying the same twenty lines at every control break. A batch JOB might PERFORM CALC-TAX from detail logic and again from an exception path. A report defines BEFORE-LINE. PROC the product invokes before each printed line without explicit PERFORM from your code. Online SCREEN activities use BEFORE-SCREEN and AFTER-SCREEN hooks around terminal I/O. All share PROC and END-PROC syntax but differ in who calls them and where they may appear. Broadcom scopes procedures to the activity: JOB procedures are invisible to REPORT in the same program unless duplicated. Nesting PERFORM calls modularizes further but recursion is forbidden. This overview maps procedure categories for beginners, contrasts user PROCs with automatic hooks, explains PERFORM flow, previews nesting scope and parameters covered in later section pages, and ties procedures to arrays, file processing, and control flow tutorials you already studied. Use it as the roadmap before diving into PROC, END-PROC, nested procedures, calling conventions, scope, and parameters pages.

Progress0 of 0 lessons

Three Procedure Families

Procedure types in Easytrieve programs
FamilyInvoked byExamples
User PROCPERFORM in same activityCALC-TAX, VALIDATE-INPUT, OPEN-FILES
Report procedureReport writer automaticallyBEFORE-LINE, AFTER-BREAK, BEFORE-BREAK
Screen procedureSCREEN activity automaticallyINITIATION, BEFORE-SCREEN, AFTER-SCREEN, TERMINATION

User PROCs behave like paragraphs or sections in other languages—explicit call, explicit return via END-PROC. Report and screen procedures are event hooks tied to product lifecycle. Mixing them confuses beginners who PERFORM BEFORE-LINE from JOB logic—that hook runs only when report engine prints a line.

Basic User PROC Syntax

text
1
2
3
4
5
6
7
8
9
10
11
12
13
CALC-TAX. PROC IF GROSS GT EXEMPT-AMT TAX = (GROSS - EXEMPT-AMT) * RATE ELSE TAX = 0 END-IF END-PROC JOB INPUT PAYFILE PERFORM CALC-TAX IF TAX GT 0 PERFORM WRITE-TAX-RECORD END-IF

Label ends with period before PROC keyword per Easytrieve conventions. Statements between PROC and END-PROC execute on each PERFORM. Control returns to statement after PERFORM unless EXIT or STOP inside PROC terminates broader flow.

PERFORM and Return Flow

PERFORM name transfers control once per invocation. Nested PERFORM stacks returns like subroutine calls. END-PROC is mandatory delimiter; omitting it merges procedures with catastrophic compile errors or runaway flow. GOTO inside PROC can branch within procedure or exit depending on target labels—prefer structured IF and PERFORM over GOTO for maintainability. STOP RUN inside PROC ends entire program—not just procedure.

Activity Scope Rules

JOB activity PROCs serve JOB INPUT and JOB logic. REPORT activity PROCs serve that report subactivity. SCREEN PROCs belong to named SCREEN block. SORT activity may define PROCs for sort processing hooks. Cannot PERFORM JOB PROC from REPORT PROC—duplicate shared code into a Library macro included in both activities if maintenance requires single source. Activity boundary is compile-time enforcement beginners hit when copying sample code across sections.

Report Procedure Placement

Broadcom requires report special procedures immediately after the REPORT subactivity they serve—not grouped at file bottom far from REPORT statement. BEFORE-LINE runs before detail line print; AFTER-LINE after. BEFORE-BREAK and AFTER-BREAK bracket control field changes. Sequence matters for readability and some release diagnostics. See report control breaks tutorial for WHEN BREAK interaction.

text
1
2
3
4
5
6
7
8
9
REPORT PAYRPT SEQUENCE DEPT EMP-NO LINE DEPT EMP-NO GROSS TAX BEFORE-LINE. PROC IF LINE-COUNT GT 55 SKIP 2 END-IF END-PROC

Screen Procedure Overview

INITIATION once at SCREEN start. BEFORE-SCREEN each display cycle before map send. AFTER-SCREEN after terminal input. TERMINATION at SCREEN end. Restrictions apply: GOTO SCREEN invalid in BEFORE-SCREEN. Screen procedures parallel report hooks but target online I/O. Batch programmers learning SCREEN should read screen section tutorial after this overview.

Nesting and Modular Design

PROC A may PERFORM B; B may PERFORM C. Depth limited by product and shop standards—not infinite recursion. A calling B calling A is recursion and forbidden. Design leaf PROCs for smallest reusable units—format date, validate state code—and composite PROCs that PERFORM leaves. Array iteration tutorials use PERFORM PROCESS-ELEMENT inside DO loops—same modular idea.

Procedures Versus Paragraphs

Easytrieve also documents paragraph labels for GOTO targets without full PROC envelope in some contexts. Procedures are preferred for PERFORM modularization. Paragraphs suit sparse GOTO flow in legacy code. New development should default to PROC and END-PROC for clarity. Paragraphs page compares details.

Procedures Versus Macros

MACRO in Library expands at compile time—copy source in multiple activities. PROC is runtime call in one activity. Share cross-activity logic with macros; share repeated logic within activity with PROC. Macro page covers WHEN to choose expansion versus call overhead—usually negligible in batch.

Section Learning Path

  1. Procedures overview (this page) — map categories and scope.
  2. PROC — label, PROC keyword, body rules.
  3. END-PROC — termination and return semantics.
  4. Nested procedures — call chains and depth.
  5. Calling procedures — PERFORM variants and placement.
  6. Procedure scope — activity and name visibility.
  7. Procedure parameters — passing data when release supports parameter lists.

When to Create a Procedure

  • Same logic appears twice in one activity.
  • Detail and exception paths share validation block.
  • Report line setup exceeds five lines—move to BEFORE-LINE PROC.
  • Screen field initialization repeats each cycle—BEFORE-SCREEN PROC.
  • Unit testing mindset: PROC boundary is logical test chunk in walkthroughs.

Common Beginner Mistakes

  • PERFORM across activity boundary.
  • Missing END-PROC.
  • PERFORM report hook from JOB expecting manual invocation.
  • Recursion between two PROCs cleaning up shared flags.
  • STOP RUN inside utility PROC killing batch unexpectedly.

Explain It Like I'm Five

A procedure is a recipe card with a name. When the main program says perform recipe CALC-TAX, the computer follows that card and comes back to continue the main recipe. Some recipe cards are called automatically by the report printer before each line—that is BEFORE-LINE. You cannot use the report card from the homework section and the homework card from the report section—they live in different binders called activities.

Exercises

  1. Write CALC-TAX PROC with END-PROC and one PERFORM from JOB INPUT.
  2. List three special-name report procedures and when they run.
  3. Explain why JOB PROC cannot be PERFORMed from REPORT.
  4. Sketch call chain A performs B performs C without recursion.
  5. Decide PROC versus MACRO for logic shared by JOB and REPORT.

Quiz

Test Your Knowledge

1. User procedures are invoked with:

  • PERFORM procedure-name
  • JCL EXEC
  • FILE INPUT
  • DD *

2. Procedures are local to:

  • The activity where they are defined
  • Entire library globally
  • JCL only
  • SYSPRINT

3. Report BEFORE-LINE is:

  • A special-name report procedure
  • A JCL statement
  • A FILE type
  • An operator command

4. Recursion between PROCs is:

  • Not permitted
  • Required
  • Unlimited
  • Only in batch

5. Every PROC must end with:

  • END-PROC
  • END-JOB
  • END-IF only
  • STOP RUN always
Published
Read time16 min
AuthorMainframeMaster
Reviewed by MainframeMaster teamVerified: Broadcom Easytrieve 11.6 PROC, PERFORM, report and screen proceduresSources: Broadcom Easytrieve 11.6 Language Reference PROC, PERFORM, Report Procedures, Screen ProceduresApplies to: Easytrieve procedure structure overview