Function Module to retrieve data from excel into an internal table of any type
Function Module to retrieve data from excel into an internal table of any type
FM to retrieve data from excel into an internal table of any type
FM ‘Y_EXCEL_TO_ITAB ‘, which takes an excel file name and a structure/table name as inputs. And parses the excel content into an internal table with the same structure given as input.
Background:
SAP has provided us the means to create data at run-time. We can use various RTTS (Run Time Type Services), Data references, Field-Symbols to achieve this.
So, we utilize this to develop a general purpose FM, which can read any excel file and put it in an internal table of the specified structure.
Applications:
Having a general/common FM to retrieve data from an excel file into any internal table following the specified structure.
With just the path of the file and the target structure, this FM can be re-used in any place where the data from excel needs to be dumped into an internal table.
Potential Enhancements:
The functionality can be extended to actually update the excel content to DB tables (with just a few lines of code. Example provided.)
Clearer error messages with message variables
More validations and messages
Pre-requisites:
The format of data in the excel should match the format settings of the SAP user executing the FM. e.g., if the date format is dd.mm.yyyy in SU01 for the user, the excel should have date values in the same format.
If just part of the fields of a given structure are available in the excel, make sure to label the columns with the correct field names
If no header is specified with the field names, make sure the ordering of fields in the excel are the same as the ordering of the fields in the table/structure definition.
Advanced ABAP Programming for SAP PDF
Comments
Post a Comment