sponsored links

Collapse

Announcement

Collapse
No announcement yet.

Substring in RPG

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

  • Substring in RPG

    I need to ask an IF statement about the first byte of a three byte chararcter field in RPG III. Can I accomplish this in one step or do I have to substring the field in the first spec and in the next statement ask the "IF".
    Examples would help . Field name is GRPID. In cobol I could use reference modification and say:
    If GRPID (1:1) = "M"
    then do this
    else take the day off


    Thanks,
    John
    John M. Mauro
    Software Engineer
    MedAssets

  • #2
    Re: Substring in RPG

    in RPGIII you will need to just create a data structure with 3 subfields all 1 *char long.
    then reference that field....

    if you get on a system with code that isnt over 17 years old then just do:

    if %subst(myfield:1:1) = 'A';
    endif;
    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: Substring in RPG

      I just want to point out that you dont have to be stuck in RPGIII. You can take this program forward into RPGIV by using the CvtRpgSrc command and use the new stuff in RPG. (Or, at least the stuff thats new since 1995.) You will save enormous amounts of coding time if you do.
      Michael Catalani
      IS Director, eCommerce & Web Development
      Acceptance Insurance Corporation
      www.AcceptanceInsurance.com
      www.ProvatoSys.com

      Comment


      • #4
        Re: Substring in RPG

        Thanks for the replies. With regards to the versions. We have the PGM in RPGILE too, but need to support the older versions for clients who never upgraded.
        Again Thanks !!!!
        John
        John M. Mauro
        Software Engineer
        MedAssets

        Comment


        • #5
          Re: Substring in RPG

          Hi John,

          If you use the CvtRpgSrc command and do nothing else to the program, it is as OPM as the RPGIII program. ( In other words, its non-ile, and runs in the DAG just like RPGIII programs do). But it does allow you to use the new RPG opcodes back to the release the customer is on.

          I used to own a software company that had multiple application packages to support. ( We even had to support across the Cisc / Risc barrier ) So I know what a giant pain to support back-release levels. (It was such torture to see the new opcodes for RPG come out, and know that we couldnt use them because they would keep a program from being compiled to a previous version.)

          But you should be able to convert the RPGIII to non-ile RPGIV wih no issues, and it will save you a ton of coding and support headaches. You wouldnt be able to use subprocedures, activation groups, and other ILE concepts, but you can take advantage of the new RPG opcodes that make life so much easier. (Especially date and string manipulations.)

          You may know all of this, but I keep bringing it up because there's still a lot of people who dont, and they are missing out on a ton of productivity. They hang back on the RPGIII compiler because they believe the CvtRpgSrc command will make their program ILE. It doesnt. It simply brings the code forward to the RPGIV compiler, which is the compiler thats been updated for the past 17 years. In order to make the program ILE, you have to specify DftActGrp(*NO) on either the control spec or at compile time. As long as that statement doesnt exist, the program is as OPM as an RPGIII program, it was simply run through the newer compiler.
          Last edited by MichaelCatalani; June 15th, 2011, 09:59 AM.
          Michael Catalani
          IS Director, eCommerce & Web Development
          Acceptance Insurance Corporation
          www.AcceptanceInsurance.com
          www.ProvatoSys.com

          Comment


          • #6
            Re: Substring in RPG

            create a DS with a subfield containing only that 1st character and compare that in your condition seems the easiest approach in RPG III
            I'm not anti-social, I just don't like people -Tommy Holden

            Comment


            • #7
              Re: Substring in RPG

              Hi John:
              PHP Code:
                 c           movel my3char my1char
               
                 c   my1char ifeq 
              'M'
                 
              c           endif 
              at least that's the way I used to do it

              Best of Luck
              gls
              The problem with quotes on the internet is that it is hard to verify their authenticity.....Abraham Lincoln

              Comment


              • #8
                Re: Substring in RPG

                thank you!!!

                Comment


                • #9
                  Re: Substring in RPG

                  Nobody thought of creating a 1 character field and doing a MOVEL...

                  I wasn't aware you had to source upgrade RPGIII to RPGIV though, but it's worth moving programs to RPGLE if you are going to be doing any major updates to them.

                  Having said that, we have 3 programmers here who work in RPGIV. They can't comprehend RPGLE.

                  I must admit that for the most part I write my RPGH still in Upper Case, because my brain has been programmed for 31 years to see RPG code in Upper Case. I don't use procedures, Binding etc. Have a couple of times but it's just another way of doing the same thing I always have, and seems more complicated.

                  What I love about RPGLE is the use of the EVAL statement, %functions, nested IF's etc. They not only make coding simpler to do, they make it simpler to read as well.

                  I still use the RPG cycle too. It saves a lot of hard work, especially if processing a whole file and doing level breaks. That was what RPG was designed around, until a bunch of folks from the next generation said that it wasn't correct to write RPG that way. What do they know anyhow...
                  Poddys Rambles On

                  Comment


                  • #10
                    Re: Substring in RPG

                    Not sure if I'm missing something.
                    Does this

                    if %subst(GRPID:1:1) = 'M';
                    require a DS? It's just one field, isn't it?
                    ‘No bird soars too high if he soars with his own wings’ – William Blake

                    Comment


                    • #11
                      Re: Substring in RPG

                      Hi Kausix777:
                      No ds required. You are comparing the first position of a field to a constant.

                      Best of Luck
                      GLS
                      The problem with quotes on the internet is that it is hard to verify their authenticity.....Abraham Lincoln

                      Comment


                      • #12
                        Re: Substring in RPG

                        Originally posted by GLS400 View Post
                        Hi John:
                        PHP Code:
                           c           movel my3char my1char
                         
                           c   my1char ifeq 
                        'M'
                           
                        c           endif 
                        at least that's the way I used to do it

                        Best of Luck
                        gls
                        Another approach is this:
                        Code:
                              *          FACT1     OP   FACT2     RESULT         
                             C           1         SUBSTCHAR3:1   CHAR1   1
                        but I think the MOVEL is easier to read/understand.
                        http://www.linkedin.com/in/chippermiller

                        Comment


                        • #13
                          Re: Substring in RPG

                          Originally posted by Poddys View Post
                          I still use the RPG cycle too. It saves a lot of hard work, especially if processing a whole file and doing level breaks. That was what RPG was designed around, until a bunch of folks from the next generation said that it wasn't correct to write RPG that way. What do they know anyhow...
                          Yes -- the cycle makes it easy to crank out code with level breaks. Have never understood why people would want to have a bunch of fields to track when a level break occurs and all the extra code to handle level breaks without the cycle.
                          http://www.linkedin.com/in/chippermiller

                          Comment


                          • #14
                            Re: Substring in RPG

                            Rather than confess they don't understand the cycle gist some people prefer to broadcast that it's old school
                            Philippe

                            Comment


                            • #15
                              Re: Substring in RPG

                              Originally posted by Chipper View Post
                              Yes -- the cycle makes it easy to crank out code with level breaks. Have never understood why people would want to have a bunch of fields to track when a level break occurs and all the extra code to handle level breaks without the cycle.
                              It's nice to know that a few years down the road people are brave enough to stand up for the RPG cycle.

                              The amount of code required to manually check for detail time and total time level breaks, not to mention making sure you got the code right... when the RPG cycle does it all for you.

                              As with everything else, take the best of the new and the best of the old and use what works best.
                              Poddys Rambles On

                              Comment

                              sponsored links

                              Collapse

                              Working...
                              X