If I have two programs, PGMA and PGMB, PGMA calls PGMB. PGMB returns to PGMA, and then PGMB is removed from the...
call stack since it has returned instead of SETON LR. How will the file used remain opened when the program is not in the call stack still?
You are correct in that when you do a return, some of the resources associated to that job stay allocated even though the program no longer exists in the call stack. If you are calling a program repeatedly, using a RETURN instead of a SETON LR has big performance advantages because the files are already open and ready to use when you call the program repeatedly from the same job. Here are a couple of things to watch out for when using RETURN instead of LR:
1. Your program variables are left in the state they were in the last time you called the program. If you use a RETURN, proper variable initialization is important.
2. If you are using an *INZSR to initialize your program variables, that is only executed the first time the program is called and not on subsequent calls to the program. If that's the case, you'll probably want to make a separate subroutine to initialize your variables and control the execution in your program.
MORE INFORMATION ON THIS TOPIC
The Best Web Links: tips, tutorials and more.
Ask your programming questions--or help out your peers by answering them--in our live discussion forums.
Ask the Experts yourself: Our application development gurus are waiting to answer your programming questions.
Dig Deeper on iSeries CL programming
Have a question for an expert?
Please add a title for your question
Get answers from a TechTarget expert on whatever's puzzling you.