<?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: declaring type definition dynamically in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/declaring-type-definition-dynamically/m-p/6755400#M1460822</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You can create a dynamic structure like this.   &amp;lt;fs_structure&amp;gt; will be the structure with 20 string fields.&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;TYPE-POOLS: abap.

DATA:
  lr_structdescr    TYPE REF TO cl_abap_structdescr,
  lr_datadescr      TYPE REF TO cl_abap_datadescr,
  lt_components     TYPE abap_component_tab,
  ls_component      TYPE LINE OF abap_component_tab,
  lr_struct         TYPE REF TO data.

DATA: lv_index_num(3) TYPE n.
DATA: lv_index_char(3) TYPE c.

FIELD-SYMBOLS: &amp;lt;fs_structure&amp;gt; TYPE ANY.

START-OF-SELECTION.

  DO 20 TIMES.
    lv_index_num = sy-index.
    lv_index_char = lv_index_num.
    CONCATENATE 'value' lv_index_char INTO ls_component-name.
    ls_component-type ?= cl_abap_elemdescr=&amp;gt;get_string( ).
    INSERT ls_component INTO TABLE lt_components.
  ENDDO.

* get structure descriptor -&amp;gt; lr_STRUCTDESCR
  lr_structdescr ?= cl_abap_structdescr=&amp;gt;create( lt_components ).

* create a structure
  CREATE DATA lr_struct TYPE HANDLE lr_structdescr.
  ASSIGN lr_struct-&amp;gt;* TO &amp;lt;fs_structure&amp;gt;.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,.&lt;/P&gt;&lt;P&gt;Rich Heilman&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 16 Apr 2010 18:26:34 GMT</pubDate>
    <dc:creator>RichHeilman</dc:creator>
    <dc:date>2010-04-16T18:26:34Z</dc:date>
    <item>
      <title>declaring type definition dynamically</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/declaring-type-definition-dynamically/m-p/6755398#M1460820</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;hi guys,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;i have a strange issue. i need to define a varaible that refers to a below type definition.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;types : begin of t_str,&lt;/P&gt;&lt;P&gt;        var1 type string,&lt;/P&gt;&lt;P&gt;vcar2 type string,&lt;/P&gt;&lt;P&gt;.&lt;/P&gt;&lt;P&gt;.&lt;/P&gt;&lt;P&gt;.&lt;/P&gt;&lt;P&gt;.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;end of t_str,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data:  variable type t_str.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;the problem is i do not know how many var's will be there until run time. so my type definition needs to be dynamic. is there any way to do it.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;thanks&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 16 Apr 2010 18:07:38 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/declaring-type-definition-dynamically/m-p/6755398#M1460820</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2010-04-16T18:07:38Z</dc:date>
    </item>
    <item>
      <title>Re: declaring type definition dynamically</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/declaring-type-definition-dynamically/m-p/6755399#M1460821</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You need to use RTTS to generate the Dynamic Type for you. Check the Example in this post: &lt;A href="http://help-abap.blogspot.com/2008/09/dynamic-internal-table-creation.html" target="test_blank"&gt;http://help-abap.blogspot.com/2008/09/dynamic-internal-table-creation.html&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Once you create the type in the given example, you need to assign that type to the Field Symbol to work with it.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
* 3. Create a New Type
  lo_new_type = cl_abap_structdescr=&amp;gt;create( lt_tot_comp ).

* 5. data to handle the new table type
  CREATE DATA lo_data TYPE HANDLE lo_new_type.
*
* 6. New internal table in the fieldsymbols
  field-symbols: &amp;lt;f_structure&amp;gt; type any.
  ASSIGN lo_data-&amp;gt;* TO &amp;lt;f_structure&amp;gt;

* Access fields within it
  field-symbols: &amp;lt;fs_field&amp;gt; type any.
  assign component 'KSTAR' of structure &amp;lt;lfs_strucutre&amp;gt; to &amp;lt;lfs_field&amp;gt;.
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Naimesh Patel&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 16 Apr 2010 18:25:13 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/declaring-type-definition-dynamically/m-p/6755399#M1460821</guid>
      <dc:creator>naimesh_patel</dc:creator>
      <dc:date>2010-04-16T18:25:13Z</dc:date>
    </item>
    <item>
      <title>Re: declaring type definition dynamically</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/declaring-type-definition-dynamically/m-p/6755400#M1460822</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You can create a dynamic structure like this.   &amp;lt;fs_structure&amp;gt; will be the structure with 20 string fields.&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;TYPE-POOLS: abap.

DATA:
  lr_structdescr    TYPE REF TO cl_abap_structdescr,
  lr_datadescr      TYPE REF TO cl_abap_datadescr,
  lt_components     TYPE abap_component_tab,
  ls_component      TYPE LINE OF abap_component_tab,
  lr_struct         TYPE REF TO data.

DATA: lv_index_num(3) TYPE n.
DATA: lv_index_char(3) TYPE c.

FIELD-SYMBOLS: &amp;lt;fs_structure&amp;gt; TYPE ANY.

START-OF-SELECTION.

  DO 20 TIMES.
    lv_index_num = sy-index.
    lv_index_char = lv_index_num.
    CONCATENATE 'value' lv_index_char INTO ls_component-name.
    ls_component-type ?= cl_abap_elemdescr=&amp;gt;get_string( ).
    INSERT ls_component INTO TABLE lt_components.
  ENDDO.

* get structure descriptor -&amp;gt; lr_STRUCTDESCR
  lr_structdescr ?= cl_abap_structdescr=&amp;gt;create( lt_components ).

* create a structure
  CREATE DATA lr_struct TYPE HANDLE lr_structdescr.
  ASSIGN lr_struct-&amp;gt;* TO &amp;lt;fs_structure&amp;gt;.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,.&lt;/P&gt;&lt;P&gt;Rich Heilman&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 16 Apr 2010 18:26:34 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/declaring-type-definition-dynamically/m-p/6755400#M1460822</guid>
      <dc:creator>RichHeilman</dc:creator>
      <dc:date>2010-04-16T18:26:34Z</dc:date>
    </item>
  </channel>
</rss>

