COBOL - VerbsThe Procedure division contains the code used to perform the manipulation of the data described in the Data Division. The procedure division uses COBOL verbs for data processing. A statement always initiates with a COBOL verb. In COBOL, there are several verbs with different types of actions.
Input/output VerbsInput/output verbs are used to obtain the user data and display the output of COBOL programs. For this process, the following two verbs are used: ACCEPTAccept verb obtains data from the OS or the user. It gets data like day, date, time. If a program accepts user data, it needs to be passed by the user. We can use the FROM option when extracting data from the operating system, as shown in the example below: DISPLAYThis verb displays a COBOL program's output. Example: After compiling and running the program, the program will prompt you to enter the name and date. Enter the subject name and date. And press Enter. It will display the following output: Output: Data Manipulation/Arithmetic VerbsThese verbs are used for data processing and to perform arithmetic operations. INITIALIZEThis verb is used to initialize a specific item or group item. ZEROES replace numeric data items. It is not possible to initialize data names with the RENAME clause. Alphanumeric or alphabetic data objects are replaced by SPACES. If we include the term REPLACING, the data items can be initialized to the replacement value. As shown in the given example: Example: Output: MOVEMove verb is used to copy data from source to destination data. We can use it for both group and elementary data items. For group items, MOVE CORRESPONDING / CORR is used.Use the MOVE(x: l) where x is the starting position, and l is the length to transfer data from a string. The data will be truncated if the PIC clause for the destination data item is less than the PIC clause for the source data item. If the PIC clause for the destination data item is above, then the PIC clause for the source data item, the additional bytes will include ZEROS or SPACES. Example: Let's see one example to make all the things clear: Output: The following are the legal moves:
ADDThis verb adds two or more numbers and stores the result in the destination operand. Syntax: Let's see some examples: Example 1: Here, suppose the value of A is 5; after the execution of the above statement, a will be 15. Means, (10 + A). Example 2: Here, A, B, C, D are added and the result is stored in E (E = A + B + C + D). Example 3: Here, subgroup items within A and B are added, and the results are added, and the result is stored in B. Example:Now, let's see one example through the program in COBOL: Output: SUBTRACTThis verb is used to perform subtraction operations. Syntax: Here, ROUNDED is optional. Before using the SUBTRACT verb, there are some rules: All the values before the word FROM summed up and subtracted from each data-item/constant after the word FROM.
Example 1: Here, 10 will be subtracted from A, and the result will be stored in A., i.e. (10 + A). Example 2: Here, A, B, C are added and subtracted from D. The result is stored in E (E = D-(A+B+C)). Example 3: Here, sub-group items within WS-GROUP1 and WS-GROUP2 are subtracted, and the result is stored in WS-GROUP2. Example:Now, let's see one example through the program in COBOL: Output: MULTIPLYA multiply verb is used to perform multiplication operations. Syntax: Here, ROUNDED is optional. Example 1: Here, values in A and B will be multiplied, and the result will be stored in B. (B = A * B). Example 2: Here, values in A and B will be multiplied, and the result is stored in B (B = A * B). Values in A and C are multiplied, and the result is stored in C (C = A * C). Example 3: Here, values in A and B are multiplied, and the result is stored in E (E=A * B). Example:Now, let's see one example through the program in COBOL: Output: DIVIDEDIVIDE verb is used to perform a division operation. Syntax: Example 1: Here, the value of B is divided by the value of A, and the result is stored in B (B = B/A). Here, the value of A is divided by the value of B, and the result is stored in C (C = A/B), and the Remainder is stored in R. Example:Now, let's see one example through the program in COBOL: Output: COMPUTECOMPUTE verb in COBOL writes arithmetic expressions. Compute verb is a substitute for Add, subtract, multiply, and divide verbs. Example:Output: Next TopicCOBOL Data Layout |