COBOL Accept Statement
ACCEPT statement accepts the data from the outside of the program which may be from input device or system defined data items.
ACCEPT transfers the accepted data to the specified identifier along with ACCEPT.
ACCEPT statement used to receive the data during the program execution.
ACCEPT variable/identifier [FROM TIME/DATE/SYSTEM DEFINES ITEMS]
In the above syntax,
Variable/identifier may be an elementary or group item.
Variable/identifier can be of any data type in COBOL.
FROM clause is optional for the ACCEPT statement.
If FROM clause not coded in program, the program expects the data from in-stream data of JCL.
If ACCEPT statement coded in the program, both FROM clause or in-stream data not available program will ABEND.
ACCEPT statement is restricted to batch programs.
It is not advisable to code ACCEPT in Online programs. Because during the program execution, it stops at ACCEPT statement and waiting for user to enter the data.
If ACCEPT is receiving the data from SYSTEM DEFINED ITEMS, the actual declaration length and type of the identifier/variable should be the same as SYSTEM DEFINED ITEMS returning length.
For example, DAY keyword returns YYDDD of length 5 bytes. So the variable/identifier receiving the DAY should have the declaration length 5 bytes.
IDENTIFICATION DIVISION. PROGRAM-ID. ACCPTST. ENVIRONMENT DIVISION. DATA DIVISION. WORKING-STORAGE SECTION. 01 AGE PIC 9(03). 01 GENDER PIC X(01). PROCEDURE DIVISION. ACCEPT AGE. ACCEPT GENDER. EVALUATE TRUE ALSO TRUE WHEN AGE > 018 ALSO GENDER = 'M' DISPLAY 'THE BOY IS MAJOR ' WHEN AGE > 018 ALSO GENDER = 'F' DISPLAY 'THE GIRL IS MAJOR ' WHEN AGE <= 018 ALSO GENDER = 'M' DISPLAY 'THE BOY IS MINOR ' WHEN AGE <= 018 ALSO GENDER = 'F' DISPLAY 'THE GIRL IS MINOR ' WHEN OTHER DISPLAY 'INVALID INPUT ' END-EVALUATE. STOP RUN.
COBOL Sequence Programming Construction COBOL Call Statement