<?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: Create a dynamic internal table horizontally from another internal table in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/create-a-dynamic-internal-table-horizontally-from-another-internal-table/m-p/6928302#M1485374</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Yes, this is feasible. Refer the below snippet.&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
DATA: BEGIN OF itab OCCURS 0,
        atext TYPE atext,
        stdaz TYPE stdaz,
      END OF itab.

DATA: it_fcat TYPE lvc_t_fcat WITH HEADER LINE.
DATA: l_fieldname TYPE string,
      l_idx(3) TYPE n,
      l_lines type i.
DATA: r_new_tab TYPE REF TO data.

FIELD-SYMBOLS: &amp;lt;new_tab&amp;gt; TYPE INDEX TABLE,
               &amp;lt;wa_tab&amp;gt; TYPE ANY,
               &amp;lt;comp&amp;gt; TYPE ANY.

itab-atext = 'Annual Leave'.
itab-stdaz = 8.
APPEND itab.
itab-atext = 'Sick Leave'.
itab-stdaz = 4.
APPEND itab.


LOOP AT itab.
  "new field name
  it_fcat-fieldname = itab-atext.
  replace ` ` in it_fcat-fieldname with ''. "AnnualLeave, SickLeave
  "make this fiels of same type as PA2006-STDAZ
  it_fcat-ref_field = 'STDAZ'.
  it_fcat-ref_table = 'PA2001'.
  it_fcat-scrtext_s = it_fcat-scrtext_m = it_fcat-scrtext_l = itab-atext. "Annnual Leave, Sick Leave
  APPEND it_fcat.
ENDLOOP.

"create this new table
CALL METHOD cl_alv_table_create=&amp;gt;create_dynamic_table
  EXPORTING
    it_fieldcatalog           = it_fcat[]
  IMPORTING
    ep_table                  = r_new_tab
  EXCEPTIONS
    generate_subpool_dir_full = 1
    OTHERS                    = 2.

"address the content of that new empty table
ASSIGN r_new_tab-&amp;gt;* TO &amp;lt;new_tab&amp;gt;.

"now you need to get for each 2 lines in ITAB one line in &amp;lt;NEW_TAB&amp;gt;
DESCRIBE TABLE itab lines l_lines.
l_lines = l_lines / 2.
l_idx = 1.

DO l_lines TIMES. "number of records in itab / 2
  APPEND INITIAL LINE TO &amp;lt;new_tab&amp;gt; ASSIGNING &amp;lt;wa_tab&amp;gt;.

  DO 2 TIMES.
    READ TABLE itab INDEX l_idx.
    IF sy-subrc = 0.
      ASSIGN COMPONENT sy-index OF STRUCTURE &amp;lt;wa_tab&amp;gt; TO &amp;lt;comp&amp;gt;.
      IF sy-subrc = 0.
        &amp;lt;comp&amp;gt; = itab-stdaz.
      ENDIF.
      l_idx = l_idx + 1.
    ENDIF.
  ENDDO.
ENDDO.
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;As you may see you can't really have columns in &amp;lt;NEW_TAB&amp;gt; named "Annual Leave" and "Sick Leave" as there musn't be a space in names. Anyhow if you replace it with "AnnualLeave" or "SickLeave" this is acceptable. Please note, however, that these names must be unique, so that the new column names are also unique.&lt;/P&gt;&lt;P&gt;The rest is just a matter of generating new dynamic table and moving data from ITAB table to &amp;lt;new_tab&amp;gt;.&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, 11 May 2010 14:34:29 GMT</pubDate>
    <dc:creator>MarcinPciak</dc:creator>
    <dc:date>2010-05-11T14:34:29Z</dc:date>
    <item>
      <title>Create a dynamic internal table horizontally from another internal table</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/create-a-dynamic-internal-table-horizontally-from-another-internal-table/m-p/6928301#M1485373</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Dear SAP HR users,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Kindly assist me on this matter. Let say I have an internal table like below;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;ATEXT                  STDAZ&lt;/P&gt;&lt;P&gt;Annual Leave        8.00&lt;/P&gt;&lt;P&gt;Sick Leave            4.00&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Is it possible to create another table based on the table above for example;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Annual Leave Sick Leave&lt;/P&gt;&lt;P&gt;   8                      4&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks in advance !&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 11 May 2010 12:29:48 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/create-a-dynamic-internal-table-horizontally-from-another-internal-table/m-p/6928301#M1485373</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2010-05-11T12:29:48Z</dc:date>
    </item>
    <item>
      <title>Re: Create a dynamic internal table horizontally from another internal table</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/create-a-dynamic-internal-table-horizontally-from-another-internal-table/m-p/6928302#M1485374</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Yes, this is feasible. Refer the below snippet.&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
DATA: BEGIN OF itab OCCURS 0,
        atext TYPE atext,
        stdaz TYPE stdaz,
      END OF itab.

DATA: it_fcat TYPE lvc_t_fcat WITH HEADER LINE.
DATA: l_fieldname TYPE string,
      l_idx(3) TYPE n,
      l_lines type i.
DATA: r_new_tab TYPE REF TO data.

FIELD-SYMBOLS: &amp;lt;new_tab&amp;gt; TYPE INDEX TABLE,
               &amp;lt;wa_tab&amp;gt; TYPE ANY,
               &amp;lt;comp&amp;gt; TYPE ANY.

itab-atext = 'Annual Leave'.
itab-stdaz = 8.
APPEND itab.
itab-atext = 'Sick Leave'.
itab-stdaz = 4.
APPEND itab.


LOOP AT itab.
  "new field name
  it_fcat-fieldname = itab-atext.
  replace ` ` in it_fcat-fieldname with ''. "AnnualLeave, SickLeave
  "make this fiels of same type as PA2006-STDAZ
  it_fcat-ref_field = 'STDAZ'.
  it_fcat-ref_table = 'PA2001'.
  it_fcat-scrtext_s = it_fcat-scrtext_m = it_fcat-scrtext_l = itab-atext. "Annnual Leave, Sick Leave
  APPEND it_fcat.
ENDLOOP.

"create this new table
CALL METHOD cl_alv_table_create=&amp;gt;create_dynamic_table
  EXPORTING
    it_fieldcatalog           = it_fcat[]
  IMPORTING
    ep_table                  = r_new_tab
  EXCEPTIONS
    generate_subpool_dir_full = 1
    OTHERS                    = 2.

"address the content of that new empty table
ASSIGN r_new_tab-&amp;gt;* TO &amp;lt;new_tab&amp;gt;.

"now you need to get for each 2 lines in ITAB one line in &amp;lt;NEW_TAB&amp;gt;
DESCRIBE TABLE itab lines l_lines.
l_lines = l_lines / 2.
l_idx = 1.

DO l_lines TIMES. "number of records in itab / 2
  APPEND INITIAL LINE TO &amp;lt;new_tab&amp;gt; ASSIGNING &amp;lt;wa_tab&amp;gt;.

  DO 2 TIMES.
    READ TABLE itab INDEX l_idx.
    IF sy-subrc = 0.
      ASSIGN COMPONENT sy-index OF STRUCTURE &amp;lt;wa_tab&amp;gt; TO &amp;lt;comp&amp;gt;.
      IF sy-subrc = 0.
        &amp;lt;comp&amp;gt; = itab-stdaz.
      ENDIF.
      l_idx = l_idx + 1.
    ENDIF.
  ENDDO.
ENDDO.
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;As you may see you can't really have columns in &amp;lt;NEW_TAB&amp;gt; named "Annual Leave" and "Sick Leave" as there musn't be a space in names. Anyhow if you replace it with "AnnualLeave" or "SickLeave" this is acceptable. Please note, however, that these names must be unique, so that the new column names are also unique.&lt;/P&gt;&lt;P&gt;The rest is just a matter of generating new dynamic table and moving data from ITAB table to &amp;lt;new_tab&amp;gt;.&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, 11 May 2010 14:34:29 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/create-a-dynamic-internal-table-horizontally-from-another-internal-table/m-p/6928302#M1485374</guid>
      <dc:creator>MarcinPciak</dc:creator>
      <dc:date>2010-05-11T14:34:29Z</dc:date>
    </item>
    <item>
      <title>Re: Create a dynamic internal table horizontally from another internal table</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/create-a-dynamic-internal-table-horizontally-from-another-internal-table/m-p/6928303#M1485375</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;You can also create a  Create a dynamic structure or RTTS type object and then Create a dynamic internal table and workarea using the RTTS type object.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Refer to my article for a code sample and explanation-&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="http://divulgesap.com/blog.php?p=MTI4" target="test_blank"&gt;http://divulgesap.com/blog.php?p=MTI4&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Hope it helps.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Ravikiran&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 11 May 2010 14:54:20 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/create-a-dynamic-internal-table-horizontally-from-another-internal-table/m-p/6928303#M1485375</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2010-05-11T14:54:20Z</dc:date>
    </item>
    <item>
      <title>Re: Create a dynamic internal table horizontally from another internal table</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/create-a-dynamic-internal-table-horizontally-from-another-internal-table/m-p/6928304#M1485376</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks for the help so far, I've managed to create the dynamic table and now I need to display it in ALV, anyone can help me on this ?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The scenario:&lt;/P&gt;&lt;P&gt;First table containing all the necessary information such as the pernr, age, etc etc&lt;/P&gt;&lt;P&gt;Declared with a table T_DATA&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Second table containing leave information where it stores the pernr and the values according to the absence type.&lt;/P&gt;&lt;P&gt;Declared dynamic table &amp;lt;FS_ITAB&amp;gt;, the sample;&lt;/P&gt;&lt;P&gt;Pernr LT_0100 LT_0101 LT_0132&lt;/P&gt;&lt;P&gt;141 0 0 4&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;How should I display this two table in ALV ? So far I've managed to display the first table without any problem but im stucked on the second table.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Should I combined both tables first then display in ALV ? Or do a separate command for ALV for both tables.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks in advance !&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 14 May 2010 02:56:00 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/create-a-dynamic-internal-table-horizontally-from-another-internal-table/m-p/6928304#M1485376</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2010-05-14T02:56:00Z</dc:date>
    </item>
    <item>
      <title>Re: Create a dynamic internal table horizontally from another internal table</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/create-a-dynamic-internal-table-horizontally-from-another-internal-table/m-p/6928305#M1485377</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Yes, you have to combine both tables' structures into one new table, move data from both to corresponding fields in this new table and then pass that one to ALV. &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>Fri, 14 May 2010 07:05:08 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/create-a-dynamic-internal-table-horizontally-from-another-internal-table/m-p/6928305#M1485377</guid>
      <dc:creator>MarcinPciak</dc:creator>
      <dc:date>2010-05-14T07:05:08Z</dc:date>
    </item>
    <item>
      <title>Re: Create a dynamic internal table horizontally from another internal table</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/create-a-dynamic-internal-table-horizontally-from-another-internal-table/m-p/6928306#M1485378</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Understabd the following code to populate the dynamic internal table&lt;/P&gt;&lt;P&gt;call method cl_alv_table_create=&amp;gt;create_dynamic_table&lt;/P&gt;&lt;P&gt;exporting&lt;/P&gt;&lt;P&gt;it_fieldcatalog = y_i_fcat&lt;/P&gt;&lt;P&gt;importing&lt;/P&gt;&lt;P&gt;ep_table = y_i_dyn.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;assign y_i_dyn-&amp;gt;* to &amp;lt;y_i_dyn&amp;gt;.&lt;/P&gt;&lt;P&gt;create data y_wa_dyn like line of &amp;lt;y_i_dyn&amp;gt;.&lt;/P&gt;&lt;P&gt;assign y_wa_dyn-&amp;gt;* to &amp;lt;y_wa_dyn&amp;gt;.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;*Move data from Final table to dynamic table &amp;lt;y_i_dyn&amp;gt;&lt;/P&gt;&lt;P&gt;loop at y_i_final into y_wa_final.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;assign component 'VBELN' of structure &amp;lt;y_wa_dyn&amp;gt; to &amp;lt;y_v_fld&amp;gt;.&lt;/P&gt;&lt;P&gt;&amp;lt;y_v_fld&amp;gt; = y_wa_final-vbeln.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;y_lv_cntr = y_lv_cntr + 1.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;concatenate 'PARVW' '-' y_lv_cntr into y_lv_parvw.&lt;/P&gt;&lt;P&gt;assign component y_lv_parvw of structure &amp;lt;y_wa_dyn&amp;gt; to &amp;lt;y_v_fld&amp;gt;.&lt;/P&gt;&lt;P&gt;&amp;lt;y_v_fld&amp;gt; = y_wa_final-parvw.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;concatenate 'KUNNR' '-' y_lv_cntr into y_lv_kunnr.&lt;/P&gt;&lt;P&gt;assign component y_lv_kunnr of structure &amp;lt;y_wa_dyn&amp;gt; to &amp;lt;y_v_fld&amp;gt;.&lt;/P&gt;&lt;P&gt;&amp;lt;y_v_fld&amp;gt; = y_wa_final-kunnr.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;concatenate 'ADRNR' '-' y_lv_cntr into y_lv_adrnr.&lt;/P&gt;&lt;P&gt;assign component y_lv_adrnr of structure &amp;lt;y_wa_dyn&amp;gt; to &amp;lt;y_v_fld&amp;gt;.&lt;/P&gt;&lt;P&gt;&amp;lt;y_v_fld&amp;gt; = y_wa_final-adrnr.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;at end of vbeln.&lt;/P&gt;&lt;P&gt;append &amp;lt;y_wa_dyn&amp;gt; to &amp;lt;y_i_dyn&amp;gt;.&lt;/P&gt;&lt;P&gt;free: &amp;lt;y_wa_dyn&amp;gt;,&amp;lt;y_v_fld&amp;gt;.&lt;/P&gt;&lt;P&gt;clear y_lv_cntr.&lt;/P&gt;&lt;P&gt;endat.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;endloop.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;P&gt;RK&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 14 May 2010 07:09:31 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/create-a-dynamic-internal-table-horizontally-from-another-internal-table/m-p/6928306#M1485378</guid>
      <dc:creator>rthoodi</dc:creator>
      <dc:date>2010-05-14T07:09:31Z</dc:date>
    </item>
    <item>
      <title>Re: Create a dynamic internal table horizontally from another internal table</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/create-a-dynamic-internal-table-horizontally-from-another-internal-table/m-p/6928307#M1485379</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks for the help guys.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 15 Jun 2010 08:10:26 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/create-a-dynamic-internal-table-horizontally-from-another-internal-table/m-p/6928307#M1485379</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2010-06-15T08:10:26Z</dc:date>
    </item>
  </channel>
</rss>

