MainframeMaster

COBOL Tutorial

COBOL END-ADD Statement

The END-ADD statement represents a critical component of structured arithmetic programming in COBOL, serving as an explicit scope terminator that clearly defines the boundaries of ADD statement blocks. This statement embodies modern programming principles by providing unambiguous termination points for arithmetic operations, enabling sophisticated error handling for size overflow conditions, and supporting the development of robust, maintainable enterprise applications that require precise control over numerical calculations and their associated error conditions.

In contemporary enterprise COBOL development, END-ADD plays a vital role in creating reliable financial and business applications that must handle complex arithmetic operations with comprehensive error checking and recovery mechanisms. By providing explicit termination for ADD blocks, this statement enables developers to implement sophisticated numerical processing logic while maintaining code clarity and ensuring that arithmetic operations are properly bounded and controlled within the application's execution flow.

Understanding END-ADD Architecture

The END-ADD statement implements a sophisticated scope management system specifically designed for arithmetic operations. This architecture addresses the complexity inherent in modern business calculations where ADD statements must manage multiple operands, size error conditions, rounding requirements, and conditional processing paths. The explicit termination provided by END-ADD ensures that all these operations are properly contained within defined boundaries.

The architectural design of END-ADD reflects the evolution of COBOL toward structured programming paradigms that emphasize precision, reliability, and error prevention in numerical computations. When used with conditional phrases like ON SIZE ERROR and NOT ON SIZE ERROR, END-ADD creates a comprehensive framework for handling both successful arithmetic operations and overflow conditions that may arise during calculations.

END-ADD also plays a crucial role in compiler optimization and numerical analysis. Modern COBOL compilers can perform more sophisticated analysis when arithmetic blocks are explicitly terminated, leading to better error detection during compilation, more efficient runtime code generation, and improved numerical precision handling. This capability is particularly important in financial applications where accuracy and reliability are paramount.

Key END-ADD Capabilities:

  • Explicit Scope Termination: Provides clear boundaries for ADD statement blocks, eliminating ambiguity in nested arithmetic structures.
  • Size Error Handling: Works with ON SIZE ERROR and NOT ON SIZE ERROR phrases to create comprehensive overflow handling frameworks.
  • Nested Operation Management: Enables proper handling of complex nested arithmetic scenarios with multiple ADD statements.
  • Precision Control: Supports sophisticated precision and rounding control by clearly defining the scope of arithmetic operations.
  • Code Readability Enhancement: Improves code structure and readability by providing explicit termination points for arithmetic operations.
  • Compiler Optimization: Enables better compiler analysis and optimization by providing clear block boundaries for arithmetic operations.

Arithmetic Processing Patterns

END-ADD enables the implementation of sophisticated arithmetic processing patterns that are essential for modern enterprise applications. These patterns include financial calculations with comprehensive error handling, batch processing with running totals and overflow detection, and complex multi-step calculations that require precise control over the arithmetic flow and error management.

The use of END-ADD in conjunction with conditional phrases creates powerful arithmetic processing frameworks that can handle various overflow conditions, precision requirements, and rounding scenarios while maintaining application stability and providing meaningful feedback about calculation results. This capability is particularly valuable in financial applications that must process high volumes of numerical data with absolute accuracy.

Modern enterprise applications often implement layered arithmetic processing architectures where END-ADD statements work in conjunction with validation frameworks, precision control systems, and business rule engines to create comprehensive calculation solutions that meet the complex requirements of contemporary financial and business systems.

END-ADD Syntax and Implementation

Basic END-ADD Usage

The basic implementation of END-ADD follows a consistent pattern where it serves as the explicit terminator for ADD statement blocks. This pattern is particularly important when ADD 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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
IDENTIFICATION DIVISION. PROGRAM-ID. END-ADD-BASIC. DATA DIVISION. WORKING-STORAGE SECTION. 01 FINANCIAL-CALCULATIONS. 05 ACCOUNT-BALANCE PIC 9(9)V99. 05 DEPOSIT-AMOUNT PIC 9(7)V99. 05 INTEREST-EARNED PIC 9(7)V99. 05 BONUS-PAYMENT PIC 9(7)V99. 05 NEW-BALANCE PIC 9(9)V99. 01 CALCULATION-CONTROLS. 05 CALCULATION-ERROR-FLAG PIC X VALUE 'N'. 88 CALCULATION-ERROR VALUE 'Y'. 88 CALCULATION-OK VALUE 'N'. 05 OVERFLOW-DETECTED-FLAG PIC X VALUE 'N'. 88 OVERFLOW-DETECTED VALUE 'Y'. 88 NO-OVERFLOW VALUE 'N'. 01 TRANSACTION-TOTALS. 05 DAILY-DEPOSIT-TOTAL PIC 9(11)V99. 05 MONTHLY-INTEREST-TOTAL PIC 9(11)V99. 05 YEARLY-BONUS-TOTAL PIC 9(11)V99. 05 GRAND-TOTAL PIC 9(13)V99. 01 ERROR-HANDLING. 05 ERROR-MESSAGE PIC X(80). 05 ERROR-COUNT PIC 9(5). 05 PROCESSED-COUNT PIC 9(5). PROCEDURE DIVISION. MAIN-PROCESSING. PERFORM INITIALIZE-CALCULATIONS PERFORM PROCESS-ACCOUNT-UPDATES PERFORM GENERATE-TOTALS PERFORM DISPLAY-RESULTS STOP RUN. INITIALIZE-CALCULATIONS. MOVE 1500.75 TO ACCOUNT-BALANCE MOVE 250.50 TO DEPOSIT-AMOUNT MOVE 15.25 TO INTEREST-EARNED MOVE 100.00 TO BONUS-PAYMENT MOVE 'N' TO CALCULATION-ERROR-FLAG MOVE 'N' TO OVERFLOW-DETECTED-FLAG MOVE ZEROS TO DAILY-DEPOSIT-TOTAL, MONTHLY-INTEREST-TOTAL, YEARLY-BONUS-TOTAL, GRAND-TOTAL MOVE ZEROS TO ERROR-COUNT, PROCESSED-COUNT. PROCESS-ACCOUNT-UPDATES. *> Basic ADD with END-ADD and size error handling ADD DEPOSIT-AMOUNT TO ACCOUNT-BALANCE ON SIZE ERROR MOVE 'Overflow in account balance calculation' TO ERROR-MESSAGE SET CALCULATION-ERROR TO TRUE SET OVERFLOW-DETECTED TO TRUE ADD 1 TO ERROR-COUNT DISPLAY ERROR-MESSAGE NOT ON SIZE ERROR ADD 1 TO PROCESSED-COUNT DISPLAY 'Deposit processed: ' DEPOSIT-AMOUNT DISPLAY 'New account balance: ' ACCOUNT-BALANCE END-ADD. *> ADD with GIVING clause and error handling ADD INTEREST-EARNED TO ACCOUNT-BALANCE GIVING NEW-BALANCE ON SIZE ERROR MOVE 'Overflow in interest calculation' TO ERROR-MESSAGE SET CALCULATION-ERROR TO TRUE SET OVERFLOW-DETECTED TO TRUE ADD 1 TO ERROR-COUNT DISPLAY ERROR-MESSAGE NOT ON SIZE ERROR MOVE NEW-BALANCE TO ACCOUNT-BALANCE ADD 1 TO PROCESSED-COUNT DISPLAY 'Interest added: ' INTEREST-EARNED DISPLAY 'Updated balance: ' ACCOUNT-BALANCE END-ADD. *> Conditional ADD with complex logic IF ACCOUNT-BALANCE > 1000.00 ADD BONUS-PAYMENT TO ACCOUNT-BALANCE ON SIZE ERROR MOVE 'Overflow in bonus calculation' TO ERROR-MESSAGE SET CALCULATION-ERROR TO TRUE SET OVERFLOW-DETECTED TO TRUE ADD 1 TO ERROR-COUNT DISPLAY ERROR-MESSAGE NOT ON SIZE ERROR ADD 1 TO PROCESSED-COUNT DISPLAY 'Bonus added: ' BONUS-PAYMENT DISPLAY 'Final balance: ' ACCOUNT-BALANCE END-ADD ELSE DISPLAY 'Account balance too low for bonus' END-IF. GENERATE-TOTALS. *> Multiple ADD operations with comprehensive error handling ADD DEPOSIT-AMOUNT TO DAILY-DEPOSIT-TOTAL ON SIZE ERROR MOVE 'Overflow in daily deposit total' TO ERROR-MESSAGE SET CALCULATION-ERROR TO TRUE ADD 1 TO ERROR-COUNT DISPLAY ERROR-MESSAGE NOT ON SIZE ERROR DISPLAY 'Daily deposit total updated: ' DAILY-DEPOSIT-TOTAL END-ADD. ADD INTEREST-EARNED TO MONTHLY-INTEREST-TOTAL ON SIZE ERROR MOVE 'Overflow in monthly interest total' TO ERROR-MESSAGE SET CALCULATION-ERROR TO TRUE ADD 1 TO ERROR-COUNT DISPLAY ERROR-MESSAGE NOT ON SIZE ERROR DISPLAY 'Monthly interest total updated: ' MONTHLY-INTEREST-TOTAL END-ADD. ADD BONUS-PAYMENT TO YEARLY-BONUS-TOTAL ON SIZE ERROR MOVE 'Overflow in yearly bonus total' TO ERROR-MESSAGE SET CALCULATION-ERROR TO TRUE ADD 1 TO ERROR-COUNT DISPLAY ERROR-MESSAGE NOT ON SIZE ERROR DISPLAY 'Yearly bonus total updated: ' YEARLY-BONUS-TOTAL END-ADD. *> Complex ADD with multiple operands ADD DAILY-DEPOSIT-TOTAL, MONTHLY-INTEREST-TOTAL, YEARLY-BONUS-TOTAL TO GRAND-TOTAL ON SIZE ERROR MOVE 'Overflow in grand total calculation' TO ERROR-MESSAGE SET CALCULATION-ERROR TO TRUE ADD 1 TO ERROR-COUNT DISPLAY ERROR-MESSAGE NOT ON SIZE ERROR DISPLAY 'Grand total calculated: ' GRAND-TOTAL END-ADD. DISPLAY-RESULTS. DISPLAY 'Processing Summary:' DISPLAY 'Successful operations: ' PROCESSED-COUNT DISPLAY 'Errors encountered: ' ERROR-COUNT IF CALCULATION-ERROR DISPLAY 'Warning: Calculation errors occurred' ELSE DISPLAY 'All calculations completed successfully' END-IF DISPLAY 'Final Account Balance: ' ACCOUNT-BALANCE DISPLAY 'Grand Total: ' GRAND-TOTAL.

Advanced END-ADD Patterns

Advanced END-ADD patterns involve complex nested structures, sophisticated error handling, and integration with other COBOL constructs to create comprehensive arithmetic 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
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
IDENTIFICATION DIVISION. PROGRAM-ID. ADVANCED-END-ADD. DATA DIVISION. WORKING-STORAGE SECTION. 01 PAYROLL-PROCESSING. 05 EMPLOYEE-SALARY PIC 9(7)V99. 05 OVERTIME-HOURS PIC 9(3)V99. 05 OVERTIME-RATE PIC 9(3)V99. 05 BONUS-PERCENTAGE PIC V999. 05 COMMISSION-RATE PIC V999. 05 SALES-AMOUNT PIC 9(9)V99. 01 CALCULATED-AMOUNTS. 05 OVERTIME-PAY PIC 9(7)V99. 05 BONUS-AMOUNT PIC 9(7)V99. 05 COMMISSION-AMOUNT PIC 9(7)V99. 05 GROSS-PAY PIC 9(9)V99. 05 NET-PAY PIC 9(9)V99. 01 DEDUCTIONS. 05 TAX-AMOUNT PIC 9(7)V99. 05 INSURANCE-AMOUNT PIC 9(5)V99. 05 RETIREMENT-AMOUNT PIC 9(7)V99. 05 TOTAL-DEDUCTIONS PIC 9(9)V99. 01 PROCESSING-CONTROLS. 05 EMPLOYEE-COUNT PIC 9(5). 05 CURRENT-EMPLOYEE PIC 9(5). 05 ERROR-COUNT PIC 9(5). 05 PROCESSED-COUNT PIC 9(5). 01 VALIDATION-FLAGS. 05 CALCULATION-VALID-FLAG PIC X VALUE 'Y'. 88 CALCULATION-VALID VALUE 'Y'. 88 CALCULATION-INVALID VALUE 'N'. 05 OVERFLOW-FLAG PIC X VALUE 'N'. 88 OVERFLOW-OCCURRED VALUE 'Y'. 88 NO-OVERFLOW VALUE 'N'. 01 PAYROLL-TOTALS. 05 TOTAL-GROSS-PAY PIC 9(11)V99. 05 TOTAL-NET-PAY PIC 9(11)V99. 05 TOTAL-DEDUCTIONS-PAID PIC 9(11)V99. 05 TOTAL-OVERTIME-PAID PIC 9(11)V99. 05 TOTAL-BONUSES-PAID PIC 9(11)V99. PROCEDURE DIVISION. MAIN-PROCESSING. PERFORM INITIALIZE-PAYROLL-SYSTEM PERFORM PROCESS-EMPLOYEE-PAYROLL PERFORM CALCULATE-PAYROLL-TOTALS PERFORM GENERATE-PAYROLL-REPORT STOP RUN. INITIALIZE-PAYROLL-SYSTEM. MOVE 2500.00 TO EMPLOYEE-SALARY MOVE 8.5 TO OVERTIME-HOURS MOVE 25.00 TO OVERTIME-RATE MOVE 0.05 TO BONUS-PERCENTAGE MOVE 0.03 TO COMMISSION-RATE MOVE 15000.00 TO SALES-AMOUNT MOVE 10 TO EMPLOYEE-COUNT MOVE 0 TO CURRENT-EMPLOYEE, ERROR-COUNT, PROCESSED-COUNT MOVE ZEROS TO PAYROLL-TOTALS. PROCESS-EMPLOYEE-PAYROLL. PERFORM VARYING CURRENT-EMPLOYEE FROM 1 BY 1 UNTIL CURRENT-EMPLOYEE > EMPLOYEE-COUNT PERFORM CALCULATE-EMPLOYEE-PAY PERFORM CALCULATE-EMPLOYEE-DEDUCTIONS PERFORM CALCULATE-NET-PAY PERFORM UPDATE-PAYROLL-TOTALS END-PERFORM. CALCULATE-EMPLOYEE-PAY. SET CALCULATION-VALID TO TRUE SET NO-OVERFLOW TO TRUE *> Calculate overtime pay with nested error handling IF OVERTIME-HOURS > ZERO MULTIPLY OVERTIME-HOURS BY OVERTIME-RATE GIVING OVERTIME-PAY ON SIZE ERROR DISPLAY 'Overflow in overtime calculation for employee: ' CURRENT-EMPLOYEE SET CALCULATION-INVALID TO TRUE SET OVERFLOW-OCCURRED TO TRUE ADD 1 TO ERROR-COUNT END-MULTIPLY ELSE MOVE ZERO TO OVERTIME-PAY END-IF. *> Calculate bonus with complex conditional logic IF CALCULATION-VALID MULTIPLY EMPLOYEE-SALARY BY BONUS-PERCENTAGE GIVING BONUS-AMOUNT ON SIZE ERROR DISPLAY 'Overflow in bonus calculation for employee: ' CURRENT-EMPLOYEE SET CALCULATION-INVALID TO TRUE SET OVERFLOW-OCCURRED TO TRUE ADD 1 TO ERROR-COUNT NOT ON SIZE ERROR DISPLAY 'Bonus calculated: ' BONUS-AMOUNT END-MULTIPLY ELSE MOVE ZERO TO BONUS-AMOUNT END-IF. *> Calculate commission with validation IF CALCULATION-VALID AND SALES-AMOUNT > ZERO MULTIPLY SALES-AMOUNT BY COMMISSION-RATE GIVING COMMISSION-AMOUNT ON SIZE ERROR DISPLAY 'Overflow in commission calculation for employee: ' CURRENT-EMPLOYEE SET CALCULATION-INVALID TO TRUE SET OVERFLOW-OCCURRED TO TRUE ADD 1 TO ERROR-COUNT NOT ON SIZE ERROR DISPLAY 'Commission calculated: ' COMMISSION-AMOUNT END-MULTIPLY ELSE MOVE ZERO TO COMMISSION-AMOUNT END-IF. *> Calculate gross pay with comprehensive error handling IF CALCULATION-VALID ADD EMPLOYEE-SALARY TO OVERTIME-PAY GIVING GROSS-PAY ON SIZE ERROR DISPLAY 'Overflow in initial gross pay calculation for employee: ' CURRENT-EMPLOYEE SET CALCULATION-INVALID TO TRUE SET OVERFLOW-OCCURRED TO TRUE ADD 1 TO ERROR-COUNT NOT ON SIZE ERROR ADD BONUS-AMOUNT TO GROSS-PAY ON SIZE ERROR DISPLAY 'Overflow adding bonus to gross pay for employee: ' CURRENT-EMPLOYEE SET CALCULATION-INVALID TO TRUE SET OVERFLOW-OCCURRED TO TRUE ADD 1 TO ERROR-COUNT NOT ON SIZE ERROR ADD COMMISSION-AMOUNT TO GROSS-PAY ON SIZE ERROR DISPLAY 'Overflow adding commission to gross pay for employee: ' CURRENT-EMPLOYEE SET CALCULATION-INVALID TO TRUE SET OVERFLOW-OCCURRED TO TRUE ADD 1 TO ERROR-COUNT NOT ON SIZE ERROR DISPLAY 'Gross pay calculated: ' GROSS-PAY ADD 1 TO PROCESSED-COUNT END-ADD END-ADD END-ADD END-IF. CALCULATE-EMPLOYEE-DEDUCTIONS. IF CALCULATION-VALID *> Calculate tax amount (25% of gross pay) MULTIPLY GROSS-PAY BY 0.25 GIVING TAX-AMOUNT ON SIZE ERROR DISPLAY 'Overflow in tax calculation for employee: ' CURRENT-EMPLOYEE SET CALCULATION-INVALID TO TRUE ADD 1 TO ERROR-COUNT END-MULTIPLY *> Calculate insurance (fixed amount) MOVE 125.50 TO INSURANCE-AMOUNT *> Calculate retirement (5% of gross pay) MULTIPLY GROSS-PAY BY 0.05 GIVING RETIREMENT-AMOUNT ON SIZE ERROR DISPLAY 'Overflow in retirement calculation for employee: ' CURRENT-EMPLOYEE SET CALCULATION-INVALID TO TRUE ADD 1 TO ERROR-COUNT END-MULTIPLY *> Calculate total deductions ADD TAX-AMOUNT, INSURANCE-AMOUNT, RETIREMENT-AMOUNT TO TOTAL-DEDUCTIONS ON SIZE ERROR DISPLAY 'Overflow in total deductions calculation for employee: ' CURRENT-EMPLOYEE SET CALCULATION-INVALID TO TRUE ADD 1 TO ERROR-COUNT NOT ON SIZE ERROR DISPLAY 'Total deductions calculated: ' TOTAL-DEDUCTIONS END-ADD END-IF. CALCULATE-NET-PAY. IF CALCULATION-VALID SUBTRACT TOTAL-DEDUCTIONS FROM GROSS-PAY GIVING NET-PAY ON SIZE ERROR DISPLAY 'Error in net pay calculation for employee: ' CURRENT-EMPLOYEE SET CALCULATION-INVALID TO TRUE ADD 1 TO ERROR-COUNT NOT ON SIZE ERROR DISPLAY 'Net pay calculated: ' NET-PAY END-SUBTRACT END-IF. UPDATE-PAYROLL-TOTALS. IF CALCULATION-VALID ADD GROSS-PAY TO TOTAL-GROSS-PAY ON SIZE ERROR DISPLAY 'Overflow in total gross pay accumulation' ADD 1 TO ERROR-COUNT NOT ON SIZE ERROR DISPLAY 'Total gross pay updated: ' TOTAL-GROSS-PAY END-ADD ADD NET-PAY TO TOTAL-NET-PAY ON SIZE ERROR DISPLAY 'Overflow in total net pay accumulation' ADD 1 TO ERROR-COUNT NOT ON SIZE ERROR DISPLAY 'Total net pay updated: ' TOTAL-NET-PAY END-ADD ADD TOTAL-DEDUCTIONS TO TOTAL-DEDUCTIONS-PAID ON SIZE ERROR DISPLAY 'Overflow in total deductions accumulation' ADD 1 TO ERROR-COUNT NOT ON SIZE ERROR DISPLAY 'Total deductions updated: ' TOTAL-DEDUCTIONS-PAID END-ADD ADD OVERTIME-PAY TO TOTAL-OVERTIME-PAID ON SIZE ERROR DISPLAY 'Overflow in total overtime accumulation' ADD 1 TO ERROR-COUNT NOT ON SIZE ERROR DISPLAY 'Total overtime updated: ' TOTAL-OVERTIME-PAID END-ADD ADD BONUS-AMOUNT TO TOTAL-BONUSES-PAID ON SIZE ERROR DISPLAY 'Overflow in total bonuses accumulation' ADD 1 TO ERROR-COUNT NOT ON SIZE ERROR DISPLAY 'Total bonuses updated: ' TOTAL-BONUSES-PAID END-ADD END-IF. CALCULATE-PAYROLL-TOTALS. DISPLAY 'Calculating final payroll totals...' DISPLAY 'Total employees processed: ' PROCESSED-COUNT DISPLAY 'Total errors encountered: ' ERROR-COUNT. GENERATE-PAYROLL-REPORT. DISPLAY 'Payroll Processing Report:' DISPLAY 'Total Gross Pay: ' TOTAL-GROSS-PAY DISPLAY 'Total Net Pay: ' TOTAL-NET-PAY DISPLAY 'Total Deductions: ' TOTAL-DEDUCTIONS-PAID DISPLAY 'Total Overtime: ' TOTAL-OVERTIME-PAID DISPLAY 'Total Bonuses: ' TOTAL-BONUSES-PAID DISPLAY 'Employees Processed: ' PROCESSED-COUNT DISPLAY 'Calculation Errors: ' ERROR-COUNT.

END-ADD Best Practices

Recommended Practices
  • Always use END-ADD with size error handling
  • Implement comprehensive overflow detection
  • Use consistent indentation with END-ADD
  • Validate operands before ADD operations
Common Mistakes
  • Omitting END-ADD in nested structures
  • Not handling ON SIZE ERROR conditions
  • Poor error message handling
  • Inconsistent use of END-ADD

Interactive Tutorial

Hands-On END-ADD Practice
Practice implementing END-ADD in various arithmetic scenarios

Exercise 1: Basic Addition with Error Handling

Complete the following code with proper END-ADD statements:

cobol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
ADD SALES-AMOUNT TO TOTAL-SALES ON SIZE ERROR DISPLAY 'Overflow in sales total calculation' MOVE 'Y' TO ERROR-FLAG NOT ON SIZE ERROR DISPLAY 'Sales total updated: ' TOTAL-SALES ADD 1 TO PROCESSED-COUNT *> Add END-ADD here ADD COMMISSION-RATE TO BASE-SALARY GIVING GROSS-PAY ON SIZE ERROR DISPLAY 'Overflow in gross pay calculation' MOVE 'Y' TO ERROR-FLAG NOT ON SIZE ERROR DISPLAY 'Gross pay calculated: ' GROSS-PAY *> Add END-ADD here

Exercise 2: Nested Arithmetic Processing

Add appropriate END-ADD statements to this nested structure:

cobol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
PERFORM VARYING COUNTER FROM 1 BY 1 UNTIL COUNTER > 10 IF ACCOUNT-BALANCE(COUNTER) > ZERO ADD INTEREST-RATE TO ACCOUNT-BALANCE(COUNTER) ON SIZE ERROR DISPLAY 'Overflow in account: ' COUNTER ADD 1 TO ERROR-COUNT NOT ON SIZE ERROR ADD ACCOUNT-BALANCE(COUNTER) TO TOTAL-BALANCE ON SIZE ERROR DISPLAY 'Overflow in total balance' ADD 1 TO ERROR-COUNT NOT ON SIZE ERROR ADD 1 TO PROCESSED-COUNT *> Add END-ADD here *> Add END-ADD here END-IF END-PERFORM

Knowledge Check Quiz

Test Your Understanding

Frequently Asked Questions