MainframeMaster

COBOL Tutorial

COBOL END-ACCEPT Statement

The END-ACCEPT statement represents a crucial component of structured COBOL programming, serving as an explicit scope terminator that clearly defines the boundaries of ACCEPT statement blocks. This statement embodies modern programming principles by providing unambiguous termination points for input processing operations, enabling sophisticated error handling, and supporting the development of robust, maintainable enterprise applications that require precise control over user input and data acquisition processes.

In contemporary enterprise COBOL development, END-ACCEPT plays a vital role in creating interactive applications that must handle complex input scenarios, validation requirements, and error conditions. By providing explicit termination for ACCEPT blocks, this statement enables developers to implement sophisticated input processing logic while maintaining code clarity and ensuring that input operations are properly bounded and controlled within the application's execution flow.

Understanding END-ACCEPT Architecture

The END-ACCEPT statement implements a sophisticated scope management system specifically designed for input processing operations. This architecture addresses the complexity inherent in modern input handling scenarios where ACCEPT statements must manage multiple input sources, validation rules, error conditions, and conditional processing paths. The explicit termination provided by END-ACCEPT ensures that all these operations are properly contained within defined boundaries.

The architectural design of END-ACCEPT reflects the evolution of COBOL toward structured programming paradigms that emphasize clarity, maintainability, and error prevention. When used with conditional phrases like ON EXCEPTION and NOT ON EXCEPTION, END-ACCEPT creates a comprehensive framework for handling both successful input operations and error conditions that may arise during data acquisition.

END-ACCEPT also plays a crucial role in compiler optimization and code analysis. Modern COBOL compilers can perform more sophisticated analysis when input processing blocks are explicitly terminated, leading to better error detection during compilation and more efficient runtime code generation. This capability is particularly important in enterprise environments where performance and reliability are critical requirements.

Key END-ACCEPT Capabilities:

  • Explicit Scope Termination: Provides clear boundaries for ACCEPT statement blocks, eliminating ambiguity in nested input processing structures.
  • Conditional Processing Support: Works with ON EXCEPTION and NOT ON EXCEPTION phrases to create comprehensive error handling frameworks.
  • Nested Structure Management: Enables proper handling of complex nested input scenarios with multiple ACCEPT statements.
  • Error Handling Integration: Supports sophisticated error handling patterns by clearly defining the scope of exception processing.
  • Code Readability Enhancement: Improves code structure and readability by providing explicit termination points for input operations.
  • Compiler Optimization: Enables better compiler analysis and optimization by providing clear block boundaries.

Input Processing Patterns

END-ACCEPT enables the implementation of sophisticated input processing patterns that are essential for modern enterprise applications. These patterns include interactive data entry with real-time validation, batch input processing with comprehensive error handling, and complex multi-step input scenarios that require precise control over the input flow and error management.

The use of END-ACCEPT in conjunction with conditional phrases creates powerful input processing frameworks that can handle various error conditions, timeout scenarios, and validation failures while maintaining application stability and providing meaningful feedback to users. This capability is particularly valuable in applications that must process high volumes of user input or integrate with external data sources.

Modern enterprise applications often implement layered input processing architectures where END-ACCEPT statements work in conjunction with validation frameworks, data transformation services, and business rule engines to create comprehensive input processing solutions that meet the complex requirements of contemporary business systems.

END-ACCEPT Syntax and Implementation

Basic END-ACCEPT Usage

The basic implementation of END-ACCEPT follows a consistent pattern where it serves as the explicit terminator for ACCEPT statement blocks. This pattern is particularly important when ACCEPT statements include conditional processing or when they are nested within other constructs.

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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
IDENTIFICATION DIVISION. PROGRAM-ID. END-ACCEPT-BASIC. DATA DIVISION. WORKING-STORAGE SECTION. 01 USER-INPUT-FIELDS. 05 EMPLOYEE-ID PIC X(10). 05 EMPLOYEE-NAME PIC X(30). 05 EMPLOYEE-SALARY PIC 9(7)V99. 05 DEPARTMENT-CODE PIC X(5). 01 INPUT-STATUS-FLAGS. 05 INPUT-SUCCESSFUL-FLAG PIC X VALUE 'N'. 88 INPUT-SUCCESSFUL VALUE 'Y'. 88 INPUT-FAILED VALUE 'N'. 05 VALIDATION-FLAG PIC X VALUE 'N'. 88 VALIDATION-PASSED VALUE 'Y'. 88 VALIDATION-FAILED VALUE 'N'. 01 ERROR-HANDLING. 05 ERROR-MESSAGE PIC X(80). 05 RETRY-COUNT PIC 9(2) VALUE 0. 05 MAX-RETRIES PIC 9(2) VALUE 3. PROCEDURE DIVISION. MAIN-PROCESSING. PERFORM INITIALIZE-PROGRAM PERFORM COLLECT-EMPLOYEE-DATA PERFORM PROCESS-INPUT-RESULTS STOP RUN. INITIALIZE-PROGRAM. DISPLAY 'Employee Data Entry System' MOVE 'N' TO INPUT-SUCCESSFUL-FLAG MOVE 'N' TO VALIDATION-FLAG MOVE SPACES TO ERROR-MESSAGE MOVE 0 TO RETRY-COUNT. COLLECT-EMPLOYEE-DATA. PERFORM UNTIL INPUT-SUCCESSFUL OR RETRY-COUNT >= MAX-RETRIES PERFORM GET-EMPLOYEE-ID PERFORM GET-EMPLOYEE-NAME PERFORM GET-EMPLOYEE-SALARY PERFORM GET-DEPARTMENT-CODE PERFORM VALIDATE-INPUT-DATA IF VALIDATION-PASSED SET INPUT-SUCCESSFUL TO TRUE ELSE ADD 1 TO RETRY-COUNT DISPLAY 'Please correct the errors and try again' END-IF END-PERFORM. GET-EMPLOYEE-ID. DISPLAY 'Enter Employee ID (10 characters): ' WITH NO ADVANCING ACCEPT EMPLOYEE-ID ON EXCEPTION MOVE 'Error accepting Employee ID' TO ERROR-MESSAGE DISPLAY ERROR-MESSAGE SET INPUT-FAILED TO TRUE NOT ON EXCEPTION DISPLAY 'Employee ID accepted: ' EMPLOYEE-ID END-ACCEPT. GET-EMPLOYEE-NAME. DISPLAY 'Enter Employee Name (30 characters): ' WITH NO ADVANCING ACCEPT EMPLOYEE-NAME ON EXCEPTION MOVE 'Error accepting Employee Name' TO ERROR-MESSAGE DISPLAY ERROR-MESSAGE SET INPUT-FAILED TO TRUE NOT ON EXCEPTION DISPLAY 'Employee Name accepted: ' EMPLOYEE-NAME END-ACCEPT. GET-EMPLOYEE-SALARY. DISPLAY 'Enter Employee Salary (numeric): ' WITH NO ADVANCING ACCEPT EMPLOYEE-SALARY ON EXCEPTION MOVE 'Error accepting Employee Salary' TO ERROR-MESSAGE DISPLAY ERROR-MESSAGE SET INPUT-FAILED TO TRUE NOT ON EXCEPTION DISPLAY 'Employee Salary accepted: ' EMPLOYEE-SALARY END-ACCEPT. GET-DEPARTMENT-CODE. DISPLAY 'Enter Department Code (5 characters): ' WITH NO ADVANCING ACCEPT DEPARTMENT-CODE ON EXCEPTION MOVE 'Error accepting Department Code' TO ERROR-MESSAGE DISPLAY ERROR-MESSAGE SET INPUT-FAILED TO TRUE NOT ON EXCEPTION DISPLAY 'Department Code accepted: ' DEPARTMENT-CODE END-ACCEPT. VALIDATE-INPUT-DATA. SET VALIDATION-PASSED TO TRUE IF EMPLOYEE-ID = SPACES DISPLAY 'Employee ID cannot be blank' SET VALIDATION-FAILED TO TRUE END-IF IF EMPLOYEE-NAME = SPACES DISPLAY 'Employee Name cannot be blank' SET VALIDATION-FAILED TO TRUE END-IF IF EMPLOYEE-SALARY = ZERO DISPLAY 'Employee Salary must be greater than zero' SET VALIDATION-FAILED TO TRUE END-IF IF DEPARTMENT-CODE = SPACES DISPLAY 'Department Code cannot be blank' SET VALIDATION-FAILED TO TRUE END-IF. PROCESS-INPUT-RESULTS. IF INPUT-SUCCESSFUL DISPLAY 'Employee data collected successfully:' DISPLAY 'ID: ' EMPLOYEE-ID DISPLAY 'Name: ' EMPLOYEE-NAME DISPLAY 'Salary: ' EMPLOYEE-SALARY DISPLAY 'Department: ' DEPARTMENT-CODE ELSE DISPLAY 'Failed to collect employee data after ' MAX-RETRIES ' attempts' END-IF.

Advanced END-ACCEPT Patterns

Advanced END-ACCEPT patterns involve complex nested structures, sophisticated error handling, and integration with other COBOL constructs to create comprehensive input processing solutions.

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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
IDENTIFICATION DIVISION. PROGRAM-ID. ADVANCED-END-ACCEPT. DATA DIVISION. WORKING-STORAGE SECTION. 01 COMPLEX-INPUT-PROCESSING. 05 MENU-CHOICE PIC X. 88 VALID-CHOICE VALUE '1' THRU '5'. 88 EXIT-CHOICE VALUE '5'. 05 TRANSACTION-TYPE PIC X(10). 05 TRANSACTION-AMOUNT PIC 9(9)V99. 05 ACCOUNT-NUMBER PIC X(15). 05 CONFIRMATION-CODE PIC X(10). 01 PROCESSING-CONTROLS. 05 INPUT-PHASE PIC X(20). 05 CURRENT-STEP PIC 9(2). 05 TOTAL-STEPS PIC 9(2) VALUE 5. 05 STEP-COMPLETED-FLAG PIC X VALUE 'N'. 88 STEP-COMPLETED VALUE 'Y'. 05 PROCESS-COMPLETE-FLAG PIC X VALUE 'N'. 88 PROCESS-COMPLETE VALUE 'Y'. 01 ERROR-MANAGEMENT. 05 ERROR-OCCURRED-FLAG PIC X VALUE 'N'. 88 ERROR-OCCURRED VALUE 'Y'. 05 ERROR-TYPE PIC X(20). 05 ERROR-DESCRIPTION PIC X(100). 05 RECOVERY-ACTION PIC X(50). PROCEDURE DIVISION. MAIN-PROCESSING. PERFORM INITIALIZE-SYSTEM PERFORM PROCESS-USER-INTERACTION PERFORM CLEANUP-SYSTEM STOP RUN. INITIALIZE-SYSTEM. DISPLAY 'Advanced Transaction Processing System' MOVE 'N' TO STEP-COMPLETED-FLAG MOVE 'N' TO PROCESS-COMPLETE-FLAG MOVE 'N' TO ERROR-OCCURRED-FLAG MOVE 1 TO CURRENT-STEP. PROCESS-USER-INTERACTION. PERFORM UNTIL PROCESS-COMPLETE OR ERROR-OCCURRED EVALUATE CURRENT-STEP WHEN 1 PERFORM DISPLAY-MENU PERFORM GET-MENU-SELECTION WHEN 2 PERFORM GET-TRANSACTION-TYPE WHEN 3 PERFORM GET-TRANSACTION-DETAILS WHEN 4 PERFORM GET-CONFIRMATION WHEN 5 PERFORM PROCESS-TRANSACTION SET PROCESS-COMPLETE TO TRUE WHEN OTHER MOVE 'Invalid processing step' TO ERROR-DESCRIPTION SET ERROR-OCCURRED TO TRUE END-EVALUATE IF NOT ERROR-OCCURRED AND NOT PROCESS-COMPLETE ADD 1 TO CURRENT-STEP END-IF END-PERFORM. DISPLAY-MENU. DISPLAY 'Transaction Menu:' DISPLAY '1. Deposit' DISPLAY '2. Withdrawal' DISPLAY '3. Transfer' DISPLAY '4. Balance Inquiry' DISPLAY '5. Exit' DISPLAY 'Please select an option (1-5): ' WITH NO ADVANCING. GET-MENU-SELECTION. ACCEPT MENU-CHOICE ON EXCEPTION MOVE 'INPUT-ERROR' TO ERROR-TYPE MOVE 'Unable to accept menu selection' TO ERROR-DESCRIPTION MOVE 'Please try again' TO RECOVERY-ACTION SET ERROR-OCCURRED TO TRUE DISPLAY ERROR-DESCRIPTION NOT ON EXCEPTION IF VALID-CHOICE IF EXIT-CHOICE DISPLAY 'Exiting system...' SET PROCESS-COMPLETE TO TRUE ELSE DISPLAY 'Menu selection: ' MENU-CHOICE SET STEP-COMPLETED TO TRUE END-IF ELSE DISPLAY 'Invalid menu selection. Please choose 1-5.' MOVE 'VALIDATION-ERROR' TO ERROR-TYPE MOVE 'Invalid menu choice entered' TO ERROR-DESCRIPTION MOVE 'Please select a valid option' TO RECOVERY-ACTION SET ERROR-OCCURRED TO TRUE END-IF END-ACCEPT. GET-TRANSACTION-TYPE. EVALUATE MENU-CHOICE WHEN '1' MOVE 'DEPOSIT' TO TRANSACTION-TYPE WHEN '2' MOVE 'WITHDRAWAL' TO TRANSACTION-TYPE WHEN '3' MOVE 'TRANSFER' TO TRANSACTION-TYPE WHEN '4' MOVE 'INQUIRY' TO TRANSACTION-TYPE WHEN OTHER MOVE 'UNKNOWN' TO TRANSACTION-TYPE END-EVALUATE DISPLAY 'Transaction Type: ' TRANSACTION-TYPE SET STEP-COMPLETED TO TRUE. GET-TRANSACTION-DETAILS. IF TRANSACTION-TYPE NOT = 'INQUIRY' DISPLAY 'Enter transaction amount: ' WITH NO ADVANCING ACCEPT TRANSACTION-AMOUNT ON EXCEPTION MOVE 'AMOUNT-INPUT-ERROR' TO ERROR-TYPE MOVE 'Unable to accept transaction amount' TO ERROR-DESCRIPTION MOVE 'Please enter a valid numeric amount' TO RECOVERY-ACTION SET ERROR-OCCURRED TO TRUE DISPLAY ERROR-DESCRIPTION NOT ON EXCEPTION IF TRANSACTION-AMOUNT > ZERO DISPLAY 'Amount accepted: ' TRANSACTION-AMOUNT ELSE DISPLAY 'Amount must be greater than zero' MOVE 'VALIDATION-ERROR' TO ERROR-TYPE MOVE 'Invalid transaction amount' TO ERROR-DESCRIPTION MOVE 'Please enter amount greater than zero' TO RECOVERY-ACTION SET ERROR-OCCURRED TO TRUE END-IF END-ACCEPT END-IF DISPLAY 'Enter account number: ' WITH NO ADVANCING ACCEPT ACCOUNT-NUMBER ON EXCEPTION MOVE 'ACCOUNT-INPUT-ERROR' TO ERROR-TYPE MOVE 'Unable to accept account number' TO ERROR-DESCRIPTION MOVE 'Please enter a valid account number' TO RECOVERY-ACTION SET ERROR-OCCURRED TO TRUE DISPLAY ERROR-DESCRIPTION NOT ON EXCEPTION IF ACCOUNT-NUMBER NOT = SPACES DISPLAY 'Account number accepted: ' ACCOUNT-NUMBER SET STEP-COMPLETED TO TRUE ELSE DISPLAY 'Account number cannot be blank' MOVE 'VALIDATION-ERROR' TO ERROR-TYPE MOVE 'Account number is required' TO ERROR-DESCRIPTION MOVE 'Please enter a valid account number' TO RECOVERY-ACTION SET ERROR-OCCURRED TO TRUE END-IF END-ACCEPT. GET-CONFIRMATION. DISPLAY 'Enter confirmation code: ' WITH NO ADVANCING ACCEPT CONFIRMATION-CODE ON EXCEPTION MOVE 'CONFIRMATION-INPUT-ERROR' TO ERROR-TYPE MOVE 'Unable to accept confirmation code' TO ERROR-DESCRIPTION MOVE 'Please enter confirmation code' TO RECOVERY-ACTION SET ERROR-OCCURRED TO TRUE DISPLAY ERROR-DESCRIPTION NOT ON EXCEPTION IF CONFIRMATION-CODE NOT = SPACES DISPLAY 'Confirmation code accepted' SET STEP-COMPLETED TO TRUE ELSE DISPLAY 'Confirmation code is required' MOVE 'VALIDATION-ERROR' TO ERROR-TYPE MOVE 'Confirmation code cannot be blank' TO ERROR-DESCRIPTION MOVE 'Please enter a valid confirmation code' TO RECOVERY-ACTION SET ERROR-OCCURRED TO TRUE END-IF END-ACCEPT. PROCESS-TRANSACTION. DISPLAY 'Processing transaction...' DISPLAY 'Type: ' TRANSACTION-TYPE DISPLAY 'Amount: ' TRANSACTION-AMOUNT DISPLAY 'Account: ' ACCOUNT-NUMBER DISPLAY 'Confirmation: ' CONFIRMATION-CODE DISPLAY 'Transaction completed successfully'. CLEANUP-SYSTEM. IF ERROR-OCCURRED DISPLAY 'System encountered errors:' DISPLAY 'Error Type: ' ERROR-TYPE DISPLAY 'Description: ' ERROR-DESCRIPTION DISPLAY 'Recovery Action: ' RECOVERY-ACTION ELSE DISPLAY 'System shutdown normally' END-IF.

END-ACCEPT Best Practices

Recommended Practices
  • Always use END-ACCEPT with conditional phrases
  • Implement comprehensive error handling
  • Use consistent indentation with END-ACCEPT
  • Validate input data after ACCEPT operations
Common Mistakes
  • Omitting END-ACCEPT in nested structures
  • Not handling ON EXCEPTION conditions
  • Poor error message handling
  • Inconsistent use of END-ACCEPT

Interactive Tutorial

Hands-On END-ACCEPT Practice
Practice implementing END-ACCEPT in various input processing scenarios

Exercise 1: Basic Input with Error Handling

Complete the following code with proper END-ACCEPT statements:

cobol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
DISPLAY 'Enter customer name: ' WITH NO ADVANCING ACCEPT CUSTOMER-NAME ON EXCEPTION DISPLAY 'Error accepting customer name' MOVE 'Y' TO ERROR-FLAG NOT ON EXCEPTION DISPLAY 'Customer name accepted: ' CUSTOMER-NAME *> Add END-ACCEPT here DISPLAY 'Enter customer age: ' WITH NO ADVANCING ACCEPT CUSTOMER-AGE ON EXCEPTION DISPLAY 'Error accepting customer age' MOVE 'Y' TO ERROR-FLAG NOT ON EXCEPTION IF CUSTOMER-AGE > 0 AND CUSTOMER-AGE < 150 DISPLAY 'Valid age entered: ' CUSTOMER-AGE ELSE DISPLAY 'Invalid age range' MOVE 'Y' TO ERROR-FLAG END-IF *> Add END-ACCEPT here

Exercise 2: Nested Input Processing

Add appropriate END-ACCEPT statements to this nested structure:

cobol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
PERFORM UNTIL VALID-INPUT OR RETRY-COUNT > MAX-RETRIES DISPLAY 'Enter product code: ' WITH NO ADVANCING ACCEPT PRODUCT-CODE ON EXCEPTION DISPLAY 'Input error occurred' ADD 1 TO RETRY-COUNT NOT ON EXCEPTION IF PRODUCT-CODE NOT = SPACES PERFORM VALIDATE-PRODUCT-CODE IF VALID-PRODUCT MOVE 'Y' TO VALID-INPUT ELSE DISPLAY 'Invalid product code' ADD 1 TO RETRY-COUNT END-IF ELSE DISPLAY 'Product code cannot be blank' ADD 1 TO RETRY-COUNT END-IF *> Add END-ACCEPT here END-PERFORM

Knowledge Check Quiz

Test Your Understanding

Frequently Asked Questions