<?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: Setting a TYPE dynamically in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/setting-a-type-dynamically/m-p/8474761#M1651679</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Can you use CL_ABAP_DATADESCR (and it's subclasses) to get the info you need at runtime?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 17 Jan 2012 16:41:02 GMT</pubDate>
    <dc:creator>bryan_cain</dc:creator>
    <dc:date>2012-01-17T16:41:02Z</dc:date>
    <item>
      <title>Setting a TYPE dynamically</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/setting-a-type-dynamically/m-p/8474755#M1651673</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi All, &lt;/P&gt;&lt;P&gt;I'm trying to create a data with a type setted dynamically. &lt;/P&gt;&lt;P&gt;I have 2 parameters : an internal table (p_reference) and the name (colonne, as a string) of one of its columns.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;My code doesnt work because the instruction : "create data: ty_type type (desired_type)"&lt;/P&gt;&lt;P&gt;wont accept these desired_type : &lt;/P&gt;&lt;P&gt;  - P(8) DECIMALS 3 &lt;/P&gt;&lt;P&gt;  - P8&lt;/P&gt;&lt;P&gt;It can only accept 'P'&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Can I set the length and the decimals later Or should I change something else to make this code work ? &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks a lot, &lt;/P&gt;&lt;P&gt;Jessie&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;  &lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;FIELD-SYMBOLS &amp;lt;table_reference&amp;gt;  TYPE STANDARD TABLE.
  ASSIGN p_reference TO &amp;lt;table_reference&amp;gt;.

  FIELD-SYMBOLS &amp;lt;table_reference_fields&amp;gt; TYPE ANY.
  DATA gs_fldname TYPE REF TO data.
  CREATE DATA gs_fldname LIKE LINE OF &amp;lt;table_reference&amp;gt;.
  ASSIGN gs_fldname-&amp;gt;* TO &amp;lt;table_reference_fields&amp;gt;.

  FIELD-SYMBOLS &amp;lt;lfs_comp_wa&amp;gt; TYPE abap_compdescr.

  l_descr_ref ?= cl_abap_typedescr=&amp;gt;describe_by_data( &amp;lt;table_reference_fields&amp;gt; ).

  LOOP AT l_descr_ref-&amp;gt;components[] ASSIGNING &amp;lt;lfs_comp_wa&amp;gt;.
    IF &amp;lt;lfs_comp_wa&amp;gt;-name = colonne.
      exit.
    endif.
  endloop.

  data desired_type type string.

" This CONCATENATE dont work but this is just an example

  concatenate &amp;lt;lfs_comp_wa&amp;gt;-type_kind 
	      &amp;lt;lfs_comp_wa&amp;gt;-length 
              ' DECIMALS ' 
              &amp;lt;lfs_comp_wa&amp;gt;-decimals
  into desired_type.


  data: ty_type type ref to data .
  field-SYMBOLS &amp;lt;fs_data&amp;gt; type any .
  create data: ty_type type (desired_type) .  " crash :(
  ASSIGN: ty_type-&amp;gt;* TO &amp;lt;fs_data&amp;gt; .&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 17 Jan 2012 14:11:59 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/setting-a-type-dynamically/m-p/8474755#M1651673</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2012-01-17T14:11:59Z</dc:date>
    </item>
    <item>
      <title>Re: Setting a TYPE dynamically</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/setting-a-type-dynamically/m-p/8474756#M1651674</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Allowed syntax are&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;DATA dref TYPE REF TO data.
CREATE DATA dref TYPE p LENGTH 11 DECIMALS 3.
* or
DATA: dref2 TYPE REF TO data,
      len TYPE i VALUE 11,
      dec TYPE i VALUE 3.
CREATE DATA dref2 TYPE p LENGTH len DECIMALS dec.
* or
DATA: dref3 TYPE REF TO data,
      dataelem type c length 30 value 'WRBTR'.
CREATE DATA dref3 TYPE (dataelem).&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Raymond&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 17 Jan 2012 14:35:40 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/setting-a-type-dynamically/m-p/8474756#M1651674</guid>
      <dc:creator>RaymondGiuseppi</dc:creator>
      <dc:date>2012-01-17T14:35:40Z</dc:date>
    </item>
    <item>
      <title>Re: Setting a TYPE dynamically</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/setting-a-type-dynamically/m-p/8474757#M1651675</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;why not reading the data type of the table field?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
    select single rollname into lv_type from dd03l
                                        where tabname   = lv_dbtab
                                        and   fieldname = ls_fld_except-fieldname.
    if sy-subrc &amp;lt;&amp;gt; 0.
      exit.
    endif.

    create data f_any type (lv_type).
    assign f_any-&amp;gt;* to &amp;lt;f_any&amp;gt;.
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 17 Jan 2012 14:39:58 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/setting-a-type-dynamically/m-p/8474757#M1651675</guid>
      <dc:creator>former_member226519</dc:creator>
      <dc:date>2012-01-17T14:39:58Z</dc:date>
    </item>
    <item>
      <title>Re: Setting a TYPE dynamically</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/setting-a-type-dynamically/m-p/8474758#M1651676</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks both of you, &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;do you mean that something like this would work : &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;TYPES : BEGIN OF ts_vbap,
             vbeln   TYPE vbap-vbeln,
             posnr   TYPE vbap-posnr,
         END OF ts_vbap.
DATA : t_vbap    TYPE TABLE OF ts_vbap.

select single rollname into lv_type from dd03l
                                    where tabname   = 't_vbap'
                                    and   fieldname = 'vbeln'.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;My internal table t_vbap has no entry in dd03l (maybe it has at runtime ?)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Jessie&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 17 Jan 2012 14:57:42 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/setting-a-type-dynamically/m-p/8474758#M1651676</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2012-01-17T14:57:42Z</dc:date>
    </item>
    <item>
      <title>Re: Setting a TYPE dynamically</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/setting-a-type-dynamically/m-p/8474759#M1651677</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;you have to refer to a DDIC table, VBAP in your case.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 17 Jan 2012 15:21:35 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/setting-a-type-dynamically/m-p/8474759#M1651677</guid>
      <dc:creator>former_member226519</dc:creator>
      <dc:date>2012-01-17T15:21:35Z</dc:date>
    </item>
    <item>
      <title>Re: Setting a TYPE dynamically</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/setting-a-type-dynamically/m-p/8474760#M1651678</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Sure. Thanks for the tip, it will be useful later, but in this case I cannot refer to VBAP : &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am working with an internal table : can I find the name of the table to which the column refers and then use it and your solution ?  &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Jessie&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Edited by: jcmartin01 on Jan 17, 2012 5:35 PM&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 17 Jan 2012 15:34:16 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/setting-a-type-dynamically/m-p/8474760#M1651678</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2012-01-17T15:34:16Z</dc:date>
    </item>
    <item>
      <title>Re: Setting a TYPE dynamically</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/setting-a-type-dynamically/m-p/8474761#M1651679</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Can you use CL_ABAP_DATADESCR (and it's subclasses) to get the info you need at runtime?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 17 Jan 2012 16:41:02 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/setting-a-type-dynamically/m-p/8474761#M1651679</guid>
      <dc:creator>bryan_cain</dc:creator>
      <dc:date>2012-01-17T16:41:02Z</dc:date>
    </item>
    <item>
      <title>Re: Setting a TYPE dynamically</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/setting-a-type-dynamically/m-p/8474762#M1651680</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Yes, I'm using this class, and I get a list of object of type abap_compdescr. &lt;/P&gt;&lt;P&gt;But then I have to use the tip that Ryamond gave me to 'reconstruct' a type for my data.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I was looking for a direct way to get the type of the columns of my internal table.&lt;/P&gt;&lt;P&gt; I think I' ll have to work with my code and Raymond's except if someone finds a better solution....&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Jessie&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 17 Jan 2012 18:12:27 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/setting-a-type-dynamically/m-p/8474762#M1651680</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2012-01-17T18:12:27Z</dc:date>
    </item>
    <item>
      <title>Re: Setting a TYPE dynamically</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/setting-a-type-dynamically/m-p/8474763#M1651681</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Did you try a cl_abap_typedescr-&amp;gt;get_ddic_object to get a ddic reference to your field ?&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;REPORT zgetddic.

TYPE-POOLS: abap.

DATA: field LIKE mara-matnr, " try various way to define field here
      lo_abap_typedescr TYPE REF TO cl_abap_typedescr,
      lt_ddic_objects TYPE dd_x031l_table,
      ls_ddic_object LIKE LINE OF ddic_objects.

CALL METHOD cl_abap_datadescr=&amp;gt;describe_by_data
  EXPORTING
    p_data      = field
  RECEIVING
    p_descr_ref = lo_abap_typedescr.

CALL METHOD lo_abap_typedescr-&amp;gt;get_ddic_object
  RECEIVING
    p_object = lt_ddic_objects.

READ TABLE lt_ddic_objects INDEX 1 INTO ls_ddic_object.

WRITE: / sy-subrc, ls_ddic_object-tabname.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Raymond&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 18 Jan 2012 07:16:22 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/setting-a-type-dynamically/m-p/8474763#M1651681</guid>
      <dc:creator>RaymondGiuseppi</dc:creator>
      <dc:date>2012-01-18T07:16:22Z</dc:date>
    </item>
    <item>
      <title>Re: Setting a TYPE dynamically</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/setting-a-type-dynamically/m-p/8474764#M1651682</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Try out this:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;REPORT ZZAETEST_DYNAMIC_DATA .&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;DATA XVBAP TYPE TABLE OF VBAP.&lt;/P&gt;&lt;P&gt;DATA COLUMN(30) VALUE 'NETWR'.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;FIELD-SYMBOLS &amp;lt;TABLE_REFERENCE&amp;gt;  TYPE STANDARD TABLE.&lt;/P&gt;&lt;P&gt;ASSIGN XVBAP TO &amp;lt;TABLE_REFERENCE&amp;gt;.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;FIELD-SYMBOLS &amp;lt;TABLE_REFERENCE_FIELDS&amp;gt; TYPE ANY.&lt;/P&gt;&lt;P&gt;DATA GS_FLDNAME TYPE REF TO DATA.&lt;/P&gt;&lt;P&gt;CREATE DATA GS_FLDNAME LIKE LINE OF &amp;lt;TABLE_REFERENCE&amp;gt;.&lt;/P&gt;&lt;P&gt;ASSIGN GS_FLDNAME-&amp;gt;* TO &amp;lt;TABLE_REFERENCE_FIELDS&amp;gt;.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;FIELD-SYMBOLS &amp;lt;SINGLE_FIELD&amp;gt;.&lt;/P&gt;&lt;P&gt;ASSIGN COMPONENT COLUMN OF&lt;/P&gt;&lt;P&gt;  STRUCTURE &amp;lt;TABLE_REFERENCE_FIELDS&amp;gt; TO &amp;lt;SINGLE_FIELD&amp;gt;.&lt;/P&gt;&lt;P&gt;IF SY-SUBRC &amp;lt;&amp;gt; 0.&lt;/P&gt;&lt;P&gt;  EXIT.&lt;/P&gt;&lt;P&gt;ENDIF.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;FIELD-SYMBOLS &amp;lt;FS_DATA&amp;gt; TYPE ANY .&lt;/P&gt;&lt;P&gt;DATA: TY_TYPE TYPE REF TO DATA .&lt;/P&gt;&lt;P&gt;CREATE DATA: TY_TYPE LIKE &amp;lt;SINGLE_FIELD&amp;gt;.&lt;/P&gt;&lt;P&gt;ASSIGN: TY_TYPE-&amp;gt;* TO &amp;lt;FS_DATA&amp;gt; .&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;lt;FS_DATA&amp;gt; = '123.45'.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;BREAK-POINT.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Kind Regards Alfons&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 18 Jan 2012 09:21:48 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/setting-a-type-dynamically/m-p/8474764#M1651682</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2012-01-18T09:21:48Z</dc:date>
    </item>
  </channel>
</rss>

