Page 1 of 2 12 LastLast
Results 1 to 20 of 21

Thread: Substring in RPG

  1. #1
    Experienced Forum Member
    Join Date
    Dec 2007
    Location
    Bedford,Ma
    Age
    56
    Posts
    74
    Rep Power
    728

    Smile 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. # 666
    Circuit advertisement
    Join Date
    Aug 1965
    Location
    Yakutsk, Russia
    Age
    21
    Posts
    1,000,000
     

  3. #2
    Driver of cars, eater of food jamief's Avatar
    Join Date
    Jan 2004
    Location
    Belvidere, IL - United States of America
    Age
    49
    Posts
    9,416
    Rep Power
    12605

    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

  4. #3
    Lord of the Dance
    Join Date
    Aug 2008
    Location
    Memphis - Nashville TN
    Posts
    1,692
    Rep Power
    4708

    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
    Manager of eCommerce Development
    Acceptance Insurance Corporation
    www.AcceptanceInsurance.com
    www.ProvatoSys.com

  5. #4
    Experienced Forum Member
    Join Date
    Dec 2007
    Location
    Bedford,Ma
    Age
    56
    Posts
    74
    Rep Power
    728

    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

  6. #5
    Lord of the Dance
    Join Date
    Aug 2008
    Location
    Memphis - Nashville TN
    Posts
    1,692
    Rep Power
    4708

    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 at 10:59 AM.
    Michael Catalani
    Manager of eCommerce Development
    Acceptance Insurance Corporation
    www.AcceptanceInsurance.com
    www.ProvatoSys.com

  7. #6
    Harbinger of Doom tomholden's Avatar
    Join Date
    Dec 2007
    Location
    Lebanon, Tennessee, United States
    Posts
    4,326
    Rep Power
    8642

    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

  8. #7
    Analyst GLS400's Avatar
    Join Date
    May 2006
    Location
    connecticut
    Posts
    1,900
    Rep Power
    5796

    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

  9. #8
    Code400 Newbie
    Join Date
    Jun 2011
    Location
    Prescott
    Posts
    1
    Rep Power
    0

    Re: Substring in RPG

    thank you!!!

  10. #9
    IBM Midrange Veteran Poddys's Avatar
    Join Date
    Jun 2011
    Location
    Southampton
    Posts
    109
    Rep Power
    356

    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...

  11. #10
    "Like"r of the i kausix777's Avatar
    Join Date
    Jan 2006
    Location
    Bangalore, India
    Age
    37
    Posts
    266
    Rep Power
    1607

    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

  12. #11
    Analyst GLS400's Avatar
    Join Date
    May 2006
    Location
    connecticut
    Posts
    1,900
    Rep Power
    5796

    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

  13. #12
    Experienced Forum Member Chipper's Avatar
    Join Date
    Mar 2007
    Location
    Greenbelt, Maryland, United States
    Age
    52
    Posts
    776
    Rep Power
    1977

    Re: Substring in RPG

    Quote 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.

  14. #13
    Experienced Forum Member Chipper's Avatar
    Join Date
    Mar 2007
    Location
    Greenbelt, Maryland, United States
    Age
    52
    Posts
    776
    Rep Power
    1977

    Thumbs up Re: Substring in RPG

    Quote 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.

  15. #14
    Programmer Mercury's Avatar
    Join Date
    Feb 2007
    Location
    Paris, France
    Posts
    1,831
    Rep Power
    5424

    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

  16. #15
    IBM Midrange Veteran Poddys's Avatar
    Join Date
    Jun 2011
    Location
    Southampton
    Posts
    109
    Rep Power
    356

    Re: Substring in RPG

    Quote 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.

  17. #16
    Blreen-O-holic vikramx's Avatar
    Join Date
    May 2006
    Location
    Chennai, India
    Posts
    231
    Rep Power
    1380

    Re: Substring in RPG

    I think I should look into the RPG cycle one more time and try to understand it. This is because when I started working on the AS400 people (who I worked with) did not encourage the use NOR did I find any existing programs which had them. Seems like I'm missing out on something here.

    Just because something's old doesnt meant its not good.

    The main thing that I like about RPG/LE and the general AS400 stuff is the ease with which the programs interact with the database tables. I have worked with multiple languages and apart from PL/SQL and/or SQL, I didnt find any other lanugage interacting with database tables as easily as RPG/LE or COBOL/400 or CL/400 does.
    Last edited by vikramx; July 8th, 2011 at 03:10 AM. Reason: Edit: Too many grammatical mistakes :(

  18. #17
    IBM Midrange Veteran Poddys's Avatar
    Join Date
    Jun 2011
    Location
    Southampton
    Posts
    109
    Rep Power
    356

    Re: Substring in RPG

    The one thing to note about the RPG Cycle is that it's really these days only applicable when you are reading all records from an input file (IP = Input Primary), processing them and creating output (another file or a report).

    The input can be extracted and sorted (usually done using OPNQRYF), and you have to assign an indicator to the incoming record (traditionally "01").

    To process the record, in the detail line specifications you would have:

    C 01 DO
    C ------
    C ENDDO

    I don't have any examples handy online, will see if I can dig one out and upload the key portions to help give you an example - unless anyone else wants to beat me to it.

    Using the RPG Cycle you don't have to (a) read your main input file, (b) prat around with a lot of code to check for level breaks, (c) depending on what the program is doing you can output your data/reports using the RPG Cycle too.

    The generation who tried to enforce the use of Structured Programming on RPG forgot that RPG does in fact stand for Report Program Generator, and the language was designed to help make it easier to create reports, hence the Level Break indicators etc.

    To not use these is like re-inventing the wheel, complete with pneumatic tires etc, and coming up with a wooden version like they used in ancient times.

  19. #18
    Blreen-O-holic vikramx's Avatar
    Join Date
    May 2006
    Location
    Chennai, India
    Posts
    231
    Rep Power
    1380

    Re: Substring in RPG

    An example would be great and if I can use it some instance, then I will gladly do so (provided a better alternative is unavailable).

    And yes, I do remember it standing for Report Program Generator .

    On a side note, we have cleverly side tracked what seemed to be a question on how to substring in RPG XD.

  20. #19
    IBM Midrange Veteran Poddys's Avatar
    Join Date
    Jun 2011
    Location
    Southampton
    Posts
    109
    Rep Power
    356

    Re: Substring in RPG

    Quote Originally Posted by vikramx View Post
    On a side note, we have cleverly side tracked what seemed to be a question on how to substring in RPG XD.
    You are correct. I wonder if there are threads on the RPG Cycle already. I would be surprised if there were not.

  21. #20
    Harbinger of Doom tomholden's Avatar
    Join Date
    Dec 2007
    Location
    Lebanon, Tennessee, United States
    Posts
    4,326
    Rep Power
    8642

    Re: Substring in RPG

    Quote Originally Posted by Poddys View Post
    The one thing to note about the RPG Cycle is that it's really these days only applicable when you are reading all records from an input file (IP = Input Primary), processing them and creating output (another file or a report).

    The input can be extracted and sorted (usually done using OPNQRYF), and you have to assign an indicator to the incoming record (traditionally "01").

    To process the record, in the detail line specifications you would have:

    C 01 DO
    C ------
    C ENDDO

    I don't have any examples handy online, will see if I can dig one out and upload the key portions to help give you an example - unless anyone else wants to beat me to it.

    Using the RPG Cycle you don't have to (a) read your main input file, (b) prat around with a lot of code to check for level breaks, (c) depending on what the program is doing you can output your data/reports using the RPG Cycle too.

    The generation who tried to enforce the use of Structured Programming on RPG forgot that RPG does in fact stand for Report Program Generator, and the language was designed to help make it easier to create reports, hence the Level Break indicators etc.

    To not use these is like re-inventing the wheel, complete with pneumatic tires etc, and coming up with a wooden version like they used in ancient times.
    well technically if you do not use the MAIN keyword on your H spec (and that is like v6.1 and higher) then you're "using" the cycle even if you don't think you are. *INLR if used is actually telling the RPG cycle to close all open files, etc. implicitly. so far the most part people are still using the CYCLE...just not the file processing, etc. portions
    I'm not anti-social, I just don't like people -Tommy Holden

  22. # 666
    Circuit advertisement
    Join Date
    Aug 1965
    Location
    Yakutsk, Russia
    Posts
    1,000,000
     

Facebook Comments


Similar Threads

  1. Substring in a declare
    By iPort in forum SQL
    Replies: 2
    Last Post: December 1st, 2009, 03:42 PM
  2. CL variable substring
    By casporov in forum CLP/CLLE
    Replies: 4
    Last Post: January 20th, 2009, 03:34 AM
  3. Update substring
    By tintin in forum SQL
    Replies: 8
    Last Post: October 11th, 2007, 11:23 AM
  4. substring
    By sudha in forum RPG/RPGLE
    Replies: 3
    Last Post: September 2nd, 2006, 07:14 AM
  5. substring
    By alexi in forum SQL
    Replies: 2
    Last Post: November 24th, 2005, 08:27 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •