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 😉