Easytrieve Procedure Scope

Procedure scope answers one question: who may PERFORM whom? In Easytrieve the answer is strict—only code inside the same activity as the PROC definition. A module at the end of JOB PAYROLL is invisible to PERFORM in JOB BONUS even when both activities sit in one source member. Library fields are program-wide, but procedure labels are activity-local. This tutorial maps activity boundaries, duplicate label rules across activities, report PROC placement within JOB scope, SCREEN isolation, SORT BEFORE procs, and refactoring patterns when shared logic must cross activity lines. Scope errors compile as undefined procedure and frustrate beginners who assume global visibility like COBOL COPY sharing.

Progress0 of 0 lessons

Activity as Scope Boundary

An activity is a major division of an Easytrieve program: JOB name, SORT name, SCREEN name, PROGRAM name. Each activity contains executable statements plus PROC modules defined at its tail (or embedded for SCREEN). The compiler associates each PROC label with exactly one activity context. PERFORM resolves labels only in the current activity during compilation of that activity's executable section. Cross-activity PERFORM is not supported—you duplicate logic, use macros for compile-time reuse, or CALL external programs for runtime sharing.

text
1
2
3
4
5
6
7
8
9
10
11
12
13
JOB INPUT FILE-A PERFORM PROCESS-A PROCESS-A. PROC COUNT-A = COUNT-A + 1 END-PROC JOB INPUT FILE-B PERFORM PROCESS-B PROCESS-B. PROC COUNT-B = COUNT-B + 1 END-PROC

PROCESS-A cannot be PERFORMed from the second JOB; PROCESS-B cannot be reached from the first. COUNT-A and COUNT-B fields in Library remain visible everywhere if defined globally, but labels are not linked across the JOB boundary.

Scope Versus Data Visibility

Beginners conflate procedure scope with variable scope. Easytrieve PROC modules do not create private variable namespaces like block scope in C. Fields defined in Library, FILE layouts, and working storage are visible in all activities unless your design uses separate files or deliberate naming conventions. PROC scope limits PERFORM label resolution only. Two activities may read and write the same GRAND-TOTAL field while maintaining separate CALC. PROC modules that each add to GRAND-TOTAL—coordinate concurrency if both activities run in one execution path.

What scope controls versus what stays global
ItemScope behavior
PROC label for PERFORMActivity-local only
Library DEFINE fieldsProgram-wide unless redefined per rules
FILE record buffersVisible per FILE definition across activities using that FILE
Report special-name PROCTied to REPORT within same JOB activity
MACRO expanded codeCompile-time copy into each use site

Duplicate Labels in Different Activities

Reusing CALC-TAX. PROC in two JOB activities is legal: each JOB owns its copy. Maintenance must update both when tax rules change unless you convert shared lines to a stored MACRO invoked in each activity. Some teams suffix labels CALC-TAX-A and CALC-TAX-B to force visual distinction in PERFORM lists even when logic is identical. Duplicate labels within one activity remain illegal—the compiler rejects two PROCESS-A. PROC definitions in the same JOB.

Report PROC Scope Within JOB

REPORT subactivities live inside a JOB activity. Report PROCs immediately follow their REPORT and share that JOB's procedure namespace with user job PROCs like START and CALC-TOTAL. BEFORE-LINE in REPORT DETAIL may PERFORM CALC-TOTAL defined among job PROCs above the REPORT block. Report PROCs from REPORT SUMMARY are not visible to REPORT DETAIL—each REPORT carries its own hook set. Multiple REPORTs mean multiple BEFORE-LINE modules with the same special name but different source positions tied to each REPORT.

SCREEN and SORT Activity Isolation

SCREEN activities define INITIATION, BEFORE-SCREEN, and related PROCs inside the SCREEN block. JOB PERFORM cannot reach them. Online programs that also batch may duplicate validation PROC logic or extract shared validation to CALLed COBOL. SORT activities name BEFORE prescreen PROCs on the SORT statement; that label opens with PROC after the SORT activity header. JOB following SORT in program order is a separate activity—prescreen PROC cannot PERFORM job modules from a later JOB unless you restructure so both share one activity, which is usually impossible for SORT versus JOB roles.

Refactoring Across Scope Boundaries

MACRO for compile-time sharing

When identical statement blocks must appear in two activities, a MACRO with parameters expands into each site at compile time. Runtime PERFORM linkage does not cross scope; macro expansion does not need PERFORM.

CALL external subprogram

Tax calculation in COBOL called from PROC inside each activity shares one load module. Prepare USING fields before CALL identically in each duplicated thin PROC wrapper.

Accept controlled duplication

Small divergent activities may tolerate two similar PROC copies when merge cost exceeds benefit. Document both in change control when business rules update.

Scope and Program Structure Planning

  1. List activities in program execution order before coding PROCs.
  2. Place shared utilities inside each activity that needs them or choose macro/CALL strategy upfront.
  3. Keep report PROCs adjacent to their REPORT—never consolidate report hooks at file bottom away from REPORT.
  4. Name user PROCs distinctly when logic differs even if labels could legally duplicate across activities.
  5. Review compile listing activity sections to confirm PROC labels appear under expected activity headers.

Common Scope Mistakes

  • PERFORM from second JOB to PROC defined only in first JOB.
  • Assuming Library PROC or COPY makes labels global—they do not.
  • Moving report PROCs away from their REPORT invalidates hook binding.
  • Expecting SCREEN PROC from batch JOB in mixed programs without duplication.
  • Duplicate label in same activity after merge conflict in source control.
  • Confusing macro reuse with PERFORM scope crossing activities.

Explain It Like I'm Five

Each classroom has its own box of name tags for helper jobs. You can only pick a name tag from the box in your classroom. If two classrooms both have a tag called line-leader, they are different kids because the boxes are separate. Everyone in the school can still use the same hallway clock—that is like shared fields—but the name tags for helpers stay in each room's box.

Exercises

  1. Draw two JOB activities and mark which PERFORM links are valid with arrows.
  2. Explain why BEFORE-LINE can PERFORM a job PROC but second JOB cannot.
  3. Propose macro versus CALL for shared validation across JOB and SCREEN.
  4. Find duplicate label risk in a merged source with two CALC-TAX. PROC in one JOB.
  5. Write team documentation distinguishing field visibility from PROC label scope.

Quiz

Test Your Knowledge

1. A PROC defined in JOB PAYROLL can be PERFORMed from:

  • Only within JOB PAYROLL activity
  • Any JOB in the source
  • JCL PROC
  • Library PARM

2. Two JOB activities may each define CALC-TAX. PROC because:

  • Labels are scoped per activity
  • Labels must be globally unique
  • Second definition overrides first
  • Compiler merges them

3. Report PROCs must appear:

  • Immediately after their REPORT subactivity
  • Before PARM
  • In STEPLIB
  • Only in SCREEN

4. Library DEFINE fields inside a PROC are visible:

  • Throughout the program including all activities
  • Only inside that PROC
  • Only in JCL
  • Never to PERFORM callers

5. PERFORM from JOB A to PROC in JOB B fails because:

  • Activity scope prevents cross-activity procedure linkage
  • END-PROC missing
  • Labels too long
  • REPORT required
Published
Read time14 min
AuthorMainframeMaster
Reviewed by MainframeMaster teamVerified: Broadcom Easytrieve Report Generator 11.6 procedure activity scopeSources: Broadcom Easytrieve 11.6 Language Reference PROC, activity structure, PERFORMApplies to: Easytrieve procedure scope and activity-local PERFORM