EJECT Statement
EJECT Statement
The EJECT statement specifies the next source statement should print as the first statement of the next page. It is compiler-directive statement and does not affect the compilation and execution of the program. It can be written in either Area-A or Area-B.
Syntax -
EJECT[.]
Rules -
- It should be coded as the only statement on the entire line.
- It can be written in Area-A or Area-B and terminated with a separator period.
Examples -
Scenario1 - Coding EJECT statement in COBOL program.
Copybook - MATEPK.COBOL.COPYLIB(EMPREC)
----+----1----+----2----+----3----+----4----+
05 EMP-NUM PIC 9(05).
05 EMP-NAME PIC X(10).
05 EMP-DESG PIC X(15).
05 EMP-SALARY PIC 9(10).
Code -
----+----1----+----2----+----3----+----4----+
01 EMP-REC.
COPY EMPREC.
EJECT.
01 WS-VAR.
05 WS-INPUT1 PIC X(10).
Explaining Example -
- The EJECT statement won't display in the program listing.
- The EJECT statement skips the current page listing, and WS-VAR starts displaying as the next page's first line of the program listing.
Scenario2 - Two EJECT statements in the COBOL program.
Copybook - MATEPK.COBOL.COPYLIB(EMPREC)
----+----1----+----2----+----3----+----4----+
05 :EMP:-NUM PIC 9(05).
05 :EMP:-NAME PIC X(10).
05 :EMP:-DESG PIC X(15).
05 :EMP:-SALARY PIC 9(10).
Code -
----+----1----+----2----+----3----+----4----+
01 EMP-INPUT-REC.
COPY EMPREC REPLACING "==:EMP:==" BY "==EMP-INPUT==".
EJECT.
01 EMP-OUTPUT-REC.
COPY EMPREC REPLACING "==:EMP:==" BY "==EMP-OUTPUT==".
EJECT.
01 WS-VAR.
05 WS-INPUT1 PIC X(10).
Explaining Example -
In the above example:
- The EJECT statement won't display in the program listing.
- The first EJECT statement skips the current page display and EMP-OUTPUT-REC, WS-VAR starts displaying as the next page's first line of the program listing.
- The second EJECT statement skips the EMP-OUTPUT-REC current page listing, and WS-VAR starts displaying as the next page's first line of the program listing.