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 code snippet to convert VBAK data from XLSX to an internal table.

And that is it. It's that easy to read data from XLSX to your internal table. However, you have to be careful around date and time fields and make sure to convert them to their internal format.

Below is a complete ready to execute program code with date and time field handling. It reads data from the VBAK type structure table stored in the XLSX file. Try it out in your system.

As always, Hope you like the post and use this information in your day to day work.

 

Popular posts from this blog

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

Application Logging in ABAP