<?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: How to insert a header string to a DYNAMIC Internal Table? in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/how-to-insert-a-header-string-to-a-dynamic-internal-table/m-p/5592559#M1274826</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Answered.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 15 Oct 2009 00:59:14 GMT</pubDate>
    <dc:creator>Former Member</dc:creator>
    <dc:date>2009-10-15T00:59:14Z</dc:date>
    <item>
      <title>How to insert a header string to a DYNAMIC Internal Table?</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/how-to-insert-a-header-string-to-a-dynamic-internal-table/m-p/5592554#M1274821</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I have a dynamic internal table created via&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
  DATA: e_dyntab_tb            TYPE lvc_t_fcat,
        i_reftab               TYPE REF   TO data.

  CALL METHOD cl_alv_table_create=&amp;gt;create_dynamic_table
    EXPORTING
      it_fieldcatalog = e_dyntab_tb          "Pass alv_fcat here
    IMPORTING
      ep_table        = i_reftab.

* Create Dynamic Work Area and assign to FS
  ASSIGN i_reftab-&amp;gt;* TO &amp;lt;fs_final_itab&amp;gt;.      "Assigning the Final Table,
  CREATE DATA t_line_reftab LIKE LINE OF &amp;lt;fs_final_itab&amp;gt;.

  ASSIGN t_line_reftab-&amp;gt;* TO &amp;lt;fs_line_reftab&amp;gt;.  "Create a Work Area
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;e_dyntab_tb contains the structure of lvc_t_fcat and is being populated by:&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
  MOVE: c_matnr      TO e_dyntab_wa-fieldname.
  APPEND e_dyntab_wa TO e_dyntab_tb.

  MOVE: c_maktx         TO e_dyntab_wa-fieldname.
  APPEND e_dyntab_wa TO e_dyntab_tb.

  MOVE: c_meins      TO e_dyntab_wa-fieldname.
  APPEND e_dyntab_wa TO e_dyntab_tb.
 
  So onu2026
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The Class cl_alv_table_create=&amp;gt;create_dynamic_table automatically inherits the data type definition of the field being populated in the e_dyntab_wa;&lt;/P&gt;&lt;P&gt;For instance, matnru2019s data type is character(18) and meinsu2019 data type is unit., etc&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;PROBLEM:&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;How can I append a column string header  in the fist row of the dynamic internal table ( &amp;lt;fs_final_itab&amp;gt; ) ?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Please take note that the structure of &amp;lt;fs_final_itab&amp;gt; is metadata (different data types) so there will be a type mismatch for moving the word u2018WEEK1u2019 to field MENGE which is one of the data type definition in the structure of &amp;lt;fs_final_itab&amp;gt;.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Edited by: Jaime Cabanban on May 6, 2009 2:03 AM&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 05 May 2009 17:48:01 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/how-to-insert-a-header-string-to-a-dynamic-internal-table/m-p/5592554#M1274821</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-05-05T17:48:01Z</dc:date>
    </item>
    <item>
      <title>Re: How to insert a header string to a DYNAMIC Internal Table?</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/how-to-insert-a-header-string-to-a-dynamic-internal-table/m-p/5592555#M1274822</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Jaime,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I think you are mixing things up.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;First of all you have to know that we distinguish &lt;EM&gt;technical&lt;/EM&gt; and &lt;EM&gt;semantic&lt;/EM&gt; attirbutes. First ones are used in all programs simply for defining a data object, a structure, a table. These are also visible at &lt;STRONG&gt;domain&lt;/STRONG&gt; level in ABAP Dictionary, whereas the latter are available at &lt;STRONG&gt;date element&lt;/STRONG&gt; level. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Now how this reflects in your program.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Generally programs usues only technical attributes i.e when you define such structure:&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
data: begin of my_structure,
            molga type T500l-molga,
            ...
         end of my_structure.
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;As you can see &lt;EM&gt;molga&lt;/EM&gt; here doesn't tell us what is the desciption behind it. It is a &lt;EM&gt;type&lt;/EM&gt; which does the trick. During runtime system checks semantic attributes of T500L-MOLGA (semantic here means its label for example). &lt;EM&gt;molga&lt;/EM&gt; here could be easily changed to &lt;EM&gt;my_field&lt;/EM&gt; but would mean the same as long as the typing wouldn't change (still we would have the same description). &lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Technical&lt;/STRONG&gt; attributes, on the other hand, just describe what is the lenght and type of this field.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;When you run the program in debug mode, you can see that no &lt;STRONG&gt;description&lt;/STRONG&gt; of the column would be visible. Column would be named &lt;EM&gt;molgda&lt;/EM&gt; not &lt;EM&gt;Contry Grouping&lt;/EM&gt; . It is task of screen processor to get this description once you display your field in ALV or use this field on screen.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Having this knowledge you probably already realized that you can't provide desription of the column in your dynamic table. It will have technical names of fields like C_MATNR, C_MEINS but never 'Material' etc.&lt;/P&gt;&lt;P&gt;This will show up only when this column is used in your ALV.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;For this in your fieldcatalog you need to provide a reference to a data element or field of a table from DDIC.&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
e_dyntab_wa-REF_FIELD = "here provide field name of a DDIC table which you are refering to 
e_dyntab_wa-REF_TABLE = "and a DDIC table name
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;That's all you need. In debugger you will still only see technical description but on the screen, &lt;EM&gt;screen processor&lt;/EM&gt; will pull out the description of column for you.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;P&gt;Marcin&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 05 May 2009 19:27:52 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/how-to-insert-a-header-string-to-a-dynamic-internal-table/m-p/5592555#M1274822</guid>
      <dc:creator>MarcinPciak</dc:creator>
      <dc:date>2009-05-05T19:27:52Z</dc:date>
    </item>
    <item>
      <title>Re: How to insert a header string to a DYNAMIC Internal Table?</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/how-to-insert-a-header-string-to-a-dynamic-internal-table/m-p/5592556#M1274823</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Marcin,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Yes the &lt;EM&gt;screen processor&lt;/EM&gt; will automatically put the description of the column for me in my ALV output. &lt;/P&gt;&lt;P&gt;My scenario is quite unique though,&lt;/P&gt;&lt;P&gt;since I manually remove the SAP standard ALV buttons, I need to add a customize functionality to extract the current ALV output (&lt;EM&gt;dynamic&lt;/EM&gt;), and put into an internal table where it will be use to the functionality of &lt;STRONG&gt;download to file /MS Excel&lt;/STRONG&gt;.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;So the Algo goes like this:&lt;/P&gt;&lt;P&gt;1. Display ALV output &lt;/P&gt;&lt;P&gt;2. Remove all the SAP standard ALV buttons, replace it with one custom button&lt;/P&gt;&lt;P&gt;3. When the user click this custom button, it will extract all the data of the &lt;STRONG&gt;current&lt;/STRONG&gt; ALV output which is &lt;STRONG&gt;dynamic&lt;/STRONG&gt;, so the extraction will include the column header description as the first row, then the succeeding rows will the data entries &lt;STRONG&gt;respective&lt;/STRONG&gt; to its column header.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;At #3, I'm currently &lt;EM&gt;stagnant&lt;/EM&gt; .... &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Jaime&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Edited by: Jaime Cabanban on May 7, 2009 12:10 AM&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 06 May 2009 16:10:45 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/how-to-insert-a-header-string-to-a-dynamic-internal-table/m-p/5592556#M1274823</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-05-06T16:10:45Z</dc:date>
    </item>
    <item>
      <title>Re: How to insert a header string to a DYNAMIC Internal Table?</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/how-to-insert-a-header-string-to-a-dynamic-internal-table/m-p/5592557#M1274824</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Jaime,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;As you noticed before, there will be a type conflict of column header (which is of C type) and its data which are of different types. You have to rewrite data from one dynamic table (having your custom type columns) to another dynamic one which has to be of type C. Otherwise you can't store all those data if one table. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You query is not so trival, but I think this is what you need.&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
TYPE-POOLS: abap.

"1. --------------- typing (you may also create those typing dynamically but here I used static approach)

"your type (can be dynamic)
TYPES: BEGIN OF t_dyn,
        pernr TYPE pa0001-pernr,
        begda TYPE pa0001-begda,
       END OF t_dyn.

"table type
TYPES: tt_dyn TYPE TABLE OF t_dyn.

"new dyn type
TYPES: BEGIN OF t_new_dyn,
        field1 TYPE c LENGTH 60,
        field2 TYPE c LENGTH 60,
       END OF t_new_dyn.

"table type
TYPES: tt_new_dyn TYPE TABLE OF t_new_dyn.

"2. --------------- references &amp;amp; data objects

DATA: r_dyn_tab TYPE REF TO data,
      r_dyn_str TYPE REF TO data,
      r_new_dyn_tab TYPE REF TO data,
      r_struct TYPE REF TO cl_abap_structdescr,  "to describe strcutre
      r_elem TYPE REF TO cl_abap_elemdescr. "to describe data object

DATA: dfies_str TYPE dfies,
      fields_tab TYPE abap_component_tab,
      header TYPE dfies-fieldtext,
      index TYPE i.

"3. --------------- dynamic creation
CREATE DATA r_dyn_tab TYPE tt_dyn.  "dynamic table
CREATE DATA r_dyn_str TYPE t_dyn.   "and dynamic structure like line of dynamic table
CREATE DATA r_new_dyn_tab TYPE tt_new_dyn. "new dynamic table


"4. --------------- getting struture components (to get their header later)
"we will work on strucutre to get its components and describe them, that's why I create also a structure
"describe your structure
r_struct ?= cl_abap_typedescr=&amp;gt;describe_by_data_ref( r_dyn_str ).
"get its components
fields_tab = r_struct-&amp;gt;get_components( ).

"field symbols to address references
FIELD-SYMBOLS: &amp;lt;wa_fields&amp;gt; LIKE LINE OF fields_tab,
               &amp;lt;new_tab&amp;gt; TYPE tt_new_dyn,
               &amp;lt;wa_new_tab&amp;gt; TYPE t_new_dyn,
               &amp;lt;new_comp&amp;gt; TYPE ANY.  "to address specific field

ASSIGN r_new_dyn_tab-&amp;gt;* TO &amp;lt;new_tab&amp;gt;.
APPEND INITIAL LINE TO &amp;lt;new_tab&amp;gt; ASSIGNING &amp;lt;wa_new_tab&amp;gt;.
"&amp;lt;wa_new_tab&amp;gt; now points to first row


BREAK-POINT.
"5. --------------- populating new dyn table with header as first row
LOOP AT fields_tab ASSIGNING &amp;lt;wa_fields&amp;gt;.
  index = sy-tabix.

  r_elem ?= &amp;lt;wa_fields&amp;gt;-type.
  dfies_str = r_elem-&amp;gt;get_ddic_field( ).

  "here you have header desciption of a column
  header = dfies_str-fieldtext.

  "assing header to a field
  ASSIGN COMPONENT index OF STRUCTURE &amp;lt;wa_new_tab&amp;gt; TO &amp;lt;new_comp&amp;gt;.
  IF sy-subrc = 0.
    &amp;lt;new_comp&amp;gt; = header.
  ENDIF.

ENDLOOP.

"6. ---------------- here you just move entries from  r_dyn_tab  to  r_new_dyn_tab
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;P&gt;Marcin&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 07 May 2009 11:04:21 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/how-to-insert-a-header-string-to-a-dynamic-internal-table/m-p/5592557#M1274824</guid>
      <dc:creator>MarcinPciak</dc:creator>
      <dc:date>2009-05-07T11:04:21Z</dc:date>
    </item>
    <item>
      <title>Re: How to insert a header string to a DYNAMIC Internal Table?</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/how-to-insert-a-header-string-to-a-dynamic-internal-table/m-p/5592558#M1274825</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Marcin,&lt;/P&gt;&lt;P&gt;Yes your suggestion makes sense but somehow I was able to manage to define everything as TYPE C and amazingly ABAP can still do accurate arithmetic computation even if all of them are defined as type C.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;On your suggestion below, when I'll migrate the dynamic_itab(which is metadata) to dynamic_itab(pure character), an issue will occur on entries with negative number, the - (minus) sign will always appear as it is, so if I'm going to send it to Excel, it is not treated as number but rather as text.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Solution i'm thinking: On the ABAP, search the string for -(minus sign) at the end of every string, if found, put it at the beginning; but this might consume some memory though.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;What do you think?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Jaime&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 14 May 2009 00:10:25 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/how-to-insert-a-header-string-to-a-dynamic-internal-table/m-p/5592558#M1274825</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-05-14T00:10:25Z</dc:date>
    </item>
    <item>
      <title>Re: How to insert a header string to a DYNAMIC Internal Table?</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/how-to-insert-a-header-string-to-a-dynamic-internal-table/m-p/5592559#M1274826</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Answered.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 15 Oct 2009 00:59:14 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/how-to-insert-a-header-string-to-a-dynamic-internal-table/m-p/5592559#M1274826</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-10-15T00:59:14Z</dc:date>
    </item>
  </channel>
</rss>

