Warning: Declaration of TCB_Menu_Walker::walk($elements, $max_depth) should be compatible with Walker::walk($elements, $max_depth, ...$args) in /home/nicklit/www/www/wp-content/plugins/thrive-visual-editor/inc/classes/class-tcb-menu-walker.php on line 620

Warning: session_start(): Cannot start session when headers already sent in /home/nicklit/www/www/wp-content/plugins/userpro/includes/class-userpro.php on line 222
Change Case in RPG - UPPER to lower using XLATE vs. SQL - Nick Litten is IBM-i, AS400 iSeries RPG Programmer and Nerd

Change Case in RPG – UPPER to lower using XLATE vs. SQL

AS400

Apr 15

Changing SENTENCE CASE didnt used to be something that the grey haired AS400 and iSERIES programmers ever worried about. Back in the pre-internet days, most data entry was in UPPERCASE, plugged into giant green on black terminals by people wearing 1970’s flares and thick glass spectacles. But now it’s a new age of Internet connectivity, webservices and UPPER to lower using XLATE %BIF’s in modern RPG.

Why do we care about sentence CASE checking so much?

Simply put – in programmig terms the word “Muffin” is not the same as the work “muffin” which is also different to “MuFfiN”. You see? So, changing an input string (for example parameter sent in from a webservices request) to the same CASE as the database makes comparing  you range of exciting tasty “muffins” much easier.

Changing sentence case is easy with RPG

dcl-c lowerCase ('abcdefghijklmnopqrstuvwxyz');
dcl-c upperCase ('ABCDEFGHIJKLMNOPQRSTUVWXYZ');

dcl-s inputString varchar(200);
dcl-s outputString varchar(200);


 //CONVERT FROM UPPERCASE TO LOWERCASE
 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; 

Changing sentence case is easier with SQL RPG

But it’s even easier with RPG and SQL because you dont even need the XLATE variables and this will let you catch all the special characters for that language:

dcl-s inputString varchar(200);
dcl-s outputString varchar(200);
CharField = 'hello db2 summit!';
//CONVERT FROM UPPERCASE TO LOWERCASE
EXEC SQL SET :outputString = UPPER(:inputString);

I will leave the syntax for the lower to your imagination 😉

Follow

About the Author

IBM i Software Developer, Digital Dad, AS400 Anarchist, RPG Modernizer, Alpha Nerd and Passionate Eater of Cheese and Biscuits. Nick Litten Dot Com is a mixture of blog posts that can be sometimes serious, frequently playful and probably down-right pointless all in the space of a day. Enjoy your stay, feel free to comment and in the words of the most interesting man in the world: Stay thirsty my friend.