‎2008 Aug 18 10:35 AM
Hi All,
I have a requirement to sort an ALV grid and get the subtotal according to an unique combination of keys.
The subtotal should be based on an unique combination of
cost center, internal order and product.
For example:
cost center, internal order, product, amount
25110 550145 100 50000
25110 550145 100 75000
Cost center 25110 125000
25110 550145 200 5000
Cost center 25110 5000
25110 650021 300 30000
Cost center 25110 30000
35100 550145 150 50000
35100 550145 200 6000
Cost center 35100 56000
Edited by: The Iceman on Aug 18, 2008 11:38 AM
‎2008 Aug 18 11:24 AM
This is what i am doing currently; it wont sort properly, am i doing something wrong here?
wa_sort-fieldname = 'RZZFPROD1'.
wa_sort-tabname = 'INT_OUTPUT'.
wa_sort-spos = '01'.
wa_sort-up = 'X'.
wa_sort-subtot = 'X'.
APPEND wa_sort TO int_sort.
CLEAR wa_sort.
wa_sort-fieldname = 'USER0'.
wa_sort-tabname = 'INT_OUTPUT'.
wa_sort-spos = '02'.
wa_sort-up = 'X'.
wa_sort-subtot = 'X'.
APPEND wa_sort TO int_sort.
CLEAR wa_sort.
wa_sort-fieldname = 'RCNTR1'.
wa_sort-tabname = 'INT_OUTPUT'.
wa_sort-spos = '03'.
wa_sort-up = 'X'.
wa_sort-subtot = 'X'.
APPEND wa_sort TO int_sort.
CLEAR wa_sort.
‎2008 Aug 18 10:39 AM
‎2008 Aug 18 10:39 AM
>The subtotal should be based on an unique combination of
>cost center, internal order and product.
in that case you populate the sort table based on the fields cost center, internal order and product.
sort-fieldname = 'KOSTL'.
sort-up = 'X'.
append sort to it_sort.
sort-fieldname = 'AUFNR'.
sort-up = 'X'.
append sort to it_sort.
sort-fieldname = 'MATNR'.
sort-up = 'X'.
sort-subtot = 'X'.
append sort to it_sort.this will take care.
pass this sort table to ALV .
‎2008 Aug 18 10:41 AM
Hi,
Just go through the below link
http://www.sapdev.co.uk/reporting/alv/alvgrid_sort.htm
Thanks,
Ruthra
‎2008 Aug 18 10:41 AM
‎2008 Aug 18 10:43 AM
Hi,
try to fill sort catelogue in the following manner
DATA:
fs_sort_data TYPE slis_sortinfo_alv.
DATA:
t_sort_data TYPE slis_t_sortinfo_alv.
fs_sort_data-fieldname = 'COSTCENTRE'.
fs_sort_data-spos = '01'.
fs_sort_data-up = c_flag_x.
APPEND fs_sort_data TO t_sort_data.
fs_sort_data-fieldname = 'IORDER'.
fs_sort_data-spos = '02'.
fs_sort_data-up = c_flag_x.
APPEND fs_sort_data TO t_sort_data.
fs_sort_data-fieldname = 'PRODUCT'.
fs_sort_data-spos = '03'.
fs_sort_data-up = c_flag_x.
APPEND fs_sort_data TO t_sort_data.
And then supply table t_sort_data to it_sort in REUSE_ALV_GRID_DISPALY
Regards.
Eshwar.
‎2008 Aug 18 10:52 AM
Hi,
Use sort table.
data: ls_sort type slis_sortinfo_alv.
use as the following for which you want the sum for the key fields and append to sort internal table.Here in your case, use for first three fields you mentioned.
ls_sort-fieldname = 'fieldname'.
ls_sort-up = 'X'.
ls_sort-subtot = 'X'.
Regards,
S Raju
‎2008 Aug 18 10:57 AM
Thank you all, i have done the same way that you people have pointed out but it still doesnt work
it gives the subtotal only for a single field like cost center and not for a unique combination for all three
this is wat it gives
cost center, internal order, product, amount
25110 550145 100 50000
25110 550145 100 75000
25110 550145 200 5000
25110 650021 300 30000
Cost center 25110 160000
35100 550145 150 50000
35100 550145 200 6000
Cost center 35100 56000
This is what i want
cost center, internal order, product, amount
25110 550145 100 50000
25110 550145 100 75000
Cost center 25110 125000
25110 550145 200 5000
Cost center 25110 5000
25110 650021 300 30000
Cost center 25110 30000
35100 550145 150 50000
35100 550145 200 6000
Cost center 35100 56000
‎2008 Aug 18 11:00 AM
‎2008 Aug 18 11:07 AM
‎2008 Aug 18 11:03 AM
the collect statement would work but then i would have to change the processing in the internal table.
isnt there a way to do it through ALV directly?
‎2008 Aug 18 11:09 AM
not sure if this is what you want...but try it.
once your ALV is displayed, select the columns cost center, internal order, product using the CNTRL key and press the button "Ascending Sort". The once again select all the three columns and then click the button Subtotals(sigma/sigma).
pk
‎2008 Aug 18 11:16 AM
lol! that is totally possible but i would like to do it programatically
‎2008 Aug 18 11:20 AM
sorry for stating the obvious... but you never know with people with the kind of posts you get here
pk
‎2008 Aug 18 11:24 AM
This is what i am doing currently; it wont sort properly, am i doing something wrong here?
wa_sort-fieldname = 'RZZFPROD1'.
wa_sort-tabname = 'INT_OUTPUT'.
wa_sort-spos = '01'.
wa_sort-up = 'X'.
wa_sort-subtot = 'X'.
APPEND wa_sort TO int_sort.
CLEAR wa_sort.
wa_sort-fieldname = 'USER0'.
wa_sort-tabname = 'INT_OUTPUT'.
wa_sort-spos = '02'.
wa_sort-up = 'X'.
wa_sort-subtot = 'X'.
APPEND wa_sort TO int_sort.
CLEAR wa_sort.
wa_sort-fieldname = 'RCNTR1'.
wa_sort-tabname = 'INT_OUTPUT'.
wa_sort-spos = '03'.
wa_sort-up = 'X'.
wa_sort-subtot = 'X'.
APPEND wa_sort TO int_sort.
CLEAR wa_sort.
‎2008 Aug 18 11:25 AM
I tried from my side with a small code,. check it once..
REPORT ztest_alv_sort.
TYPE-POOLS: slis.
DATA: BEGIN OF it_data OCCURS 0,
kostl LIKE csks-kostl,
aufnr LIKE aufk-aufnr,
matnr LIKE vbap-matnr,
qty LIKE vbap-kwmeng,
END OF it_data.
DATA:
it_fieldcat TYPE slis_t_fieldcat_alv,
wa_fcat LIKE LINE OF it_fieldcat,
it_sort TYPE slis_t_sortinfo_alv,
sort LIKE LINE OF it_sort.
CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
EXPORTING
i_program_name = sy-repid
i_internal_tabname = 'IT_DATA'
i_inclname = sy-repid
CHANGING
ct_fieldcat = it_fieldcat
EXCEPTIONS
inconsistent_interface = 1
program_error = 2.
wa_fcat-do_sum = 'X'.
MODIFY it_fieldcat FROM wa_fcat TRANSPORTING do_sum
WHERE fieldname = 'QTY'.
it_data-kostl = '25110'.
it_data-aufnr = '550145'.
it_data-matnr = '50000'.
it_data-qty = '100.00'.
APPEND it_data.
it_data-kostl = '25110'.
it_data-aufnr = '550145'.
it_data-matnr = '75000'.
it_data-qty = '100.00'.
APPEND it_data.
it_data-kostl = '25110'.
it_data-aufnr = '650021'.
it_data-matnr = '30000'.
it_data-qty = '300.00'.
APPEND it_data.
it_data-kostl = '35100'.
it_data-aufnr = '550145'.
it_data-matnr = '50000'.
it_data-qty = '100.00'.
APPEND it_data.
it_data-kostl = '35100'.
it_data-aufnr = '550145'.
it_data-matnr = '60000'.
it_data-qty = '100.00'.
APPEND it_data.
sort-fieldname = 'KOSTL'.
sort-up = 'X'.
APPEND sort TO it_sort.
CLEAR sort.
sort-fieldname = 'AUFNR'.
sort-up = 'X'.
APPEND sort TO it_sort.
sort-fieldname = 'MATNR'.
sort-up = 'X'.
sort-subtot = 'X'.
APPEND sort TO it_sort.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
i_callback_program = sy-repid
it_fieldcat = it_fieldcat
it_sort = it_sort
TABLES
t_outtab = it_data
EXCEPTIONS
program_error = 1.
‎2008 Aug 18 11:34 AM
I wouldnt do something revolutionary-ily different from what you,ve done. Sadly, dont have the luxury of debugging your code to check whts amiss.
pk
‎2008 Aug 18 12:28 PM
‎2008 Aug 18 11:33 AM
Hi,
use SLIS_SORTINFO_ALV for creating one internal table.
then fill this table with waht ever the fields you want to sort.
then add this table to final alv function module(reuse_alv_list_display)
Regards,
venkat
‎2008 Aug 18 12:05 PM
Hi
Do it in this way
TYPE-POOLS: slis.
TYPES: BEGIN OF x_marc,
matnr TYPE matnr,
werks TYPE werks_d,
abc TYPE char10,
losfx TYPE losfx,
END OF x_marc.
DATA: i_marc TYPE STANDARD TABLE OF x_marc INITIAL SIZE 0,
i_marc1 TYPE STANDARD TABLE OF x_marc INITIAL SIZE 0,
wa_marc TYPE x_marc,
i_fieldcat TYPE slis_t_fieldcat_alv, "Field Catalog
wa_layout TYPE slis_layout_alv, "Field Layout
wa_fieldcat TYPE slis_fieldcat_alv, "Field Catalog
l_losfx TYPE losfx,
l_tabix TYPE i.
wa_marc-matnr = '01'.
wa_marc-werks = '11'.
wa_marc-abc = 'AAA'.
wa_marc-losfx = '1000'.
APPEND wa_marc TO i_marc.
CLEAR: wa_marc.
wa_marc-matnr = '01'.
wa_marc-werks = '11'.
wa_marc-abc = 'AAA'.
wa_marc-losfx = '2000'.
APPEND wa_marc TO i_marc.
CLEAR: wa_marc.
wa_marc-matnr = '01'.
wa_marc-werks = '11'.
wa_marc-abc = 'BBB'.
wa_marc-losfx = '1000'.
APPEND wa_marc TO i_marc.
CLEAR: wa_marc.
wa_marc-matnr = '01'.
wa_marc-werks = '11'.
wa_marc-abc = 'CCC'.
wa_marc-losfx = '1000'.
APPEND wa_marc TO i_marc.
CLEAR: wa_marc.
SORT i_marc BY matnr werks abc.
LOOP AT i_marc INTO wa_marc.
l_losfx = l_losfx + wa_marc-losfx.
APPEND wa_marc TO i_marc1.
AT END OF abc.
CLEAR: wa_marc.
wa_marc-matnr = 'Total'.
wa_marc-losfx = l_losfx.
APPEND wa_marc TO i_marc1.
CLEAR l_losfx.
ENDAT.
ENDLOOP.
Prepare ALV field catalog
PERFORM sub_populate_fieldcat USING :
'MATNR' '18' 'Material Number'(008),
'WERKS' '4' 'plant'(009),
'ABC' '10' 'type'(010),
'LOSFX' '20' 'Amount'.
Layout
wa_layout-zebra = 'X'.
Optimize the column width
wa_layout-colwidth_optimize = 'X'.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
i_callback_program = sy-repid
is_layout = wa_layout
it_fieldcat = i_fieldcat[]
TABLES
t_outtab = i_marc1[]
EXCEPTIONS
program_error = 1
OTHERS = 2.
IF sy-subrc <> 0.
ENDIF.
&----
*& Form sub_populate_fieldcat
&----
text
----
-->P_FIELDNAME text
-->P_LENGTH text
-->P_TEXT text
----
FORM sub_populate_fieldcat USING p_fieldname TYPE slis_fieldname
p_length TYPE dd03p-leng
p_text TYPE dd03p-scrtext_l.
CLEAR wa_fieldcat.
wa_fieldcat-tabname = 'I_MARC'. " Internal Table name
wa_fieldcat-fieldname = p_fieldname. " Field name
wa_fieldcat-outputlen = p_length. " Field length
wa_fieldcat-just = 'L'. " Position
wa_fieldcat-seltext_l = p_text. " Field text
Append word area to Internal table
APPEND wa_fieldcat TO i_fieldcat .
ENDFORM. " sub_populate_fieldcat
Edited by: Subhankar Garani on Aug 18, 2008 1:06 PM
Edited by: Subhankar Garani on Aug 18, 2008 1:07 PM