Saturday 11 February 2023

COBOL Accept Statement: A Complete Guide for Beginners!

COBOL ACCEPT Statement, COBOL ACCEPT VERB
COBOL ACCEPT Statement.


The COBOL ACCEPT statement is one of the most crucial functions of the COBOL programming language. The COBOL accept verb is used to input data from the keyboard or any other input device into a COBOL program. In this article, we will explore the significance of the COBOL ACCEPT statement and how it works in COBOL. Let's get started with the ACCEPT Statement in COBOL.

Introduction to COBOL Accept Statement. 

The term COBOL stands for Common Business Oriented Language. It is a high-level programming language widely used for enterprise computing. COBOL is fully loaded with tons of functions that can be leveraged by programmers to accomplish their business requirements. The COBOL Accept statement or COBOL Accept verb is one such feature of COBOL that enables users to interact with the program. 

What is a COBOL Accept Statement?

The ACCEPT statement in COBOL is used to receive input from the user in a COBOL program. In fact, the COBOL accepts statements that allow you to create interactive programs that can prompt the user for input and store the entered data in COBOL variables for further processing. 

Purpose of using COBOL Accept Statement

The function of the COBOL ACCEPT statement is to receive data from the user, that can be used in the program for further processing. The ACCEPT statement in COBOL is commonly used in interactive COBOL programs, where the user needs to enter data for the program to process. The COBOL Accept statement can be used to create input screens, prompt messages, and accept data from the user in a COBOL program.

How to use COBOL Accept Statement

The COBOL Accept statement is pretty straight forwards and can use in the procedure division of the COBOL program. The syntax of the COBOL Accept statement is as follows:

Syntax of COBOL Accept Statement:

The syntax of the COBOL Accept statement is as follows:


ACCEPT identifier  FROM [ mnemonic name | DATE | DAY | TIME ]

 

Note: If the FROM option is omitted, then the data is read into the identifier with left JUSTIFICATION from the operator’s console. However, if the FROM option is included, then the data is read from either the specified hardware device or the operating system.

Implementing COBOL Accept Statement in a Program.

In order, to implement the COBOL Accept verb in your program you have to follow the following steps:
  • Declare the data item in the working storage section. This data item will be used to store value input by the user. 
  • In the procedure division, use the COBOL ACCEPT statement to receive input from the user.
  • Store the entered data in the declared data item.

1. COBOL ACCEPT Statement with Examples.

Here is an example of how to use the COBOL Accept statement to prompt the user for input and store the entered data in a COBOL program:

 IDENTIFICATION DIVISION.
  PROGRAM-ID. EMP001.
  AUTHOR.     MAINFRAME FORUM. 
*
* THIS PROGRAM SHOWCASES THE USE OF  
COBOL ACCEPT STATEMENT. 
*
 DATA DIVISION.
 WORKING-STORAGE SECTION.
 
  01 WS-EMP-NAME        PIC X(20).
 PROCEDURE DIVISION.
 0000-CORE-BUSINESS-LOGIC. 
 ...
 ...
 ... 
  
  DISPLAY "ENTER YOUR NAME:".
  ACCEPT   WS-EMP-NAME.
...
...
 STOP RUN. 


2. COBOL ACCEPT Statement with Examples.

  • ACCEPT WS-TDY-DTE FROM DATE YYYYMMDD: Transfers system date in the YYYYMMDD format to the identifier WS-TDY-DATE.
  • ACCEPT WS-EMP-NAME FROM INP-DEV: Accepts a value for WS-EMP-NAME from an input device whose mnemonic name is INP-DEV. 
So, this is how you can use accept statements in your COBOL program to accomplish your requirements. 

Conclusion. 

In conclusion, the COBOL Accept statement is an essential tool for creating interactive programs and collecting data from users in COBOL. With its straightforward syntax and easy implementation, the Accept statement in COBOL makes it simple to incorporate user interaction into COBOL programs. Do check out our post on the COBOL Display Statement. 


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™



No comments:

Post a Comment

New In-feed ads