Posts

Showing posts with the label Robust ABAP

Difference between Chaining operator(&&) and Literal Operator(&)

Image
Recently I talked about the Chaining Operator(&&) and how it simplifies dealing with texts and strings. I wanted to talk about a similar-looking operator with some similar functions to the chaining operator which makes it easy to confuse each other. A literal operator( & ) is used to join two or more literals to produce a single literal. However, there is a hard character length limit of 255. Example of using a literal operator: There are more features and limitations to a literal operator. Below are the points on which it's similar/different to a Chaining operator.     - Similar to the chaining operator, you can use join string templates using & .     - Any trailing blank in text field literals is preserved, unlike chaining operator.     - Can span multiline:      - Calculated at compile-time.     -  Can not have more than 255 c...

ABAP OBSOLETE Statement: MOVE

It's time to talk about another obsolete statement that unfortunately still gets seen around. It's the good old MOVE statement. Syntax: MOVE " Source " TO " Destination ". It's an obsolete form of assignment back from the days when ABAP was more descriptive and English in nature than it is now. Also, the statement  MOVE was created at a time when assignments were only made between individual data objects. This statement is not appropriate in a modern, expression-oriented ABAP program that exploits all options on the left and right sides of assignments. Replacement Statement is assignment Operator( '=' ).  Below is a small example:

ABAP text field literal vs text string literal

Have you ever had a variable containing text? I am sure you did and regularly do. What is your preferred way to do declare it? If you don't know or use the second option, then this post is for you. There is a minute difference in the way text literal has been defined in options one and two.  First of all the declaration is a literal being passed to a variable, and some of you may ask: what is a literal?     L iterals are defined in the source code of a program by specifying a string representing a value.     Possible literals are numeric literals and character literals. The character literal comprises text       field literals and text string literals. So there are two kinds of text literal, let's see them in detail. Text Field Literals:   - Defined using single inverted commas (').   - Data type is c  with the length of the included characters, including trailing blanks.   ...

ABAP Characters , Strings and Traps of Trailing Blanks

Image
No matter how much I try to move away, I keep coming back to this. I have talked about this multiple times in multiple posts and yet it seems less. So bear with me and hope you stay sane/awake by the time we reach the end. Alright, The issue is simple. Handling of trailing blanks . No need to read further if you know it all. For the rest of the mortals like me, let's proceed. When it comes to character string processing, ABAP gives you two built-in options:  C - Fixed length, trailing blanks are ignored , minimum length is 1. STRING - Dynamic length, trailing blanks are relevant , minimum length is 0. Before you start feeling unrewarded for all the build-up at the start, I have a program to share: Running the program gives this output. The Output is different even with the seemingly same code.  Why? Because the devil is in the details, c_text_space is type c and contains one blank (trailing) which gets i...

ABAP various ways to Exit processing Blocks

No matter which programming language you are working with, at the end of the day your job revolves around manipulating its processing block to achieve the desired results. One of them is exiting it. In this post, I wanted to talk about various ways you could exit an ABAP processing block.  But first, What is a Processing Block?      Modularization unit of an ABAP program that cannot be split or nested. Processing blocks are     -  Procedures like subroutines or methods ,     -  Dialog modules declared for screens , and      -  Event blocks like reporting events such as load-of-program, start-of-selection ,  etc.      To summarise,            Each non-declared statement in an ABAP program is part of a processing block. Now , coming back to the point of the post. Below are the different ABAP statements that you can us...

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

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...