<?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 Dynamic Internal Table creation and population in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/dynamic-internal-table-creation-and-population/m-p/5703197#M1295308</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi gurus !&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;my issue refers to the slide 10 provided in this slideshow : &lt;A href="https://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/b332e090-0201-0010-bdbd-b735e96fe0ae" target="test_blank"&gt;https://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/b332e090-0201-0010-bdbd-b735e96fe0ae&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;My example is gonna sound dumb, but anyway: I want to dynamically select from a table into a dynamically created itab.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Letu2019s use only EKPO, and only field MENGE.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;For this, I use Classes &lt;STRONG&gt;cl_abap_elemdescr&lt;/STRONG&gt;, &lt;STRONG&gt;cl_sql_result_set&lt;/STRONG&gt; and the &lt;STRONG&gt;Data Ref&lt;/STRONG&gt; for table creation. But while fetching the resultset, program dumps when fields like MENGE, WRBTR are accessed. Obviously their type are not correctly taken into account by my program.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Here it comes:&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
DATA: element_ref             TYPE REF TO cl_abap_elemdescr,
	 vl_fieldname	          TYPE string,
       	 tl_components         TYPE abap_component_tab,
       	 sl_components         LIKE LINE OF tl_components_alv,
 linetype_lcl          	TYPE REF TO cl_abap_structdescr,
 ty_table_type            TYPE REF TO cl_abap_tabledescr,
 g_resultset   		TYPE REF TO cl_sql_result_set

u2026

CONCATENATE sg_columns-table_name '-' sg_columns-column_name INTO vl_fieldname.
* sg_columns-table_name contains 'EKPO'
* sg_columns-column_name contains 'MENGE'


* getting the element as a component
element_ref ?= cl_abap_elemdescr=&amp;gt;describe_by_name( vl_fieldname ).

sl_components-name  = sg_columns-column_name.
sl_components-type ?= element_ref.

APPEND sl_components TO tl_components.


* dynamic creation of internal table
linetype_lcl = cl_abap_structdescr=&amp;gt;create( tl_components ).

ty_table_type = cl_abap_tabledescr=&amp;gt;create(
                  p_line_type = linetype_lcl ).


u2026


* Then I will create my field symbol table and line. Code has been cut here.
CREATE DATA dy_line LIKE LINE OF &amp;lt;dyn_table&amp;gt;.

u2026

* Then I will execute my query. Here itu2019s: Select MENGE From EKPO Where Rownum = 1.
  g_resultset = g_stmt_ref-&amp;gt;execute_query( stmt_str ).

* Then structure for the Resultset is set
  CALL METHOD g_resultset-&amp;gt;set_param_struct
    EXPORTING
      struct_ref = dy_line.


* Fetching the lines of the resultset  =&amp;gt; Dumpu2026
  WHILE g_resultset-&amp;gt;next( ) &amp;gt; 0.
    ASSIGN dy_line-&amp;gt;* TO &amp;lt;dyn_wa&amp;gt;.
    APPEND &amp;lt;dyn_wa&amp;gt; TO &amp;lt;dyn_table&amp;gt;.
  ENDWHILE.
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Anyone has any clue to how prevent my Dump ??&lt;/P&gt;&lt;P&gt;The component for MENGE seems to be described as a P7 with 2 decimals. And the resultset wanna use a QUAN type... or something like that ! &lt;SPAN __jive_emoticon_name="happy"&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 12 Jun 2009 16:17:36 GMT</pubDate>
    <dc:creator>Former Member</dc:creator>
    <dc:date>2009-06-12T16:17:36Z</dc:date>
    <item>
      <title>Dynamic Internal Table creation and population</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/dynamic-internal-table-creation-and-population/m-p/5703197#M1295308</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi gurus !&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;my issue refers to the slide 10 provided in this slideshow : &lt;A href="https://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/b332e090-0201-0010-bdbd-b735e96fe0ae" target="test_blank"&gt;https://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/b332e090-0201-0010-bdbd-b735e96fe0ae&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;My example is gonna sound dumb, but anyway: I want to dynamically select from a table into a dynamically created itab.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Letu2019s use only EKPO, and only field MENGE.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;For this, I use Classes &lt;STRONG&gt;cl_abap_elemdescr&lt;/STRONG&gt;, &lt;STRONG&gt;cl_sql_result_set&lt;/STRONG&gt; and the &lt;STRONG&gt;Data Ref&lt;/STRONG&gt; for table creation. But while fetching the resultset, program dumps when fields like MENGE, WRBTR are accessed. Obviously their type are not correctly taken into account by my program.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Here it comes:&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
DATA: element_ref             TYPE REF TO cl_abap_elemdescr,
	 vl_fieldname	          TYPE string,
       	 tl_components         TYPE abap_component_tab,
       	 sl_components         LIKE LINE OF tl_components_alv,
 linetype_lcl          	TYPE REF TO cl_abap_structdescr,
 ty_table_type            TYPE REF TO cl_abap_tabledescr,
 g_resultset   		TYPE REF TO cl_sql_result_set

u2026

CONCATENATE sg_columns-table_name '-' sg_columns-column_name INTO vl_fieldname.
* sg_columns-table_name contains 'EKPO'
* sg_columns-column_name contains 'MENGE'


* getting the element as a component
element_ref ?= cl_abap_elemdescr=&amp;gt;describe_by_name( vl_fieldname ).

sl_components-name  = sg_columns-column_name.
sl_components-type ?= element_ref.

APPEND sl_components TO tl_components.


* dynamic creation of internal table
linetype_lcl = cl_abap_structdescr=&amp;gt;create( tl_components ).

ty_table_type = cl_abap_tabledescr=&amp;gt;create(
                  p_line_type = linetype_lcl ).


u2026


* Then I will create my field symbol table and line. Code has been cut here.
CREATE DATA dy_line LIKE LINE OF &amp;lt;dyn_table&amp;gt;.

u2026

* Then I will execute my query. Here itu2019s: Select MENGE From EKPO Where Rownum = 1.
  g_resultset = g_stmt_ref-&amp;gt;execute_query( stmt_str ).

* Then structure for the Resultset is set
  CALL METHOD g_resultset-&amp;gt;set_param_struct
    EXPORTING
      struct_ref = dy_line.


* Fetching the lines of the resultset  =&amp;gt; Dumpu2026
  WHILE g_resultset-&amp;gt;next( ) &amp;gt; 0.
    ASSIGN dy_line-&amp;gt;* TO &amp;lt;dyn_wa&amp;gt;.
    APPEND &amp;lt;dyn_wa&amp;gt; TO &amp;lt;dyn_table&amp;gt;.
  ENDWHILE.
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Anyone has any clue to how prevent my Dump ??&lt;/P&gt;&lt;P&gt;The component for MENGE seems to be described as a P7 with 2 decimals. And the resultset wanna use a QUAN type... or something like that ! &lt;SPAN __jive_emoticon_name="happy"&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 12 Jun 2009 16:17:36 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/dynamic-internal-table-creation-and-population/m-p/5703197#M1295308</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-06-12T16:17:36Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamic Internal Table creation and population</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/dynamic-internal-table-creation-and-population/m-p/5703198#M1295309</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have expanded your sample coding for selecting three fields out of EKPO:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
*&amp;amp;---------------------------------------------------------------------*
*&amp;amp; Report  ZUS_SDN_SQL_RESULT_SET
*&amp;amp;
*&amp;amp;---------------------------------------------------------------------*
*&amp;amp; Thread: Dynamic Internal Table creation and population
*&amp;amp; &amp;lt;a class="jive_macro jive_macro_thread" href="" __jive_macro_name="thread" modifiedtitle="true" __default_attr="1375510"&amp;gt;&amp;lt;/a&amp;gt;
*&amp;amp;
*&amp;amp; NOTE: Coding for dynamic structure / itab creation taken from:
*&amp;amp; Creating Flat and Complex Internal Tables Dynamically using RTTI
*&amp;amp; &amp;lt;a href="https://wiki.sdn.sap.com/wiki/display/Snippets/Creating+Flat+and+" TARGET="test_blank"&amp;gt;https://wiki.sdn.sap.com/wiki/display/Snippets/Creating+Flat+and+&amp;lt;/a&amp;gt;
*&amp;amp; Complex+Internal+Tables+Dynamically+using+RTTI
*&amp;amp;---------------------------------------------------------------------*

REPORT  zus_sdn_sql_result_set.

TYPE-POOLS: abap.

DATA:
 go_sql_stmt       TYPE REF TO cl_sql_statement,
 go_resultset      TYPE REF TO cl_sql_result_set,
 gd_sql_clause     TYPE string.

DATA:
  gd_tabfield      TYPE string,
  go_table         TYPE REF TO cl_salv_table,
  go_sdescr_new    TYPE REF TO cl_abap_structdescr,
  go_tdescr        TYPE REF TO cl_abap_tabledescr,
  gdo_handle       TYPE REF TO data,
  gdo_record       TYPE REF TO data,
  gs_comp          TYPE abap_componentdescr,
  gt_components    TYPE abap_component_tab.

FIELD-SYMBOLS:
  &amp;lt;gs_record&amp;gt;   TYPE ANY,
  &amp;lt;gt_itab&amp;gt;     TYPE STANDARD TABLE.

START-OF-SELECTION.

continued.
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 14 Jun 2009 20:34:02 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/dynamic-internal-table-creation-and-population/m-p/5703198#M1295309</guid>
      <dc:creator>uwe_schieferstein</dc:creator>
      <dc:date>2009-06-14T20:34:02Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamic Internal Table creation and population</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/dynamic-internal-table-creation-and-population/m-p/5703199#M1295310</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;PRE&gt;&lt;CODE&gt;
continued.

START-OF-SELECTION.

  DO 3 TIMES.
    CASE syst-index.
      WHEN '1'. gd_tabfield = 'EKPO-EBELN'.
      WHEN '2'. gd_tabfield = 'EKPO-EBELP'.
      WHEN '3'. gd_tabfield = 'EKPO-MENGE'.
    ENDCASE.

    CLEAR: gs_comp.
    gs_comp-type ?= cl_abap_datadescr=&amp;gt;describe_by_name( gd_tabfield ).
    gs_comp-name  = gd_tabfield+5.  " EKPO-EBELN =&amp;gt; EBELN
    APPEND gs_comp TO gt_components.
  ENDDO.

  "   Create instances of dynamic structure and dynamic internal table
  go_sdescr_new  = cl_abap_structdescr=&amp;gt;create( gt_components ).
  go_tdescr      = cl_abap_tabledescr=&amp;gt;create( go_sdescr_new ).
  "   Create data refence followed by table creation
  CREATE DATA gdo_record TYPE HANDLE go_sdescr_new.
  CREATE DATA gdo_handle TYPE HANDLE go_tdescr.  " !!!


  CREATE OBJECT go_sql_stmt.
  gd_sql_clause = 'SELECT EBELN, EBELP, MENGE FROM EKPO'.

* Execute the query
  go_resultset = go_sql_stmt-&amp;gt;execute_query( gd_sql_clause ).

* Then structure for the Resultset is set
  CALL METHOD go_resultset-&amp;gt;set_param_struct( struct_ref = gdo_record ).

* Fetching the lines of the resultset
  TRY.
      WHILE go_resultset-&amp;gt;next( ) &amp;gt; 0.
        ASSIGN gdo_record-&amp;gt;* TO &amp;lt;gs_record&amp;gt;.
        APPEND &amp;lt;gs_record&amp;gt; TO &amp;lt;gt_itab&amp;gt;.
      ENDWHILE.
    CATCH cx_sql_exception .
    CATCH cx_parameter_invalid_type .
  ENDTRY.
  go_resultset-&amp;gt;close( ).

  CALL METHOD cl_salv_table=&amp;gt;factory
    IMPORTING
      r_salv_table = go_table
    CHANGING
      t_table      = &amp;lt;gt_itab&amp;gt;.
  go_table-&amp;gt;display( ).

END-OF-SELECTION.


Regards
  Uwe
&lt;/CODE&gt;&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 14 Jun 2009 20:35:54 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/dynamic-internal-table-creation-and-population/m-p/5703199#M1295310</guid>
      <dc:creator>uwe_schieferstein</dc:creator>
      <dc:date>2009-06-14T20:35:54Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamic Internal Table creation and population</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/dynamic-internal-table-creation-and-population/m-p/5703200#M1295311</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks a lot Uwe, you made it crystal clear!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I had most of the elements, and some mistake (my components where created with element, not data), and your post has highlighted all those issues perfectly.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;N.H&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 15 Jun 2009 09:58:58 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/dynamic-internal-table-creation-and-population/m-p/5703200#M1295311</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-06-15T09:58:58Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamic Internal Table creation and population</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/dynamic-internal-table-creation-and-population/m-p/5703201#M1295312</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I think the problem with your coding was that if the result set consists of a single field then you need to take a &lt;EM&gt;field&lt;/EM&gt; (instead of a structure) as returning "structure" for the result set instance.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;P&gt;  Uwe&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 15 Jun 2009 10:16:57 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/dynamic-internal-table-creation-and-population/m-p/5703201#M1295312</guid>
      <dc:creator>uwe_schieferstein</dc:creator>
      <dc:date>2009-06-15T10:16:57Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamic Internal Table creation and population</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/dynamic-internal-table-creation-and-population/m-p/5703202#M1295313</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Actually, I was using &lt;STRONG&gt;cl_abap_elemdescr&lt;/STRONG&gt; to get my component type, instead of &lt;STRONG&gt;cl_abap_datadescr&lt;/STRONG&gt;. This syntax seems to work and no error are found in the code. But at runtime, type is incomplete and a short dump occurs.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Another point (not stated in my 1st post) was that I was creating myself the field catalog for the ALV, but the &lt;STRONG&gt;cl_salv_table&lt;/STRONG&gt; you've provided me with, does that better than me ! &lt;SPAN __jive_emoticon_name="happy"&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 15 Jun 2009 13:12:35 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/dynamic-internal-table-creation-and-population/m-p/5703202#M1295313</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-06-15T13:12:35Z</dc:date>
    </item>
  </channel>
</rss>

