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:
//SYSIN DD * MAHENDER /* //
COBOL:
WORKING-STORAGE SECTION. 01 WK-INPUT. 05 WK-INP-1 PIC X(10) VALUE SPACES. PROCEDURE DIVISION. ACCEPT WK-INPUT. DISPLAY 'WK-INPUT>'WK-INPUT STOP RUN.
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:
//SYSIN DD * MAHENDER REDDY /* //
COBOL:
01 WS-INPUT. 05 WS-INP1 PIC X(10) VALUE SPACES 05 WS-INP2 PIC X(10) VALUE SPACES PROCEDURE DIVISION. ACCEPT ACCEPT WS-INPUT. DISPLAY 'INP-ONE--'WS-INP1 DISPLAY 'INP TWO--'WS-INP2 DISPLAY 'INP THR--'WS-INPUT STOP RUN.
Result:
As we have used WS-INPUT in the accept verb, it has not received the full data.
INP-ONE--MAHENDER INP-TWO-- INP-THR--MAHENDER
This can be achieved by using multiple ACCEPT statements
ACCEPT WS-INP1 DISPLAY '1ST DISPLY--'WS-INP1 DISPLAY '2ND DISPLY--'WS-INP2 ACCEPT WS-INP2 DISPLAY '1ST DISPLY--'WS-INP1 DISPLAY '2ND DISPLY--'WS-INP2
Result:
1ST DISPLY--MAHENDER 2ND DISPLY-- 1ST DISPLY--MAHENDER 2ND DISPLY--REDDY
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:
//SYSIN DD * MAHENDER REDDY VISWA KALLU *** /* //
COBOL:
01 WW-INPT. 05 WW-INP1 PIC X(10) VALUE SPACES. 01 WS-EOF-FLAG PIC X(01) VALUE SPACES. 88 WS-END-OF-INP VALUE 'Y'. PROCEDURE DIVISION. PERFORM UNTIL WS-END-OF-INP MOVE SPACES TO WW-INP1 ACCEPT WW-INP1 IF WW-INP1 = '***' SET WS-END-OF-INP TO TRUE ELSE DISPLAY 'INPT-->' WW-INP1 END-IF END-PERFORM STOP RUN.
Result:
INPT--MAHENDER INPT--REDDY INPT--VISWA INPT--KALLU
Accepting DATE TIME data:
Different Date and Time data stored in the system can be accepted.
- ACCEPT WW-DATE FROM DATE –> it gives the 6 digit data in YYMMDD format.
Ex:190528 - ACCEPT WW-DATE1 FROM DATE YYYYMMDD
Ex: 20190528 - 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 - Year can be formatted as Four digit year with below
ACCEPT WW-DAY FROM DAY YYYYDDD
ex: 2019148 - ACCEPT WW-DAYWK FROM DAY-OF-WEEK –> It gives the Day in that week. 1 for Monday, 2 for Tuesday and so on.
- ACCEPT WW-TIME FROM TIME – Gives the time in HHMMSSmm