Posts

Showing posts with the label TIPS

ABAP capture result of submitted program using cl_salv_bs_runtime_info

Image
Let's talk about a hypothetical scenario, You are meditating in your fortress of solitude. A wild customer appears virtually/physically.The person shows you a report output and wants you to fetch exact data as the report displays in your current development. Scared , you begin to analyse the code of the report to reuse its logic only to see your fear come out alive i.e. the report has all the logic embedded. Proudly , you suggest refactoring the report, extracting the logic globally, and using it for your objects. Swiftly , your hope helicopter is shot down by the customer's stinger missile of an increase in testing efforts and with support troops of "nearing the deadline" hand a lack of super users to confirm the original report works as intended post refactor. Now, If the above scenario is not so much hypothetical in your experience, you are left with some limited choices. 1. Copy the logic ( Hello dark side) 2. Somehow get...

ABAP convert internal table to excel (.xlsx) format and Send email or download

Reporting is incomplete without file interfacing. Sometimes the requirement is to send a file via email or download it to a PC. but what to do when the user requests the file in XLSX format? In today's post, I am sharing how to convert an internal table to .xlsx format and then send it to a PC or email. One of the quickest ways I found it been done is using SALV classes. Below is the Code snippet Now once you have the xstring with you, simply pass it to relevant libraries to handle the output. Downloading to PC: Sending via Email It's that simple. Hope you like the post and use it in your day to day work.

Send mail with out using commit work with cl_bcs_message class

 In my last post  Send mail using CL_BCS library  We explored the class to achieve mail sending functionalities. The class is a really powerful tool but it has a shortcoming i.e. it needs to commit work . It's not a problem most of the time unless you are working with User-Exit and BADI. In this post, I wanted to showcase the usage of CL_BCS_MESSAGE class. The class only collects data and depending upon how you set the attributes of the class object, function module SBCS_SEND or SBCS_SEND_UPDATE is called. This means we can use this class to send emails from User-exit or BADI. Below is a sample code. Hope You like the snippet and use this information in your day to day work.

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

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

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.

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]: