Saturday, 29 July 2017

SQLRPGLE UPPER (or LOWER) function: An alternative to %XLATE

In RPGLE, %XLATE is used to convert given string to upper or lower case (see below). Please note that this is just a work around, there is no inbuilt function to do this directly in RPGLE. To do this, two variables are defined with alphabets in upper and lower case which then be used with %XLATE function for string conversion.


0001.00 Hoption(*nodebugio:*srcstmt)                                        
0002.00  *                                                                  
0003.00 Dlowercase        s             26a   inz('abcdefghijklmnopqrstuvwxyz')
0004.00 Duppercase        s             26a   inz('ABCDEFGHIJKLMNOPQRSTUVWXYZ')
0005.00 Dstring1          s             50a                                  
0006.00 Dstring2          s                   like(string1)                  
0007.00  *                                                                  
0008.00  /Free                                                              
0009.00                                                                      
0010.00     string1 = 'this string will be converted';                      
0011.00     dsply string1;                                                  
0012.00     string1 = %xlate(lowercase:uppercase:string1);                  
0013.00     dsply string1;                                                  
0014.00                                                                      

RESULT -

DSPLY  this string will be converted    
DSPLY  THIS STRING WILL BE CONVERTED    

We have another way of doing this - by using SQL function and this can be done in single shot. (see below)

0015.00     string1 = 'this is another way of converting';      
0016.00     dsply string1;                                      
0017.00     exec sql set :string2 = upper(:string1);            
0018.00     dsply string2;                                      

RESULT -

DSPLY  this is another way of converting  
DSPLY  THIS IS ANOTHER WAY OF CONVERTING  

No comments:

Post a Comment

Progress bar in AS400 (version 2)

This is another version of progress which most people like (previous version is here ). Source of display file A                     ...