<?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: Determining internal table structure dynamically in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/determining-internal-table-structure-dynamically/m-p/1726220#M316543</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Liam&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;  Please check below sample code which might help you:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;types: begin of t_dat,
         matnr type matnr,
         werks type werks,
         fld1(10) type c,
       end of t_dat.

data: it_dat type standard table of t_dat,
      wa_dat type t_dat.

data: it_comp type table of RSTRUCINFO.
CALL FUNCTION 'GET_COMPONENT_LIST'
  EXPORTING
    PROGRAM          = sy-repid
    FIELDNAME        = 'WA_DAT'
  TABLES
    COMPONENTS       = it_comp.
  &lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Kind Regards&lt;/P&gt;&lt;P&gt;Eswar&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 13 Nov 2006 02:25:50 GMT</pubDate>
    <dc:creator>Former Member</dc:creator>
    <dc:date>2006-11-13T02:25:50Z</dc:date>
    <item>
      <title>Determining internal table structure dynamically</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/determining-internal-table-structure-dynamically/m-p/1726219#M316542</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I have a number of internal tables in my program which I declare using types. As an example:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;TYPES: begin of ty_hierarchy,&lt;/P&gt;&lt;P&gt;               control_id(6)   type c,&lt;/P&gt;&lt;P&gt;               node_id(10)     type c,&lt;/P&gt;&lt;P&gt;               node_name       type bezei40,&lt;/P&gt;&lt;P&gt;               material        type matnr,&lt;/P&gt;&lt;P&gt;               node_level      type prodh_stuf,&lt;/P&gt;&lt;P&gt;               node_parent(10) type c,&lt;/P&gt;&lt;P&gt;            end of ty_hierarchy.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;DATA: it_hierarchy type ty_hierarchy occurs 0.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Further down my program I need to determine the structure of internal table IT_HIERARCHY dynamically. Because I have a number of internal tables, I need to determine which internal table is being processed. Therefore it's important that I know the structure of the table that I'm currently processing.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am aware of CL_ABAP* classes and functions like GET_COMPONENT_LIST. However because I have declared my tables using the TYPE statement the method/function cannot read my table structure correctly. If I changed my declaration to be as below, the method/function work! However I don't want to do this as I use field symbols to reference my internal tables and need to use the TYPE statement. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;DATA: begin of ty_hierarchy,&lt;/P&gt;&lt;P&gt;               control_id(6)   type c,&lt;/P&gt;&lt;P&gt;               node_id(10)     type c,&lt;/P&gt;&lt;P&gt;               node_name       type bezei40,&lt;/P&gt;&lt;P&gt;               material        type matnr,&lt;/P&gt;&lt;P&gt;               node_level      type prodh_stuf,&lt;/P&gt;&lt;P&gt;               node_parent(10) type c,&lt;/P&gt;&lt;P&gt;            end of ty_hierarchy.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;DATA: begin of it_hierarchy occurs 0.&lt;/P&gt;&lt;P&gt;             include structure ty_hierarchy&lt;/P&gt;&lt;P&gt;DATA: end of it_hierarchy.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Does anyone know on how I can determine my  internal table structure dynamically but still keeping my internal table declarations using TYPE statement?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Any help would be greatly appreciated with reward points .....&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;Liam&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Nov 2006 22:20:05 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/determining-internal-table-structure-dynamically/m-p/1726219#M316542</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2006-11-12T22:20:05Z</dc:date>
    </item>
    <item>
      <title>Re: Determining internal table structure dynamically</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/determining-internal-table-structure-dynamically/m-p/1726220#M316543</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Liam&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;  Please check below sample code which might help you:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;types: begin of t_dat,
         matnr type matnr,
         werks type werks,
         fld1(10) type c,
       end of t_dat.

data: it_dat type standard table of t_dat,
      wa_dat type t_dat.

data: it_comp type table of RSTRUCINFO.
CALL FUNCTION 'GET_COMPONENT_LIST'
  EXPORTING
    PROGRAM          = sy-repid
    FIELDNAME        = 'WA_DAT'
  TABLES
    COMPONENTS       = it_comp.
  &lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Kind Regards&lt;/P&gt;&lt;P&gt;Eswar&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 13 Nov 2006 02:25:50 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/determining-internal-table-structure-dynamically/m-p/1726220#M316543</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2006-11-13T02:25:50Z</dc:date>
    </item>
    <item>
      <title>Re: Determining internal table structure dynamically</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/determining-internal-table-structure-dynamically/m-p/1726221#M316544</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello Liam&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Both the ABAP-OO as well as the FM-based approach described by Eswar work well with your way of defining the itabs. I described three different ways how to get the structure of your itab dynamically:&lt;/P&gt;&lt;P&gt;- directly using the itab&lt;/P&gt;&lt;P&gt;- using a field symbol&lt;/P&gt;&lt;P&gt;- using a data reference&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;*&amp;amp;---------------------------------------------------------------------*

REPORT  zus_sdn_dynamic_itabs.

TYPE-POOLS: abap.


TYPES: BEGIN OF ty_hierarchy,
control_id(6) TYPE c,
node_id(10) TYPE c,
node_name TYPE bezei40,
material TYPE matnr,
node_level TYPE prodh_stuf,
node_parent(10) TYPE c,
END OF ty_hierarchy.

DATA:
  gs_hierarchy    TYPE ty_hierarchy,
  it_hierarchy    TYPE ty_hierarchy OCCURS 0.

DATA:
  gt_comp         TYPE abap_compdescr_tab,
  gs_comp_a       LIKE LINE OF gt_comp,
  gd_type         TYPE abap_typekind,

  gs_comp    TYPE rstrucinfo,
  it_comp TYPE TABLE OF rstrucinfo.


DATA:
  go_struct    TYPE REF TO cl_abap_structdescr,
  go_table     TYPE REF TO cl_abap_tabledescr,
  gdo_data     TYPE REF TO data.

FIELD-SYMBOLS:
  &amp;lt;gt_itab&amp;gt;    TYPE table.



START-OF-SELECTION.


  GET REFERENCE OF it_hierarchy INTO gdo_data.
  ASSIGN gdo_data-&amp;gt;* TO &amp;lt;gt_itab&amp;gt;.

* (1) Describe directly by using the itab
*  go_table  ?= cl_abap_structdescr=&amp;gt;describe_by_data( it_hierarchy ).
* (2) Describe indirectly by using field symbol
*  go_table  ?= cl_abap_structdescr=&amp;gt;describe_by_data( &amp;lt;gt_itab&amp;gt; ).
* (3) Describe by data reference to itab
  go_table  ?= cl_abap_structdescr=&amp;gt;describe_by_data_ref( gdo_data ).
  go_struct ?= go_table-&amp;gt;get_table_line_type( ).

  WRITE: / 'ABAP-OO Version:'.
  gt_comp = go_struct-&amp;gt;components.
  LOOP AT gt_comp INTO gs_comp_a.
    WRITE: / gs_comp_a-name,
             gs_comp_a-length,
             gs_comp_a-type_kind,
             gs_comp_a-decimals.
  ENDLOOP.
  SKIP 2.




  CALL FUNCTION 'GET_COMPONENT_LIST'
    EXPORTING
      program    = sy-repid
      fieldname  = 'GS_HIERARCHY'
    TABLES
      components = it_comp.

  WRITE: / 'Function Module Version:'.
  LOOP AT it_comp INTO gs_comp.
    WRITE: / gs_comp-compname,
             gs_comp-level,
             gs_comp-leng,
             gs_comp-type,
             gs_comp-olen,
             gs_comp-decs.

  ENDLOOP.

END-OF-SELECTION.&lt;/CODE&gt;&lt;/PRE&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, 13 Nov 2006 04:41:27 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/determining-internal-table-structure-dynamically/m-p/1726221#M316544</guid>
      <dc:creator>uwe_schieferstein</dc:creator>
      <dc:date>2006-11-13T04:41:27Z</dc:date>
    </item>
  </channel>
</rss>

