Improved performance for repetitious program calls

It is customary in RPG programs to either allow the RPG cycle to set on the LR indicator after the last record in a primary file, or to manually set on *INLR when not using a primary file. This works perfectly well. However, if one program repeatedly calls another program, when the called program ends with LR on, the next call to that program must re-initialize the program.

Setting on the RT indicator, or using the RETURN (or RETRN in RPG III) opcode without setting on LR can result in a significant performance increase. I performed a benchmark test in which program B performed one simple addition, and program A calls program B 10000 times and ends. On the box that I ran this test, program A executed in around 5.2 seconds for 10000 calls to program B when program B ended with LR on, but ran in only 0.21 seconds when program B was changed to set the RT indicator on, rather that the LR.

Caution should be used here -- when the called program ends without LR on, and is called again, the variables will have the same values as when the program last returned, and all files will be open, and any file pointer from a READ, READP, READE, or READPE will remain uninitialized. The *INZSR will NOT run on the subsequent calls, so any variable initialization that you wish to be done on each call should be performed within the main program C specs.

This was first published in June 2001

There are Comments. Add yours.

TIP: Want to include a code block in your comment? Use <pre> or <code> tags around the desired text. Ex: <code>insert code</code>

REGISTER or login:

Forgot Password?
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
Sort by: OldestNewest

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to:

Disclaimer: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.