Wednesday, February 17, 2010

3. ACCEPT/DISPLAY verbs

The PROCEDURE DIVISION contains all the instructions required for processing. It is divided into various paragraphs or modules. Each module consists of sentences.

The ACCEPT and DISPLAY verbs are used for input and output in conjunction with storage fields that are not part of any files.

ACCEPT
The instruction ACCEPT identifier enable the user to enter input data directly from a keyboard.

Eg 3.1:
ACCEPT MY-NAME.

DISPLAY
DISPLAY can reference a series of identifiers or literals.

Eg 3.2:
DISPLAY MY-NAME.
DISPLAY “HELLO”.

STOP RUN
The verb STOP RUN terminates program execution. A program may contain more than one STOP RUN statement, depending on the logic of the program. STOP RUN signifies the logical end of the program.

A program using DISPLAY and ACCEPT.
Eg 3.3:
IDENTIFICATION DIVISION.
PROGRAM-ID. SAMPLE2.
*This program accepts the user’s name and displays a message.
AUTHOR. XYZ.
DATE-WRITTEN. 1-JUN-2000.
DATE-COMPILED.

ENVIRONMENT DIVISION.
CONFIGURATION SECTION.
SOURCE-COMPUTER. IBM-PC.
OBJECT-COMPUTER. IBM-PC.

DATA DIVISION.
WORKING-STORAGE SECTION.
01 USER-NAME PIC X(15).
PROCEDURE DIVISION.
0000-MAIN.
DISPLAY “Enter your name : “.
ACCEPT USER-NAME.
DISPLAY “HELLO “ USER-NAME.
STOP RUN.

Back to COBOL Index

No comments: