Javatpoint Logo
Javatpoint Logo

COBOL - Verbs

The 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 Verbs
    • ACCEPT
    • DISPLAY
  • Data Manipulation/Arithmetic Verbs
    • INITIALIZE
    • MOVE
    • ADD
    • SUBTRACT
    • MULTIPLY
    • DIVIDE
    • COMPUTE
  • String Handling Verbs
    • STRING
    • UNSTRING
    • INSPECT
  • File Handling Verbs
    • OPEN
    • CLOSE
    • READ
    • WRITE
    • REWRITE
    • START
    • DELETE
  • Program Branching Verbs
    • CALL
    • EXIT
    • EXIT PROGRAM
    • GO TO
    • PERFORM
    • STOP
    • STOP RUN
Let's discuss these verbs in detail:

Input/output Verbs

Input/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:

ACCEPT

Accept 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:

DISPLAY

This 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.

COBOL Verbs

And press Enter. It will display the following output:

Output:

COBOL Verbs

Data Manipulation/Arithmetic Verbs

These verbs are used for data processing and to perform arithmetic operations.

INITIALIZE

This 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:

COBOL Verbs

MOVE

Move 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:

COBOL Verbs

The following are the legal moves:

Alphabetic Alphanumeric Numeric
Alphabetic Possible Possible Not Possible
Alphanumeric Possible Possible Possible
Numeric Not Possible Possible Possible

ADD

This 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:

COBOL Verbs

SUBTRACT

This 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.

  • The result will be stored in the data items given after the word GIVING when using the GIVING option.
  • When the GIVING option is not used, the result will be stored in the data items given after 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:

COBOL Verbs

MULTIPLY

A 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:

COBOL Verbs

DIVIDE

DIVIDE 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:

COBOL Verbs

COMPUTE

COMPUTE verb in COBOL writes arithmetic expressions. Compute verb is a substitute for Add, subtract, multiply, and divide verbs.

Example:

Output:

COBOL Verbs
Next TopicCOBOL Data Layout




Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA