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.
Similar Reads
Linkage Section in COBOL The linkage Section in COBOL is used to declare the variables and it is used in calling the variable from another program. It is used in calling the variable or data from the called program by using the CALL statement. The linkage Section helps in sending the data to the calling program or receivin
4 min read
Coding Sheet in COBOL Every language needs an environment or platform to write codes. For example, in Java, we use notepad to write codes then compile them to run. Similarly, COBOL requires a coding sheet to write codes. COBOL is a business-oriented high-level language. It was developed for business, finance, and adminis
7 min read
File Section in COBOL COBOL is a high-level programming language for business applications or business use. It was designed in 1959 by the Conference on Data Systems Language (CODASYL). It was primarily used in business, finance, and administration system for companies and governments. COBOL is still widely used in appli
6 min read
Search in COBOL The SEARCH keyword is used to check for the presence or absence of some particular elements in any tables or arrays. We can find an element either by performing loop operations or by using the SEARCH keyword. We can even go for SEARCH ALL but this article will read about the SEARCH keywords only. Sy
2 min read
Internal Sort in COBOL Internal Sequential files are often used in big data operational processing applications, necessitating the records to be arranged in an operational ascending or descending order. This ensures quick access to the data and makes it easier to retrieve. Furthermore, sorting data in a file or combining
4 min read
Input-Output Section in COBOL In COBOL, the INPUT-OUTPUT SECTION is a section of the program where you can define file-handling statements. These statements are used to read from or write to external files, such as data files or report files. The INPUT-OUTPUT SECTION follows the FILE SECTION and comes before the PROCEDURE DIVISI
6 min read