ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

Shall we discuss Cycle main and Linear main?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Shall we discuss Cycle main and Linear main?

    I'm just mainly wondering if we're all using linear main now vs cycle main. Also added thought on it is isn't '*inlr=*on' a more convenient cleanup than making sure the main cycle closes/unlocks all resources before returning?


  • #2
    If by cycle main you mean logic cycle, then in my 14 years as an RPG dev I have never written a program that uses the logic cycle. Though I have maintained some older (1980's) programs that did.

    During my first 8 years I worked at a company that did not embrace the modern, and had stuck with fixed format instead of free, F-spec IO instead of SQL, and subroutines instead of subprocedures. Which means there was no main procedure, so the program technically loaded with the logic cycle and needed *inlr, even though the cycle was not used for IO.
    The company I work for now we use all-free and main procedures for all new programs.

    Comment


    • #3
      Nice. You're right. The only other time I used cycle main was when I was working for a bank that forced rpg III only. But weird enough, the other rpg develoeprs I work with right now still use cycle main. Which made me wonder if there was some advantage that I was not seeing

      Comment


      • #4
        It's true that using cycle main with *INLR=*ON is an easy way to get RPG to close files and unlock data areas even if the Primary-File aspect of the cycle main isn't being used.

        You can use CLOSE *ALL to close files and (and UNLOCK *DTAARA to unlock data areas) in a linear main, but you would have to open the files and lock the data areas again when the program is called again.

        Code:
        dcl-f file1;
        
        dcl-proc mypgm;
           if not %open(file1);
              open file1;
           endif;
          
           ... do stuff ...
        
           if cleanup_now;
              close *all;
           endif;
        end-proc;
        Me, I like the explicitness of the extra code but if everyone working on the code understands all the impliciations of *INLR=*ON, I can understand taking advantage of it.
        Code:
        dcl-f file1;
        
        ... do stuff ...
        
        if cleanup_now;
           *inlr = *on;
        endif;

        Comment

        Working...
        X