COBOL GobackCOBOL Exit Program COBOL Initialize
GOBACK gives the control back from where it received it.
GOBACK statement is the logical end of the called program or invoked method.
GOBACK also responsible for returning the control to the calling program.
GOBACK can be coded in both main program and sub program.
If GOBACK coded in the Main program, returns the control to the system.
If GOBACK coded in the sub program, returns the control to the calling program.
GOBACK passed control to the statement which is immediately next to the active CALL statement in the main program.
If no active CALL statement is active, GOBACK passes the control to exit through next executable statement like EXIT PROGRAM.
GOBACK is a PROCEDURE DIVISION statement which should be always in AREA B.
Main program - code:
IDENTIFICATION DIVISION. PROGRAM-ID. MAINPROG. ENVIRONMENT DIVISION. DATA DIVISION. WORKING-STORAGE SECTION. 01 INPUT1 PIC 9(02). 01 INPUT2 PIC 9(02). 01 OUT-PUT PIC 9(03). PROCEDURE DIVISION. ACCEPT INPUT1. ACCEPT INPUT2. CALL 'SUBPROG' USING INPUT1, INPUT2, OUT-PUT. DISPLAY OUT-PUT. STOP RUN.
Sub program - code:
IDENTIFICATION DIVISION. PROGRAM-ID. SUBPROG. ENVIRONMENT DIVISION. DATA DIVISION. LINKAGE SECTION. 01 IP1 PIC 9(02). 01 IP2 PIC 9(02). 01 OP PIC 9(03). PROCEDURE DIVISION USING IP1,IP2,OP. COMPUTE OP = IP1 * IP2. GO BACK.
COBOL Exit Program COBOL Initialize