ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

Changing Uppercase to Lowercase

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

  • Changing Uppercase to Lowercase

    Once again, I'm trying to learn coding in RPGLE. This time, I'm trying to take a street address from a physical file that is in all capitals and having only the first letter capitalized with the rest being lowercase. I'm using the %SCAN, %SUBST, and %XLATE to do this. I am able to get my city names to display correctly but I can't seem to figure out how to walk the string to get my street address to display correctly. Right now, it's just adding the beginning of the street address to the end. It compiles correctly but I'm also getting a "Length or position out of range" error. My code is as follows:
    Code:
    SAMPLE OUTPUT
    
    BEEBE Dennis           
       4401 Milham rd. Milh
       Kalamazoo MI 49045  
    
    ARMINE Yvonne          
       3300 Mckinley Mckinl
       St. Joseph MI 49003 
    
    The code:
    
          Address = %TRIM(STREET);                       
          Adrscan = %SCAN(' ':Address);                  
          IF Adrscan >  1;                               
             Adrnumb = %SUBST(Address:1:Adrscan- 1);    
             Adrscnd = %SUBST(Address:Adrscan+ 1);      
             Adrscnd= %XLATE(UC:LC:Adrscnd:2);          
             Adrscan2 = %SCAN(' ':Address:Adrscan+ 2);  
             IF Adrscan2 > 1;                             
                Adrthrd = %SUBST(Adrscnd:1:Adrscan2 - 1);
                Adrfour = %SUBST(Adrscnd:Adrscan2 + 1);  
                Adrthrd = %XLATE(UC:LC:Adrthrd:2);       
                Adrfour = %XLATE(UC:LC:Adrfour:2);       
             ENDIF;                                      
          ENDIF;                                         
           Address = %TRIM(Adrnumb) + ' ' + %TRIM(Adrscnd) + ' ' +
                     %TRIM(Adrthrd) + ' ' + %TRIM(Adrfour);       
           Address = %TRIM(Address);
    Any help for this RPG IV newbie is greatly appreciated!!

  • #2
    Re: Changing Uppercase to Lowercase

    here is an old thing I wrote......you can convert to free....




    jamie
    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: Changing Uppercase to Lowercase

      A couple of comments. At the beginning of the routine add
      Code:
      Eval Address= *blanks
      Also note that the last line Address = %trim(Address) is useless. The length of "Address" is fixed.

      fwiw: I think I would have done it differently. I would probably scan the field to find the columns to capitalize, the lower case the whole line, then subst back the 1 or 2 columns that need to be caps.

      Comment


      • #4
        Re: Changing Uppercase to Lowercase

        arrow483
        Thank you for the suggestions. I found I didn't need the line that you suggested of address = *blanks. Also, I was being overly cautious when I put in the %TRIM(address) line. Thank you for suggesting to take it out.

        jamief
        Thank you very much for the code. Although I don't totally understand where everything is coming from (by stepping through the code) I was able to take parts of it and convert it over to RPG IV. It now works the way I had hoped it would.

        Thank you both for your help!!!

        Comment

        Working...
        X