The NEXT SENTENCE statement in COBOL transfers control to the statement following the next period (sentence terminator) in the program. It is commonly used within IF statements to skip the execution of subsequent statements.
The NEXT SENTENCE statement has a simple syntax:
1NEXT SENTENCE.
NEXT SENTENCE transfers control to the statement after the next period.
1234567IF condition NEXT SENTENCE ELSE PERFORM some-procedure. DISPLAY "This will be executed if condition is false.". * Control transfers here if condition is true
12345678910IF condition1 NEXT SENTENCE ELSE IF condition2 NEXT SENTENCE ELSE PERFORM default-procedure. DISPLAY "Default action taken.". * Control transfers here if either condition is true
Here are some practical uses of NEXT SENTENCE in COBOL:
1234567891011VALIDATE-INPUT. IF input-field = SPACES NEXT SENTENCE ELSE IF input-field IS NOT NUMERIC NEXT SENTENCE ELSE PERFORM PROCESS-VALID-INPUT. DISPLAY "Input processed successfully.". * Control continues here if input is invalid
Skips processing if input validation fails.
12345678PROCESS-RECORD. IF record-status = "ERROR" NEXT SENTENCE ELSE PERFORM PROCESS-VALID-RECORD. DISPLAY "Record processed.". * Error records are skipped, control continues here
Skips processing of error records.
1. What does the NEXT SENTENCE statement do in COBOL?
2. Where is NEXT SENTENCE typically used?
3. What is the difference between NEXT SENTENCE and CONTINUE?
4. Is NEXT SENTENCE considered good practice in modern COBOL?
5. What happens if NEXT SENTENCE is used outside an IF statement?