Posts

Showing posts from 2021

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 cod

Easily send emails from ABAP using Custom utility class ZCL_SEND_MAIL

in the previous post,s I shared how to use CL_BCS class to send emails . and I also shared how to use cl_bcs_message class to send email in user-exit and BADI . The standard libraries even though useful, are cumbersome to use so I have created a utility that combines the power of both CL_BCS and CL_BCS_MESSAGE to let you send an email with ease from anywhere in the system. Below are examples and source links to the utility class ZCL_SEND_MAIL A simple example: Sending email from user exit/Badi Link to Source:  ZCL_SEND_MAIL As usual, Hope you like the post and use the information in your day to day work.

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.

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 where condition and other semantics. Hit OK. T