NEXT SENTENCE Statement


  • NEXT SENTENCE transfers the control to the following COBOL statement immediately after the explicit scope terminator (period - '.') in the flow.
  • It means skip processing all statements in middle and executing the subsequent statements block.
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 -

  • NEXT SENTENCE can be coded anywhere in the PROCEDURE DIVISION.
  • It is used to change the execution flow based on the condition.
  • It impacts the program flow by skipping the statements between NEXT SENTENCE and the explicit scope terminator (period—'.').

Practical Example -


Scenario - Add 2000 to salary if it is less than 5000.

Code -

----+----1----+----2----+----3----+----4----+----5----+
       ...
       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. 
           ...

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