Q
Problem solve Get help with specific problems with your technologies, process and projects.

Using RETURN vs. LR

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.


This was last published in September 2003

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.

You will be able to add details on the next page.

Start the conversation

Send me notifications when other members comment.

By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Please create a username to comment.

-ADS BY GOOGLE

SearchDataCenter

Close