Posts

Use CL_BCS library to send email with ABAP

Many a time you need a report for which the output needs to be an email. SO_NEW_DOCUMENT_SEND_API1 is heavily used to achieve the task but let's explore another way of achieving the same using CL_BCS. This post talks about how to use the CL_BCS library provided by SAP to easily send emails. CL_BCS Library The class serves as the interface from BCS to the applications. The methods of the class cater for the send functions. Using CL_BCS, You can: – Attach files to email – Build the HTML/raw of the body. – Set email’s Senders & Receiver – Send an email, etc. Let's see the steps one by one: Initiating CL_BCS: The first thing you need is to initiate a persistent send request. Creating BCS Document: Create the BCS document object which will be sent with the CL_BCS interface to BCS. In this case the Email. SET_DOCUMENT Once we have the document, It needs to be set to the send request. SET_SENDER Assign the sender to the send request. ADD_RECIPIENT Pass ...

ABAP Custom code generator dynamic pattern: ZCODEGEN

Image
 In My last post about  ABAP editor custom dynamic patterns . I talked about how to create new custom patterns to help you speed up various aspects of your day to day development. Today I wanted to share with you a Custom dynamic pattern Utility that I built. Here is what it looks like: Starting the pattern: The UI: Features: You can declare:   Types - With auto data declarations(Global/Local)    Data     Selection Screen - with Validation   Basic SQL queries  Setup Config to change prefixes of generated code. Here is an example of generating a simple report to fetch data based on MATNR from MARA . Declare Types: Press the get fields button: Select field and copy: Set data declaration checkboxes Move on to the selection screen tab. Get fields to choose from as a selection screen. Select field and copy and set obligatory and check table. Move to the SQL tab. Select fields for queries either directly or from local declared types, some for wh...

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