Monday, 28 July 2014

Mastering the DISPLAY Statement in COBOL: Printing Output with Ease!

COBOL Display statement
DISPLAY Statement in COBOL.

COBOL has a rich set of features, including the DISPLAY statement, which provides a way for the programmer to display output data, messages, or prompts to the user. The DISPLAY statement is a simple and straightforward way to display output in COBOL. 

Whether you are displaying literal text or the value of a variable, the DISPLAY statement provides a convenient way to present data to the user. In this article, we will take a closer look at the DISPLAY statement in COBOL and see how it can be used to print output on the screen.

COBOL Display Statement - Introduction. 

COBOL (Common Business Oriented Language) is a high-level programming language that is mainly used for developing business applications. In COBOL, the DISPLAY statement is used to print data on the screen or console. This statement provides a way for the programmer to display output data, messages, or prompts to the user.

It is an important tool for debugging and testing COBOL programs, as it allows developers to see the values of variables and intermediate results during the execution of a program. 

COBOL DISPLAY Statement vs COBOL ACCEPT Statement. 

The DISPLAY and ACCEPT statements in COBOL serve different purposes:

COBOL DISPLAY Verb:
  • Used to output data stored in variables or literals to the console.
  • It displays information on the screen but does not wait for user input.
  • Commonly used for debugging, displaying messages, or showing results of computations.

COBOL ACCEPT Verb:
  • Used to receive input from the user.
  • It prompts the user to enter data, which is then stored in a specified variable.
  • Commonly used for accepting user input, such as data for calculations, user names, and passwords.
In short, DISPLAY outputs data to the screen, while ACCEPT receives data from the user.

Note: The function of the DISPLAY verb is exactly opposite to that of the ACCEPT statement. It is used to display low-volume results on the operator’s console or some other output device. 

Display Statment Syntax.

The syntax of the DISPLAY statement in COBOL is as follows:
COBOL DISPLAY Statement.


However, the simplified format of the COBOL Display statement is showcased below: 

   DISPLAY [ literal-string | identifier ]

Note: Where the literal string is the text that you want to display on the screen, and the identifier is a variable that holds the data you want to display.

COBOL Display Statement Example. 

Here is an example of how the DISPLAY statement can be used in COBOL:

    IDENTIFICATION DIVISION.
    PROGRAM-ID. EMP001.
...
...
...
    PROCEDURE DIVISION.
...
        DISPLAY "HELLO WORLD!".
...
...
    STOP RUN.

In this example, the DISPLAY statement is used to print the string "Hello World!" on the screen. The STOP RUN statement is used to end the program.

COBOL Display Statement with Variables Example.

You can also use the DISPLAY statement to display the value of a variable. For example:

    IDENTIFICATION DIVISION.
...
    PROGRAM-ID. EMP002.
...
    DATA DIVISION.
...
    WORKING-STORAGE SECTION.
...
    01 WS-NAME     PIC X(30).
...
...
    PROCEDURE DIVISION.
...
        MOVE "MAINFRAME FORUM" TO WS-NAME.
        DISPLAY WS-NAME.
...
...
    STOP RUN.

In this example, the DISPLAY statement is used to display the value of the variable WS-NAME, which holds the string "MAINFRAME FORUM".

Conclusion.

In conclusion, the DISPLAY verb is a fundamental statement in COBOL used for outputting information to the console. It allows you to display data stored in variables or literals and is commonly used for debugging, displaying messages, or showing results of computations. Understanding and properly utilizing the DISPLAY verb is essential for effective COBOL programming. 


Subscribe to Topictrick & Don't forget to press THE BELL ICON to never miss any updates. Also, Please visit mention the link below to stay connected with Topictrick and the Mainframe forum on - 

► Youtube
► Facebook 
► Reddit

Thank you for your support. 

Mainframe Forum™

Created with Artisteer

No comments:

Post a Comment