<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: How to use Dynamic SQL in ABAP in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/how-to-use-dynamic-sql-in-abap/m-p/884901#M52309</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Nandan&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Dynamic SELECT statement may be writen as follows:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
data: begin of ftab occurs 0 ,
        fname(30) type c ,
      end of ftab .
data: begin of condtab ocurs 0 ,
        cond_line(60) type c ,
      end of condtab .

refresh ftab .
ftab-fname = 'MARA' .
append ftab .

refresh condtab .
CONCATENATE 'MATNR =' p_matnr into condtab-cond_line
            separated by space .
append condtab .

SELECT (ftab) from (lv_dbtabname)
       INTO CORRESPONDING FIELDS OF &amp;lt;target&amp;gt;
       WHERE (condtab) .&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;However, you see the INTO statement needs a defined structure. So, you can have a structure comprising all possibilities and use "CORRESPONDING FIELDS" addition.&lt;/P&gt;&lt;P&gt;Or you can generate an internal table dynamicaly using "cl_alv_table_create", but I do not know whether INTO-statement can handle field-symbols.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Secondly, displaying fields dynamicaly needs further coding.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Hope this much helps...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;*--Serdar&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 03 Feb 2005 11:00:02 GMT</pubDate>
    <dc:creator>ssimsekler</dc:creator>
    <dc:date>2005-02-03T11:00:02Z</dc:date>
    <item>
      <title>How to use Dynamic SQL in ABAP</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/how-to-use-dynamic-sql-in-abap/m-p/884899#M52307</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;If I have mara table and I have an selection screen where I have allowed user to select the fields of MARA,Now What I want is depending on his selection we should be able to execute the sql command.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;E.g.&lt;/P&gt;&lt;P&gt;Tables: mara.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;selection-screen&lt;/P&gt;&lt;P&gt;MATNR , ERSDA , ERNAM , MTART , MEINS.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;NOW THE OUTPUT SHOULD BE ABLE TO DISPLAY ONLY THE SELECTED FIELD VALUE.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 03 Feb 2005 10:31:12 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/how-to-use-dynamic-sql-in-abap/m-p/884899#M52307</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2005-02-03T10:31:12Z</dc:date>
    </item>
    <item>
      <title>Re: How to use Dynamic SQL in ABAP</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/how-to-use-dynamic-sql-in-abap/m-p/884900#M52308</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Nandan,&lt;/P&gt;&lt;P&gt;I need some more clarification. regarding ur requirement.what i infer is that u want the user to be able to select the fields he wants to see in the report.&lt;/P&gt;&lt;P&gt;regards &lt;/P&gt;&lt;P&gt;varun&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 03 Feb 2005 10:49:23 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/how-to-use-dynamic-sql-in-abap/m-p/884900#M52308</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2005-02-03T10:49:23Z</dc:date>
    </item>
    <item>
      <title>Re: How to use Dynamic SQL in ABAP</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/how-to-use-dynamic-sql-in-abap/m-p/884901#M52309</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Nandan&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Dynamic SELECT statement may be writen as follows:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
data: begin of ftab occurs 0 ,
        fname(30) type c ,
      end of ftab .
data: begin of condtab ocurs 0 ,
        cond_line(60) type c ,
      end of condtab .

refresh ftab .
ftab-fname = 'MARA' .
append ftab .

refresh condtab .
CONCATENATE 'MATNR =' p_matnr into condtab-cond_line
            separated by space .
append condtab .

SELECT (ftab) from (lv_dbtabname)
       INTO CORRESPONDING FIELDS OF &amp;lt;target&amp;gt;
       WHERE (condtab) .&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;However, you see the INTO statement needs a defined structure. So, you can have a structure comprising all possibilities and use "CORRESPONDING FIELDS" addition.&lt;/P&gt;&lt;P&gt;Or you can generate an internal table dynamicaly using "cl_alv_table_create", but I do not know whether INTO-statement can handle field-symbols.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Secondly, displaying fields dynamicaly needs further coding.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Hope this much helps...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;*--Serdar&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 03 Feb 2005 11:00:02 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/how-to-use-dynamic-sql-in-abap/m-p/884901#M52309</guid>
      <dc:creator>ssimsekler</dc:creator>
      <dc:date>2005-02-03T11:00:02Z</dc:date>
    </item>
    <item>
      <title>Re: How to use Dynamic SQL in ABAP</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/how-to-use-dynamic-sql-in-abap/m-p/884902#M52310</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You can achieve this fairly easily using ALV.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Define an internal table T_MARA of line type MARA.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Create a field table, FTAB, as Serdar describes.  Populate this with the field names that the user selects.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Your select would then be:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;SELECT (FTAB) FROM TABLE MARA
  INTO CORRESPONDING FIELDS OF TABLE T_MARA
  WHERE ...&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Now you need to display the results to the user.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Build a field catalog using MARA as the input structure.  Loop thru the field catalog and set TECH = 'X' for all fields that you do NOT want to display.  Now display the ALV Grid and all TECH fields will never be displayed.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 03 Feb 2005 15:11:03 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/how-to-use-dynamic-sql-in-abap/m-p/884902#M52310</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2005-02-03T15:11:03Z</dc:date>
    </item>
    <item>
      <title>Re: How to use Dynamic SQL in ABAP</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/how-to-use-dynamic-sql-in-abap/m-p/884903#M52311</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello Nandan,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Try the following code. It works.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;tables: mara.
data: tablename  type tabname,
      fname      type fieldname,
      fieldnames type fieldname occurs 0.

field-symbols : &amp;lt;fs_tableline&amp;gt; type any,
                &amp;lt;fs_fieldval&amp;gt;  type any.


initialization.
  tablename = 'MARA'.
  assign (tablename) to &amp;lt;fs_tableline&amp;gt; .

  fname = 'MATNR'.
  append fname to fieldnames.

  fname = 'MTART'.
  append fname to fieldnames.


select (fieldnames)
  from (tablename)
  up to 20 rows
  into corresponding fields of &amp;lt;fs_tableline&amp;gt;.

  loop at fieldnames into fname.
    assign component fname of structure &amp;lt;fs_tableline&amp;gt; to &amp;lt;fs_fieldval&amp;gt;.
    write : &amp;lt;fs_fieldval&amp;gt;.
  endloop.

  new-line.

endselect.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The &amp;lt;b&amp;gt;tables&amp;lt;/b&amp;gt; statement is very important. You should at least have the list of the tables which you expect the user to enter.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Please do get back if you have any doubts. If you think the question is answered, please reward the points to the useful answers and close the thread.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Anand Mandalika.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 03 Feb 2005 16:02:24 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/how-to-use-dynamic-sql-in-abap/m-p/884903#M52311</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2005-02-03T16:02:24Z</dc:date>
    </item>
  </channel>
</rss>

