MainframeMaster

COBOL Tutorial

COBOL NO

The NO keyword represents comprehensive negation and condition control capabilities within COBOL programming environments, providing sophisticated logical operations, advanced condition management features, and intelligent control flow mechanisms that enable precise program behavior specification, conditional processing control, and systematic error handling. This keyword embodies modern conditional programming principles by supporting explicit negation operations, enabling comprehensive condition testing workflows, and facilitating precise control requirements while maintaining processing clarity, ensuring predictable logical behavior, and enabling flexible conditional architectures across enterprise applications requiring sophisticated condition management, logical control operations, and reliable negation handling throughout complex business logic scenarios and conditional processing requirements.

NO Usage Contexts

NO in Different COBOL 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
*> File operations with NO OPEN INPUT file-name NO REWIND CLOSE file-name NO REWIND *> Arithmetic operations with NO SIZE ERROR ADD amount TO total NO SIZE ERROR DISPLAY "Addition successful" ON SIZE ERROR DISPLAY "Arithmetic overflow occurred" END-ADD *> Condition testing with NO IF NO-DATA-FOUND DISPLAY "No records available" END-IF *> Database operations (SQL embedded) EXEC SQL SELECT COUNT(*) INTO :record-count FROM customer-table WHERE status = 'ACTIVE' END-EXEC IF SQLCODE = 100 *> NO DATA FOUND DISPLAY "No active customers found" END-IF *> Control structures with NO EVALUATE transaction-type WHEN "CREDIT" PERFORM PROCESS-CREDIT WHEN "DEBIT" PERFORM PROCESS-DEBIT WHEN OTHER DISPLAY "No valid transaction type" END-EVALUATE *> Error handling with NO CALL program-name NO OVERFLOW DISPLAY "Program called successfully" ON OVERFLOW DISPLAY "Call stack overflow" END-CALL *> File positioning with NO READ file-name NO ADVANCING AT END DISPLAY "No more records" END-READ
Negation
Condition Control
Logical Operations

Comprehensive NO Examples

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
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
IDENTIFICATION DIVISION. PROGRAM-ID. NO-KEYWORD-DEMO. ENVIRONMENT DIVISION. INPUT-OUTPUT SECTION. FILE-CONTROL. SELECT TRANSACTION-FILE ASSIGN TO "TRANS.DAT" ORGANIZATION IS SEQUENTIAL ACCESS MODE IS SEQUENTIAL FILE STATUS IS WS-FILE-STATUS. SELECT MASTER-FILE ASSIGN TO "MASTER.DAT" ORGANIZATION IS INDEXED ACCESS MODE IS DYNAMIC RECORD KEY IS MASTER-KEY FILE STATUS IS WS-MASTER-STATUS. DATA DIVISION. FILE SECTION. FD TRANSACTION-FILE. 01 TRANSACTION-RECORD. 05 TRANS-ID PIC X(8). 05 TRANS-TYPE PIC X(6). 05 TRANS-AMOUNT PIC 9(8)V99. 05 TRANS-DATE PIC 9(8). 05 CUSTOMER-ID PIC X(6). FD MASTER-FILE. 01 MASTER-RECORD. 05 MASTER-KEY PIC X(8). 05 CUSTOMER-NAME PIC X(30). 05 ACCOUNT-BALANCE PIC S9(10)V99. 05 CREDIT-LIMIT PIC 9(8)V99. 05 LAST-ACTIVITY PIC 9(8). WORKING-STORAGE SECTION. *> File status and control fields 01 WS-FILE-CONTROLS. 05 WS-FILE-STATUS PIC X(2). 05 WS-MASTER-STATUS PIC X(2). 05 WS-EOF-FLAG PIC X VALUE 'N'. 05 WS-NO-DATA-FLAG PIC X VALUE 'N'. *> Processing counters and flags 01 WS-PROCESSING-CONTROLS. 05 WS-RECORDS-PROCESSED PIC 9(6) VALUE 0. 05 WS-ERRORS-FOUND PIC 9(4) VALUE 0. 05 WS-VALID-TRANSACTIONS PIC 9(6) VALUE 0. 05 WS-NO-MATCH-COUNT PIC 9(4) VALUE 0. *> Arithmetic operation fields 01 WS-CALCULATION-FIELDS. 05 WS-CALC-RESULT PIC S9(12)V99. 05 WS-TEMP-AMOUNT PIC S9(10)V99. 05 WS-SIZE-ERROR-FLAG PIC X VALUE 'N'. 05 WS-NO-OVERFLOW-FLAG PIC X VALUE 'Y'. *> Validation and condition flags 01 WS-VALIDATION-FLAGS. 05 WS-NO-ERRORS-FOUND PIC X VALUE 'Y'. 05 WS-NO-WARNINGS PIC X VALUE 'Y'. 05 WS-NO-DATA-AVAILABLE PIC X VALUE 'N'. 05 WS-NO-MATCHES PIC X VALUE 'N'. *> Business logic fields 01 WS-BUSINESS-LOGIC. 05 WS-MINIMUM-BALANCE PIC S9(8)V99 VALUE -1000.00. 05 WS-MAXIMUM-TRANSACTION PIC 9(8)V99 VALUE 50000.00. 05 WS-DAILY-LIMIT PIC 9(8)V99 VALUE 10000.00. *> Error and status tracking 01 WS-ERROR-TRACKING. 05 WS-ERROR-COUNT PIC 9(4) VALUE 0. 05 WS-WARNING-COUNT PIC 9(4) VALUE 0. 05 WS-SUCCESS-COUNT PIC 9(6) VALUE 0. PROCEDURE DIVISION. MAIN-NO-DEMONSTRATION. DISPLAY "=== COBOL NO KEYWORD DEMONSTRATION ===" DISPLAY SPACES PERFORM DEMONSTRATE-FILE-NO-OPERATIONS PERFORM DEMONSTRATE-ARITHMETIC-NO-SIZE-ERROR PERFORM DEMONSTRATE-CONDITION-NO-TESTING PERFORM DEMONSTRATE-NO-DATA-SCENARIOS PERFORM DEMONSTRATE-VALIDATION-NO-ERRORS PERFORM DEMONSTRATE-BUSINESS-LOGIC-NO-CONDITIONS DISPLAY "=== NO KEYWORD DEMO COMPLETE ===" STOP RUN. DEMONSTRATE-FILE-NO-OPERATIONS. DISPLAY "=== FILE OPERATIONS WITH NO ===" DISPLAY SPACES DISPLAY "Opening files with NO REWIND..." *> Open files with NO REWIND (tape file example) OPEN INPUT TRANSACTION-FILE IF WS-FILE-STATUS = "00" DISPLAY " ✓ Transaction file opened successfully (NO REWIND implied)" ELSE DISPLAY " ✗ Error opening transaction file: " WS-FILE-STATUS MOVE 'Y' TO WS-NO-DATA-FLAG END-IF OPEN I-O MASTER-FILE IF WS-MASTER-STATUS = "00" DISPLAY " ✓ Master file opened successfully" ELSE DISPLAY " ✗ Error opening master file: " WS-MASTER-STATUS MOVE 'Y' TO WS-NO-DATA-FLAG END-IF *> Process with NO ADVANCING example IF WS-NO-DATA-FLAG = 'N' PERFORM PROCESS-TRANSACTIONS-NO-ADVANCING END-IF *> Close files with NO REWIND CLOSE TRANSACTION-FILE CLOSE MASTER-FILE DISPLAY " Files closed (NO REWIND for tape files)" DISPLAY SPACES. PROCESS-TRANSACTIONS-NO-ADVANCING. DISPLAY "Processing transactions with NO ADVANCING control..." READ TRANSACTION-FILE AT END MOVE 'Y' TO WS-EOF-FLAG NOT AT END ADD 1 TO WS-RECORDS-PROCESSED END-READ PERFORM UNTIL WS-EOF-FLAG = 'Y' *> Process current transaction PERFORM VALIDATE-TRANSACTION IF WS-NO-ERRORS-FOUND = 'Y' PERFORM UPDATE-MASTER-RECORD ADD 1 TO WS-VALID-TRANSACTIONS ELSE ADD 1 TO WS-ERRORS-FOUND DISPLAY " ⚠️ Transaction " TRANS-ID " has errors" END-IF *> Read next transaction (NO ADVANCING not used here but shown for concept) READ TRANSACTION-FILE AT END MOVE 'Y' TO WS-EOF-FLAG NOT AT END ADD 1 TO WS-RECORDS-PROCESSED END-READ END-PERFORM DISPLAY " Transactions processed: " WS-RECORDS-PROCESSED DISPLAY " Valid transactions: " WS-VALID-TRANSACTIONS DISPLAY " Errors found: " WS-ERRORS-FOUND. DEMONSTRATE-ARITHMETIC-NO-SIZE-ERROR. DISPLAY "=== ARITHMETIC OPERATIONS WITH NO SIZE ERROR ===" DISPLAY SPACES DISPLAY "Testing arithmetic operations with NO SIZE ERROR..." MOVE 999999999.99 TO WS-TEMP-AMOUNT MOVE 1.00 TO TRANS-AMOUNT *> Safe addition with NO SIZE ERROR handling ADD TRANS-AMOUNT TO WS-TEMP-AMOUNT NO SIZE ERROR DISPLAY " ✓ Addition completed without overflow" DISPLAY " Result: " WS-TEMP-AMOUNT MOVE 'Y' TO WS-NO-OVERFLOW-FLAG ON SIZE ERROR DISPLAY " ⚠️ Size error detected in addition" MOVE 'N' TO WS-NO-OVERFLOW-FLAG ADD 1 TO WS-ERROR-COUNT END-ADD *> Test multiplication with potential overflow MOVE 50000.00 TO WS-TEMP-AMOUNT MOVE 25000.00 TO TRANS-AMOUNT MULTIPLY TRANS-AMOUNT BY WS-TEMP-AMOUNT NO SIZE ERROR DISPLAY " ✓ Multiplication completed successfully" DISPLAY " Result: " WS-TEMP-AMOUNT ON SIZE ERROR DISPLAY " ⚠️ Multiplication overflow detected" MOVE WS-MAXIMUM-TRANSACTION TO WS-TEMP-AMOUNT DISPLAY " Capped at maximum: " WS-TEMP-AMOUNT ADD 1 TO WS-ERROR-COUNT END-MULTIPLY *> Division with NO SIZE ERROR MOVE 100.00 TO WS-TEMP-AMOUNT MOVE 3 TO TRANS-AMOUNT DIVIDE TRANS-AMOUNT INTO WS-TEMP-AMOUNT NO SIZE ERROR DISPLAY " ✓ Division completed successfully" DISPLAY " Result: " WS-TEMP-AMOUNT ON SIZE ERROR DISPLAY " ⚠️ Division error (possibly divide by zero)" ADD 1 TO WS-ERROR-COUNT END-DIVIDE DISPLAY " Arithmetic operations summary:" DISPLAY " Overflow conditions: " WS-ERROR-COUNT DISPLAY " Successful operations: " WS-SUCCESS-COUNT DISPLAY SPACES. DEMONSTRATE-CONDITION-NO-TESTING. DISPLAY "=== CONDITION TESTING WITH NO ===" DISPLAY SPACES DISPLAY "Testing various NO conditions..." *> Test NO DATA conditions MOVE 0 TO WS-RECORDS-PROCESSED IF WS-RECORDS-PROCESSED = 0 MOVE 'Y' TO WS-NO-DATA-AVAILABLE DISPLAY " 📊 NO DATA condition detected" DISPLAY " No records have been processed yet" ELSE MOVE 'N' TO WS-NO-DATA-AVAILABLE DISPLAY " 📊 Data is available for processing" END-IF *> Test NO ERRORS condition MOVE 0 TO WS-ERROR-COUNT IF WS-ERROR-COUNT = 0 MOVE 'Y' TO WS-NO-ERRORS-FOUND DISPLAY " ✅ NO ERRORS condition - processing is clean" ELSE MOVE 'N' TO WS-NO-ERRORS-FOUND DISPLAY " ❌ Errors detected: " WS-ERROR-COUNT END-IF *> Test NO MATCHES condition MOVE 0 TO WS-NO-MATCH-COUNT EVALUATE WS-NO-MATCH-COUNT WHEN 0 MOVE 'Y' TO WS-NO-MATCHES DISPLAY " 🔍 NO MATCHES found in search operation" WHEN OTHER MOVE 'N' TO WS-NO-MATCHES DISPLAY " 🔍 Matches found: " WS-NO-MATCH-COUNT END-EVALUATE *> Complex NO condition testing IF WS-NO-DATA-AVAILABLE = 'Y' AND WS-NO-ERRORS-FOUND = 'Y' DISPLAY " ⭐ Optimal condition: NO DATA and NO ERRORS" DISPLAY " System is ready for new processing" ELSE DISPLAY " ⚙️ System has data or errors to handle" END-IF DISPLAY SPACES. DEMONSTRATE-NO-DATA-SCENARIOS. DISPLAY "=== NO DATA SCENARIOS ===" DISPLAY SPACES DISPLAY "Simulating various NO DATA conditions..." *> Simulate empty file scenario MOVE 0 TO WS-RECORDS-PROCESSED MOVE 'Y' TO WS-NO-DATA-AVAILABLE PERFORM CHECK-NO-DATA-CONDITION *> Simulate no matching records scenario MOVE 'Y' TO WS-NO-MATCHES PERFORM CHECK-NO-MATCHES-CONDITION *> Simulate successful data processing (NO more NO DATA) MOVE 100 TO WS-RECORDS-PROCESSED MOVE 'N' TO WS-NO-DATA-AVAILABLE MOVE 'N' TO WS-NO-MATCHES PERFORM CHECK-DATA-AVAILABILITY DISPLAY SPACES. CHECK-NO-DATA-CONDITION. IF WS-NO-DATA-AVAILABLE = 'Y' DISPLAY " 📂 NO DATA AVAILABLE condition detected" DISPLAY " Recommended actions:" DISPLAY " - Check file existence" DISPLAY " - Verify file permissions" DISPLAY " - Confirm data source" DISPLAY " - Review selection criteria" ELSE DISPLAY " 📂 Data is available for processing" DISPLAY " Records ready: " WS-RECORDS-PROCESSED END-IF. CHECK-NO-MATCHES-CONDITION. IF WS-NO-MATCHES = 'Y' DISPLAY " 🔍 NO MATCHES condition in search operation" DISPLAY " Possible reasons:" DISPLAY " - Search criteria too restrictive" DISPLAY " - Data not in expected format" DISPLAY " - Index needs rebuilding" DISPLAY " - Timing of data updates" ELSE DISPLAY " 🔍 Successful match operations" DISPLAY " Matches found and processed" END-IF. CHECK-DATA-AVAILABILITY. EVALUATE TRUE WHEN WS-NO-DATA-AVAILABLE = 'Y' DISPLAY " 📊 Status: NO DATA - Empty processing queue" WHEN WS-NO-MATCHES = 'Y' DISPLAY " 📊 Status: NO MATCHES - Refine search criteria" WHEN WS-NO-ERRORS-FOUND = 'N' DISPLAY " 📊 Status: ERRORS PRESENT - Review processing" WHEN OTHER DISPLAY " 📊 Status: OPTIMAL - Ready for operations" DISPLAY " ✓ Data available" DISPLAY " ✓ NO errors detected" DISPLAY " ✓ Successful matching" END-EVALUATE. DEMONSTRATE-VALIDATION-NO-ERRORS. DISPLAY "=== VALIDATION WITH NO ERRORS ===" DISPLAY SPACES DISPLAY "Performing validation with NO ERRORS tracking..." *> Initialize validation counters MOVE 0 TO WS-ERROR-COUNT MOVE 0 TO WS-WARNING-COUNT MOVE 'Y' TO WS-NO-ERRORS-FOUND MOVE 'Y' TO WS-NO-WARNINGS *> Sample transaction data for validation MOVE "TXN12345" TO TRANS-ID MOVE "CREDIT" TO TRANS-TYPE MOVE 1500.00 TO TRANS-AMOUNT MOVE "CUST01" TO CUSTOMER-ID PERFORM COMPREHENSIVE-VALIDATION *> Report validation results IF WS-NO-ERRORS-FOUND = 'Y' AND WS-NO-WARNINGS = 'Y' DISPLAY " ✅ VALIDATION PASSED - NO ERRORS and NO WARNINGS" DISPLAY " Transaction " TRANS-ID " is valid for processing" ADD 1 TO WS-SUCCESS-COUNT ELSE DISPLAY " ⚠️ VALIDATION ISSUES DETECTED" IF WS-NO-ERRORS-FOUND = 'N' DISPLAY " Errors found: " WS-ERROR-COUNT END-IF IF WS-NO-WARNINGS = 'N' DISPLAY " Warnings found: " WS-WARNING-COUNT END-IF END-IF DISPLAY SPACES. COMPREHENSIVE-VALIDATION. *> Validate transaction ID IF TRANS-ID = SPACES OR TRANS-ID = LOW-VALUES ADD 1 TO WS-ERROR-COUNT MOVE 'N' TO WS-NO-ERRORS-FOUND DISPLAY " ❌ Error: Transaction ID is missing" END-IF *> Validate transaction type EVALUATE TRANS-TYPE WHEN "CREDIT" WHEN "DEBIT" WHEN "TRANSFER" CONTINUE *> Valid types - NO errors WHEN OTHER ADD 1 TO WS-ERROR-COUNT MOVE 'N' TO WS-NO-ERRORS-FOUND DISPLAY " ❌ Error: Invalid transaction type" END-EVALUATE *> Validate amount (NO negative amounts for credits) IF TRANS-TYPE = "CREDIT" AND TRANS-AMOUNT <= 0 ADD 1 TO WS-ERROR-COUNT MOVE 'N' TO WS-NO-ERRORS-FOUND DISPLAY " ❌ Error: Credit amount must be positive" END-IF *> Check for warnings (NO major issues but worth noting) IF TRANS-AMOUNT > WS-DAILY-LIMIT ADD 1 TO WS-WARNING-COUNT MOVE 'N' TO WS-NO-WARNINGS DISPLAY " ⚠️ Warning: Amount exceeds daily limit" END-IF *> Validate customer ID IF CUSTOMER-ID = SPACES ADD 1 TO WS-ERROR-COUNT MOVE 'N' TO WS-NO-ERRORS-FOUND DISPLAY " ❌ Error: Customer ID is required" END-IF. DEMONSTRATE-BUSINESS-LOGIC-NO-CONDITIONS. DISPLAY "=== BUSINESS LOGIC WITH NO CONDITIONS ===" DISPLAY SPACES DISPLAY "Implementing business rules with NO conditions..." *> Sample customer data MOVE "CUST001" TO MASTER-KEY MOVE "JOHN SMITH" TO CUSTOMER-NAME MOVE 2500.00 TO ACCOUNT-BALANCE MOVE 5000.00 TO CREDIT-LIMIT *> Sample transaction MOVE 3000.00 TO TRANS-AMOUNT MOVE "DEBIT" TO TRANS-TYPE PERFORM BUSINESS-RULE-VALIDATION DISPLAY SPACES DISPLAY "Business logic summary:" DISPLAY " Successful validations: " WS-SUCCESS-COUNT DISPLAY " Errors encountered: " WS-ERROR-COUNT DISPLAY " Warnings issued: " WS-WARNING-COUNT DISPLAY SPACES. BUSINESS-RULE-VALIDATION. DISPLAY " Checking business rules..." *> Rule 1: NO overdraft beyond credit limit COMPUTE WS-CALC-RESULT = ACCOUNT-BALANCE - TRANS-AMOUNT IF WS-CALC-RESULT < (CREDIT-LIMIT * -1) DISPLAY " ❌ Rule violation: NO OVERDRAFT allowed beyond credit limit" DISPLAY " Current balance: $" ACCOUNT-BALANCE DISPLAY " Transaction amount: $" TRANS-AMOUNT DISPLAY " Resulting balance: $" WS-CALC-RESULT DISPLAY " Credit limit: $" CREDIT-LIMIT ADD 1 TO WS-ERROR-COUNT MOVE 'N' TO WS-NO-ERRORS-FOUND ELSE DISPLAY " ✅ Rule passed: NO OVERDRAFT violation" ADD 1 TO WS-SUCCESS-COUNT END-IF *> Rule 2: NO transactions above maximum limit IF TRANS-AMOUNT > WS-MAXIMUM-TRANSACTION DISPLAY " ❌ Rule violation: NO TRANSACTIONS above maximum" DISPLAY " Transaction: $" TRANS-AMOUNT DISPLAY " Maximum allowed: $" WS-MAXIMUM-TRANSACTION ADD 1 TO WS-ERROR-COUNT MOVE 'N' TO WS-NO-ERRORS-FOUND ELSE DISPLAY " ✅ Rule passed: NO MAXIMUM limit violation" ADD 1 TO WS-SUCCESS-COUNT END-IF *> Rule 3: NO credits to accounts with negative balance restrictions IF TRANS-TYPE = "CREDIT" AND ACCOUNT-BALANCE < 0 DISPLAY " ⚠️ Warning: Credit to negative balance account" DISPLAY " Consider account review" ADD 1 TO WS-WARNING-COUNT MOVE 'N' TO WS-NO-WARNINGS ELSE DISPLAY " ✅ Rule passed: NO NEGATIVE balance restriction" END-IF. VALIDATE-TRANSACTION. *> Reset validation flags MOVE 'Y' TO WS-NO-ERRORS-FOUND MOVE 0 TO WS-ERROR-COUNT *> Basic validation - NO missing data IF TRANS-ID = SPACES MOVE 'N' TO WS-NO-ERRORS-FOUND ADD 1 TO WS-ERROR-COUNT END-IF IF CUSTOMER-ID = SPACES MOVE 'N' TO WS-NO-ERRORS-FOUND ADD 1 TO WS-ERROR-COUNT END-IF IF TRANS-AMOUNT <= 0 MOVE 'N' TO WS-NO-ERRORS-FOUND ADD 1 TO WS-ERROR-COUNT END-IF. UPDATE-MASTER-RECORD. *> Simulate master record update DISPLAY " Updating master record for customer: " CUSTOMER-ID *> This would typically involve: *> - Reading master record *> - Applying transaction *> - Rewriting master record *> - Handling any NO RECORD FOUND conditions CONTINUE.

NO Usage Patterns

Arithmetic NO SIZE ERROR
  • • Overflow detection and handling
  • • Safe arithmetic operations
  • • Result validation and control
  • • Error prevention strategies
File NO Operations
  • • NO REWIND for tape files
  • • NO ADVANCING in print operations
  • • Position control and management
  • • Sequential processing control

Interactive Tutorial

Hands-On Exercise: Error-Free Processing
Practice using NO conditions for robust error handling and validation

Exercise 1: Safe Calculator

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
01 WS-CALCULATOR. 05 WS-OPERAND-1 PIC S9(8)V99. 05 WS-OPERAND-2 PIC S9(8)V99. 05 WS-RESULT PIC S9(10)V99. 05 WS-OPERATION PIC X(8). 05 WS-NO-ERRORS PIC X VALUE 'Y'. PROCEDURE DIVISION. SAFE-CALCULATION. MOVE 1000000.50 TO WS-OPERAND-1 MOVE 999999.75 TO WS-OPERAND-2 MOVE "ADD" TO WS-OPERATION EVALUATE WS-OPERATION WHEN "ADD" ADD WS-OPERAND-2 TO WS-OPERAND-1 GIVING WS-RESULT NO SIZE ERROR DISPLAY "✓ Addition: " WS-RESULT MOVE 'Y' TO WS-NO-ERRORS ON SIZE ERROR DISPLAY "❌ Addition overflow detected" MOVE 'N' TO WS-NO-ERRORS END-ADD WHEN "MULTIPLY" MULTIPLY WS-OPERAND-1 BY WS-OPERAND-2 GIVING WS-RESULT NO SIZE ERROR DISPLAY "✓ Multiplication: " WS-RESULT ON SIZE ERROR DISPLAY "❌ Multiplication overflow" MOVE WS-OPERAND-1 TO WS-RESULT END-MULTIPLY WHEN "DIVIDE" IF WS-OPERAND-2 NOT = 0 DIVIDE WS-OPERAND-1 BY WS-OPERAND-2 GIVING WS-RESULT NO SIZE ERROR DISPLAY "✓ Division: " WS-RESULT ON SIZE ERROR DISPLAY "❌ Division overflow" END-DIVIDE ELSE DISPLAY "❌ NO DIVISION by zero allowed" MOVE 'N' TO WS-NO-ERRORS END-IF END-EVALUATE IF WS-NO-ERRORS = 'Y' DISPLAY "✅ Calculation completed with NO ERRORS" ELSE DISPLAY "⚠️ Calculation had errors" END-IF.

Exercise 2: Data Validation System

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
01 WS-VALIDATION-SYSTEM. 05 WS-INPUT-DATA PIC X(50). 05 WS-DATA-TYPE PIC X(10). 05 WS-NO-ERRORS PIC X VALUE 'Y'. 05 WS-NO-WARNINGS PIC X VALUE 'Y'. 05 WS-ERROR-COUNT PIC 9(3) VALUE 0. PROCEDURE DIVISION. VALIDATE-INPUT-DATA. MOVE "12345.67" TO WS-INPUT-DATA MOVE "NUMERIC" TO WS-DATA-TYPE *> Reset validation flags MOVE 'Y' TO WS-NO-ERRORS MOVE 'Y' TO WS-NO-WARNINGS MOVE 0 TO WS-ERROR-COUNT EVALUATE WS-DATA-TYPE WHEN "NUMERIC" IF WS-INPUT-DATA IS NUMERIC DISPLAY "✓ NO ERRORS - Valid numeric data" ELSE ADD 1 TO WS-ERROR-COUNT MOVE 'N' TO WS-NO-ERRORS DISPLAY "❌ Non-numeric data detected" END-IF WHEN "ALPHA" IF WS-INPUT-DATA IS ALPHABETIC DISPLAY "✓ NO ERRORS - Valid alphabetic data" ELSE ADD 1 TO WS-ERROR-COUNT MOVE 'N' TO WS-NO-ERRORS DISPLAY "❌ Non-alphabetic data detected" END-IF WHEN "ALPHANUMERIC" IF WS-INPUT-DATA IS ALPHANUMERIC DISPLAY "✓ NO ERRORS - Valid alphanumeric data" ELSE ADD 1 TO WS-ERROR-COUNT MOVE 'N' TO WS-NO-ERRORS DISPLAY "❌ Invalid data format" END-IF END-EVALUATE *> Check for empty data (NO DATA condition) IF WS-INPUT-DATA = SPACES ADD 1 TO WS-ERROR-COUNT MOVE 'N' TO WS-NO-ERRORS DISPLAY "❌ NO DATA provided for validation" END-IF *> Final validation summary IF WS-NO-ERRORS = 'Y' AND WS-NO-WARNINGS = 'Y' DISPLAY "🎉 Validation complete: NO ERRORS, NO WARNINGS" ELSE DISPLAY "⚠️ Validation issues detected:" DISPLAY " Errors: " WS-ERROR-COUNT IF WS-NO-WARNINGS = 'N' DISPLAY " Warnings present" END-IF END-IF.

Best Practices

Knowledge Check

Test Your Understanding

Question 1: NO SIZE ERROR

What happens when NO SIZE ERROR is specified in arithmetic operations?

Answer: When NO SIZE ERROR is specified, the statements following it execute only when no arithmetic overflow occurs. If overflow happens, control passes to the ON SIZE ERROR statements instead, providing explicit overflow handling.

Question 2: NO vs NOT

What's the difference between NO and NOT in COBOL?

Answer: NO is used in specific COBOL phrases and contexts (NO SIZE ERROR, NO REWIND, NO DATA), while NOT is a general logical negation operator that can be used with any condition. NO appears in predefined language constructs.

Question 3: NO DATA Conditions

How should NO DATA conditions be handled in business applications?

Answer: NO DATA conditions should be explicitly tested and handled with appropriate user messages, alternative processing paths, or default behaviors. Always validate data availability before processing and provide meaningful feedback when no data is found.

Related Pages