ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

Reg L0 indicator in RPG cycle

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

  • Reg L0 indicator in RPG cycle

    Hello friends,

    Can anybody explain me the use of L0 indicator in RPG cycle programming (probably with a practical example).I know that L1-L9 are used to test for certain conditions.But why L0 is used.


    I have got some idea that it is used instead of Blank specification between two lines where control level indicators are used. Am i write?
    To every equation there is a solution....
    Regards
    Sai.

  • #2
    Re: Reg L0 indicator in RPG cycle

    No, you are not correct. The L0 indicator is a level break indicator that is turned on every record. Therefore, it is always on. Its purpose is to allow a calculation line to be processed at total time (instead of detail time), but on every cycle - even if no other level breaks occur.

    It might get used where you are trying to create an antificial level break. For example, if you are printing totals at L1 time, but in certains cases you want totals even though L1 has not happened.

    Here is an example where if could be used, but there are other ways that would probably be better.

    Code:
         IMyFile    NS  01                                            
         I                                          Country       L1  
         I                                          Region            
         I                                                            
         C                   Eval      TotSales += Sales              
         C                                                            
         CL0NL1              If        Country = 'CANADA'             
         C                   Except    EXTotals                       
         C                   EndIf                                    
         C                                                            
         CL1                 Except    EXTotals
    In this example, we want totals by country, unless its Canada. There we want every line to be printed.

    Comment


    • #3
      Re: Reg L0 indicator in RPG cycle

      The RPG cycle.... ugh. Please tell me you are not developing new code using the RPG cycle.

      Comment


      • #4
        Re: Reg L0 indicator in RPG cycle

        Thanks, arrow! There are two things I've always been curious about:
        1) A practical example of using L0.
        2) How MxxZO works.
        This curiosity is a holdover from when I was a little boy. I would take things apart to see how they worked. Wasn't always able to put them together again.
        http://www.linkedin.com/in/chippermiller

        Comment


        • #5
          Re: Reg L0 indicator in RPG cycle

          Thanks Arrow, That helped me a lot for better analysis.

          Yes soupdog,Iam not developing any code, Iam just making changes to the old existing one and got really suffered to understand it(RPG logic cycle, lot of I & E-specs.old type of C-spec code....)

          p.s: please can you put your signature, iam really feeling bad to address you.
          To every equation there is a solution....
          Regards
          Sai.

          Comment


          • #6
            Re: Reg L0 indicator in RPG cycle

            Originally posted by soup_dog View Post
            The RPG cycle.... ugh. Please tell me you are not developing new code using the RPG cycle.
            I recently wrote a MonthEnd purge program that has an Input Primary and 11 Input Secondary Files. Also uses matching records. (Ducks to avoid the crossfire.)
            http://www.linkedin.com/in/chippermiller

            Comment


            • #7
              Re: Reg L0 indicator in RPG cycle

              eewww gross input primary and secondary, matching records, level indicators...haven't used them in 20 years.
              Bill
              "A good friend will bail you out of jail,
              A true friend would be sitting beside you saying,
              'Wow, that was fun.'"

              Comment


              • #8
                Re: Reg L0 indicator in RPG cycle

                "I just threw up a little bit in my mouth"...

                Comment


                • #9
                  Re: Reg L0 indicator in RPG cycle

                  Hey guys, just because it is an old tool, doesn't mean it isn't a good tool. Matching record and level breaks are incredibly powerful and still very useful tools in some cases.

                  I have seen some hideous "modern" programs were the programmer was trying to emulate one of these processes. The old "cycle" is a well documented and proven technique. That has got to be better than some of the undocumented mutations of level break coding I have seen.

                  I still use a GOTO at times. I know a programmer who refuses to ever use a GOTO. I can't see where DOs within DOs and conditional LEAVEs are really a better way to program. This guy would write 50 lines of code to avoid a simple GOTO.
                  Denny

                  If authority was mass, stupidity would be gravity.

                  Comment


                  • #10
                    Re: Reg L0 indicator in RPG cycle

                    Originally posted by Denny View Post
                    Hey guys, just because it is an old tool, doesn't mean it isn't a good tool. Matching record and level breaks are incredibly powerful and still very useful tools in some cases.
                    I like that phrase, "Just because it is an old tool, doesn't mean it isn't a good tool." Thanks for the support, Denny!

                    Originally posted by Denny View Post
                    I still use a GOTO at times. I know a programmer who refuses to ever use a GOTO. I can't see where DOs within DOs and conditional LEAVEs are really a better way to program. This guy would write 50 lines of code to avoid a simple GOTO.
                    Just out of curiosity, is there still a situation where other opcodes don't suffice. I used to do the following (pesudocode):

                    Subr to evaluated if rcd s/b processed:
                    1) Set ind off, will be turned on if passes validation tests
                    2) Perform a test, if fails test, GOTO -- tag on the ENDSR line.
                    3) Repeat #2 as much as necessary.
                    4) If it falls to the line before the ENDSR, turn on the ind. Returning from the subr with ind on means process the record.
                    In the above sutation, I now use LEAVESR. Similarly, LEAVE, ITER, etc.

                    Can you show a case where you could not do something with current opcodes and must use GOTO? (Note: Cannot write voice inflection into written language -- my tone of voice is meant to be "I'm curious about this..." not "I can't believe you're saying this...")
                    http://www.linkedin.com/in/chippermiller

                    Comment


                    • #11
                      Re: Reg L0 indicator in RPG cycle

                      When the only reason the subroutine exists is so you can exit from the logic with a LEAVESR, then the goto would be simpler.

                      The same thing applies to creating a DO loop only because you need to jump out of the loop occasionally with a LEAVE. A LEAVE or an ITER is nothing more than a camouflaged GOTO. Or maybe they are GOTOs in drag.

                      It gets worse when you have DOs within DOs.

                      DO THIS
                      ...
                      DO THAT
                      ...
                      DO THEOTHER
                      ...
                      WHEN CONDITION1
                      LEAVE 1 DO LOOP
                      WHEN CONDITION2
                      LEAVE 2 DO LOOPS
                      WHEN CONDITION3
                      LEAVE THE NEIGHERHOOD
                      ...
                      ENDDO
                      ...
                      ENDDO
                      ...
                      ENDDO

                      At least with a GOTO you always jump to a absolute TAG. I have seen some nightmares created when a DO was removed or added and the LEAVE/ITER started going to the wrong place.

                      On the other side of the coin, I have always been amazed that it was LEGAL in RPG IV/LE to GOTO a TAG in the mainline from within a subroutine. Doing that should caused the programmer to be terminated!
                      Denny

                      If authority was mass, stupidity would be gravity.

                      Comment


                      • #12
                        Re: Reg L0 indicator in RPG cycle

                        Can you show a case where you could not do something with current opcodes and must use GOTO?
                        Probably not. But I can show plenty of examples where the code is (1) easier to read, (2) easier to debug, (3) easier to maintain. Of course, GOTO make make a nightmare , too.

                        But please define "current opcodes". If you don't want to use "old" opcodes, we have to leave out stuff like CHAIN, READ, SETLL, etc as well as the ones EVAL has replaced ADD, MULT, MOVE, etc. What about EXCEPT ? That's been around a long time, too. Hey, wait a minute ! Seems like SQL been around for decades, too! Is that "current"? Or is "current" mean "looks like Java"?

                        And while I am ducking stones anyway, I find fixed just as easy to use and understand as /free (except with embedded SQL).

                        Comment


                        • #13
                          Re: Reg L0 indicator in RPG cycle

                          Originally posted by arrow483 View Post
                          Probably not. But I can show plenty of examples where the code is (1) easier to read, (2) easier to debug, (3) easier to maintain. Of course, GOTO make make a nightmare , too.
                          I heartily agree -- GOTO makes for horrible spaghetti code.

                          Originally posted by arrow483 View Post
                          But please define "current opcodes".
                          Perhaps a better way for me to say this is, "Some opcodes should not be used because there have been enhancements to RPG that make them obsolete." The question becomes, "Is there another opcode that makes this easier to understand?" (Particularly for the poor guy who has to come in behind me.)

                          Example:
                          Code:
                               *
                                * EXAMPLE OF CODE FROM WHEN OUR CUSTOM PACKAGE WAS WRITTEN IN 1987
                                *
                               C           BEGLOP    TAG
                               C                     READ FILE                     70
                               C   70                GOTO ENDLOP
                                *      
                               C           A         COMP B                    3030
                               C   30                GOTO BEGLOP
                                *
                               C           C         COMP D                    3030
                               C   30                GOTO ENDLOP
                                *
                               C                     GOTO BEGLOP
                                *
                               C           ENDLOP    TAG
                                *
                          Today, it would look like this:
                          Code:
                                /FREE
                          
                                    DoU %EOF(File);
                          
                                       Read File;
                          
                                       // I know this is redundant with the DoU loop, but I do this to
                                       // minimize nesting levels.
                                       If %EOF(File);
                                          Leave;
                                       ElseIf (A <> B);
                                          Iter;
                                       ElseIf (C <> D);
                                          Leave;
                                       EndIf;
                          
                                    EndDo;
                          
                                /END-FREE
                          Last edited by Chipper; July 31, 2008, 03:36 PM.
                          http://www.linkedin.com/in/chippermiller

                          Comment


                          • #14
                            Re: Reg L0 indicator in RPG cycle

                            Originally posted by Denny View Post
                            On the other side of the coin, I have always been amazed that it was LEGAL in RPG IV/LE to GOTO a TAG in the mainline from within a subroutine. Doing that should caused the programmer to be terminated!
                            Boy do I agree with you here.

                            Originally posted by Denny View Post
                            A LEAVE or an ITER is nothing more than a camouflaged GOTO. Or maybe they are GOTOs in drag.
                            I agree that they are camouflaged GOTOs. It's just that you know where you are "going to." A "No GoTo policy" is easier than "This kind of GoTo is allowed, this kind (e.g. jump from subr to mainline) isn't. Just my personal preference/style here, YMMV.

                            Any thoughts on Subr vs Sub-Proc?
                            http://www.linkedin.com/in/chippermiller

                            Comment


                            • #15
                              Re: Reg L0 indicator in RPG cycle

                              Hey Chipper:

                              Code:
                                   C           BEGLOP    TAG
                                   C                     READ FILE                     70
                                   C   70                GOTO ENDLOP
                                    *      C           A         COMP B                    3030
                                   C   30                GOTO BEGLOP
                                    *      C           C         COMP D                    3030
                                   C   30                GOTO ENDLOP
                                    *
                                   C                     GOTO BEGLOP
                                    *
                                   C           ENDLOP    TAG
                              Unless my eyes are going bad (which they may be) it looks like the a comp b and the c comp d are commented out so you are left with:
                              Code:
                                   C           BEGLOP    TAG
                                   C                     READ FILE                     70
                                   C   70                GOTO ENDLOP
                                   C   30                GOTO BEGLOP
                                   C   30                GOTO ENDLOP....you will never execute this        *
                                   C                     GOTO BEGLOP
                                    *
                                   C           ENDLOP    TAG
                              So you are reading until end of file regardless.

                              The point is bad code is bad code regardless of it being in free rpgle rpgIII or rpgII.

                              GLS

                              *
                              The problem with quotes on the internet is that it is hard to verify their authenticity.....Abraham Lincoln

                              Comment

                              Working...
                              X