3

*inlr (last record indicator) switched on at the end of the rpgle program. What is the main reason for switching on last record indicator. What will happen if this indicator is not switched on.

Kunal Roy
  • 729
  • 3
  • 11

1 Answers1

9

You don't always have to switch that indicator on. Sometimes you can just code RETURN to end the program.

*inlr is part of the "RPG Cycle" which is used by cycle modules. If you don't have the MAIN or NOMAIN keyword in your Control statements, it is a cycle module.

This page in the documentaiton explains about the three types of RPG modules, and it describes how *inlr affects a cycle module. https://www.ibm.com/support/knowledgecenter/ssw_ibm_i_74/rzasd/cycvslinear.htm

Barbara Morris
  • 3,195
  • 8
  • 10
  • I emphasize the inportance of *INLR and RETURN vs. the compiler settings regarding activation groups. Unexpected state retains can happen if used wrong. :-) – PoC Jan 31 '21 at 14:24
  • It is my understanding that in a cycle program that was launched from another program, if you call `RETURN` without setting on `*INLR`, the second program will remain loaded in memory, and if you call it again, you will not get a new instance, but will run the same program instance and your variables values, open files, etc. will all still be there. Can you confirm this? – Mike Feb 01 '21 at 19:31
  • Mike, you're right. But it's not necessarily a "cycle program". It might be a "cycle module". A program can have several cycle modules, each with its own private RPG cycle. But it's true that in general, most programs only have one cycle module, and most service programs don't have cycle modules. – Barbara Morris Feb 02 '21 at 21:05
  • What PoC said is also relevant though. If the program runs in a *NEW activation group, it doesn't matter whether you end your cycle modules with *INLR on or off. Files will be closed when the program ends. Next time you call the program, variables will have their initial value. – Barbara Morris Feb 02 '21 at 21:06