Next Sentence in COBOL
Last Updated :
12 Aug, 2022
In COBOL programming language we have three types of logical statements:
1. Sequence Statements: Used when we need to execute some piece of code repeatedly till some sequence. Like reading each data/record from some file till the end.
2. Selection Statements: Used when we want to flow the program based on some condition results, Like IF-ELSE condition or we can say true – a false type of condition.
3. Iteration Statements: It is nothing but loop statements, used when we want to execute some code repeatedly based on some condition
Next Sentence:
In COBOL Next Sentence will be used to pass the control to the next executable statement, next to the states where it finds the period(i.e. dot “.“). As we know COBOL will consider the period as the end of the ongoing statement.
Syntax:
NEXT SENTENCE
Example:
Cobol
COBOL program for Next Sentence
IDENTIFICATION DIVISION .
PROGRAM - ID . NEXTSENTENCE.
DATA DIVISION .
WORKING-STORAGE SECTION .
01 WS-EMP-NAME PIC X( 20 ).
01 WS-EMP-RATING PIC 9 ( 01 ).
01 WS-BONUS PIC 9 ( 06 )V99.
01 WS-SALARY PIC 9 ( 06 )V99 VALUE 600000.00 .
01 WS-INCREMENTED-SALARY PIC 9 ( 07 )V99.
01 WS-PERCENT PIC 9 ( 03 )V99 VALUE ZEROES.
01 WS-FLAG PIC X( 01 ).
PROCEDURE DIVISION .
DISPLAY 'ENTER THE NAME OF EMPLOYEE: '
ACCEPT WS-EMP-NAME
DISPLAY 'ENTER THE RATING OF EMPLOYEE OUT OF 5: '
ACCEPT WS-EMP-RATING
DISPLAY 'EMPLOYEE NAME IS: ' WS-EMP-NAME
DISPLAY 'EMPLOYEE SALARY IS: ' WS-SALARY
DISPLAY 'EMPLOYEE RATING IS: ' WS-EMP-RATING
IF WS-EMP-RATING < 3
NEXT SENTENCE
ELSE
MOVE 'T' TO WS-FLAG
DISPLAY 'ENTER THE BONUS OF EMPLOYEE: '
ACCEPT WS-BONUS
ADD WS-BONUS,WS-SALARY TO WS-INCREMENTED-SALARY
COMPUTE WS-PERCENT = (WS-BONUS/WS-SALARY)* 100
DISPLAY 'INCREMENTAL PERCENTAGE : ' WS-PERCENT ' %'
DISPLAY 'NEW SALARY IS : ' WS-INCREMENTED-SALARY
END - IF .
IF WS-FLAG = 'T'
DISPLAY 'CONGRATULATION...'
ELSE
DISPLAY 'NO BONUS FOR EMPLOYEE...'
END - IF .
STOP RUN .
|
Output:
Explanation:
In this example we are considering the annual appraisal of the employee in any organization, if the rating of the employee is more than ‘3’ then he/she should get a bonus and his/her salary should get increase. so we are printing the incremented salary and incremented percentage of the employee in the positive test scenario.
For the negative test case, if the rating of the employee is less than 3 then we are using NEXT SENTENCE which will skip the adding bonus statement and directly come out of the program by displaying the final statement.
Share your thoughts in the comments
Please Login to comment...