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.
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.
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;
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 😉
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.
Copying iSeries fields from numeric to Alpha – aka using SQL to change column data type
Developerworks Connections Sunset – How to Extend RDi
Why use IBM i RDi?
How to Install IBM Access Client Solutions (ACS)
IBM i Data Obfuscation – Making Data Foggy Murky and Squinty
How to rename Fresche (BCD) Presto Library – XL_PRESTO
What is AS400 modernization?
IBM i ACS 5250 EMULATOR FONT – and other ridiculous mumbo jumbo
IBM i SQL statement to convert or compare hundred year date format