Let's understand Mainframe
Home Tutorials Interview Q&A Quiz Mainframe Memes Contact us About us

MODULE 7: COBOL Control statements


NEXT SENTENCE

  • “NEXT STENETECE” is used to transfer control to the next sentence. As you already know multiple COBOL statements are combined to form a sentence and sentence is terminated by period (.)
  • We already studied that CONTINUE statement is used to do nothing and just passes control to next statement (whereas NEXT SENTENCE passes control to next sentence)
  • NEXT SENTENCE also does nothing, it just transfer control to next statement after the nearest period(.) which marks the end of current sentence
  • Syntax:-

    NEXT SENTENCE

  • Example:-
    Below example will demonstrate use of NEXT SENTENCE. Please note that in below example, we are using program logic as used in example of CONTINUE statement (in previous topic). This will help you understand the difference between NEXT SENTENCE and CONTINUE.
    In PROCEDURE DIVISION,

    MOVE 10000 TO EMP-SALARY. IF EMP-GRADE = ‘C’ THEN NEXT SENTENCE ELSE ADD 1000 TO EMP-SALARY END-ID DISPLAY ‘NEW SALARY: ‘ EMP-SALARY. DISPLAY ‘EMP-GRADE: ‘ EMP-GRADE.

    Let say, in above code snippet, EMP-GRADE can be either ‘A’, ’B’ or ‘C’. Now, since we have used NEXT SENTENCE in THEN part of IF statement, if suppose EMP-GRADE=’C’, then control will be transferred to next sentence i.e. directly EMP-GRADE will be displayed. NEW-SALARY will not be displayed because that DISPLAY statement is part of sentence where IF and NEXT SENTENCE is coded. That sentence ends by period after DISPLAY of NEW-SALARY
    In above example, it makes more sense to use NEXT SENTENCE instead of CONTINUE because definitely when there is no increment for grade ‘C’ employees, it makes no sense to display their New Salary since they already know their default salary.
    SYSOUT display (output) when EMP-GRADE = ‘A’:-

    NEW-SALARY: 11000 EMP-GRADE: A

    SYSOUT display (output) when EMP-GRADE = ‘C’:-

    EMP-GRADE: C

  • Flow diagram to demonstrate code flow of above example:-
  • You can compare above flow diagram with flow diagram provided in previous topic “CONTINUE” to better understand difference between NEXT SENTENCE and CONTINUE






© copyright mainframebug.com
Privacy Policy