Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Abap Read exel file dynamically into internal table

former_member2492
Active Participant
0 Kudos

Hello,

I have an excel file that the number of columns might vary so its not fixed.

I want to read this excel file into an internal table correctly.

Right now I have declared a structure and can upload it to internal table.

 begin of t_record,
 previous_username type alsmex_tabline-value,
 new_username type alsmex_tabline-value,
 valid_until type alsmex_tabline-value,
 valid_from type alsmex_tabline-value,
 end of t_record .
"then call 
FM : ALSM_EXCEL_TO_INTERNAL_TABLE
and loop at table to create the records...works

How to do it when the number of columns in an excel file is not fixed?

Thank you in advance!

1 ACCEPTED SOLUTION

NTeunckens
Active Contributor

I would suggest using the "ABAP2XLSX" OpenSource Project to fullfill your Requirements regarding the Excel-Sheet. See the Project on the following GitHub link.

Additionally, you can make use of the "RunTime Type Services" (RTTS) to enable you to create or read the DataTypes of the elements within your Table : SAP Help Link

I realize this is (a bit of) a ReDesign, but it is far more powerful than coding your way around the FunctionModules having to take all kinds of requirements into account.

Some good Code-Samples to help you understand the integrated scenario can be found here : link


Hope this helps

Nic T.

8 REPLIES 8

NTeunckens
Active Contributor

I would suggest using the "ABAP2XLSX" OpenSource Project to fullfill your Requirements regarding the Excel-Sheet. See the Project on the following GitHub link.

Additionally, you can make use of the "RunTime Type Services" (RTTS) to enable you to create or read the DataTypes of the elements within your Table : SAP Help Link

I realize this is (a bit of) a ReDesign, but it is far more powerful than coding your way around the FunctionModules having to take all kinds of requirements into account.

Some good Code-Samples to help you understand the integrated scenario can be found here : link


Hope this helps

Nic T.

0 Kudos

Hi ,the code samples do the other way around from internal table to excel.thank you for the effort

Abap2Xls do the two ways

and for your question, we put a random limit and pray to never have more column thant the limit

0 Kudos

frdric.girod can you post here the part of the code which does this? Maybe I am missing smth

johnu951 just download the ABAP2XLSX package and you'll find around 30 example programs doing everything, from multi-sheets download with graphs, to upload and send via email.

p244500
Active Contributor
0 Kudos

Hi,

Use the FM

TEXT_CONVERT_XLS_TO_SAP it will be easy .

NTeunckens
Active Contributor

Hello Jonathan Blavatsky

See the "ZIF_EXCEL_READER" or "ZCL_EXCEL_READER_HUGE_FILE" Objects related to the "ABAP2XLSX" Project on GitHub. You can try to use the "ZIF_EXCEL_READER~LOAD_FILE" Method, import the Data and either :

  • Inspect and Recreate each Column as a Dynamic DataType using RTTS / RTTC / RTTI ...
  • Or Store the Data as a Column of your "ALSMEX_TABLINE" ...


PS : SAP-Note 933420 offers information on the specifics of using "ALSM_EXCEL_TO_INTERNAL_TABLE", such as the 50CHAR limitation ...

0 Kudos

I will definitively check and let you know