ACCEPT Statement


ACCEPT statement receives the data from external sources like JCL or the system during the program execution. ACCEPT places the received information into the variable coded with it. It won't perform any data editing or error checking while receiving the data.

It has two different formats, and those are -

  • Simple ACCEPT
  • Accepting system date-related information

Simple ACCEPT -


ACCEPT statement receives the data only from external sources like JCL. FROM is optional. When the FROM phrase is ignored, the default system input device is considered as the input device, and the user should provide the input.

Syntax -

ACCEPT variable1 [FROM environment-name].
Note! All statements coded in [ ] are optional.
  • variable1 - The receiving variable, which can be an alphanumeric group variable or an elementary variable of usage DISPLAY.
  • environment-name - Specifies the source of input data. An environment name is SYSIN, SYSIPT, SYSOUT, or SYSLST.

Accepting system date-related information -


ACCEPT statement can receive the system-related information during the program runtime. The system-related information is DATE, DATE YYYYMMDD, DAY, DAY YYYYDDD, DAY-OF-WEEK, or TIME.

Syntax -

ACCEPT variable2 [FROM  DATE [YYYYMMDD]]
                       [DAY  [YYYYDDD]]
                       [DAY-OF-WEEK]
                       [TIME].
  • Variable2 - Specifies the receiving variable.
  • DATE - Returns the system date in YYMMDD format. Variable2 should be defined as 9(6) DISPLAY.
  • DATE YYYYMMDD - Returns the system date in YYYYMMDD format. Variable2 should be defined as 9(8) DISPLAY.
  • DAY - Returns the system date in the format YYDDD. Variable2 should be defined as 9(5) DISPLAY.
  • DAY YYYYDDD - Returns the system date in the format YYYYDDD. Variable2 should be defined as 9(7) DISPLAY.
  • DAY-OF-WEEK - Returns the system day of the week. Variable2 should be defined as 9(1) DISPLAY.
    • 1 - represents Monday
    • 2 - represents Tuesday
    • 3 - represents Wednesday
    • 4 - represents Thursday
    • 5 - represents Friday
    • 6 - represents Saturday
    • 7 - represents Sunday
  • TIME - Returns the current system time in the format HHMMSSTT. Variable2 should be defined as 9(8) DISPLAY. The sequence of data elements (from left to right) is -
    • Two digits for hour of day
    • Two digits for minute of hour
    • Two digits for second of minute
    • Two digits for hundredths of second

Practical Example -


Scenario - Receiving data from JCL and receiving the system date using ACCEPT statement.

Code -

----+----1----+----2----+----3----+----4----+----5----+
       IDENTIFICATION DIVISION.
       PROGRAM-ID. ACCPTST.

       DATA DIVISION.
       WORKING-STORAGE SECTION.
       01 WS-VAR.
          05 WS-NAME            PIC X(20).
          05 WS-TODAY           PIC 9(08).
       PROCEDURE DIVISION.
      * Receiving name from JCL
           ACCEPT WS-NAME.

      * Receiving date from SYSTEM
           ACCEPT WS-TODAY FROM DATE YYYYMMDD.

           DISPLAY 'RECEIVED NAME:  ' WS-NAME.
           DISPLAY 'RECEIVED DATE:  ' WS-TODAY.

           STOP RUN.

JCL -

//MATEPKRJ JOB MSGLEVEL=(1,1),NOTIFY=&SYSUID
//**
//STEP01  EXEC PGM=ACCPTST
//STEPLIB  DD  DSN=MATEPK.COBOL.LOADLIB,DISP=SHR
//SYSIN    DD  *
PAWAN KUMAR Y S
/* 
//SYSOUT   DD  SYSOUT=*

Output -

RECEIVED NAME:  PAWAN KUMAR Y S
RECEIVED DATE:  20230706

Explaining Example -

In the above example:

  • WS-NAME received from the Run JCL SYSIN DD statement as it has no FROM clause.
  • WS-TODAY is obtained from the system in the format YYYYMMDD and requires no input from Run JCL.