Reputation: 5143
I need to ask what is the problem in this my menu program,when i call another program
by tapping 1 or 2, and when the program called i could not go back to my menu program,
can you help me please how can i get back to my menu when i press Esc key,or does
my Call statment is wrong.
this is the code for my menu program.
LINKAGE SECTION.
01 MY-PROG1 PIC X.
01 MY-PROG2 PIC X.
......
......
......
MAIN.
DISPLAY MENU-HEADER ERROR-MESSAGE.
PERFORM ENTRY-MENU UNTIL CHOICE = 3.
STOP RUN.
ENTRY-MENU.
ACCEPT MENU-SELECT.
PERFORM INPUT-CHOICE UNTIL CHOICE = 3.
STOP RUN.
INPUT-CHOICE.
IF CHOICE = 1
CALL 'MY-PROGRAM1' USING MY-PROG1
ELSE IF CHOICE =2
CALL 'MY-PROGRAM2' USING MY-PROG2
ELSE
MOVE "INVALID INPUT....." TO ERRMSG
DISPLAY ERROR-MESSAGE.
this is MY-PROGRAM1.COB this is how i call back the menu program when i press Esc key
LINKAGE SECTION.
01 MY-PROG1 PIC X.
01 MY-MENU PIC X.
......
......
......
MAIN.
.......
.......
STOP RUN.
ENTER-BIRTHDATE.
ACCEPT...
.......
IF ESC-KEY
DISPLAY CLEAR-SCREEN
CALL 'MENU'
ELSE IF F10
.....
.....
Upvotes: 1
Views: 540
Reputation: 20065
You should replace the STOP RUN
statement in the called programm with GOBACK
.
This is the general rules of using STOP RUN
and GOBACK
:
The GOBACK statement marks the logical end of a called program.
General Rules If a GOBACK statement is executed in a program which is under the control of a calling runtime element, the object program operates as if executing an EXIT PROGRAM statement that has the same clauses as the GOBACK statement. See the topic The EXIT Statement. If a GOBACK statement without the ADDRESS OF clause is executed in a program which is not under the control of a calling runtime element, the object program operates as if executing a STOP RUN statement that has the same clauses as the GOBACK statement. If a GOBACK statement with the ADDRESS OF clause is executed in a program which is not under the control of a calling runtime element, the object program operates as if executing a STOP RUN statement except that an arbitrary returned value is set in the system area. The GOBACK statement may result in more compact code than the equivalent EXIT PROGRAM and STOP RUN statement. A GOBACK statement must not be executed while executing a declarative procedure in which the GLOBAL phrase is specified except in a program called while executing that declarative procedure. If a GOBACK statement is executed in a function, the function operates as if executing an EXIT FUNCTION statement. If a GOBACK statement is executed in a method, the method operates as if executing an EXIT METHOD statement. If a GOBACK statement is executed in an iterator, the iterator operates as if executing an EXIT ITERATOR statement.
STOP RUN. This depends on your system. STOP RUN on most compilers terminates the program and if it is called by another cobol program then the whole process is terminated.
At the end of this link you can find a nice schema that represent all those relations.
Edit : (from an old Microsoft Cobol documentation)
EXIT PROGRAM STATEMENT : The EXIT PROGRAM statement, appearing in a called subprogram, causes control to be returned to the next executable statement after CALL in the calling program. This statement must be a paragraph by itself.
Upvotes: 4