Posts

Showing posts with the label code snippets

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

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.

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