‎2009 Jan 06 6:42 AM
Hi Gurus,
This is my first post here with a hope that I will get my problem resolved.
I want to create a query to give me internal table using the table name. This logic will be used for some other work I have to accomplish.
I am selecting the field names from the table DD03L for my Z-table.
SELECT * FROM dd03l into corresponding fields of table mytable
WHERE tabname = 'ZMS_MCLINT'.
sort mytable by position.
Again, based on the fields selected I will create a select query
QueryStr = 'Select'.
assign QueryStr to <fs>.
Loop at mytable.
if not mytable-fieldname(1) = '.'.
concatenate <fs> mytable-fieldname into <fs> separated by SPACE .
endif.
endloop.
concatenate <fs> 'from ' mytable-fieldname 'into table itab.' into <fs> separated by SPACE .
This will give me the result as
Select MANDT CLCODE CLNAME ADDRESS1 ADDRESS2 ADDRESS3 AREA CITY PINCODE from PINCODE into table itab
Now My requirement is to execute the query which i have build on the fly to get the data into iTAB. How can I execute the query which is assigned in field symbol <FS>.
If there is any other logic also its welcome.
Thanks in advance.
Regards
Munir Solkar (MS)
‎2009 Jan 06 6:46 AM
Hi,
check this link.
https://www.sdn.sap.com/irj/scn/wiki?path=/display/snippets/creatingFlatandComplexInternalTablesDynamicallyusingRTTI
regards,
Santosh Thorat
‎2009 Jan 06 6:46 AM
Hi,
check this link.
https://www.sdn.sap.com/irj/scn/wiki?path=/display/snippets/creatingFlatandComplexInternalTablesDynamicallyusingRTTI
regards,
Santosh Thorat
‎2009 Jan 06 7:06 AM
Dear +Santosh,+
Thanks for the quick response.
That was really helpful.
Regards
MS
‎2009 Jan 06 9:21 AM
Dear Friends,
The above link is applicable for only a single table. What if we have to extract fields dynamically from two different tables.
my requirement is as follows.
I need to display fields from VBAK and VBAP tables with relation as VBAK-VBELN = VBAP-VBELN.
A separate table is created Z_IF_FIELDS to store the columns required to be displayed for a particular report.
The data is as follows:
Report Name Position Column Name
SO_REPORT 1 VBAK-VBELN
SO_REPORT 2 VBAP-POSNR
SO_REPORT 3 VBAP-MATNR
SO_REPORT 4 VBAP-KWMENG
The program should fetch only above fields from two tables mentioned (vbak, vbap) in an internal table and display the result as an output to the user (either list view and ALV).
Kindly help at the earliest.
Regards
MS
‎2009 Jan 06 9:23 AM
‎2009 Jan 06 9:58 AM
Hi...
Instead of forming the whole query through concatenation, concatenate only the fieldnames.
Then pass it in the query as follows:
Loop at mytable.
if not wa_mytable-fieldname(1) = '.'.
concatenate <fields> wa_mytable-fieldname into fields separated by SPACE .
endif.
endloop.
select <fields> from into into table itab .
Hope it helps you.
Regards,
K.Tharani.
‎2009 Jan 06 10:08 AM
Hi,
Store your filed names separately then use it like,
select (fileds) from (table) into table itab.Regards,
Manoj Kumar P