The ENTRY statement establishes an alternate entry point into a COBOL called subprogram. When a CALL statement that specifies the alternate entry point is executed in a calling program, control is transferred to the next executable statement following the ENTRY statement.
We have to link edit the sub-program with the main program, if the sub-program has ENTRY points.
In the below example, when the sub-program is called first time, the DISPLAY statement in the beginning of the sub-program is skipped and control goes to ENTRY point “POINT1”. In the same way, during second call, control directly goes to ENTRY point “POINT2”. During both the ENTRY point calls, the sub-program was able to access the working-storage field.
Main program
IDENTIFICATION DIVISION.
PROGRAM-ID. FINGFIXA.
ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
DATA DIVISION.
WORKING-STORAGE SECTION.
PROCEDURE DIVISION.
DISPLAY 'GOING TO CALL ENTRY POINT 1..'
CALL 'POINT1'.
DISPLAY 'CONTROL IS IN MAIN PRORGAM....'
DISPLAY 'GOING TO CALL ENTRY POINT 2..'
CALL 'POINT2'.
GOBACK.
Sub program with ENTRY points
ID DIVISION.
PROGRAM-ID. DISP.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 X PIC X(41) VALUE 'THIS IS COMMON FIELD FOR ALL ENTRY POINTS'.
PROCEDURE DIVISION.
DISPLAY 'BEGINIING OF THE PROGRAM'.
ENTRY 'POINT1'.
DISPLAY 'ENTERING ENTRY POINT1..'
DISPLAY X.
DISPLAY 'EXITING ENTRY POINT1..'
GOBACK.
ENTRY 'POINT2'.
DISPLAY 'ENTERING ENTRY POINT2..'
DISPLAY X.
DISPLAY 'EXITING ENTRY POINT2..'
GOBACK.
Output
GOING TO CALL ENTRY POINT 1..
ENTERING ENTRY POINT1..
THIS IS COMMON FIELD FOR ALL ENTRY POINTS
EXITING ENTRY POINT1..
CONTROL IS IN MAIN PRORGAM....
GOING TO CALL ENTRY POINT 2..
ENTERING ENTRY POINT2..
THIS IS COMMON FIELD FOR ALL ENTRY POINTS
EXITING ENTRY POINT2..
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.