Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

converting a string of uppercase letters with a call pgm

Status
Not open for further replies.

hpaul14

Programmer
Feb 24, 2004
3
US
How do i write a call program that converts a string of uppercase letters to a string in which the first character in the field and any other character immediately following a blank remain upper case but all other letters are converted to lower case? It has to be done in a way so that it passes a value in the first parameter and stores the converted string in the second parameter field before returing.
 
I don't recall how to convert case, but if you read each character individually (aka %subst(myfield:x:1) then you can look for blanks add 2 to x then continue converting.

Something like:
Code:
/free
  y = %len(%trim(myfield));
  dow x <= y;
    select;
      when %subst(myfield:x:1) = ' ';
         x += 2;
      other;
         cvt2lc(%subst(myfield:x:1);
         x += 2;
    endsl;
  enddo;
/end-free

cvt2lc is a subproceedure that will convert a character to lowercase. There are many sites out there that have case conversion examples in RPG (try midrange.com archives first).

I hope this helps.

iSeriesCodePoet
iSeries Programmer/Lawson Software Administrator
[pc2]
See my progress to converting to linux.
 
I love free...isn't it great!

good post iSeries...and I'm not sure if RPG has of yet added a upper case function. I needed one a while back and ended up with something similar to yours above after a few minutes of looking and not ahving the time to research it further

___________________________________________________________________

The answer to your ??'s may be closer then you think.
Check out Tek-Tips knowledge bank by clicking the FAQ link at the top of the page
 
Hi hpaul14,
A few months ago I had the same problem. I show you my procedure that does exactly what you want whatever the number of blanks between words.

HTH -- Philippe

Code:
     D up              C                   'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
     D lo              C                   'abcdefghijklmnopqrstuvwxyz'

     D inpstring       S            100A
     D outstring       S                   like( inpstring )

     D work            S              1A
     D pos             S              5U 0
     D i               S              5U 0 inz( 0 )


     C     *entry        plist
     C                   parm                    inpstring
     C                   parm                    outstring

      /FREE

          outstring = %XLATE( up:lo:inpstring );
          work = %XLATE( lo: up: %subst( outstring: 1: 1 ) );
          outstring = work + %subst( outstring: 2 : %len( outstring ) - 1 );

           dou i >= %len( inpstring );
             i = i + 1;

             if i >= %len( inpstring );
               leave;
             endif;

             pos = %scan( ' ': outstring : i );
             work = %XLATE( lo: up: %subst( outstring: pos+1: 1 ) );
             outstring = %REPLACE( work: outstring: pos+1: 1 );
             i = pos;
           enddo;

           *inlr = '1';

      /END-FREE


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top