NEXT SENTENCE Statement
NEXT SENTENCE Statement
The NEXT SENTENCE statement transfers the control to the next COBOL statement immediately after the next period ('.'). It means skipping over certain statements and proceeding to the subsequent set of statements.
Note! It's important to note that, over the years, the use of NEXT SENTENCE has reduced, and the CONTINUE statement is now more commonly used to serve the same purpose.
Syntax -
NEXT SENTENCE
Rules -
- The NEXT SENTENCE statement can use anywhere in the PROCEDURE DIVISION.
- It is used to change the flow of the execution based on the condition.
- It has a impact on the program flow that skips the statements in between NEXT SENTENCE and period.
Practical Example -
Scenario - Add 2000 to salary if it is less than 5000.
Code -
----+----1----+----2----+----3----+----4----+----5----+
IDENTIFICATION DIVISION.
PROGRAM-ID. NEXTSENT.
AUTHOR. MTH.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 WS-VAR.
05 WS-SALARY PIC 9(04).
PROCEDURE DIVISION.
* Accepting Salary amount from input
ACCEPT WS-SALARY.
* Salary is greater than 5000, do nothing
IF WS-SALARY GREATER THAN 5000
NEXT SENTENCE
END-IF
COMPUTE WS-SALARY = WS-SALARY + 2000.
* Displaying Salary
DISPLAY "SALARY: " WS-SALARY.
STOP RUN.
Run JCL -
//MATESYD JOB MSGLEVEL=(1,1),NOTIFY=&SYSUID //* //STEP01 EXEC PGM=NEXTSENT //STEPLIB DD DSN=MATESY.COBOL.LOADLIB,DISP=SHR //SYSOUT DD SYSOUT=* //SYSIN DD * 7000 /*
Output -
SALARY: 7000
Explaining example -
In the above example, the input salary is 7000 which is greater than 5000. So, the NEXT SENTENCE gets executed and control transfers to the next sentence in the flow (DISPLAY statement).