<?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 itab structure creation in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/itab-structure-creation/m-p/6739410#M1458422</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;03.11.2009 - 05.03.2010.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Have calculated it and stored it in an itab(say itab1) as follows:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Meaterial  land  month    Qtydelivered&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;100         A    nov.09    5&lt;/P&gt;&lt;P&gt;100         A    Dec.09    10&lt;/P&gt;&lt;P&gt;100         A    Feb.10    15&lt;/P&gt;&lt;P&gt;100         B    Dec.09    5&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Now from the above itab,I have to get a display as in the attached image.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Please see the image link:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;[http://img195.imageshack.us/img195/8176/test1nr.jpg]&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Using Write statements I have to write it, format it, and align it as in the image.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I write the column headers (Meaterial,land and months) using the write statement. Please note that the "months" column headers are dynamic depending on the user input.&lt;/P&gt;&lt;P&gt;I calculated the above months using selection option "Low" ,"hIGH" parameters and using some Function module.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Now I have to create a new itab structure(itab2) that matches exactly the column headers so that while writing it to screen it comes under the corresponding months.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;this itab2 structure has to be filled from itab1 by looping through itab1.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Have structure as follows where Iam storing the required months&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In my example the range was between &lt;/P&gt;&lt;P&gt;03.11.2009 - 05.03.2010.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Period-Month mapping itab: &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;01 - Nov.09&lt;/P&gt;&lt;P&gt;02 - Dec.09&lt;/P&gt;&lt;P&gt;03 - Jan.10&lt;/P&gt;&lt;P&gt;04 - Feb.10&lt;/P&gt;&lt;P&gt;05 - Mar.10&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Now I have to create an itab as follows:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Itab row structure:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Material&lt;/P&gt;&lt;P&gt;Land&lt;/P&gt;&lt;P&gt;Qty_Period01 //should store the quantity from november.&lt;/P&gt;&lt;P&gt;Qty_Period02&lt;/P&gt;&lt;P&gt;...&lt;/P&gt;&lt;P&gt;Qty_Period13&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;How could I accomplish this or how can I create such an itab....&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks a lot...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;A sample code would be very helpful.....&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;P&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 16 Mar 2010 22:16:20 GMT</pubDate>
    <dc:creator>Former Member</dc:creator>
    <dc:date>2010-03-16T22:16:20Z</dc:date>
    <item>
      <title>itab structure creation</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/itab-structure-creation/m-p/6739410#M1458422</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;03.11.2009 - 05.03.2010.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Have calculated it and stored it in an itab(say itab1) as follows:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Meaterial  land  month    Qtydelivered&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;100         A    nov.09    5&lt;/P&gt;&lt;P&gt;100         A    Dec.09    10&lt;/P&gt;&lt;P&gt;100         A    Feb.10    15&lt;/P&gt;&lt;P&gt;100         B    Dec.09    5&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Now from the above itab,I have to get a display as in the attached image.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Please see the image link:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;[http://img195.imageshack.us/img195/8176/test1nr.jpg]&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Using Write statements I have to write it, format it, and align it as in the image.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I write the column headers (Meaterial,land and months) using the write statement. Please note that the "months" column headers are dynamic depending on the user input.&lt;/P&gt;&lt;P&gt;I calculated the above months using selection option "Low" ,"hIGH" parameters and using some Function module.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Now I have to create a new itab structure(itab2) that matches exactly the column headers so that while writing it to screen it comes under the corresponding months.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;this itab2 structure has to be filled from itab1 by looping through itab1.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Have structure as follows where Iam storing the required months&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In my example the range was between &lt;/P&gt;&lt;P&gt;03.11.2009 - 05.03.2010.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Period-Month mapping itab: &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;01 - Nov.09&lt;/P&gt;&lt;P&gt;02 - Dec.09&lt;/P&gt;&lt;P&gt;03 - Jan.10&lt;/P&gt;&lt;P&gt;04 - Feb.10&lt;/P&gt;&lt;P&gt;05 - Mar.10&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Now I have to create an itab as follows:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Itab row structure:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Material&lt;/P&gt;&lt;P&gt;Land&lt;/P&gt;&lt;P&gt;Qty_Period01 //should store the quantity from november.&lt;/P&gt;&lt;P&gt;Qty_Period02&lt;/P&gt;&lt;P&gt;...&lt;/P&gt;&lt;P&gt;Qty_Period13&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;How could I accomplish this or how can I create such an itab....&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks a lot...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;A sample code would be very helpful.....&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;P&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 16 Mar 2010 22:16:20 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/itab-structure-creation/m-p/6739410#M1458422</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2010-03-16T22:16:20Z</dc:date>
    </item>
    <item>
      <title>Re: itab structure creation</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/itab-structure-creation/m-p/6739411#M1458423</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Howdy,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Start with a base type which contains the fixed columns for the itab, eg Material, Land from your example.&lt;/P&gt;&lt;P&gt;Then generate a description of your base type.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
TYPE-POOLS: abap.

DATA:      l_output type ty_base_type,
           lo_typedescr type ref to cl_abap_typedescr,
           lo_structdescr type ref to cl_abap_structdescr,
           lt_output_components type abap_compdescr_tab.


lo_typedescr ?= cl_abap_structdescr=&amp;gt;describe_by_data( ls_output ).
lo_structdesc ?= lo_typedescr.
lt_output_components = lo_structdescr-&amp;gt;components[]
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The table lt_output_components now has a list of the components of your base type.  Add the dynamic columns you need to lt_output_components, eg QTY_PERIOD01, QTY_PERIOD02 etc.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Once lt_output_components has all the fields you need in it, create the dynamic table and table.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
DATA:      lo_new_type type ref to cl_abap_structdescr,
           lo_new_table type ref to cl_abap_tabledescr,
           lt_output_table type ref to data,
           l_output_line   type ref to data.

lo_new_type = cl_abap_structdescr=&amp;gt;create( lt_output_components ).
lo_new_table = cl_abap_tabledescr=&amp;gt;create( p_line_type = lo_new_type
                                                                          p_table_kind = cl_abap_tabledescr=&amp;gt;table_kind_std
                                                                          p_unique = abap_false ).

create data lo_output_table type handle lo_new_table.
create data lo_output_line type handle lo_new_type.
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Cheers&lt;/P&gt;&lt;P&gt;Alex&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 16 Mar 2010 23:13:49 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/itab-structure-creation/m-p/6739411#M1458423</guid>
      <dc:creator>alex_cook</dc:creator>
      <dc:date>2010-03-16T23:13:49Z</dc:date>
    </item>
    <item>
      <title>Re: itab structure creation</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/itab-structure-creation/m-p/6739412#M1458424</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Howdy,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Alex could you be little bit more precise :).Iam new to ABAP,coming from the java world.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;lo_typedescr ?= cl_abap_structdescr=&amp;gt;describe_by_data( ls_output ).&lt;/P&gt;&lt;P&gt;lo_structdesc ?= lo_typedescr.&lt;/P&gt;&lt;P&gt;lt_output_components = lo_structdescr-&amp;gt;components[]&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In your the first code block- How will I create my basetype components,I cant see the "Material" or "Land" in the code.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;How to add dynamic columns.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In the end if I create these 2 statements&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;create data lo_output_table type handle lo_new_table.// this is the itab,right&lt;/P&gt;&lt;P&gt;create data lo_output_line type handle lo_new_type. //this is the wa,right.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;How will I append things to this itab.Will it work the same way as like static itabs.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;lo_output_line-matnr = '1000'
lo_output_line-Nov09 = 25
lo_output_line-Dec09 = 25&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;append lo_output_line into lo_output_table.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Also how to write things to the screen from lo_output_table using write statement.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;loop at lo_output_table to lo_output_line .

write: / lo_output_line-matr lo_output_line-Nov09 

endloop.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If I want an itab structure as follows&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;Material -static field
Land - static field
Qty_Nov09 //dynamic Depends on the time range.
Qty_Dec09
...
Qty_Period13

Total- static field&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;will it be possible for you to give me a working sample code  to create the above itab and writing and reading from it as well.&lt;/P&gt;&lt;P&gt;Would really appreciate it pal.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 17 Mar 2010 06:42:00 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/itab-structure-creation/m-p/6739412#M1458424</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2010-03-17T06:42:00Z</dc:date>
    </item>
    <item>
      <title>Re: itab structure creation</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/itab-structure-creation/m-p/6739413#M1458425</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi again,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Apologies the declaration of lt_output_components in the first post should be type cl_abap_structdescr=&amp;gt;component_table.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;In your the first code block- How will I create my basetype components,I cant see the "Material" or "Land" in the code.&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;ls_output should be of a type that contains your base fields "Material" and "Land" - it can be a data dictionary structure or a local type, whatever your preference.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;How to add dynamic columns.&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;After you do the first lot of code, you just need to add the fieldnames you want to the table lt_output_components, eg QTY_PERIOD01 etc.  It's just an internal table so add it something like this:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
FIELD-SYMBOLS: &amp;lt;comp&amp;gt; like line of lt_output_components.
&amp;lt;comp&amp;gt;-name = 'QTY_PERIOD01'.            "You will need to generate the field name dynamically, obviously
&amp;lt;comp&amp;gt;-type = cl_abap_elemdescr=&amp;gt;get_p( p_length = 11     "For a packed decimal type
                                                                        p_decimals = 2 ).
append &amp;lt;comp&amp;gt; to lt_output_components.
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;create data lo_output_table type handle lo_new_table.// this is the itab,right&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;create data lo_output_line type handle lo_new_type. //this is the wa,right.&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Correct.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;Also how to write things to the screen from lo_output_table using write statement.&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You need to use a field symbol to do this.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
FIELD-SYMBOL: &amp;lt;field&amp;gt; type any.

assign component 'QTY_PERIOD01' of structure lo_output_line to &amp;lt;field&amp;gt;.
Write: / &amp;lt;field&amp;gt;.
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;It can be tricky but it's worth it to get the result.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Cheers&lt;/P&gt;&lt;P&gt;Alex&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 17 Mar 2010 06:51:38 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/itab-structure-creation/m-p/6739413#M1458425</guid>
      <dc:creator>alex_cook</dc:creator>
      <dc:date>2010-03-17T06:51:38Z</dc:date>
    </item>
    <item>
      <title>Re: itab structure creation</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/itab-structure-creation/m-p/6739414#M1458426</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Alex Thanks a lot for the effort...Iam closing this thread . These things look a bit complicated as a beginner for me....&lt;/P&gt;&lt;P&gt;A different idea has struck me.I will be making a post on it soon.If time please have a look....&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 17 Mar 2010 12:56:44 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/itab-structure-creation/m-p/6739414#M1458426</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2010-03-17T12:56:44Z</dc:date>
    </item>
  </channel>
</rss>

