Next Sentence Example


Scenario - Salary is greater than 5000, do nothing.

Input - 7000

Code -

----+----1----+----2----+----3----+----4----+----5----+
       IDENTIFICATION DIVISION.
       PROGRAM-ID. NEXTSENT. 
       AUTHOR. MTH.

       DATA DIVISION.
       WORKING-STORAGE SECTION.
       01 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).