The NEXT SENTENCE statement transfers control to the next COBOL statement, which is immediately after the sentence ending with period.
It does not transfer control to the logically next COBOL verb.
Statement - Format:
How to use NEXT SENTENCE in COBOL?
It can be used anywhere in the programming construction like conditional statement or normal flow of program.
It is used to change the flow of execution based on the condition passed to the logically next COBOL verb following the next period.
It has a impact on program flow which will skips the statements in between NEXT SENTENCE and period.
It will not come along with any other statement coded above or below.
In the below example, if student marks are less than 35 then the NEXT SENTENCE transfers the control to the immediate statement after the period(.)
IDENTIFICATION DIVISION. PROGRAM-ID. CBLCONTU. ENVIRONMENT DIVISION. DATA DIVISION. WORKING-STORAGE SECTION. 01 STD-MARKS PIC 9(03). 01 TOTAL-MARKS PIC 9(03) VALUE ZEROES. 01 STD-PERCENT PIC 9(03).9(02). 01 I PIC 9(01) VALUE ZEROES. 01 J PIC 9(01) VALUE ZEROES. PROCEDURE DIVISION. MOVE ZEROES TO TOTAL-MARKS. * Logic below to get 5 subject marks from input. PERFORM VARYING I FROM 1 BY 1 UNTIL I > 5 SET STD-INDEX TO 1 ACCEPT STD-MARKS IF STD-MARKS < 35 NEXT SENTENCE ELSE ADD STD-MARKS TO TOTAL-MARKS COMPUTE J = J + 1 END-IF END-PERFORM. * Logic below display student result. IF J < 5 DISPLAY 'STUDENT FAILED, NO PERCENTAGE CALCULATED' ELSE COMPUTE STD-PERCENT = TOTAL-MARKS/5 DISPLAY 'STUDENT PERCENTAGE : ' STD-PERCENT. END-IF. STOP RUN.
If student pass on all 5 subjects, then program display 'STUDENT PERCENTAGE : ' STD-PERCENT. Where STD-PERCENT hold the value 0f student percentage.
If student failed in any 1 subject, then program display message "STUDENT FAILED, NO PERCENTAGE CALCULATED"
If you have any doubts or queries related to this chapter, get them clarified from our Mainframe experts on ibmmainframer Community!