RPGLE convert lowercase to uppercase and uppercase to lowercase

We need to convert case of character string all the time but still there no Built in Function in RPGLE from IBM. The next best way to do it is using the %XLATE() Built in Function.


%XLATE translates string according to the values of from, to, and startpos.

  • The first parameter contains a list of characters that should be replaced
  • The second parameter contains their replacements.
  • The third parameter is the string to be translated. 
  • The fourth parameter is the starting position for translation.  
    • By default, translation starts at position 1.

Sample RPGLE program to convert String from lowercase to uppercase and from uppercase to lowercase

d lowerCase       c                   'abcdefghijklmnopqrstuvwxyz'
d upperCase       c                   'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
d inputString     s             50a                               
d outputString    s             50a                               
  inputString = 'Convert from lowerCase to upperCase';            
  outputString = %xlate(lowercase:uppercase:inputString);         
  dsply outputString;                                             
  //CONVERT FROM LOWERCASE TO UPPERCASE                           
  inputString = 'CONVERT FROM UPPERCASE TO LOWERCASE';            
  outputString = %xlate(uppercase:lowercase:inputString);         
  dsply outputString;                                             
  //convert from uppercase to lowercase                           
  *inlr = *on;                                                    

No comments:

Post a Comment

NO JUNK, Please try to keep this clean and related to the topic at hand.
Comments are for users to ask questions, collaborate or improve on existing.