ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

Length Of the String in RPG

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

  • Length Of the String in RPG

    HI


    How to find the Length of the string in RPG3...

    Is there any opcodes to find the lenght of the String??
    Thanks
    Venkat

  • #2
    Re: Length Of the String in RPG

    Code:
     length = %len(%trim(Mystring));
    All my answers were extracted from the "Big Dummy's Guide to the As400"
    and I take no responsibility for any of them.

    www.code400.com

    Comment


    • #3
      Re: Length Of the String in RPG

      You may check the OpCode CHECKR to find the first non blank character beginning from the right side.
      CHECK

      ... but I can't repeat it often enough!
      For get about RPGIII it is an outdated technology.

      Comment


      • #4
        Re: Length Of the String in RPG

        2 years ago, we had a LOT of RPG3 programs running in production - with new developers only knowing RPG /Free and battled to read the RPG 3 code.

        With each change request to an old program, we first converted the program sourse to RPGLE (plenty of free tools around and some in the OS)... we then also inserted /Free format code segments into the code to take advantage of the new BIFs...
        Not a very elegant way of doing it, I know... but worked for quick maintenance, while maintaining the original essence of the application.

        This makes it possible to use Jamie's example code above - as well as have access to fresh ideas from new developers.

        Today, we ONLY have RPG ILE programs and all new development is done using latest best practice

        Comment


        • #5
          Re: Length Of the String in RPG

          You could MOVE the string to an array and DO loop through the elements until you get *BLANK.
          That said, I haven't coded any RPGIII since 1996.
          Some shops are run by die-hards though, "we've been pounding nails with rocks at this company for 200 years, get your fancy hammer out of here".

          Comment


          • #6
            I recall at one point CLP chgvar had a %len op code that RPG didn't (or we didn't know about).
            You could write a CL to pass two fields - data and datal and do the length calc there?

            Comment


            • #7
              Re: Length Of the String in RPG

              He could also use embedded SQL in RPGIII to retrieve the length:

              Code:
              C/EXEC SQL   Set :MyLen = Length(Trim(:MyVar))
              C/END-EXEC
              Birgitta

              Comment


              • #8
                Re: Length Of the String in RPG

                Originally posted by B.Hauser View Post
                He could also use embedded SQL in RPGIII to retrieve the length:

                Code:
                C/EXEC SQL   Set :MyLen = Length(Trim(:MyVar))
                C/END-EXEC
                Birgitta
                I suspect that if they are still using an obsolete version of RPG Birgitta that embedded SQL is a bit beyond them. As a minimum you'd need to translate to the nasty old fixed form version.

                Why oh why do people still use that old crap when RPG IV is virtually 100% compatible ... OK - I feel better now - back to work.

                Comment


                • #9
                  Re: Length Of the String in RPG

                  Originally posted by JonBoy View Post
                  I suspect that if they are still using an obsolete version of RPG Birgitta that embedded SQL is a bit beyond them. As a minimum you'd need to translate to the nasty old fixed form version.

                  Why oh why do people still use that old crap when RPG IV is virtually 100% compatible ... OK - I feel better now - back to work.
                  That's why I didn't point to embedded SQL in my first anwser.
                  But ... I sometimes used this trick when I had to do small changes but didn't want or could not convert from RPGIII to RPGIV (because of multiple copy members etc)

                  Birgitta

                  Comment


                  • #10
                    Re: Length Of the String in RPG

                    Originally posted by JonBoy View Post
                    I suspect that if they are still using an obsolete version of RPG Birgitta that embedded SQL is a bit beyond them. As a minimum you'd need to translate to the nasty old fixed form version.

                    Why oh why do people still use that old crap when RPG IV is virtually 100% compatible ... OK - I feel better now - back to work.
                    but...but...but i still use my claw hammer for chisel work too!!!
                    I'm not anti-social, I just don't like people -Tommy Holden

                    Comment


                    • #11
                      Re: Length Of the String in RPG

                      Why oh why do people still use that old crap when RPG IV is virtually 100% compatible ..
                      I know that a bunch of large shops (100's of developers) are using synon..
                      I've seen & worked on some of these programs they are well over 20,000 lines long.
                      Yes I wrote 20,000....

                      Anyway the only way to maintain them at this size is synon.

                      These companies have married themselves to a technology that
                      keeps them writing Inefficient, Clunky code in RPGIII.

                      I'm sure there are other reasons, but this is one I have seen first hand.
                      All my answers were extracted from the "Big Dummy's Guide to the As400"
                      and I take no responsibility for any of them.

                      www.code400.com

                      Comment


                      • #12
                        Re: Length Of the String in RPG

                        Originally posted by jamief View Post
                        I know that a bunch of large shops (100's of developers) are using synon..
                        I've seen & worked on some of these programs they are well over 20,000 lines long.
                        Yes I wrote 20,000....

                        Anyway the only way to maintain them at this size is synon.

                        These companies have married themselves to a technology that
                        keeps them writing Inefficient, Clunky code in RPGIII.

                        I'm sure there are other reasons, but this is one I have seen first hand.
                        Hmmm - I thought Synon had changed to RPG IV (fixed form) code-gen some time back - maybe it is a chargeable feature?

                        Comment


                        • #13
                          Re: Length Of the String in RPG

                          Not if you don't upgrade which leads us head first into the original problem.
                          All my answers were extracted from the "Big Dummy's Guide to the As400"
                          and I take no responsibility for any of them.

                          www.code400.com

                          Comment

                          Working...
                          X