<?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: Dynamic SQL Query in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/dynamic-sql-query/m-p/1003841#M77166</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Are you still interested in a solution?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I think I have one.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sun, 23 Oct 2005 11:06:10 GMT</pubDate>
    <dc:creator>Former Member</dc:creator>
    <dc:date>2005-10-23T11:06:10Z</dc:date>
    <item>
      <title>Dynamic SQL Query</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/dynamic-sql-query/m-p/1003836#M77161</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;         I have created one transaction which is displaying two table contols in the screen.there are two i/o field also in the same screen, where users can input the name of tables (say MARA &amp;amp; MARC) now on hitting enter, both table control will be populated by respective fieldnames of the tables.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Now if the user select some fields from both table control, and if any common field is there in the selection ( MARA-matnr, MARC-matnr), and click a button (say next)  can we create &amp;amp; execute one dynamic sql query , having join on this fields. Please note the table name, and selection of fields for join is dynamic.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 27 Sep 2005 12:16:56 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/dynamic-sql-query/m-p/1003836#M77161</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2005-09-27T12:16:56Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamic SQL Query</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/dynamic-sql-query/m-p/1003837#M77162</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;try this &lt;/P&gt;&lt;P&gt;field1 = 'matnr'&lt;/P&gt;&lt;P&gt;tabl1 = 'mara'&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;select ( field1 ) from ( tabl1 ).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;cheers,&lt;/P&gt;&lt;P&gt;sasi&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 27 Sep 2005 12:51:38 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/dynamic-sql-query/m-p/1003837#M77162</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2005-09-27T12:51:38Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamic SQL Query</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/dynamic-sql-query/m-p/1003838#M77163</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;try this&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data : c_table(10) type c value 'MARA'.&lt;/P&gt;&lt;P&gt;data : c_field(10) type c value 'MATNR'.&lt;/P&gt;&lt;P&gt;data : c_CONDITION(25) type c value 'MATNR = ''AH0904001EN'''.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data : itab_mara like mara occurs 0 with header line.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;select (C_FIELD) from (c_TABLE) into table itab_mara WHERE (C_CONDITION).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;write itab_mara-matnr.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 27 Sep 2005 12:55:25 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/dynamic-sql-query/m-p/1003838#M77163</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2005-09-27T12:55:25Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamic SQL Query</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/dynamic-sql-query/m-p/1003839#M77164</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I don't think you can do a dynamic join easily. If it were a report rather than a dialogue program, you could probably generate a subroutine pool, but I don't think that's an option here.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Rob&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 27 Sep 2005 14:44:24 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/dynamic-sql-query/m-p/1003839#M77164</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2005-09-27T14:44:24Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamic SQL Query</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/dynamic-sql-query/m-p/1003840#M77165</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Rob,&lt;/P&gt;&lt;P&gt;        Even I feel the same. Actually the purpose was creating a dynamic ALV, in which we r not aware of tables and join condition.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;However i have solved the problem partially.&lt;/P&gt;&lt;P&gt;What i did-&amp;gt; I have created one screen, havng a Table controls and one I/O field. The user will enter the Table name (Say MARA) there and click one push button.On doing that, i get the fieldnames for that table dynamically from table DD03L&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
FORM GET_TABLE_METADATA.
 SELECT FIELDNAME INTO CORRESPONDING FIELDS OF TABLE BASETABLE FROM DD03L WHERE TABNAME = TABLE_NAME.

LOOP AT BASETABLE.
IF BASETABLE-fieldname CP '*INCLU*'.
  DELETE BASETABLE WHERE fieldname = BASETABLE-fieldname.
ENDIF.
ENDLOOP.
 ENDFORM.                 " GET_TABLE_METADATA
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;where basetable is a internal table with single fieldname.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Now ones the fieldnames for that table are retrieved, they will be diplayed in the table control.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The user will select some or all the fields from the control and click another pushbutton "Display ALV".&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;on doing that, a dynamic structure is created in the following way--&amp;gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;FORM create_fieldcat.
   CLEAR: is_fieldcat,it_fieldcat,is_fcat,it_fcat.

   CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
        EXPORTING
             i_structure_name = table_name
        CHANGING
             ct_fieldcat      = it_fcat[].

   LOOP AT it_fcat INTO is_fcat.
     MOVE-CORRESPONDING is_fcat TO is_fieldcat.
     is_fieldcat-fieldname = is_fcat-fieldname.
     is_fieldcat-ref_field = is_fcat-fieldname.
     is_fieldcat-ref_table = is_fcat-ref_tabname.
     APPEND is_fieldcat TO it_fieldcat.
   ENDLOOP.

*-------------MODIFYING FIELDCAT----------------
   LOOP AT it_fieldcat INTO is_fieldcat.
   READ  TABLE basetable WITH KEY fieldname = is_fieldcat-fieldname.
     IF basetable-select_flag &amp;lt;&amp;gt; 'X'.
       DELETE it_fieldcat WHERE fieldname = is_fieldcat-fieldname.
     ELSE.                    "SETTING HEDAER
       IS_FIELDCAT-COLTEXT = BASETABLE-HEADER.
       MODIFY IT_FIELDCAT FROM IS_FIELDCAT.
     ENDIF.
   ENDLOOP.

* Create a new Table
   CALL METHOD cl_alv_table_create=&amp;gt;create_dynamic_table
          EXPORTING
           it_fieldcatalog = it_fieldcat
          IMPORTING
           ep_table        = new_table.

* Create a new Line with the same structure of the table.
   ASSIGN new_table-&amp;gt;* TO &amp;lt;l_table&amp;gt;.

 ENDFORM.                    " CREATE_FIELDCAT
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If you are  thinking what r the variables declaration here it is --&amp;gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;TYPE-POOLS: slis.&lt;/P&gt;&lt;P&gt;DATA: BEGIN OF basetable OCCURS 0,&lt;/P&gt;&lt;P&gt;       select_flag(1),&lt;/P&gt;&lt;P&gt;       fieldname LIKE dd03l-fieldname,&lt;/P&gt;&lt;P&gt;       header(30),&lt;/P&gt;&lt;P&gt;      END OF basetable.&lt;/P&gt;&lt;P&gt;DATA: table_name LIKE dd02l-tabname.&lt;/P&gt;&lt;P&gt;DATA:     new_table TYPE REF TO data,&lt;/P&gt;&lt;P&gt;          new_line TYPE  REF TO data.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;DATA:     it_fcat TYPE slis_t_fieldcat_alv,&lt;/P&gt;&lt;P&gt;          is_fcat LIKE LINE OF it_fcat.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;DATA:     it_fieldcat TYPE lvc_t_fcat,&lt;/P&gt;&lt;P&gt;          is_fieldcat LIKE LINE OF it_fieldcat.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;FIELD-SYMBOLS: &amp;lt;l_table&amp;gt; TYPE ANY TABLE,&lt;/P&gt;&lt;P&gt;               &amp;lt;l_line&amp;gt;  TYPE ANY.[/code]&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Now the z-transaction works fine, you input any table, it will retrieve the fieldsname, and let you select the fields for ALV report.Then will create and display the ALV.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I wanted to enhance the feature by giving another table control to user, where fields of a second table will be displayed and if user select a common field from both the table control then a runtime join will be performed and corresponding alv will be displayed..any suggestion is welcome.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 28 Sep 2005 04:37:57 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/dynamic-sql-query/m-p/1003840#M77165</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2005-09-28T04:37:57Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamic SQL Query</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/dynamic-sql-query/m-p/1003841#M77166</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Are you still interested in a solution?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I think I have one.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 23 Oct 2005 11:06:10 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/dynamic-sql-query/m-p/1003841#M77166</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2005-10-23T11:06:10Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamic SQL Query</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/dynamic-sql-query/m-p/1003842#M77167</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;For more information on 'Using dynamic SELECT statement', check the following link.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="https://www.sdn.sap.com/sdn/developerareas/abap.sdn?contenttype=url&amp;amp;content=/irj/servlet/prt/portal/prtroot/com.sap.km.cm.docs/documents/a1-8-4/abap" target="test_blank"&gt;https://www.sdn.sap.com/sdn/developerareas/abap.sdn?contenttype=url&amp;amp;content=/irj/servlet/prt/portal/prtroot/com.sap.km.cm.docs/documents/a1-8-4/abap&lt;/A&gt; faqs.faq&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Ashish&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 24 Oct 2005 07:27:35 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/dynamic-sql-query/m-p/1003842#M77167</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2005-10-24T07:27:35Z</dc:date>
    </item>
  </channel>
</rss>

