Posts

ABAP Editor/Workbench Custom Dynamic Patterns

Image
In my last post ABAP Editor dynamic patterns , We saw how we can use the patterns to our advantage. Today, I wanted to expand upon further features of dynamic patterns, which is the ability to write and add your own dynamic patterns. Let's say you want to define a template for the generation of DB validation code and provide your table name as input. Creating the Pattern. From the ABAP editor, Select Utilities > More Utilities > Edit Pattern > Create Pattern and enter a name for your pattern. Type name for the pattern: You will be presented with a text editor screen, Add the following code: *$&$MUSTER The above code tells the runtime to call a function module with the naming convention: <pattern_name>_editor_exit. > The next obvious step is to create the FM with the above-discussed name. The FM has a defined interface of a TABLES parameter BUFFER of type RSWSOURCET . The table is used to pass back the code to the editor. Insert Below c...

ABAP Editor(SE38/80) dynamic patterns

Image
This post is about tooling around the ABAP workbench(SE80). You can speed up your development using dynamic patterns. What are patterns? Patterns are helper plugins in the ABAP workbench to help you generate a necessary call to various ABAP constructs like Methods, function modules, declarations etc. Accessing Patterns: Implicitly invoking them by opening them on the left side category and dragging and dropping them to your editor. If you are on an ABAP 7.4+ system, It generates declarations for you too. Or, You can access them by clicking on the Pattern button on the ABAP editor in edit mode. A popup appears, providing you with Options. Providing the same class and methods in the popup results in generated code. The output depends on which system you are. ABAP 7.3: ABAP 7.4: In conclusion,  ABAP dynamic patterns are a great way of speeding up and simplifying your day-to-day development effort even though they are not the only one...

ABAP Obsolete Statement: TABLES

 As part of the Obsolete statement series , today's post is about TABLES statement.  Syntax: TABLES wa_table . Example: It declares a data object wa_table as a table work area whose data type is taken from the identically named table wa_table in the ABAP dictionary. DB tables and views can be used to declare their work areas using TABLES statement. Table work areas declared using TABLES are interface work areas ( a special data object that can act as a cross-program interface between program and screens or logical databases. The statement TABLES is not allowed within classes anyway. Since obsolete database accesses requiring the statement TABLES and shared data areas between programs are not allowed, there is no need to use the statement TABLES . In other words ,  The main purpose of the TABLES statement is to act as an interface work area to share data across programs and screens, since the shared data areas between programs are not allowed, t...

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 Chaining Operator && and how to use it

I am not particularly fond of the excess of the ABAP statements to achieve simple tasks and really like the new adaption to operators and predefined functions to achieve similar or sometimes better results. In line with that, this post is about my favourite, chaining operator or && . For folks who have never seen this or want to know more about it, What is a Chaining Operator? The chaining operator concatenates two operands in a string expression as a character string. It has the ability to allow string expressions, predefined functions or functional methods, and even method chaining at its operand position.  To Me, It's an upgrade over the good old CONCATENATE statement. Syntax: … operand1  && operand2 … . Below are a few examples of Chaining Operator and its usage. Simple Concatenation:  Adding Separator: Adding Different Separators in a text: Notice how effortlessly different separators can be embe...

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