‎2010 Mar 16 10:16 PM
03.11.2009 - 05.03.2010.
Have calculated it and stored it in an itab(say itab1) as follows:
Meaterial land month Qtydelivered
100 A nov.09 5
100 A Dec.09 10
100 A Feb.10 15
100 B Dec.09 5
Now from the above itab,I have to get a display as in the attached image.
Please see the image link:
[http://img195.imageshack.us/img195/8176/test1nr.jpg]
Using Write statements I have to write it, format it, and align it as in the image.
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.
I calculated the above months using selection option "Low" ,"hIGH" parameters and using some Function module.
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.
this itab2 structure has to be filled from itab1 by looping through itab1.
Have structure as follows where Iam storing the required months
In my example the range was between
03.11.2009 - 05.03.2010.
Period-Month mapping itab:
01 - Nov.09
02 - Dec.09
03 - Jan.10
04 - Feb.10
05 - Mar.10
Now I have to create an itab as follows:
Itab row structure:
Material
Land
Qty_Period01 //should store the quantity from november.
Qty_Period02
...
Qty_Period13
How could I accomplish this or how can I create such an itab....
Thanks a lot...
A sample code would be very helpful.....
P
‎2010 Mar 17 6:51 AM
Hi again,
Apologies the declaration of lt_output_components in the first post should be type cl_abap_structdescr=>component_table.
In your the first code block- How will I create my basetype components,I cant see the "Material" or "Land" in the code.
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.
How to add dynamic columns.
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:
FIELD-SYMBOLS: <comp> like line of lt_output_components.
<comp>-name = 'QTY_PERIOD01'. "You will need to generate the field name dynamically, obviously
<comp>-type = cl_abap_elemdescr=>get_p( p_length = 11 "For a packed decimal type
p_decimals = 2 ).
append <comp> to lt_output_components.
create data lo_output_table type handle lo_new_table.// this is the itab,right
create data lo_output_line type handle lo_new_type. //this is the wa,right.
Correct.
Also how to write things to the screen from lo_output_table using write statement.
You need to use a field symbol to do this.
FIELD-SYMBOL: <field> type any.
assign component 'QTY_PERIOD01' of structure lo_output_line to <field>.
Write: / <field>.
It can be tricky but it's worth it to get the result.
Cheers
Alex
‎2010 Mar 16 11:13 PM
Howdy,
Start with a base type which contains the fixed columns for the itab, eg Material, Land from your example.
Then generate a description of your base type.
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=>describe_by_data( ls_output ).
lo_structdesc ?= lo_typedescr.
lt_output_components = lo_structdescr->components[]
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.
Once lt_output_components has all the fields you need in it, create the dynamic table and table.
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=>create( lt_output_components ).
lo_new_table = cl_abap_tabledescr=>create( p_line_type = lo_new_type
p_table_kind = cl_abap_tabledescr=>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.
Cheers
Alex
‎2010 Mar 17 6:42 AM
Howdy,
Alex could you be little bit more precise :).Iam new to ABAP,coming from the java world.
lo_typedescr ?= cl_abap_structdescr=>describe_by_data( ls_output ).
lo_structdesc ?= lo_typedescr.
lt_output_components = lo_structdescr->components[]
In your the first code block- How will I create my basetype components,I cant see the "Material" or "Land" in the code.
How to add dynamic columns.
In the end if I create these 2 statements
create data lo_output_table type handle lo_new_table.// this is the itab,right
create data lo_output_line type handle lo_new_type. //this is the wa,right.
How will I append things to this itab.Will it work the same way as like static itabs.
lo_output_line-matnr = '1000'
lo_output_line-Nov09 = 25
lo_output_line-Dec09 = 25append lo_output_line into lo_output_table.
Also how to write things to the screen from lo_output_table using write statement.
loop at lo_output_table to lo_output_line .
write: / lo_output_line-matr lo_output_line-Nov09
endloop.If I want an itab structure as follows
Material -static field
Land - static field
Qty_Nov09 //dynamic Depends on the time range.
Qty_Dec09
...
Qty_Period13
Total- static fieldwill 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.
Would really appreciate it pal.
‎2010 Mar 17 6:51 AM
Hi again,
Apologies the declaration of lt_output_components in the first post should be type cl_abap_structdescr=>component_table.
In your the first code block- How will I create my basetype components,I cant see the "Material" or "Land" in the code.
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.
How to add dynamic columns.
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:
FIELD-SYMBOLS: <comp> like line of lt_output_components.
<comp>-name = 'QTY_PERIOD01'. "You will need to generate the field name dynamically, obviously
<comp>-type = cl_abap_elemdescr=>get_p( p_length = 11 "For a packed decimal type
p_decimals = 2 ).
append <comp> to lt_output_components.
create data lo_output_table type handle lo_new_table.// this is the itab,right
create data lo_output_line type handle lo_new_type. //this is the wa,right.
Correct.
Also how to write things to the screen from lo_output_table using write statement.
You need to use a field symbol to do this.
FIELD-SYMBOL: <field> type any.
assign component 'QTY_PERIOD01' of structure lo_output_line to <field>.
Write: / <field>.
It can be tricky but it's worth it to get the result.
Cheers
Alex
‎2010 Mar 17 12:56 PM
Alex Thanks a lot for the effort...Iam closing this thread . These things look a bit complicated as a beginner for me....
A different idea has struck me.I will be making a post on it soon.If time please have a look....