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(from:to:string{:startpos})


%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                               
                                                                  
 /free                                                            
                                                                  
  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;                                                    
  return;                                                         
                                                                  
/end-free