<?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: Dynamic type variable creation in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/dynamic-type-variable-creation/m-p/4671093#M1098650</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;It is failing because your declarations are cust_type_A and you are trying to type it to MY_CUST_TYPE_A.&lt;/P&gt;&lt;P&gt;Remove the MY_ and it will work.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;e.g.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;types: begin of type1,
                field1 type i,
                field2 type i,
                field3 type i,
            end of type1,

              begin of cust_type_a,
                   include type type1.
types:       erdat type vbak-erdat,
              end of cust_type_a,

             begin of cust_type_b,
                   include type type1.
types:       fkdat type vbrk-fkdat,
              end of cust_type_b.

data: z type ref to data.
data str type string.

field-symbols: &amp;lt;fs&amp;gt; type any.

parameters: letter type char1 default 'A'.

start-of-selection.

concatenate 'CUST_TYPE_' letter into str.
create data z type (str).&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Darren&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 28 Oct 2008 14:22:48 GMT</pubDate>
    <dc:creator>Former Member</dc:creator>
    <dc:date>2008-10-28T14:22:48Z</dc:date>
    <item>
      <title>Dynamic type variable creation</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/dynamic-type-variable-creation/m-p/4671092#M1098649</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I want to create a variable with a pre-defined TYPE, but the latter will only be known at runtime.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;For instance:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Consider that I my DEFINITIONS1 &lt;U&gt;include&lt;/U&gt; file is:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;TYPES: BEGIN OF type1,
                field1 TYPE i,
                field2 TYPE i,
                field3 TYPE i,
            END OF type1,

              BEGIN OF cust_type_A,
                   INCLUDE TYPE type1.
TYPES:       erdat TYPE vbak-erdat,
              END OF cust_type_A,

             BEGIN OF cust_type_B,
                   INCLUDE TYPE type1.
TYPES:       fkdat TYPE vbrk-fkdat,
              END OF cust_type_B.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;-&lt;/P&gt;&lt;HR originaltext="--------------------------------------------------------------------------------------" /&gt;&lt;P&gt;               &lt;/P&gt;&lt;P&gt;Than I have the following code (assume "letter" is a character parameter I receive, either 'A' or 'B'):&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;INCLUDE definitions1.

DATA: z TYPE REF to data.

FIELD-SYMBOLS: &amp;lt;fs&amp;gt; TYPE ANY.

DATA str type string.
CONCATENATE 'MY_CUST_TYPE_' letter INTO str.
CREATE DATA z TYPE (str).
*  ASSIGN z-&amp;gt;* TO &amp;lt;fs&amp;gt;.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Why is that that the CREATE DATA z TYPE (str) statement fails ?&lt;/P&gt;&lt;P&gt;How, then, I create a variable/field symbol from a specific type, which will only be known at runtime ?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;Avraham&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 28 Oct 2008 14:16:51 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/dynamic-type-variable-creation/m-p/4671092#M1098649</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-10-28T14:16:51Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamic type variable creation</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/dynamic-type-variable-creation/m-p/4671093#M1098650</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;It is failing because your declarations are cust_type_A and you are trying to type it to MY_CUST_TYPE_A.&lt;/P&gt;&lt;P&gt;Remove the MY_ and it will work.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;e.g.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;types: begin of type1,
                field1 type i,
                field2 type i,
                field3 type i,
            end of type1,

              begin of cust_type_a,
                   include type type1.
types:       erdat type vbak-erdat,
              end of cust_type_a,

             begin of cust_type_b,
                   include type type1.
types:       fkdat type vbrk-fkdat,
              end of cust_type_b.

data: z type ref to data.
data str type string.

field-symbols: &amp;lt;fs&amp;gt; type any.

parameters: letter type char1 default 'A'.

start-of-selection.

concatenate 'CUST_TYPE_' letter into str.
create data z type (str).&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Darren&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 28 Oct 2008 14:22:48 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/dynamic-type-variable-creation/m-p/4671093#M1098650</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-10-28T14:22:48Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamic type variable creation</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/dynamic-type-variable-creation/m-p/4671094#M1098651</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;This was a typo, but I'll check your example.&lt;/P&gt;&lt;P&gt;Thanks.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 28 Oct 2008 14:28:10 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/dynamic-type-variable-creation/m-p/4671094#M1098651</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-10-28T14:28:10Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamic type variable creation</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/dynamic-type-variable-creation/m-p/4671095#M1098652</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Check this code to create a dynamic type at run time using the RTTS - Run Time Type Services.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
DATA: lo_struct   TYPE REF TO cl_abap_structdescr,
      lo_element  TYPE REF TO cl_abap_elemdescr,
      lo_new_type TYPE REF TO cl_abap_structdescr,
      lo_data     TYPE REF TO data,
      lt_comp     TYPE cl_abap_structdescr=&amp;gt;component_table,
      lt_tot_comp TYPE cl_abap_structdescr=&amp;gt;component_table,
      la_comp     LIKE LINE OF lt_comp.

DATA: lc_num TYPE char10.

* field symbols to access the dynamic table
FIELD-SYMBOLS: &amp;lt;f_line&amp;gt;  TYPE ANY,
               &amp;lt;f_field&amp;gt; TYPE ANY.

PARAMETERS: p_a RADIOBUTTON GROUP rd1,
            p_b RADIOBUTTON GROUP rd1.

START-OF-SELECTION.
  DO 3 TIMES.
    lc_num = sy-index.
    CONDENSE lc_num.

*   Element Description
    lo_element ?= cl_abap_elemdescr=&amp;gt;describe_by_name( 'INT4' ).
*
*   Field name
    CONCATENATE 'FIELD' lc_num INTO la_comp-name.
*
*   Field type
    la_comp-type = cl_abap_elemdescr=&amp;gt;get_p(
                      p_length   = lo_element-&amp;gt;length
                      p_decimals = lo_element-&amp;gt;decimals ).
*
*   Filling the component table
    APPEND la_comp TO lt_tot_comp.
    CLEAR: la_comp.
  ENDDO.

  IF p_a = 'X'.
*   Element Description
    lo_element ?= cl_abap_elemdescr=&amp;gt;describe_by_name( 'ERDAT' ).
*
*   Field name
    la_comp-name = 'ERDAT'.
*
*   Field type
    la_comp-type = cl_abap_elemdescr=&amp;gt;get_p(
                      p_length   = lo_element-&amp;gt;length
                      p_decimals = lo_element-&amp;gt;decimals ).
*
*   Filling the component table
    APPEND la_comp TO lt_tot_comp.
    CLEAR: la_comp.

  ELSEIF p_b = 'X'.
*   Element Description
    lo_element ?= cl_abap_elemdescr=&amp;gt;describe_by_name( 'FKDAT' ).
*
*   Field name
    la_comp-name = 'FKDAT'.
*
*   Field type
    la_comp-type = cl_abap_elemdescr=&amp;gt;get_p(
                      p_length   = lo_element-&amp;gt;length
                      p_decimals = lo_element-&amp;gt;decimals ).
*
*   Filling the component table
    APPEND la_comp TO lt_tot_comp.
    CLEAR: la_comp.
  ENDIF.

* 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
  ASSIGN lo_data-&amp;gt;* TO &amp;lt;f_line&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>Tue, 28 Oct 2008 14:45:54 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/dynamic-type-variable-creation/m-p/4671095#M1098652</guid>
      <dc:creator>naimesh_patel</dc:creator>
      <dc:date>2008-10-28T14:45:54Z</dc:date>
    </item>
  </channel>
</rss>

