<?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: Read tables dynamically in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/read-tables-dynamically/m-p/5492095#M1256756</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;&lt;/P&gt;&lt;P&gt;Try the below code.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;DATA dref TYPE REF TO data. 
loop at i_table.

tabname = i_table-table.
    CREATE DATA dref TYPE (tabname). 
    ASSIGN dref-&amp;gt;* TO &amp;lt;fs_comp&amp;gt;. 

SELECT SINGLE * into &amp;lt;fs_comp&amp;gt;
FROM (tabname).
if sy-subrc = 0.
* Exist registers.
endif.

endloop.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Sesh&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 14 Apr 2009 10:39:28 GMT</pubDate>
    <dc:creator>seshatalpasai_madala</dc:creator>
    <dc:date>2009-04-14T10:39:28Z</dc:date>
    <item>
      <title>Read tables dynamically</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/read-tables-dynamically/m-p/5492092#M1256753</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;We need to read several tables to determine if they are empty. We have create a program that read all tables from a text file. But &amp;lt;ft_comp&amp;gt; is not assigned with header structure to read table.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;DATA: BEGIN OF i_table OCCURS 500,&lt;/P&gt;&lt;P&gt;        table(30),&lt;/P&gt;&lt;P&gt;      END   OF i_table.&lt;/P&gt;&lt;P&gt;  DATA: tabname(30).&lt;/P&gt;&lt;P&gt;  FIELD-SYMBOLS &amp;lt;fs_comp&amp;gt; type any.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;PARAMETERS p_file(128).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;START-OF-SELECTION.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;Obtains file with tables&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;  CALL FUNCTION 'WS_UPLOAD'&lt;/P&gt;&lt;P&gt;       EXPORTING&lt;/P&gt;&lt;P&gt;            filename         = p_file&lt;/P&gt;&lt;P&gt;            filetype         = 'DAT'&lt;/P&gt;&lt;P&gt;       TABLES&lt;/P&gt;&lt;P&gt;            data_tab         = i_table&lt;/P&gt;&lt;P&gt;       EXCEPTIONS&lt;/P&gt;&lt;P&gt;            conversion_error = 01&lt;/P&gt;&lt;P&gt;            file_open_error  = 02.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;Read all tables&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;loop at i_table.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;   tabname = i_table-table.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;   assign (tabname) to &amp;lt;fs_comp&amp;gt;.&lt;/P&gt;&lt;P&gt;    SELECT SINGLE * into &amp;lt;fs_comp&amp;gt;&lt;/P&gt;&lt;P&gt;    FROM (tabname).&lt;/P&gt;&lt;P&gt;   if sy-subrc = 0.&lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;Exist registers.&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;  endif.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;endloop.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 14 Apr 2009 10:19:58 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/read-tables-dynamically/m-p/5492092#M1256753</guid>
      <dc:creator>david_escofettrenado</dc:creator>
      <dc:date>2009-04-14T10:19:58Z</dc:date>
    </item>
    <item>
      <title>Re: Read tables dynamically</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/read-tables-dynamically/m-p/5492093#M1256754</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;hi there.... you need not have header line.... infact you need not select anything into a header....&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;simply use :&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;select single * from &amp;lt;table name &amp;gt; where &amp;lt;conditions&amp;gt;.&lt;/P&gt;&lt;P&gt;if even a single value is returned, then subrc will be 0, which can be checked easily. if the subrc is not zero, no value was returned and you can easily make out which table is empty. Moreover it will improve the performance also as only one record will be fetched instead of the entire table contents.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;hope this helps....&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;cheers,&lt;/P&gt;&lt;P&gt;Prem Sharma&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 14 Apr 2009 10:24:40 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/read-tables-dynamically/m-p/5492093#M1256754</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-04-14T10:24:40Z</dc:date>
    </item>
    <item>
      <title>Re: Read tables dynamically</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/read-tables-dynamically/m-p/5492094#M1256755</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;This is not running because I can assing dinamically value to &amp;lt;table name&amp;gt;. Can you write your abap code?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 14 Apr 2009 10:30:09 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/read-tables-dynamically/m-p/5492094#M1256755</guid>
      <dc:creator>david_escofettrenado</dc:creator>
      <dc:date>2009-04-14T10:30:09Z</dc:date>
    </item>
    <item>
      <title>Re: Read tables dynamically</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/read-tables-dynamically/m-p/5492095#M1256756</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;&lt;/P&gt;&lt;P&gt;Try the below code.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;DATA dref TYPE REF TO data. 
loop at i_table.

tabname = i_table-table.
    CREATE DATA dref TYPE (tabname). 
    ASSIGN dref-&amp;gt;* TO &amp;lt;fs_comp&amp;gt;. 

SELECT SINGLE * into &amp;lt;fs_comp&amp;gt;
FROM (tabname).
if sy-subrc = 0.
* Exist registers.
endif.

endloop.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Sesh&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 14 Apr 2009 10:39:28 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/read-tables-dynamically/m-p/5492095#M1256756</guid>
      <dc:creator>seshatalpasai_madala</dc:creator>
      <dc:date>2009-04-14T10:39:28Z</dc:date>
    </item>
    <item>
      <title>Re: Read tables dynamically</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/read-tables-dynamically/m-p/5492096#M1256757</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi, try this (your code adapted):&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;.DATA: BEGIN OF i_table OCCURS 500,
table(30),
END OF i_table.
DATA: tabname(30).
*FIELD-SYMBOLS &amp;lt;fs_comp&amp;gt; type any.

PARAMETERS p_file(128).

START-OF-SELECTION.

* Obtains file with tables
  CALL FUNCTION 'WS_UPLOAD'
    EXPORTING
      filename         = p_file
      filetype         = 'DAT'
    TABLES
      data_tab         = i_table
    EXCEPTIONS
      conversion_error = 01
      file_open_error  = 02.

* Read all tables
  LOOP AT i_table.

    tabname = i_table-table.

*assign (tabname) to &amp;lt;fs_comp&amp;gt;.
    SELECT COUNT( * ) FROM (tabname).
    IF sy-dbcnt &amp;gt; 0.
      WRITE:/ tabname, sy-dbcnt.
* Exist registers.
    ENDIF.

  ENDLOOP.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This should works.&lt;/P&gt;&lt;P&gt;Andrea&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 14 Apr 2009 10:41:30 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/read-tables-dynamically/m-p/5492096#M1256757</guid>
      <dc:creator>andrea_olivieri</dc:creator>
      <dc:date>2009-04-14T10:41:30Z</dc:date>
    </item>
  </channel>
</rss>

