MainframeMaster

COBOL Tutorial

COBOL END-OBJECT Clause - Quick Reference

Progress0 of 0 lessons

Overview

The END-OBJECT clause is used to terminate an object definition in object-oriented COBOL. This clause marks the end of an object scope and completes the object structure, working in conjunction with the OBJECT clause to define complete object definitions.

Purpose and Usage

  • Object termination - Mark the end of an object definition
  • Scope management - Close object scope properly
  • Structure completion - Complete object structure
  • OOP support - Support object-oriented programming
  • Compilation aid - Help compiler understand object boundaries

Object Structure Concept

Object Definition: [OBJECT] → [Object Content] → [END-OBJECT]
Object Scope: [Start of Object] → [Properties/Data] → [End of Object]
Structure: [OBJECT object-name] → [Object Body] → [END-OBJECT]
END-OBJECT properly terminates the object definition

END-OBJECT provides proper object termination and scope management.

Syntax

The END-OBJECT clause follows specific syntax patterns and is used to terminate object definitions in object-oriented 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
* Basic END-OBJECT clause syntax OBJECT object-name. * Object content goes here * Properties, data, etc. END-OBJECT. * Examples OBJECT CustomerObject. * Customer object properties and data END-OBJECT. OBJECT BankAccountObject. * Bank account object properties and data END-OBJECT. * Complete example OBJECT EmployeeObject. DATA DIVISION. WORKING-STORAGE SECTION. 01 EMPLOYEE-NAME PIC X(50). 01 EMPLOYEE-ID PIC 9(5). 01 EMPLOYEE-SALARY PIC 9(8)V99. 01 EMPLOYEE-DEPARTMENT PIC X(30). * Object properties and methods can be defined here * Additional object content END-OBJECT.

END-OBJECT terminates an object definition that was started with OBJECT.

Object Structure Requirements

ComponentRequiredPurpose
OBJECTYesStart object definition
Object contentOptionalProperties, data, methods
END-OBJECTYesTerminate object definition
DATA DIVISIONOptionalObject data and properties

Multiple Objects 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
* Multiple objects in a single program OBJECT CustomerObject. DATA DIVISION. WORKING-STORAGE SECTION. 01 CUSTOMER-NAME PIC X(50). 01 CUSTOMER-ID PIC 9(5). 01 CUSTOMER-ADDRESS PIC X(100). * Customer object properties and methods END-OBJECT. OBJECT OrderObject. DATA DIVISION. WORKING-STORAGE SECTION. 01 ORDER-NUMBER PIC 9(10). 01 ORDER-AMOUNT PIC 9(8)V99. 01 ORDER-DATE PIC 9(8). * Order object properties and methods END-OBJECT. OBJECT ProductObject. DATA DIVISION. WORKING-STORAGE SECTION. 01 PRODUCT-CODE PIC X(10). 01 PRODUCT-NAME PIC X(50). 01 PRODUCT-PRICE PIC 9(6)V99. * Product object properties and methods END-OBJECT. * Main program PROGRAM-ID MainProgram. * Main program logic here END PROGRAM.

Each object must be properly terminated with its own END-OBJECT clause.

Common Use Cases

END-OBJECT is commonly used in specific scenarios where object-oriented programming with objects is needed.

Business Entity Objects

cobol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
* Business entity object definition OBJECT CustomerObject. DATA DIVISION. WORKING-STORAGE SECTION. 01 CUSTOMER-NAME PIC X(50). 01 CUSTOMER-ID PIC 9(5). 01 CUSTOMER-ADDRESS PIC X(100). 01 CUSTOMER-PHONE PIC X(15). 01 CUSTOMER-EMAIL PIC X(100). 01 CUSTOMER-STATUS PIC X. 88 ACTIVE-CUSTOMER VALUE "A". 88 INACTIVE-CUSTOMER VALUE "I". * Customer object properties and validation rules * Business logic for customer operations END-OBJECT.

Define business entity objects with proper object termination.

Data Container Objects

cobol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
* Data container object for structured data OBJECT TransactionObject. DATA DIVISION. WORKING-STORAGE SECTION. 01 TRANSACTION-ID PIC 9(10). 01 TRANSACTION-TYPE PIC X. 88 DEBIT-TRANSACTION VALUE "D". 88 CREDIT-TRANSACTION VALUE "C". 01 TRANSACTION-AMOUNT PIC 9(8)V99. 01 TRANSACTION-DATE PIC 9(8). 01 TRANSACTION-TIME PIC 9(6). 01 ACCOUNT-NUMBER PIC 9(10). 01 TRANSACTION-DESCRIPTION PIC X(100). * Transaction object properties and validation * Data integrity rules and constraints END-OBJECT.

Create data container objects for structured data management.

Configuration Objects

cobol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
* Configuration object for application settings OBJECT ConfigObject. DATA DIVISION. WORKING-STORAGE SECTION. 01 DATABASE-URL PIC X(200). 01 DATABASE-USERNAME PIC X(50). 01 DATABASE-PASSWORD PIC X(50). 01 LOG-LEVEL PIC X. 88 DEBUG-LEVEL VALUE "D". 88 INFO-LEVEL VALUE "I". 88 ERROR-LEVEL VALUE "E". 01 MAX-CONNECTIONS PIC 9(3). 01 TIMEOUT-SECONDS PIC 9(3). 01 APPLICATION-NAME PIC X(50). 01 VERSION-NUMBER PIC X(20). * Configuration object properties and defaults * Application configuration management END-OBJECT.

Define configuration objects for application settings.

Best Practices and Tips

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

END-OBJECT Design Principles

  • Always include END-OBJECT - Never forget to terminate object definitions
  • Match OBJECT and END-OBJECT - Ensure proper object scope closure
  • Use meaningful object names - Choose descriptive object names
  • Organize object content - Structure object properties and data logically
  • Document object purpose - Clearly document what each object does
  • Test object structure - Verify that objects compile and work correctly

Common Pitfalls to Avoid

PitfallProblemSolution
Missing END-OBJECTCompilation errors, undefined object scopeAlways include END-OBJECT after object definition
Mismatched OBJECT/END-OBJECTObject structure errorsEnsure each OBJECT has corresponding END-OBJECT
Poor object organizationDifficult to maintain and understandOrganize object content logically
Unclear object namesConfusing code structureUse descriptive and meaningful object names
Not documenting objectsDifficult to understand object purposeDocument object purpose and functionality

Performance Considerations

  • Object instantiation overhead - Creating objects has overhead
  • Memory usage - Objects consume additional memory
  • Compilation time - Object-oriented features may increase compilation time
  • Runtime performance - Consider performance impact of OOP features
  • Object complexity - Complex objects may affect performance
  • Object lifecycle management - Object creation and destruction overhead

When to Use END-OBJECT

Use CaseEND-OBJECT SuitabilityReasoning
Object-oriented programmingEssentialRequired for proper object structure
Business entity modelingExcellentPerfect for modeling business entities
Data organizationGoodHelps organize data into logical units
Traditional COBOLNot applicableOnly for object-oriented COBOL
Simple programsPoorUnnecessary complexity for simple logic

END-OBJECT Clause Quick Reference

UsageSyntaxExample
Basic object terminationEND-OBJECT.END-OBJECT.
Complete object structureOBJECT name. ... END-OBJECT.OBJECT MyObject. ... END-OBJECT.
Multiple objectsMultiple OBJECT/END-OBJECT pairsOBJECT Object1. ... END-OBJECT.
OBJECT Object2. ... END-OBJECT.
Object with dataOBJECT name. DATA DIVISION. ... END-OBJECT.OBJECT MyObject. DATA DIVISION. ... END-OBJECT.
Object with propertiesOBJECT name. ... properties ... END-OBJECT.OBJECT MyObject. ... properties ... END-OBJECT.

Test Your Knowledge

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

  • To define data types
  • To terminate an object definition in object-oriented COBOL
  • To control file operations
  • To perform calculations

2. What must precede the END-OBJECT clause?

  • Any COBOL statement
  • An OBJECT clause
  • A PROCEDURE DIVISION
  • A DATA DIVISION

3. What is the relationship between OBJECT and END-OBJECT?

  • They are independent
  • OBJECT starts an object, END-OBJECT ends it
  • They serve the same purpose
  • They are optional

4. When is END-OBJECT most useful?

  • In traditional COBOL programs
  • In object-oriented COBOL programs with objects
  • Only during compilation
  • Only during program termination

5. How does END-OBJECT relate to object-oriented programming?

  • They are completely independent
  • END-OBJECT is essential for proper object structure in OOP
  • END-OBJECT overrides OOP features
  • They serve the same purpose

Frequently Asked Questions