Posts

Showing posts with the label string processing

ABAP predefined length functions STRLEN and NUMOFCHAR

 Many a time when traversing a text, you would want to know the actual length of the text. in today's predefined function series post, I wanted to welcome you with ABAP length predefined functions: strlen , numofchar . While strlen is pretty well-known, numofchar is relatively unknown so I thought we should take a look at its feature and usage as well. Let's dive right in. STRLEN : Syntax : STRLEN ( arg ). Features :  It returns the number of characters in arg.  If the data object is of fixed length then trailing blanks are ignored.  If the data object is of type string, then trailing blanks are also counted. Example : NUMOFCHAR : Syntax : NUMOFCHAR ( arg ). Features :  It returns the number of characters in arg.  Trailing blanks are ignored regardless of the data object type. Example: As you would have noticed from the examples,  numofchar always ignores the trailing blanks whereas strlen behaves differen...

ABAP String templates Examples

 After talking about string templates in the last post String processing using string templates , I was tempted to provide more examples of just how powerful and simple to use string templates can be. so without much writing, here we go. Adding Whitespaces and Comments:

String Processing using ABAP string template

String Processing is one of the core components of any development. More so true when you are working with ABAP. String processing can be painful sometimes especially when you are merging or trying to embed one or more variables. In this post, I wanted to share the usage of String templates to help process strings effortlessly. But first, What is a string template? Simply Put, A string template is enclosed in two "|" (Pipe symbol) characters.  Example:     But there is more, string templates are a powerful tool that does more than just replace string literal. One of the biggest benefits of String templates is the elimination of helper variables. A string template has three components: Literal Text: Represents its exact character string. meaning what you see is what you get. Ex: Embedded Expressions: An embedded expression is defined inside an opening and a closing curly bracket { ... } within string templates and can hold: Data objects  like variables/constants, ...

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 : 2. To_lower: Converts the input string/literal to lowercase and returns the uppercased string which can be used in operand positions.  Example: 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.  A...