‎2010 Mar 18 10:51 AM
Hi all,
Its embarassing as this is a continuation of something from my previous post.But unfortunately I have to do this as Iam new To ABAP and I have to meet a deadline tommorow.
Have an itab structure as follows(Thanks to marcin)
TYPES:BEGIN OF t_itab,
matnr TYPE matnr,
land TYPE c,
month(5) TYPE c,
qua TYPE p DECIMALS 2,
END OF t_itab.
TYPES: tt_itab TYPE TABLE OF t_itab WITH KEY matnr land month.The output of the itab is as follows:
100 A 11.09 5,00
100 A 12.09 0,00
100 A 01.10 5,00
100 A 02.10 4,00
100 A 03.10 5,00
100 B 11.09 0,00
100 B 12.09 5,00
100 B 01.10 0,00
100 B 02.10 0,00
100 B 03.10 0,00
100 C 11.09 4,00
100 C 12.09 0,00
100 C 01.10 0,00
100 C 02.10 0,00
100 C 03.10 0,00I have to write a "header" as follows using "Write" statement(In Bold) and arrange,sum up the values of the itab and show it as below.
The last "Sum" row if possible in bold .
Any thing to make it look better in the screen is welcome.
The idea for me was to get the outputLines into a string(Line) and write the line to screen.Iam working on it but it is a slow process.
MaterialNumber Land 11.09 12.09 01.10 02.10 03.10 Total
100 A 5 0 5 4 5 19
100 B 0 5 0 0 0 5
100 C 4 0 0 0 0 4
Sum 9 5 5 4 5 28Thanks
P
Edited by: pazzuzu on Mar 18, 2010 11:51 AM
‎2010 Mar 18 2:33 PM
Hi
For this one you need some exercise to do it; please find the code below;
data: begin of it_output occurs 0,
matnr type matnr,
land type land1,
month1 TYPE p DECIMALS 2, "define 30 to 40 colums as per your requirement
month2 type p decimals 2,
'
'
'
month30 type p decimals 2,
end of it_output,
begin of it_fieldinfo,
fname(6),
fval(5),
end of it_fieldinfo.
field-symbols <fs_amt> type p decimals 2.
data: l_name(20).
sort t_tab by matnr land month.
loop at t_tab.
read table it_fieldinfo with key fval = month.
if sy-subrc eq 0.
concatenate 'IT_OUTPUT-' it_fieldinfo-fname into l_name.
assign (l_name) to <fs_amt>.
if <fs_amt> is assigned.
<fs_amt> = t_tab-qua.
endif.
else.
describe table it_fieldinfo.
add 1 to sy-tfill.
l_name = sy-tfill.
concatenate 'MONTH' l_name into l_name.
shift l_name left deleting leading space.
it_fieldinf0-fname = l_name+0(6).
it_fieldinfo-fval = t_tab-month.
append it_fieldinfo.
concatenate 'IT_OUTPUT-' it_fieldinfo-fname into l_name.
assign (l_name) to <fs_amt>.
if <fs_amt> is assigned.
<fs_amt> = t_tab-qua.
endif.
endif.
it_output-matnr = t_tab-matnr.
it_output-land = t_tab-land.
append it_output.
clear: it_output,
it_fieldinfo,
t_tab.
endloop.
***write header of the output
write: /2 'Material Number',
25 'Land'.
data: l_val type i,
l_no type i.
l_val = 25.
loop at it_fieldinfo.
add 10 to l_Val.
write at pos(10) it_fieldinfo-fval.
clear it_fieldinfo.
endloop.
***write the details
*describe table it_fieldinfo lines l_no.
loop at it_output.
write: /2 it_output-matnr,
25 it_output-land,
35 it_output-month1,
'
'
'
255 it_output-month30.
at last.
sum.
write: / 35 it_output-month1,
'
'
'
255 it_output-month30.
endat.
clear it_output.
endloop.
I hope it will solve issue. Do some logic building to stop the printing month values at exact no.of months exists in the it_fieldinfo.
Thanks
Praveen
‎2010 Mar 18 12:19 PM
Hi, Pazzuzu
Bold using Write Statement is not possible, check the bellow Sample Code for some formatting,
LOOP AT itab.
WRITE: /1(1)'|', 2(20) itab-matnr CENTERED,22(1)'|', 23(12) itab-land CENTERED, 35(1)'|', 36(8) itab-month CENTERED, 44(1) '|', 45(10) itab-qua LEFT-JUSTIFIED, 55(1) '|'.
ENDLOOP.
WRITE: /1(55) sy-uline.
TOP-OF-PAGE.
WRITE: 1(1)'|', 2(20)'MATNR' CENTERED COLOR 1,22(1)'|', 23(12)'LAND' CENTERED COLOR 1, 35(1)'|', 36(8)'MONTH' CENTERED COLOR 1, 44(1) '|', 45(10)'QUANTITY' CENTERED COLOR 1, 55(1) '|',
/1(55) sy-uline.Regards,
Faisal
‎2010 Mar 18 1:05 PM
Hi ,
The result was not as expected(not right)
It was as follows.
Also The "total" and "sum" values are not in the itab.That I have to calculate...
| MATNR | LAND | MONTH | QUANTITY |
-------------------------------------------------------
|100 | C | 11.09 |4,00 |
|100 | C | 11.09 |4,00 |
|100 | C | 11.09 |4,00 |
|100 | C | 11.09 |4,00 |
|100 | C | 11.09 |4,00 |
|100 | C | 11.09 |4,00 |
|100 | C | 11.09 |4,00 |
|100 | C | 11.09 |4,00 |
|100 | C | 11.09 |4,00 |
|100 | C | 11.09 |4,00 |
|100 | C | 11.09 |4,00 |
|100 | C | 11.09 |4,00 |
|100 | C | 11.09 |4,00 |
|100 | C | 11.09 |4,00 |
|100 | C | 11.09 |4,00 |
-------------------------------------------------------Edited by: pazzuzu on Mar 18, 2010 2:06 PM
Edited by: pazzuzu on Mar 18, 2010 2:06 PM
‎2010 Mar 18 1:28 PM
hi ,
you have to clear the wa and then you need to have those number of records in the internal table.
hope this helps,
thanks
tanmaya
‎2010 Mar 18 1:43 PM
Tried it.But not working.
The cosmetics is good but the data is not the way it should be as follows.
MaterialNumber Land 11.09 12.09 01.10 02.10 03.10 Total
100 A 5 0 5 4 5 19
100 B 0 5 0 0 0 5
100 C 4 0 0 0 0 4
Sum 9 5 5 4 5 28
‎2010 Mar 18 2:11 PM
Hi pazzuzu
try to use 3 structure, 1 for the total and 1 for the sum.
for write header try to use this code.
create une table that contain all the month.
write: 'MaterialNumber' 'Land'.
loop at I_tab.
at new month.
write: Is_tab-month.
append Is_tab-month. to lt_tab_month.
endat.
endloop.
write: 'sum'.
with the table of months you can cycle with the key month in the table that contains all the data, doing so you can calculate the sum.
regards.
Marco
‎2010 Mar 18 1:11 PM
hi P,
to bold use like this.
Format intensified on.
write: 'material number' 'land'. "like this
format intensified off.
loop at itab into wa.
write: wa-matnr wa-land. "like this
endloop.
hope this helps you.
thanks
Tanmaya
‎2010 Mar 18 2:33 PM
Hi
For this one you need some exercise to do it; please find the code below;
data: begin of it_output occurs 0,
matnr type matnr,
land type land1,
month1 TYPE p DECIMALS 2, "define 30 to 40 colums as per your requirement
month2 type p decimals 2,
'
'
'
month30 type p decimals 2,
end of it_output,
begin of it_fieldinfo,
fname(6),
fval(5),
end of it_fieldinfo.
field-symbols <fs_amt> type p decimals 2.
data: l_name(20).
sort t_tab by matnr land month.
loop at t_tab.
read table it_fieldinfo with key fval = month.
if sy-subrc eq 0.
concatenate 'IT_OUTPUT-' it_fieldinfo-fname into l_name.
assign (l_name) to <fs_amt>.
if <fs_amt> is assigned.
<fs_amt> = t_tab-qua.
endif.
else.
describe table it_fieldinfo.
add 1 to sy-tfill.
l_name = sy-tfill.
concatenate 'MONTH' l_name into l_name.
shift l_name left deleting leading space.
it_fieldinf0-fname = l_name+0(6).
it_fieldinfo-fval = t_tab-month.
append it_fieldinfo.
concatenate 'IT_OUTPUT-' it_fieldinfo-fname into l_name.
assign (l_name) to <fs_amt>.
if <fs_amt> is assigned.
<fs_amt> = t_tab-qua.
endif.
endif.
it_output-matnr = t_tab-matnr.
it_output-land = t_tab-land.
append it_output.
clear: it_output,
it_fieldinfo,
t_tab.
endloop.
***write header of the output
write: /2 'Material Number',
25 'Land'.
data: l_val type i,
l_no type i.
l_val = 25.
loop at it_fieldinfo.
add 10 to l_Val.
write at pos(10) it_fieldinfo-fval.
clear it_fieldinfo.
endloop.
***write the details
*describe table it_fieldinfo lines l_no.
loop at it_output.
write: /2 it_output-matnr,
25 it_output-land,
35 it_output-month1,
'
'
'
255 it_output-month30.
at last.
sum.
write: / 35 it_output-month1,
'
'
'
255 it_output-month30.
endat.
clear it_output.
endloop.
I hope it will solve issue. Do some logic building to stop the printing month values at exact no.of months exists in the it_fieldinfo.
Thanks
Praveen
‎2010 Mar 18 2:53 PM
I think I have mislead you guys..
From the itab(Example itab output in 1st post) I want to extract each item by land ,append to a string and then use the "write" statement to write this line out.
as follows:
Ofcourse I want to calculate "Sum" and total.
So each line has to be a string for me.
MaterialNumber Land 11.09 12.09 01.10 02.10 03.10 Total
100 A 5 0 5 4 5 19
100 B 0 5 0 0 0 5
100 C 4 0 0 0 0 4
Sum 9 5 5 4 5 28My code is arranged so that i cant create a itab out of it because date headers are created dynamic.So thats why by looping through the itab ,I could store the lines in an string itab and then write it out.
‎2010 Mar 18 4:01 PM
Trying out praveens code.May be that will help me....
Praveen,I cant create something like the following co's by months are dynamic.The user gives the time period in the selection range at run time.
Thats why I want to write out the line as a string.
data: begin of it_output occurs 0,
matnr type matnr,
land type land1,
month1 TYPE p DECIMALS 2, "define 30 to 40 colums as per your requirement
month2 type p decimals 2,
'
'
'
month30 type p decimals 2,
end of it_output,
begin of it_fieldinfo,
fname(6),
fval(5),
end of it_fieldinfo.Edited by: pazzuzu on Mar 18, 2010 5:10 PM
‎2010 Mar 18 4:27 PM
Praveen,could u supply me with a running code....
Edited by: pazzuzu on Mar 18, 2010 5:30 PM
‎2010 Mar 18 5:03 PM
I think I made a mess out of my question.Using "write" statements helped.But the real question was left unanswered.
Will make a question regarding only this one....
Thanks a lot guys...
‎2010 Mar 19 4:48 AM
You can use the dynamic table creation. If this is the case, you can go for ALV, which is the best option.
Code for dynamic table creation.
FIELD-SYMBOLS: <dyn_table> type standard table,
<dyn_table1> type standard table,
<dyn_wa>,
<dyn_field> TYPE any,
<l_amt> TYPE faglflexa-hsl.
data: dy_table type ref to data,
dy_table1 type ref to data,
dy_line type ref to data,
xfc type lvc_s_fcat,
ifc type lvc_t_fcat.
xfc-fieldname = 'HEAD1'.
xfc-datatype = 'CHAR'.
xfc-inttype = 'C'.
xfc-intlen = '50'.
APPEND xfc to ifc.
xfc-fieldname = 'HEAD2'.
APPEND xfc to ifc.
xfc-fieldname = 'HEAD3'.
xfc-intlen = '10'.
APPEND xfc to ifc.
xfc-fieldname = 'HEAD4'.
xfc-intlen = '6'.
APPEND xfc to ifc.
xfc-fieldname = 'HEAD5'.
APPEND xfc to ifc.
CLEAR xfc.
CALL METHOD cl_alv_table_create=>create_dynamic_table
EXPORTING
it_fieldcatalog = ifc
IMPORTING
ep_table = dy_table
* EXCEPTIONS
* generate_subpool_dir_full = 1
* others = 2
.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
assign dy_table->* to <dyn_table>.
* Create dynamic work area and assign to FS
create data dy_line like line of <dyn_table>.
assign dy_line->* to <dyn_wa>.
CONCATENATE 'HEAD' l_col INTO l_text.
ASSIGN COMPONENT l_text OF STRUCTURE <dyn_wa> TO <dyn_field>.