ACCEPT Statement


  • ACCEPT statement receives the data from external sources like JCL or the system runtime environment during the program execution.
  • It 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 -

  • Receiving input from JCL
  • Receiving system date-related information

Receiving input from JCL -


ACCEPT statement without FROM phrasse used to accept the data from JCL. The default system input device is considered as the input device when FROM phrase is ignored, and the user should provide the input.

Syntax -

ACCEPT variable1 [FROM environment-name].
  • variable1 - The receiving variable, which can be an alphanumeric group of usage DISPLAY.
  • environment-name - Specifies the source of input data. An environment name is SYSIN, SYSIPT, SYSOUT, or SYSLST.

Points to Note -

  • All statements coded in [ ] are optional.
  • FROM is optional.

Rules to Remember -

  • The default input device is SYSIN of Run JCL.
  • One line in the SYSIN DD statement equals the one ACCEPT statement in the COBOL program.
  • The order of data in SYSIN DD should match the order of ACCEPT statements in the COBOL program.

Example -

Scenario - Receiving data from run JCL.

----+----1----+----2----+----3----+----4----+----5----+
       ...
       DATA DIVISION.
       WORKING-STORAGE SECTION.
       01 WS-VAR.
          05 WS-NAME        PIC X(20).
       ...
       PROCEDURE DIVISION.
      * Receiving name from JCL
           ACCEPT WS-NAME.
		   ...
//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
/* 

Accepting system date-related information -


ACCEPT statement used to receive the system-related information during the program execution. 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 (Default). Variable2 should declare as 9(6) DISPLAY.
  • DATE YYYYMMDD - Returns the system date in YYYYMMDD format. Variable2 should declare as 9(8) DISPLAY.
  • DAY - Returns the system date in the format YYDDD. Variable2 should declare as 9(5) DISPLAY.
  • DAY YYYYDDD - Returns the system date in the format YYYYDDD. Variable2 should declare as 9(7) DISPLAY.
  • DAY-OF-WEEK - Returns the system day of the week. Variable2 should declare 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 declare 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

Example -

Scenario - Receiving system date.

----+----1----+----2----+----3----+----4----+----5----+
       ...
       DATA DIVISION.
       WORKING-STORAGE SECTION.
       01 WS-VAR.
          05 WS-DATE-YYMMDD       PIC 9(06).
       ...
       PROCEDURE DIVISION.
      * Receiving system date in default format.
           ACCEPT WS-DATE-YYMMDD FROM DATE.
		   ...

Output -

DATE YYMMDD  :  240507