AS/400 RPGLE: Difference between Return vs. *INLR

450 pts.
AS 400
What is difference between Return vs *inlr in RPGLE? I have below scenario:
PGM 1                    PGM2
SOME LINES     some lines
CALL pgm2        Return
some lines
What will happen in the above scenario?

Answer Wiki

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

From the ILE reference manual  PDF page 849

The RETURN operation causes a return to the caller. If a value is returned to the
caller, the return value is specified in the expression operand.
The actions which occur as a result of the RETURN operation differ depending on
whether the operation is in a cycle-main procedure or subprocedure. When a
cycle-main procedure returns, the following occurs:
1. The halt indicators are checked. If a halt indicator is on, the procedure ends
abnormally. (All open files are closed, an error return code is set to indicate to
the calling routine that the procedure has ended abnormally, and control
returns to the calling routine.)
2. If no halt indicators are on, the LR indicator is checked. If LR is on, the
program ends normally. (Locked data area structures, arrays, and tables are
written, and external indicators are reset.)
3. If no halt indicator is on and LR is not on, the procedure returns to the calling
routine. Data is preserved for the next time the procedure is run. Files and data
areas are not written out. See the chapter on calling programs and procedures
in the IBM Rational Development Studio for i: ILE RPG Programmer’s Guide for
information on how running in a *NEW activation group affects the operation
When a subprocedure returns, the return value, if specified on the prototype of the
called program or procedure, is passed to the caller. Automatic files are closed.
Nothing else occurs automatically. All static or global files and data areas must be
closed manually. You can set on indicators such as LR, but this will not cause
program termination to occur. For information on how operation extenders H, M, and R are used, see “Precision
Rules for Numeric Operations” on page 486.
In a subprocedure that returns a value, a RETURN operation must be coded within
the subprocedure. The actual returned value has the same role as the left-hand side
of the EVAL expression, while the extended factor 2 of the RETURN operation has
the same role as the right-hand side. An array may be returned only if the
prototype has defined the return value as an array.

Discuss This Question: 5  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.
  • TheRealRaven
    This reads like a quiz question. Since help text and system documentation provide the answer, please post your understanding, and we'll try to guide past misconceptions.
    36,035 pointsBadges:
  • vivekntt21
    After return statement the control goes to *inlr directly or it will execute in between lines in the above example?
    450 pointsBadges:
  • GregManzo
    The Return statement exits immediately (and will check *INLR to decide if it will close files etc.)
    *INLR wont exit until the next cycle. But these days very few people use or understand the old RPG cycle anyway (I think there are about 5 of us left on the planet).
    For most major application programs you probably want both, seton LR & Return - this will exit now and close files on the way out.
    If you are writing a subordinate program (whether as a pgm to be called for some minor task or as a *SRVPGM) then you need to think about whether you want files closed every time you get called or leave them open for the next call.
    2,970 pointsBadges:
  • vivekntt21
    Thanks for your explanation but still i am not clear so could you explain the below scenario what happens here, After call goes to program whether it will return and execute those lines or else it will go to *inlr = *on and ends?

    PGM 1                    PGM2
    SOME LINES     some lines
    CALL pgm2        Return
    some lines
    *INLR = *ON
    450 pointsBadges:
  • Splat
    Write some code & test it. If you want to see the code execute, put it in debug.
    12,915 pointsBadges:

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.

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


Share this item with your network: