COBOL Accept Statement

COBOL ACCEPT Statement:

Accept statement in COBOL with examples – It is used to receive the data that has been sent from outside of that program. Data can be sent from any Terminal or from JCL or from system defined items like date functions. ACCEPTING multiple records from input is also possible.

Accepting Data from JCL using ACCEPT:

Input data should be given in SYSIN DD as an in-stream data and in the cobol program it should be accepted.

JCL:

COBOL:

So it Accepts the data from SYSIN and transfers it in to the working storage variable WW-INPUT.

Accepting MULTIPLE RECORDS from JCL using ACCEPT:

Multiple records can be passed from JCL via SYSIN and can be processed them in the program.

Example:

JCL:

COBOL:

Result:
As we have used WS-INPUT in the accept verb, it has not received the full data.

This can be achieved by using multiple ACCEPT statements

Result:

Above method works fine, if the number of records being passed to COBOL program are known but if it not known, then it fails.
So in that case, an EOF record should be given in the data at the end of the input stream to recognize the end of data after every ACCEPT it should be checked as below

Example:

JCL:

COBOL:

Result:

Accepting DATE TIME data:

Different Date and Time data stored in the system can be accepted.

  1. ACCEPT WW-DATE FROM DATE –> it gives the 6 digit data in YYMMDD format.
    Ex:190528
  2.  ACCEPT WW-DATE1 FROM DATE YYYYMMDD
    Ex: 20190528
  3. ACCEPT WW-DAY FROM DAY –> first two digits represents the Year and next three day number. May 28 is represented here as 148
    Ex: 19148
  4. Year can be formatted as Four digit year with below
    ACCEPT WW-DAY FROM DAY YYYYDDD
    ex: 2019148
  5. ACCEPT WW-DAYWK FROM DAY-OF-WEEK –> It gives the Day in that week. 1 for Monday, 2 for Tuesday and so on.
  6. ACCEPT WW-TIME FROM TIME – Gives the time in HHMMSSmm

Leave a Reply

Your email address will not be published. Required fields are marked *