Basic Verbs in COBOL
Introduction
- Verbs in COBOL are used for processing the data in the procedure division.
- A statement always begins with the COBOL verb.
Various Verbs in COBOL
1. Input / Output Verbs
These verbs are used to get data from the user i.e input and shows the output of the COBOL program.
Two verbs are used for this process:
i. Accept Verb- Accept verb is used to get the data like date, time and day from the user or operating system.
- The data is required to pass via JCL when it accepts from the user.
- It includes the FROM option while getting data from the operating system.
For example:
ACCEPT WS-EMPLOYEE-NAME.
ACCEPT WS-DATE FROM SYSTEM-DATE.
ii. Display Verb
The output of a COBOL program is shown using display verb.
For example:
DISPLAY WS-EMPLOYEE-NAME.
DISPLAY “System date is : “ WS-DATE.
2. Initialize Verb- Initialize verb is used for initializing the group or elementary item.
- It cannot initialize the data names with RENAME clause.
- It replaces the numeric data items by ZERO(0).
- It replaces alphabetic or alphanumeric data items by SPACE.
Example : Demonstration of initialize verb using REPLACING term
IDENTIFICATION DIVISION.
PROGRAM-ID. IN-VERB.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 WS-EMP-NAME PIC A(30) VALUE 'UVWXYZ'.
01 WS-EMP-ID PIC 9(7).
01 WS-EMP-ADDRESS.
05 WS-STREET-NUMBER PIC 9(2).
05 WS-STATE PIC X(15).
05 WS-PIN-CODE PIC 9(5) VALUE 67993.
PROCEDURE DIVISION.
A000-FIRST-PARA.
INITIALIZE WS-EMP-NAME, WS-EMP-ADDRESS.
INITIALIZE WS-EMP-ID REPLACING NUMERIC DATA BY 258791.
DISPLAY "EMP name is : "WS-EMP-NAME.
DISPLAY "EMP ID is : "WS-EMP-ID.
DISPLAY "Address : "WS-EMP-ADDRESS.
DISPLAY "Street Number : "WS-STREET-NUMBER.
DISPLAY "State : "WS-STATE.
DISPLAY "Pin-code : "WS-PIN-CODE.
STOP RUN.
Output:
EMP name is :
EMP ID is : 0258791
Address : 00 00000
Street Number : 00
State :
Pin-code : 00000