<?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: Select from database dynamically in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/select-from-database-dynamically/m-p/7100066#M1508329</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Check if this helps:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;DATA: dref TYPE REF TO data,
      lt_tabname TYPE STANDARD TABLE OF tabname,
      ls_tablename TYPE tabname,
      et_func_ids TYPE STANDARD TABLE OF sysuuid_x,
      es_func_ids TYPE sysuuid_x.

FIELD-SYMBOLS: &amp;lt;itab&amp;gt; TYPE STANDARD TABLE,
               &amp;lt;wa&amp;gt; TYPE ANY ,
               &amp;lt;val&amp;gt; TYPE ANY.

DATA: v_err TYPE string,
      lcx_root TYPE REF TO cx_root.

LOOP AT lt_tabname INTO ls_tablename.
  CREATE DATA dref TYPE STANDARD TABLE OF (ls_tablename).
  ASSIGN dref-&amp;gt;* TO &amp;lt;itab&amp;gt;.
  TRY .
      SELECT DISTINCT trace_fct_id FROM (ls_tablename)
      INTO CORRESPONDING FIELDS OF TABLE &amp;lt;itab&amp;gt;.
      CHECK sy-subrc = 0.
      LOOP AT &amp;lt;itab&amp;gt; ASSIGNING &amp;lt;wa&amp;gt;.
        ASSIGN COMPONENT 'TRACE_FCT_ID' OF STRUCTURE &amp;lt;wa&amp;gt; TO &amp;lt;val&amp;gt;.
        CHECK sy-subrc = 0.
        es_func_ids = &amp;lt;val&amp;gt;.
        APPEND es_func_ids TO et_func_ids.
        CLEAR et_func_ids.
      ENDLOOP.
    CATCH cx_sy_open_sql_error INTO lcx_root."Catch block for SQL errors
      v_err = lcx_root-&amp;gt;get_text( ).
      WRITE: / v_err.
  ENDTRY.

  REFRESH &amp;lt;itab&amp;gt;.

ENDLOOP.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;BR,&lt;/P&gt;&lt;P&gt;Suhas&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 27 Jul 2010 10:12:52 GMT</pubDate>
    <dc:creator>SuhaSaha</dc:creator>
    <dc:date>2010-07-27T10:12:52Z</dc:date>
    <item>
      <title>Select from database dynamically</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/select-from-database-dynamically/m-p/7100062#M1508325</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello colleague,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;i am trying to read a database whose name is dynamically identified. There are several fields but i am interested in one. I want all the entries for that field in the table. The field "trace_fct_id" is type SYSUUID_x(16). I want it to be populated in the CHAR32 field ie GUID.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;  LOOP AT lt_tabname INTO ls_tablename.&lt;/P&gt;&lt;P&gt;    CREATE DATA dref TYPE STANDARD TABLE OF (ls_tablename-name).&lt;/P&gt;&lt;P&gt;    ASSIGN dref-&amp;gt;* TO &amp;lt;itab&amp;gt;.&lt;/P&gt;&lt;P&gt;    SELECT DISTINCT trace_fct_id FROM (ls_tablename-name) INTO CORRESPONDING FIELDS OF TABLE &amp;lt;itab&amp;gt;.&lt;/P&gt;&lt;P&gt;    MOVE &amp;lt;itab&amp;gt; TO et_func_ids.&lt;/P&gt;&lt;P&gt;  ENDLOOP.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I get all the entries from the table but i just want to return the ID, and the move does not copy it in the internal table as the column name is different. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Could you please help?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks in advance.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Best Regards,&lt;/P&gt;&lt;P&gt;Piyush&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 27 Jul 2010 08:32:43 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/select-from-database-dynamically/m-p/7100062#M1508325</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2010-07-27T08:32:43Z</dc:date>
    </item>
    <item>
      <title>Re: Select from database dynamically</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/select-from-database-dynamically/m-p/7100063#M1508326</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;you can have &lt;/P&gt;&lt;P&gt; TYPES : BEGIN OF STRUCT,&lt;/P&gt;&lt;P&gt;         REF_DATA TYPE REF TO DATA,&lt;/P&gt;&lt;P&gt;         END OF STRUCT.&lt;/P&gt;&lt;P&gt;         &lt;/P&gt;&lt;P&gt;         &lt;/P&gt;&lt;P&gt;DATA : ITAB TYPE TABLE OF STRUCT,  " this will give you a internal table of referances you will be storing...&lt;/P&gt;&lt;P&gt;            WA LIKE LINE OF ITAB.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;then you can manipulate however you want.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 27 Jul 2010 09:08:01 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/select-from-database-dynamically/m-p/7100063#M1508326</guid>
      <dc:creator>anup_deshmukh4</dc:creator>
      <dc:date>2010-07-27T09:08:01Z</dc:date>
    </item>
    <item>
      <title>Re: Select from database dynamically</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/select-from-database-dynamically/m-p/7100064#M1508327</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;1) before your loop select all possible tables from table DD03l:&lt;/P&gt;&lt;P&gt;   select * from dd03l appending corresponding fileds of table it_tabname&lt;/P&gt;&lt;P&gt;            where fieldname = 'TRACE_FCT_ID'...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;2)use this table&lt;/P&gt;&lt;P&gt; data: begin of itab occurs 0,&lt;/P&gt;&lt;P&gt;             tabn type dd03l-tabname,&lt;/P&gt;&lt;P&gt;            TRACE_FCT_ID type FDT_TRACE_0000-TRACE_FCT_ID,&lt;/P&gt;&lt;P&gt;            end of itab.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;3) try sth like this:&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt; 
LOOP AT lt_tabname INTO ls_tablename.
 clear itab.
 itab-tabn = ls_tablename-name.

 SELECT DISTINCT trace_fct_id FROM (ls_tablename-name) INTO itab-TRACE_FCT_ID
             group by TRACE_FCT_ID.

 collect itab.
 endselect.

ENDLOOP.
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;hope that helps&lt;/P&gt;&lt;P&gt;Andrras&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Edited by: Andreas Mann on Jul 27, 2010 11:24 AM&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 27 Jul 2010 09:22:53 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/select-from-database-dynamically/m-p/7100064#M1508327</guid>
      <dc:creator>andreas_mann3</dc:creator>
      <dc:date>2010-07-27T09:22:53Z</dc:date>
    </item>
    <item>
      <title>Re: Select from database dynamically</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/select-from-database-dynamically/m-p/7100065#M1508328</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;If you sure that all the database table have the field trace_fct_id then you can directly select that field only.&lt;/P&gt;&lt;P&gt;Then you can the below code.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data: itab1 type standard table of trace_fct_id,&lt;/P&gt;&lt;P&gt;itab2 type standard table of trace_fct_id.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;LOOP AT lt_tabname INTO ls_tablename.&lt;/P&gt;&lt;P&gt;SELECT DISTINCT trace_fct_id FROM (ls_tablename-name) INTO CORRESPONDING FIELDS OF TABLE itab1.&lt;/P&gt;&lt;P&gt;append lines of Itab1 to Itab2.&lt;/P&gt;&lt;P&gt;ENDLOOP.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Then ITAB2 will contain all the required IDs.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Subhankar&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 27 Jul 2010 09:27:20 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/select-from-database-dynamically/m-p/7100065#M1508328</guid>
      <dc:creator>Subhankar</dc:creator>
      <dc:date>2010-07-27T09:27:20Z</dc:date>
    </item>
    <item>
      <title>Re: Select from database dynamically</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/select-from-database-dynamically/m-p/7100066#M1508329</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Check if this helps:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;DATA: dref TYPE REF TO data,
      lt_tabname TYPE STANDARD TABLE OF tabname,
      ls_tablename TYPE tabname,
      et_func_ids TYPE STANDARD TABLE OF sysuuid_x,
      es_func_ids TYPE sysuuid_x.

FIELD-SYMBOLS: &amp;lt;itab&amp;gt; TYPE STANDARD TABLE,
               &amp;lt;wa&amp;gt; TYPE ANY ,
               &amp;lt;val&amp;gt; TYPE ANY.

DATA: v_err TYPE string,
      lcx_root TYPE REF TO cx_root.

LOOP AT lt_tabname INTO ls_tablename.
  CREATE DATA dref TYPE STANDARD TABLE OF (ls_tablename).
  ASSIGN dref-&amp;gt;* TO &amp;lt;itab&amp;gt;.
  TRY .
      SELECT DISTINCT trace_fct_id FROM (ls_tablename)
      INTO CORRESPONDING FIELDS OF TABLE &amp;lt;itab&amp;gt;.
      CHECK sy-subrc = 0.
      LOOP AT &amp;lt;itab&amp;gt; ASSIGNING &amp;lt;wa&amp;gt;.
        ASSIGN COMPONENT 'TRACE_FCT_ID' OF STRUCTURE &amp;lt;wa&amp;gt; TO &amp;lt;val&amp;gt;.
        CHECK sy-subrc = 0.
        es_func_ids = &amp;lt;val&amp;gt;.
        APPEND es_func_ids TO et_func_ids.
        CLEAR et_func_ids.
      ENDLOOP.
    CATCH cx_sy_open_sql_error INTO lcx_root."Catch block for SQL errors
      v_err = lcx_root-&amp;gt;get_text( ).
      WRITE: / v_err.
  ENDTRY.

  REFRESH &amp;lt;itab&amp;gt;.

ENDLOOP.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;BR,&lt;/P&gt;&lt;P&gt;Suhas&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 27 Jul 2010 10:12:52 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/select-from-database-dynamically/m-p/7100066#M1508329</guid>
      <dc:creator>SuhaSaha</dc:creator>
      <dc:date>2010-07-27T10:12:52Z</dc:date>
    </item>
  </channel>
</rss>

