Return compared to Set on LR

0 pts.
Tags:
Programming Languages
RPG
What is the difference between RETURN and SET on LR indicators? What exactly each one of them does?
ASKED: April 15, 2005  8:12 PM
UPDATED: October 23, 2009  6:17 AM

Answer Wiki

Thanks. We'll let you know when a new response is added.

I believe you will find that RETRN leaves the program open where SETON LR leaves after closing the files and ending the program. You would want to use RETRN if you are calling this progam multiple times from the same calling program, in order to reduce overhead of opening and closing the files each time.

========================================================

That’s kindof like asking what the difference is between turning a car’s ignition off and setting the parking brake. They are two different operations that have different effects. A more meaningful question would be about the difference between the LR and RT indicators or the difference between RETURN and the RT indicator. Both of those questions would be about comparing directly comparable items.

The difference is that they do two different things. RETURN exits the current procedure and returns to the calling procedure.

SETON LR sets the LR indicator on, and nothing else; the next statement in the program executes just like would happen after setting on any other indicator.

But it’s not what the operations themselves do that’s interesting. It’s the effects on what happens afterward where it gets interesting.

When you execute RETURN, the current procedure is exited and control drops back to the calling procedure (or program). This is effectively the same result as executing the last statement in a procedure and dropping out of the bottom (except in a main procedure, where cycle-processing is in control).

The LR indicator is a flag that controls the types of things that happen when an exit occurs from a main procedure (either because of a RETURN, the RT indicator or from falling through the bottom of a main procedure).

As for what the effects are, there are many of them that might happen. What happens depends on whether LR is set on in a main procedure or a subprocedure (or a *NOMAIN module), whether files were implicitly or explicitly opened or were defined as USROPN, whether compile-time arrays have TOFILE() specified, whether any data areas are defined as ‘UDS’ or not, whether heap storage pointers have been allocated or not, whether it’s a cycle program or not, whether or not an Hx indicator or RT indicator is on or not, etc.

Probably the best thing you can do if you want to understand the ‘difference’ is to download both the ILE RPG Reference and the Programmer’s Guide manuals, open them and do a whole-word, case-sensitive search on “LR”. Then simply go through the search results item by item.

There are too many items of difference to list here.

Tom

Discuss This Question: 4  Replies

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

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
  • mygoodname
    RETRN only ends the program. By setting on the LR indicator when the program ends, the last record processing of the RPG Cycle is invoked. This has the effect of closing any open files and releasing storage used for program variables, which will force the program to reopen and reinitialize when it is next called. You may want to refer to the RPG manual to review the Last Record part of the cycle and see what other effects it may have.
    0 pointsBadges:
    report
  • Jaicee
    In addition to the other replies, if you are going to call the program multiple times and want to avoid the overhead leave *inLR = *OFF. But be aware that on the next call, the program variables will retain their values and file pointers will be as you left them. At least this was the behaviour of OPM programs. I haven't done enough with ILE to tell you if there are any added implications. I don't get to code as much as i used to. B(
    0 pointsBadges:
    report
  • jhutha
    I believe you will find that RETRN leaves the program open where SETON LR leaves after closing the files and ending the program. You would want to use RETRN if you are calling this progam multiple times from the same calling program, in order to reduce overhead of opening and closing the files each time. ======================================================== That's kindof like asking what the difference is between turning a car's ignition off and setting the parking brake. They are two different operations that have different effects. A more meaningful question would be about the difference between the LR and RT indicators or the difference between RETURN and the RT indicator. Both of those questions would be about comparing directly comparable items. The difference is that they do two different things. RETURN exits the current procedure and returns to the calling procedure. SETON LR sets the LR indicator on, and nothing else; the next statement in the program executes just like would happen after setting on any other indicator. But it's not what the operations themselves do that's interesting. It's the effects on what happens afterward where it gets interesting. When you execute RETURN, the current procedure is exited and control drops back to the calling procedure (or program). This is effectively the same result as executing the last statement in a procedure and dropping out of the bottom (except in a main procedure, where cycle-processing is in control). The LR indicator is a flag that controls the types of things that happen when an exit occurs from a main procedure (either because of a RETURN, the RT indicator or from falling through the bottom of a main procedure). As for what the effects are, there are many of them that might happen. What happens depends on whether LR is set on in a main procedure or a subprocedure (or a *NOMAIN module), whether files were implicitly or explicitly opened or were defined as USROPN, whether compile-time arrays have TOFILE() specified, whether any data areas are defined as 'UDS' or not, whether heap storage pointers have been allocated or not, whether it's a cycle program or not, whether or not an Hx indicator or RT indicator is on or not, etc. Probably the best thing you can do if you want to understand the 'difference' is to download both the ILE RPG Reference and the Programmer's Guide manuals, open them and do a whole-word, case-sensitive search on "LR". Then simply go through the search results item by item. There are too many items of difference to list here. Tom
    40 pointsBadges:
    report
  • TomLiotta
    I believe you will find that RETRN leaves the program open where SETON LR leaves after closing the files and ending the program.   You can believe that all you want, but you'd be wrong. Setting on the LR indicator does not cause an exit from the program. It only sets the LR indicator to *ON status.   If you wish, you can set it back off in the very next statement, and that will prove that the program was not exited when it was set on.   But as was noted in the 'Answer', the behavior of the program when a RETURN is executed is different when LR is on or off.   Regardless, SETON only sets it on. If it's never tested, it doesn't matter in the slightest if it was set on or off.   Tom
    125,585 pointsBadges:
    report

Forgot Password

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

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

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

Thanks! We'll email you when relevant content is added and updated.

Following