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.
END-PROGRAM provides proper program termination and scope management.
The END-PROGRAM clause follows specific syntax patterns and is used to terminate program definitions in COBOL.
123456789101112131415161718192021222324252627282930313233343536* 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.
Component | Required | Purpose |
---|---|---|
PROGRAM-ID | Yes | Start program definition |
Program content | Optional | Divisions, sections, logic |
END-PROGRAM | Yes | Terminate program definition |
PROCEDURE DIVISION | Optional | Program logic implementation |
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253* 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.
END-PROGRAM is commonly used in specific scenarios where program structure and termination is needed.
12345678910111213141516171819202122232425262728* 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.
123456789101112131415161718192021222324252627282930313233343536373839* 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.
12345678910111213141516171819202122232425262728293031323334* 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.
Following these best practices ensures effective use of the END-PROGRAM clause for proper program structure and termination.
Pitfall | Problem | Solution |
---|---|---|
Missing END-PROGRAM | Compilation errors, undefined program scope | Always include END-PROGRAM after program definition |
Mismatched PROGRAM-ID/END-PROGRAM | Program structure errors | Ensure each PROGRAM-ID has corresponding END-PROGRAM |
Poor program organization | Difficult to maintain and understand | Organize program content logically |
Unclear program names | Confusing code structure | Use descriptive and meaningful program names |
Not documenting programs | Difficult to understand program purpose | Document program purpose and functionality |
Use Case | END-PROGRAM Suitability | Reasoning |
---|---|---|
All COBOL programs | Essential | Required for proper program structure |
Multi-program files | Excellent | Perfect for organizing multiple programs |
Code organization | Good | Helps organize code into logical units |
Object-oriented COBOL | Good | Works well with OOP features |
Simple scripts | Poor | Unnecessary complexity for simple scripts |
Usage | Syntax | Example |
---|---|---|
Basic program termination | END PROGRAM. | END PROGRAM. |
Complete program structure | PROGRAM-ID name. ... END PROGRAM. | PROGRAM-ID MyProgram. ... END PROGRAM. |
Multiple programs | Multiple PROGRAM-ID/END PROGRAM pairs | PROGRAM-ID Program1. ... END PROGRAM. PROGRAM-ID Program2. ... END PROGRAM. |
Program with divisions | PROGRAM-ID name. ENVIRONMENT DIVISION. ... END PROGRAM. | PROGRAM-ID MyProgram. ENVIRONMENT DIVISION. ... END PROGRAM. |
Program with procedures | PROGRAM-ID name. ... PROCEDURE DIVISION. ... END PROGRAM. | PROGRAM-ID MyProgram. ... PROCEDURE DIVISION. ... END PROGRAM. |
1. What is the primary purpose of the END-PROGRAM clause in COBOL?
2. What must precede the END-PROGRAM clause?
3. What is the relationship between PROGRAM-ID and END-PROGRAM?
4. When is END-PROGRAM most useful?
5. How does END-PROGRAM relate to program structure?
Understanding the PROGRAM-ID clause for program definition.
Understanding the END-CLASS clause for class termination.
Understanding the END-OBJECT clause for object termination.
Complete guide to COBOL program organization.
Understanding object-oriented COBOL programming.