Posts

Showing posts from 2019

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, Time, Expiry date of the log along with the actual message raised by the

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.   - There is no empty text field literal:      This means,

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 ignore

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 use to exit the processing block. -> Always Use RETURN -> CHECK can be used as a guard clause at the

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: