2009 Apr 03 3:40 PM
Dear friend,
We are using material group code with a style
XXXYYZZZ
XXX = Main Group
YY = Sub Group
ZZZ = Detail
When I get some report using material group I can only display it with all of material group code.
Can I calculate sub totals with part of this style?
XX1YYZZZ
............
XX2YYZZZ
........
I want to calculate a sub total just for XXX . Is that possible?
Thanks
Mehmet
2009 Apr 03 3:49 PM
Yup, with this:
"first do sum for this column
ls_fieldcat-fieldname = 'MAIN_GROUP_FIELD'.
ls_fieldcat-do_sum = 'X'.
append ls_fieldcat to lt_fieldcat.
"then do subtotal for this column
ls_sort-fieldname = 'MAIN_GROUP_FIELD'.
ls_sort-subtot = 'X'.
APPEND ls_sort TO lt_sort.
CALL METHOD lr_alv_grid->set_table_for_first_display
....
CHANGING
...
it_fieldcatalog = lt_fieldcat
it_sort = lt_sort
...
Regards
Marcin
2009 Apr 03 6:57 PM
Thanks Marcin for your interest,
But all of data is in same field.
For example
Material Group Qnt.
RAWAAA01 100 KG
RAWAAA02 199 KG
RAWAAB01 105 KG
BSHAAA01 150 KG
This is my raw data. In this list I have just 2 column. Now; Can I display this data like below?
RAW____404 KG
AAA___299 KG
01___100 KG
02___199 KG
AAB___105 KG
BSH____150 KG
AAA__150 KG
01__150 KG
2009 Apr 03 10:34 PM
Hi Mehmet,
I don't think there is a possibility to do a subtotal based on substring in one field (what you apparently want to achieve). You can however, add 3 additional fields to your itab which would hold appropriate substrings from this field. Then you can set subtotals (as described before) for all these 3 columns, but set them as technical columns (so not for display). Instead you would still display your MATERIAL_GROUP column which should be splitted in corresponding spot. Look at this code snippet
"first add your 3 fields on the beginning of the table
data: begin of itab occurs 0,
main_group(3) type c,
sub_group(2) type c,
detail(3) type c,
material_group ... "your current field
...
end of itab.
"split the material group among 3 new fields
itab-main_group = itab-material_group(3).
itab-sub_group = itab-material_group+3(2).
itab-detail = itab-material_group+5(2).
"in fieldcatalog set QNT field to store the (sub)total
ls_fieldcat-fieldname = 'QNT'.
ls_fieldcat-do_sum = 'X'.
"...and 3 new fields to be only technical ones
ls_fieldcat-tech = 'X'.
ls_fieldcat-fieldname = 'MAIN_GROUP'.
append ls_fieldcat to lt_fieldcat.
ls_fieldcat-fieldname = 'SUB_GROUP'.
append ls_fieldcat to lt_fieldcat.
ls_fieldcat-fieldname = 'DETAIL'.
append ls_fieldcat to lt_fieldcat.
"now set sorts according to 3 new fields
ls_sort-fieldname = 'MAIN_GROUP'.
ls_sort-subtot = 'X'.
APPEND ls_sort TO lt_sort.
ls_sort-fieldname = 'SUB_GROUP'.
ls_sort-subtot = 'X'.
APPEND ls_sort TO lt_sort.
ls_sort-fieldname = 'DETAIL'.
ls_sort-subtot = 'X'.
APPEND ls_sort TO lt_sort.
CALL METHOD lr_alv_grid->set_table_for_first_display
...
This way technical columns should define subtotals but won't be provided themselves on screen. Instead you have your one column devided in the way you want. Frankly I have never tried that so far, so I am curious of the result too. Please let me know if that works.
Regards
Marcin