ABAP Predefined Case functions
Today's topic is case handling,
Abap has support for handling cases of string using both keywords and built-in methods.
I wanted to talk about the built-in methods that you can use to modify the case of a string and how they are better than their keyword counterparts.
1. To_upper:
Converts the input string/literal to uppercase and returns the uppercased string which can be used in operand positions.
Example:
REPORT sy-repid. | |
PARAMETERS: | |
p_inp TYPE char11 DEFAULT 'Hello World'. | |
START-OF-SELECTION. | |
*old way.. | |
DATA(out) = p_inp. | |
TRANSLATE out TO UPPER CASE. | |
write:/ 'Uppercase: ', out. " Output -> HELLO WORLD | |
"New way | |
write:/ 'Uppercase: ', to_upper( p_inp ). " Output -> HELLO WORLD | |
2. To_lower:
Converts the input string/literal to lowercase and returns the uppercased string which can be used in operand positions.
Example:
REPORT sy-repid. | |
PARAMETERS: | |
p_inp TYPE char11 DEFAULT 'Hello World'. | |
START-OF-SELECTION. | |
*old way.. | |
DATA(out) = p_inp. | |
TRANSLATE out TO LOWER CASE. | |
write:/ 'Lowercase: ', out. "Output-> hello world | |
"New Way | |
write:/ 'Lowercase: ', to_lower( p_inp ). "Output-> hello world |
3. To_mixed:
Converts the input string/literal to mixed case and returns the uppercased string which can be used in operand positions.
There is no equivalent keyword for this function and the function can be really helpful in manipulating the string cases.
Example:
Of course, it's just a demonstration, you can play around with a more complex scenario of mixed case function.
REPORT sy-repid. | |
START-OF-SELECTION. | |
"Default behaviour | |
write:/ 'Mixedcase: ', to_mixed( 'HELLO WORld'). "Output-> Hello world | |
"first letter Upper case after separator. | |
write:/ 'Mixedcase with searator: ', to_mixed( val = 'HELLO WORld' | |
sep = ` ` ). "Output-> HelloWorld | |
"Capitalise specific letter | |
write:/ 'Mixedcase: ', to_mixed( val = 'HELLO WORld' | |
case = 'hW' | |
sep = ` `). "Output-> helloWorld |
As always, hope you like the post and use it in your day-to-day work.