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: 

Creating dynamic internal table in SAP ABAP.

0 Kudos
19,537

Hi SAP Experts.

I want to create an internal table based on given database table name and fields.

I have created an selection screen in which I'm passing database table name and using selsct_alv FM selcting the fields as mentioned in the example.

Example1: table=mara, fields: matnr, ersda ername in this case internal table with this 3 fields creted.

Example2: table=mara, fields: matnr, ersda ername, vpsta in this case internal table with this 4 fields should be creted.

Example3: table=vbak, fields: vbeln, erdat in this case internal table with this 2 fields should be creted.

1 ACCEPTED SOLUTION

GK817
Active Contributor
5,328

Hi Vishal,

You can use FM DDIF_FIELDINFO_GET and then dynamically access structure fields. Here is a very good blog to dynamically download data. You can take the part where it creates internal table to download. Please go through it & you will have good understanding of how to do it:

https://blogs.sap.com/2019/09/20/dynamically-update-data-from-excel-to-database-table/

Regards

GK

8 REPLIES 8

GK817
Active Contributor
5,329

Hi Vishal,

You can use FM DDIF_FIELDINFO_GET and then dynamically access structure fields. Here is a very good blog to dynamically download data. You can take the part where it creates internal table to download. Please go through it & you will have good understanding of how to do it:

https://blogs.sap.com/2019/09/20/dynamically-update-data-from-excel-to-database-table/

Regards

GK

Sandra_Rossi
Active Contributor
5,328

Forget this method, it's really old-fashioned, slow, and "dumpy" (36 calls maximum in one program).

Use RTTS/RTTC instead (CREATE DATA dref TYPE HANDLE rtti)

Sandra_Rossi
Active Contributor
5,328

What is tag "1962906"?

Sandra_Rossi
Active Contributor
5,328

Use RTTS/RTTC (below is just one example, there are many ways to do it):

DATA: mara TYPE mara,
      dref TYPE REF TO DATA.
CREATE DATA dref TYPE ('MARA').
ASSIGN dref->* TO FIELD-SYMBOL(<struct>).
ASSIGN COMPONENT 'MATNR' OF STRUCTURE <struct> TO FIELD-SYMBOL(<matnr>).
ASSIGN COMPONENT 'ERSDA' OF STRUCTURE <struct> TO FIELD-SYMBOL(<ersda>).
DATA(struct_rtti) = cl_abap_structdescr=>get( VALUE #(
    ( name = 'MATNR' type = cl_abap_typedescr=>describe_by_data( <matnr> ) )
    ( name = 'ERSDA' type = cl_abap_typedescr=>describe_by_data( <ersda> ) ) ).
CREATE DATA dref TYPE HANDLE struct_rtti.
ASSIGN dref->* TO FIELD-SYMBOL(<struct2>).
CREATE DATA dref LIKE TABLE OF <struct2>.
FIELD-SYMBOLS <itab> TYPE STANDARD TABLE.
ASSIGN dref->* TO <itab>.

Sandra_Rossi
Active Contributor
5,328

The question has been asked many times in the forum!

SampathReddy
Participant
0 Kudos
5,328

satishkumarbalasubramanian

Please!

It doesn't make sense to provide answer to each and every latest question with links of SAP help.

If you know the answer that should be okay but just providing some simple links won't help.

Thanks

Sampath

former_member1716
Active Contributor
5,328

Hello Sampath Reddy Challabatla,

Idea here is to give the person some lead so that they can take it up and move forward.

I completely disagree with your point. Links do help and makes sense, atleast for Me during my initial days links meant a lot!!

Thanks!

former_member1716
Active Contributor
0 Kudos
5,328

Thanks for the correction Sandra Rossi