09-22-2005 7:19 AM
Hi All,
In ALV , <b>in list display</b>, can summations be done for numeric items based on say, sales document number or customer etc.
<i><b>I am getting the summations for grid display whereas for list am not getting the same</b></i>
Advance Thanks
09-22-2005 7:23 AM
Hi Aadarsh,
You can use the subtotal option for this.
The internal table it_sort must be filled with the sales order or customer number field.
data: wa_layout type slis_layout_alv,
it_sort type slis_t_sortinfo_alv,
wa_sort type slis_sortinfo_alv.
wa_sort-fieldname = 'STAWN'.
wa_sort-tabname = 'IT_SORT'.
wa_sort-subtot = 'X'.
wa_sort-group = '*'.
append wa_sort to it_sort.
call function 'REUSE_ALV_GRID_DISPLAY'
exporting
i_callback_program = w_repid
i_callback_top_of_page = 'ALV_TOP_OF_PAGE'
i_callback_html_top_of_page = 'ALV_HTML_TOP_OF_PAGE'
is_layout = wa_layout
it_fieldcat = it_fieldcat
it_events = i_events
it_sort = it_sort
i_default = 'X'
i_save = 'A'
....
....
Thanks
Vinod
Message was edited by: Vinod C
Message was edited by: Vinod C
09-22-2005 7:23 AM
Hi Aadarsh,
You can use the subtotal option for this.
The internal table it_sort must be filled with the sales order or customer number field.
data: wa_layout type slis_layout_alv,
it_sort type slis_t_sortinfo_alv,
wa_sort type slis_sortinfo_alv.
wa_sort-fieldname = 'STAWN'.
wa_sort-tabname = 'IT_SORT'.
wa_sort-subtot = 'X'.
wa_sort-group = '*'.
append wa_sort to it_sort.
call function 'REUSE_ALV_GRID_DISPLAY'
exporting
i_callback_program = w_repid
i_callback_top_of_page = 'ALV_TOP_OF_PAGE'
i_callback_html_top_of_page = 'ALV_HTML_TOP_OF_PAGE'
is_layout = wa_layout
it_fieldcat = it_fieldcat
it_events = i_events
it_sort = it_sort
i_default = 'X'
i_save = 'A'
....
....
Thanks
Vinod
Message was edited by: Vinod C
Message was edited by: Vinod C
09-22-2005 7:37 AM
Hi Vinod,
U r right. And also, for the field for which the summation is to be done, has to be populated with so_sum = 'X' in the field catalog. See my coding here. I repeat <b>I am getting the sub-total on VBELN in GRID but not in LIST.</b>
Here is the code :
FORM show_alv .
DATA : wa_print TYPE slis_print_alv.
DATA : it_sort TYPE slis_t_sortinfo_alv WITH HEADER LINE.
**sort on thefieldname of internal table and populaing **the data in IT_SORT
**sort by VBELN
it_sort-fieldname = 'VBELN'.
it_sort-tabname = 'ITAB'.
it_sort-up = 'X'. "sort order up
<b>**for outputting the subtotal for VBELN.
it_sort-subtot = 'X'.</b>
APPEND it_sort.
**For sorting on item after sorting on sales document no.
**Sorting on second field - POSNR (after sorting on VBELN)
CLEAR it_sort.
it_sort-fieldname = 'NETPR'.
it_sort-tabname = 'ITAB'.
it_sort-down = 'X'. "sort order down
APPEND it_sort.
**looping the fieldcat and finding the sum of this
**internal table field
LOOP AT it_fieldcat INTO wa_fieldcat.
CASE wa_fieldcat-fieldname.
WHEN 'NETPR'.
<b> wa_fieldcat-do_sum = 'X'.</b>
**Modifying the 'sum' parameter of this field in the **field catalog so that summation is done on this field
**This summation is done for every VBELN as indicated
**in the it_sort where it_sort-subtot is filled acc.ly.
MODIFY it_fieldcat FROM wa_fieldcat.
ENDCASE.
ENDLOOP.
**List Display
if p_list = 'X'.
CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
EXPORTING
I_CALLBACK_PROGRAM = sy-repid
IT_FIELDCAT = it_fieldcat
IT_SORT = it_sort[]
I_SAVE = 'X'
IMPORTING
E_EXIT_CAUSED_BY_CALLER =
ES_EXIT_CAUSED_BY_USER =
TABLES
t_outtab = itab[]
EXCEPTIONS
PROGRAM_ERROR = 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.
else.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
i_callback_program = sy-repid
it_fieldcat = it_fieldcat
it_sort = it_sort[]
*containes details of field sort order as filled above*
i_save = 'X'
IMPORTING
E_EXIT_CAUSED_BY_CALLER =
ES_EXIT_CAUSED_BY_USER =
TABLES
t_outtab = itab[] EXCEPTIONS
program_error = 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.
endif.
ENDFORM. " SHOW_ALV
Message was edited by: Aadarsh K
09-22-2005 7:47 AM
Hi Aadarsh,
Can you give the sort order in the IT_SORT internal table using the field SPOS (1,2 etc).
And also DO_SUM = 'X' in the field-catalog.
The sort table I have declared is as follows.
it_sort type slis_t_sortinfo_alv
This is without header, so declared another work area.
wa_sort type slis_sortinfo_alv
Thanks
Vinod
Message was edited by: Vinod C
09-22-2005 7:33 AM
hi,
fill subtot = 'X' for the relevant field in the field catalog.
cheers,
sasi
09-22-2005 7:37 AM
09-22-2005 7:40 AM
Hi,
Check this link.It will help you.
Field type may be required in-order for
the 'TOTAL' function to work.
http://www.sapdevelopment.co.uk/reporting/alv/alvlist_code.htm
Message was edited by: Jayanthi Jayaraman
09-22-2005 9:13 AM
Hi Jayanthi Jayaram,
I dint get what is meant by
"Field type may be required in-order for
the 'TOTAL' function to work."
Regards
09-22-2005 7:52 AM
Hi,
Check the link,
<u>http://www.sap-basis-abap.com/sapalv.htm</u>
Kindly reward points if u find it useful.Also close ur previous post if ur problem is solved.
Thanks&Regards,
Ruthra.R
09-22-2005 8:01 AM
Hi Ruthra,
I think I have closed all my previous posts except one MIGO one on which I am workign on.
I hope selecting the radiobutton 'solved on my own' in my post or 'solved the problem(10)' in the replies posted, the post is closed. Is some other process do tell me.
Regards
Message was edited by: Aadarsh K
09-22-2005 8:03 AM
Hi Adarsh,
Have you tried filling the field SPOS in the sort internal table as given in my previous post.
Thanks
Vinod
09-22-2005 8:16 AM
Yes Vinod, done that. No change. Surprisingly it(summation) works for GRID and not for LIST.
Message was edited by: Aadarsh K
09-22-2005 8:19 AM
Hi Adarsh
You have writen:
it_sort-fieldname = 'VBELN'.
it_sort-tabname = 'ITAB'.
it_sort-up = 'X'. "sort order up
**for outputting the subtotal for VBELN.
it_sort-subtot = 'X'.
APPEND it_sort.
**For sorting on item after sorting on sales document no.
**Sorting on second field - POSNR (after sorting on VBELN)
CLEAR it_sort.
it_sort-fieldname = 'NETPR'.
it_sort-tabname = 'ITAB'.
it_sort-down = 'X'. "sort order down
APPEND it_sort.
So I can't see the value of field GROUP?
Have you put a value in it?
= NEW-PAGE
UL = line
Max
09-22-2005 9:11 AM
Hi Max,
You are right in this. I have not used field GROUP. Just tell me its importance so that I can see by populating it
Regards
09-22-2005 9:21 AM
Hi
the ALV use field GROUP to decide if it has to group some fields, so when user chooses to do a subtotal for a field, the ALV create a GROUP for this field and sort by this field.
So you should to do tha same thing in your program, when you fill SORT table, if you don't set GROUP fill, ALV don't create a group so I think it can't create a subtotal because it can't know how to break the group:
By NEW-PAGE -> Insert *
By line -> Insert UL
I think that if you don't fill that field, the ALV'll sort your table only.
Max
Message was edited by: max bianchi
09-22-2005 9:32 AM
Hi Max,
Thanks for the information. I used it. But it is now taking details of each sales document no. into seperate blocks but as usual not giving the sub-total.
Anyway once again thanks for the information about 'group'
Regards
09-22-2005 9:54 AM
Hi
Now I think your code is right
Try to do this:
Use the event TOP_OF_LIST where you use the FM REUSE_ALV_LIST_LAYOUT_INFO_GET: it can return sort table and catalog table after user has choosen an action.
So put a break-point into routine for top_of_list, run your ALV list and after list is displyed choose subtotal for your field.
Now when the program stop in routine for TOP_OF_LIST you can see how the system has filled sort table and catalog table.
Max
09-22-2005 10:38 AM
Thanks Max. I will try this after I finish off one pending work. As for now I am closing this thread. Will post a new one if I cannot find the solution.
Thanks a lot
Aadarsh
09-23-2005 6:02 AM
Hi Max, Vinod etc.,
Thanks everyone for your help.
Hope you remember the issue that was being tried to be solved yesterday. THe problem was not in 'group' parameter or so in alv_field_list_display. I missed out the following bolded one in the 'reuse_alv_field_catalog_merge' function module.
CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
EXPORTING
i_program_name = sy-repid
<b> I_INTERNAL_TABNAME = 'ITAB'</b>
i_structure_name = 'ZSO_ALV'
CHANGING
ct_fieldcat = it_fieldcat
EXCEPTIONS
inconsistent_interface = 1
program_error = 2
OTHERS = 3
.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
But do not know why it was working for ALVGRID but not for LIST.
Anyway once again Thank you
Regards
Aadarsh
09-23-2005 6:48 AM
Hi,
You can do this by coding as specified above.
But that can also be done through the summation option given in the PF-status of ALV List or ALV Grid which comes by default when you make it.
Thanks and Regards
Gurpreet Singh
09-23-2005 8:05 AM
Thanks Gurpreet I will look into that too.
So this thred is closed.
Thank you all