Posts

Showing posts with the label useful lib

Get system context information using CL_ABAP_CONTEXT_INFO

 As part of the Useful Libraries  series, I am talking about a new class which allows accessing system runtime information like time, date,user, and language. As an ABAP developer, you often need to determine the user, date or time to fulfil certain business or technical requirements. For which we rely on SY/SYST structures. In its push towards cloud adaptation and decreasing reliance on a run-time-filled global structure( SY/SYST ), sap introduced the CL_ABAP_CONTEXT_INFO class to achieve the same. Here is a ready-to-run console output class showing how to use it, just copy and paste the class and hit F9. As always, Hope it helps you in your day-to-day work.

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 read excel(.XLSX) file to internal table in ABAP using CL_FDT_XL_SPREADSHEET

You are given a requirement to upload data to a custom DB table where the user provides you with the file path of the excel on his PC and the report loads the data from it to the Custom table. For experienced Abapers, the requirement is quite straightforward, except that the user wants to upload an XLSX file. There are not many options to read data from XLSX/XLS file. The TEXT_CONVERT_XLS_TO_SAP  function module is one of them but is a performance killer and uses OLE. In this post, I wanted to showcase How we can read data from the XLSX files using CL_FDT_SPOREADSHEET class. Let's start with uploading the file. Now that we have the file in xstring table, let's pass it to CL_FDT_XL_SPREADSHEET to get its object reference. From the object reference, we can retrieve each worksheet data. The data is returned in the form of an anonymous data object which can be dereferenced into a field symbol and passed to the target internal table. Below is the co...

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.

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