Posts

Showing posts from 2018

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 differently according to the data

ABAP Obsolete statements - REFRESH

Its time for another bite-sized post, This time with an obsolete statement. You have used it and I have used it, we all have used it whenever we wanted to clear the content of an internal table. Yes, I am talking about the REFRESH statement. Its almost second nature to use a CLEAR statement for clearing variables and Structures and REFRESH statements for Internal tables. To all the lovers of REFRESH statements, I have got bad news. It's Obsolete.  SO whats the replacement? its good old CLEAR statement, You might be wondering, why? It was a harmless statement. The way I see it, It became redundant with an Object-oriented setup. You see the statement REFRESH itab acts for internal tables like CLEAR itab[].  If the internal table itab has a header line , then the table body and not the header line is initialized. If the internal table itab has no header line , REFRESH itab acts like CLEAR itab. Now, Since the use of tables with header lines is obsolete and forbidden in classes, the

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,    Calculati

ABAP BOOLC and XSDBOOL use-cases

 In the previous post  ABAP Convert Logical Expressions Into Boolean Values , I talked about BOOLC and XSDBOOL functions and their respective features. I thought I would elaborate on their use cases with examples. BOOLC: Set boolean flag:

ABAP predefined functions - LINES

When dealing with internal tables, many a time, you are looking to know the number of records the table holds. In this bite-sized post, I will try to show you how to use ABAP predefined function LINES over the traditional approach of using DESCRIBE keyword.

Boolean in ABAP

Dealing with two state flags is nothing new and a very common scenario in ABAP development, Historically they have been used to represent a true or false state. For example: Y or N, X or ' ', 0 or 1. Booleans are data objects that store truth values i.e. True or False , which are results of logical expressions. Truth values are the results of logical expressions. A truth value is either true or false. ABAP does not yet support boolean data types and thus does not support data objects for truth values. Therefore, the result of a logical expression cannot be assigned directly to a data object. However, it can be achieved using Boolean functions. It has become common practice to express the truth value "true" as value " X " and the truth value "false" as a blank (" ").  which leads to one of the bad practices still prevalent: Using the Data Type abap_bool for Truth Values The type group ABAP contains a data type abap_bool of elementary type

ABAP Convert Logical Expressions Into Boolean Values

In my last post on  ways to flip a boolean , I talked about how we can use boolean   functions to flip a boolean by passing a logical expression. I thought I will elaborate further on these. Boolean in ABAP is not that straightforward . However, boolean functions help us capture the results of logical expressions as a form of truth value. Let's dive further;

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.  As always, h

Ways to flip a Boolean

Whenever working with booleans while writing code there is almost always a scenario where one has to flip the boolean state i.e. true to false or vice-versa based on some condition. In this post, I wanted to showcase different ways to do so. Using Control statements:

Case Statement usage

Case statements in ABAP are great. Not only do they let you handle your logic flow like other control flow statements but also provide a clean/ better readable way to branch into multiple sublogics. A typical use of a case statement is something like this as [ CASE  variable:  WHEN  value]: