MainframeMaster

COBOL Tutorial

COBOL END-PROGRAM Clause - Quick Reference

Progress0 of 0 lessons

Overview

The END-PROGRAM clause is used to terminate a program definition in COBOL. This clause marks the end of a program scope and completes the program structure, working in conjunction with the PROGRAM-ID clause to define complete program definitions.

Purpose and Usage

  • Program termination - Mark the end of a program definition
  • Scope management - Close program scope properly
  • Structure completion - Complete program structure
  • Compilation aid - Help compiler understand program boundaries
  • Code organization - Organize multiple programs in single file

Program Structure Concept

Program Definition: [PROGRAM-ID] → [Program Content] → [END-PROGRAM]
Program Scope: [Start of Program] → [Divisions/Sections] → [End of Program]
Structure: [PROGRAM-ID program-name] → [Program Body] → [END-PROGRAM]
END-PROGRAM properly terminates the program definition

END-PROGRAM provides proper program termination and scope management.

Syntax

The END-PROGRAM clause follows specific syntax patterns and is used to terminate program definitions in COBOL.

Basic Syntax

cobol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
* Basic END-PROGRAM clause syntax PROGRAM-ID program-name. * Program content goes here * Divisions, sections, etc. END PROGRAM. * Examples PROGRAM-ID CustomerProgram. * Customer program logic here END PROGRAM. PROGRAM-ID BankProgram. * Bank program logic here END PROGRAM. * Complete example PROGRAM-ID EmployeeProgram. ENVIRONMENT DIVISION. CONFIGURATION SECTION. SOURCE-COMPUTER. IBM-PC. OBJECT-COMPUTER. IBM-PC. DATA DIVISION. WORKING-STORAGE SECTION. 01 EMPLOYEE-NAME PIC X(50). 01 EMPLOYEE-ID PIC 9(5). PROCEDURE DIVISION. MAIN-LOGIC. DISPLAY "Employee Program Started" MOVE "John Doe" TO EMPLOYEE-NAME MOVE 12345 TO EMPLOYEE-ID DISPLAY "Employee: " EMPLOYEE-NAME DISPLAY "ID: " EMPLOYEE-ID STOP RUN. END PROGRAM.

END-PROGRAM terminates a program definition that was started with PROGRAM-ID.

Program Structure Requirements

ComponentRequiredPurpose
PROGRAM-IDYesStart program definition
Program contentOptionalDivisions, sections, logic
END-PROGRAMYesTerminate program definition
PROCEDURE DIVISIONOptionalProgram logic implementation

Multiple Programs Example

cobol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
* Multiple programs in a single file PROGRAM-ID CustomerProgram. ENVIRONMENT DIVISION. CONFIGURATION SECTION. DATA DIVISION. WORKING-STORAGE SECTION. 01 CUSTOMER-NAME PIC X(50). 01 CUSTOMER-ID PIC 9(5). PROCEDURE DIVISION. MAIN-LOGIC. DISPLAY "Customer Program" MOVE "John Doe" TO CUSTOMER-NAME MOVE 12345 TO CUSTOMER-ID DISPLAY "Customer: " CUSTOMER-NAME STOP RUN. END PROGRAM. PROGRAM-ID OrderProgram. ENVIRONMENT DIVISION. CONFIGURATION SECTION. DATA DIVISION. WORKING-STORAGE SECTION. 01 ORDER-NUMBER PIC 9(10). 01 ORDER-AMOUNT PIC 9(8)V99. PROCEDURE DIVISION. MAIN-LOGIC. DISPLAY "Order Program" MOVE 1000000001 TO ORDER-NUMBER MOVE 150.75 TO ORDER-AMOUNT DISPLAY "Order: " ORDER-NUMBER DISPLAY "Amount: " ORDER-AMOUNT STOP RUN. END PROGRAM. PROGRAM-ID ReportProgram. ENVIRONMENT DIVISION. CONFIGURATION SECTION. DATA DIVISION. WORKING-STORAGE SECTION. 01 REPORT-TITLE PIC X(50). PROCEDURE DIVISION. MAIN-LOGIC. DISPLAY "Report Program" MOVE "Monthly Sales Report" TO REPORT-TITLE DISPLAY "Title: " REPORT-TITLE STOP RUN. END PROGRAM.

Each program must be properly terminated with its own END-PROGRAM clause.

Common Use Cases

END-PROGRAM is commonly used in specific scenarios where program structure and termination is needed.

Single Program Files

cobol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
* Single program in a file PROGRAM-ID MainProgram. ENVIRONMENT DIVISION. CONFIGURATION SECTION. SOURCE-COMPUTER. IBM-PC. OBJECT-COMPUTER. IBM-PC. DATA DIVISION. WORKING-STORAGE SECTION. 01 PROGRAM-TITLE PIC X(50) VALUE "Main Application Program". 01 VERSION-NUMBER PIC X(10) VALUE "1.0". PROCEDURE DIVISION. MAIN-LOGIC. DISPLAY "Program: " PROGRAM-TITLE DISPLAY "Version: " VERSION-NUMBER PERFORM PROCESS-DATA PERFORM GENERATE-REPORT STOP RUN. PROCESS-DATA. DISPLAY "Processing data..." * Data processing logic here GENERATE-REPORT. DISPLAY "Generating report..." * Report generation logic here END PROGRAM.

Define single programs with proper program termination.

Multi-Program Files

cobol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
* Multiple programs in a single file PROGRAM-ID UtilityProgram. ENVIRONMENT DIVISION. CONFIGURATION SECTION. DATA DIVISION. WORKING-STORAGE SECTION. 01 UTILITY-NAME PIC X(30) VALUE "Data Utility". PROCEDURE DIVISION. MAIN-LOGIC. DISPLAY "Utility: " UTILITY-NAME PERFORM CLEAN-DATA STOP RUN. CLEAN-DATA. DISPLAY "Cleaning data..." * Data cleaning logic here END PROGRAM. PROGRAM-ID ReportGenerator. ENVIRONMENT DIVISION. CONFIGURATION SECTION. DATA DIVISION. WORKING-STORAGE SECTION. 01 REPORT-TYPE PIC X(20). PROCEDURE DIVISION. MAIN-LOGIC. MOVE "Sales Report" TO REPORT-TYPE DISPLAY "Generating: " REPORT-TYPE PERFORM CREATE-REPORT STOP RUN. CREATE-REPORT. DISPLAY "Creating report..." * Report creation logic here END PROGRAM.

Create multiple programs in a single file with proper termination.

Object-Oriented Programs

cobol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
* Object-oriented program with classes CLASS-ID CustomerClass. DATA DIVISION. WORKING-STORAGE SECTION. 01 CUSTOMER-NAME PIC X(50). 01 CUSTOMER-ID PIC 9(5). METHOD-ID CONSTRUCTOR. DATA DIVISION. LINKAGE SECTION. 01 CUST-NAME PIC X(50). 01 CUST-ID PIC 9(5). PROCEDURE DIVISION USING CUST-NAME CUST-ID. MOVE CUST-NAME TO CUSTOMER-NAME MOVE CUST-ID TO CUSTOMER-ID END METHOD. END-CLASS. PROGRAM-ID OOProgram. ENVIRONMENT DIVISION. CONFIGURATION SECTION. DATA DIVISION. WORKING-STORAGE SECTION. 01 CUSTOMER-OBJECT OBJECT REFERENCE CustomerClass. PROCEDURE DIVISION. MAIN-LOGIC. DISPLAY "Object-Oriented Program" INVOKE CustomerClass "new" USING "John Doe" 12345 RETURNING CUSTOMER-OBJECT DISPLAY "Customer object created" STOP RUN. END PROGRAM.

Define object-oriented programs with proper program termination.

Best Practices and Tips

Following these best practices ensures effective use of the END-PROGRAM clause for proper program structure and termination.

END-PROGRAM Design Principles

  • Always include END-PROGRAM - Never forget to terminate program definitions
  • Match PROGRAM-ID and END-PROGRAM - Ensure proper program scope closure
  • Use meaningful program names - Choose descriptive program names
  • Organize program content - Structure program divisions and sections logically
  • Document program purpose - Clearly document what each program does
  • Test program structure - Verify that programs compile and work correctly

Common Pitfalls to Avoid

PitfallProblemSolution
Missing END-PROGRAMCompilation errors, undefined program scopeAlways include END-PROGRAM after program definition
Mismatched PROGRAM-ID/END-PROGRAMProgram structure errorsEnsure each PROGRAM-ID has corresponding END-PROGRAM
Poor program organizationDifficult to maintain and understandOrganize program content logically
Unclear program namesConfusing code structureUse descriptive and meaningful program names
Not documenting programsDifficult to understand program purposeDocument program purpose and functionality

Performance Considerations

  • Program compilation - END-PROGRAM helps compiler understand program boundaries
  • Memory management - Proper program termination aids memory management
  • Code organization - END-PROGRAM improves code organization and readability
  • Multi-program files - END-PROGRAM enables multiple programs in single file
  • Scope management - Proper program scope termination prevents conflicts
  • Maintenance - Clear program boundaries improve maintainability

When to Use END-PROGRAM

Use CaseEND-PROGRAM SuitabilityReasoning
All COBOL programsEssentialRequired for proper program structure
Multi-program filesExcellentPerfect for organizing multiple programs
Code organizationGoodHelps organize code into logical units
Object-oriented COBOLGoodWorks well with OOP features
Simple scriptsPoorUnnecessary complexity for simple scripts

END-PROGRAM Clause Quick Reference

UsageSyntaxExample
Basic program terminationEND PROGRAM.END PROGRAM.
Complete program structurePROGRAM-ID name. ... END PROGRAM.PROGRAM-ID MyProgram. ... END PROGRAM.
Multiple programsMultiple PROGRAM-ID/END PROGRAM pairsPROGRAM-ID Program1. ... END PROGRAM.
PROGRAM-ID Program2. ... END PROGRAM.
Program with divisionsPROGRAM-ID name. ENVIRONMENT DIVISION. ... END PROGRAM.PROGRAM-ID MyProgram. ENVIRONMENT DIVISION. ... END PROGRAM.
Program with proceduresPROGRAM-ID name. ... PROCEDURE DIVISION. ... END PROGRAM.PROGRAM-ID MyProgram. ... PROCEDURE DIVISION. ... END PROGRAM.

Test Your Knowledge

1. What is the primary purpose of the END-PROGRAM clause in COBOL?

  • To define data types
  • To terminate a program definition in COBOL
  • To control file operations
  • To perform calculations

2. What must precede the END-PROGRAM clause?

  • Any COBOL statement
  • A PROGRAM-ID clause
  • A PROCEDURE DIVISION
  • A DATA DIVISION

3. What is the relationship between PROGRAM-ID and END-PROGRAM?

  • They are independent
  • PROGRAM-ID starts a program, END-PROGRAM ends it
  • They serve the same purpose
  • They are optional

4. When is END-PROGRAM most useful?

  • In all COBOL programs
  • In object-oriented COBOL programs only
  • Only during compilation
  • Only during program termination

5. How does END-PROGRAM relate to program structure?

  • They are completely independent
  • END-PROGRAM is essential for proper program structure
  • END-PROGRAM overrides program features
  • They serve the same purpose

Frequently Asked Questions