PROCEDURE DIVISION
MAINPARA
DISPLAY "HELLO MAIN".
GO TO PARA1.
DISPLAY " SECOND DISPLAY".
STOP RUN.
PARA1.
DISPLAY " I AM IN PARA1".
PARA2.
DISPLAY "I AM IN PARA2"
....
PARA200
I have little understanding of the flow. But, I am confused. When control jump to GO TO PARA1
, it will execute PARA1
.
Now my question is:
PARA2
and return to MAINPARA
? PARA2
towards the end of the program?I am not a COBOL programmer, and I need to understand code from a migration tool/process, AMXW COBOL. The target system is an IBM AS/400.
For a COBOL program compiled without hooks being inserted by the compiler and with optimization, if you compiled with the NOEJPD suboptions of the TEST compiler option, you can use the GOTO command if the SET WARNING is set to OFF and the runtime level allows GOTO without compiler enablement.
Your program will display :
HELLO MAIN
I AM IN PARA1
I AM IN PARA2
...
Because GO TO
moves the execution point of your program. Then it executes sequentially from where it has been moved to.
On this opposit if you replace GO TO
verb by PERFORM
verb, the program :
PROCEDURE DIVISION
MAINPARA
DISPLAY "HELLO MAIN".
PERFORM PARA1.
DISPLAY " SECOND DISPLAY".
STOP RUN.
PARA1.
DISPLAY " I AM IN PARA1".
PARA2.
DISPLAY "I AM IN PARA2"
....
PARA200
Would display :
HELLO MAIN
I AM IN PARA1
SECOND DISPLAY
GO TO
statement permanently transfers execution from one part of program to another part of program. After GO TO PARA1
, execution will jump to PARA1
label, execute the following paragraph and then continue from there.
OUTPUT:
HELLO MAIN
I AM IN PARA1
I AM IN PARA2
.
.
I AM IN PARA200
So, the execution will continue until it encounters a STOP RUN
statement or a runtime error.
Note: GO TO
statements are usually considered bad practice for a reason. It becomes harder to keep track of where the GO TO
statements go so to speak. I'd suggest using PERFORM
instead. Which returns control to where it was after executing a procedure.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With