2019 Sep 27 12:19 PM
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.
2019 Sep 27 12:36 PM
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
2019 Sep 27 12:36 PM
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
2019 Sep 27 1:56 PM
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)
2019 Sep 27 1:59 PM
2019 Sep 27 2:12 PM
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>.
2019 Sep 27 2:13 PM
The question has been asked many times in the forum!
2019 Sep 27 3:57 PM
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
2019 Sep 27 7:05 PM
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!
2019 Sep 27 7:17 PM
Thanks for the correction Sandra Rossi ☺