Posts

ABAP logging made easy using simple logger utility class ZCL_LOGGER

In the last post,  Application logging in ABAP . I talked about application logging. It's an excellent utility but it's cumbersome from a developer's point of you. Especially if you work or have worked with languages like JavaScript where logging is as easy as Console.log("your text"). to add the same level of ease, I created a utility class that makes logging easy. Starting a log is as easy as instantiating the object. Below is the example : Adding messages to the log becomes a single line code: Here is the snippet to save the log. Notice how you don't have to worry about saving the log messages.. because the class saves your messages the moment you add them, so you don't have to worry about collecting your logs and making sure the save happens in all scenarios. Now I will take the same code snippet that I shared in the last post and rewrite it using the logger class to show how convenient it is to use the...

Application Logging in ABAP

Image
Whether you are working with integration or a critical application or a complex report, logging becomes an obvious choice and activity.  Traditionally, Abapers have been logging information using a custom DB table defined specifically for a particular application. While useful, The approach has some flaws,      - Every application needs to have its own logging table      - Record purging/archiving needs to be set up in order to make sure old records are either deleted         or archived.      - There is no reusability of either the setup or the logic to log. With the introduction of Application Logging from SAP, the traditional approach can be left out.  In this post, I will be talking about how we can leverage the SAP application Logging Library to make logging easy. What is an application log? An application log is a rich type log. It contains information like User...

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

Adding Icons to selection screen elements

Image
Recently I have been trying to improve the look and feel of the screens/selection screen of my deliverables. While looking to elevate the look of the selection screen, I stumbled upon a way to add icons to elements. Icons with texts are great. They make certain elements stand out more or add visual interest.    You can add icons to elements by adding the Icon ID( like  @01@, @02@,  and so on) to selection Texts with or without text. Consider this example:

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

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