2011 Oct 13 3:37 PM
Hi ,
I am displying output data in ALV List. And I am sorting data and displayed Only SUBTOTAL. And if user want to expand it, than can do it.
I have used
wa_sort-spos = 1.
wa_sort-fieldname = 'EBELN'.
wa_sort-tabname = 'ITAB'.
wa_sort-subtot = 'X'.
wa_sort-expa = 'X'.
APPEND wa_sort TO it_sort.
Now, I need to sort data which is displaying only Subtotal without Expanding. How can I do that ?
Thanks,
2011 Oct 14 10:29 AM
Check this...It will work "Dont forget to diable the sort and sum buttons in the standard tool bar :)'
REPORT ytest_str11.
TYPE-POOLS:slis.
TYPES:BEGIN OF ty,
ebeln TYPE ekpo-ebeln,
val TYPE i,
END OF ty.
TYPES:BEGIN OF ty1,
in(1234) TYPE c,
ebeln TYPE ekpo-ebeln,
val TYPE i,
END OF ty1.
DATA:g_tabix TYPE i.
DATA:it4 TYPE SORTED TABLE OF ty WITH NON-UNIQUE KEY ebeln.
DATA:it TYPE TABLE OF ty.
DATA:it2 TYPE TABLE OF ty.
DATA:it3 TYPE TABLE OF ty1.
DATA:wa TYPE ty,
wa2 TYPE ty,
wa3 TYPE ty1,
i_fieldcat TYPE slis_t_fieldcat_alv,
i_sort TYPE slis_t_sortinfo_alv,
wa_sort TYPE slis_sortinfo_alv,
wa_lfl_fcat TYPE slis_fieldcat_alv,
i_alv_top_of_page TYPE slis_t_listheader,
i_events TYPE slis_t_event,
i_event TYPE slis_t_event,
wa_events TYPE slis_alv_event.
START-OF-SELECTION.
wa-ebeln = '100009'.
wa-val = '10'.APPEND wa TO it.wa-val = '10'.APPEND wa TO it.
wa-val = '10'.APPEND wa TO it.
wa-ebeln = '100001'.
wa-val = '4'.APPEND wa TO it.wa-val = '6'.APPEND wa TO it.
wa-val = '5'.APPEND wa TO it.
wa-ebeln = '100006'.
wa-val = '1'.APPEND wa TO it.wa-val = '1'.APPEND wa TO it.
wa-val = '1'.APPEND wa TO it.
wa-ebeln = '100002'.
wa-val = '2'.APPEND wa TO it.wa-val = '7'.APPEND wa TO it.
wa-val = '8'.APPEND wa TO it.
SORT it BY ebeln.
APPEND LINES OF it TO it4.
LOOP AT it INTO wa.
COLLECT wa INTO it2.
ENDLOOP.
SORT it2 BY val DESCENDING.
DATA:l_tabix(1234) TYPE c.
l_tabix = 0.
LOOP AT it2 INTO wa2.
l_tabix = l_tabix + 1.
SHIFT l_tabix LEFT DELETING LEADING space.
LOOP AT it4 INTO wa WHERE ebeln = wa2-ebeln.
wa3-ebeln = wa-ebeln.
wa3-val = wa-val.
wa3-in = l_tabix.
APPEND wa3 TO it3.
ENDLOOP.
ENDLOOP.
wa_lfl_fcat-fieldname = 'IN'.
wa_lfl_fcat-no_out = 'X'.
APPEND wa_lfl_fcat TO i_fieldcat.
CLEAR wa_lfl_fcat.
wa_lfl_fcat-fieldname = 'EBELN'.
APPEND wa_lfl_fcat TO i_fieldcat.
CLEAR wa_lfl_fcat.
wa_lfl_fcat-fieldname = 'VAL'.
wa_lfl_fcat-do_sum = 'X'.
APPEND wa_lfl_fcat TO i_fieldcat.
wa_sort-fieldname = 'IN'.
wa_sort-subtot = 'X'.
wa_sort-up = 'X'.
wa_sort-expa = 'X'.
APPEND wa_sort TO i_sort .
DATA:l_repid TYPE sy-repid.
l_repid = sy-repid.
DATA: l_s_event TYPE slis_alv_event.
l_s_event-form = 'SUBTOTAL_TEXT'.
l_s_event-name = 'SUBTOTAL_TEXT'.
APPEND l_s_event TO i_event.
data:lv_lines type i.
describe table it2 lines lv_lines.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
i_callback_program = l_repid
it_fieldcat = i_fieldcat
it_sort = i_sort
it_events = i_event
TABLES
t_outtab = it3[]
EXCEPTIONS
program_error = 1
OTHERS = 2.
*---------------------------------------------------------------------*
* FORM subtotal_text *
*---------------------------------------------------------------------*
* ........ *
*---------------------------------------------------------------------*
* --> P_TOTAL *
* --> P_SUBTOT_TEXT *
*---------------------------------------------------------------------*
FORM subtotal_text CHANGING
p_total TYPE any
p_subtot_text TYPE slis_subtot_text.
if g_tabix = lv_lines.
g_tabix = 0.
endif.
g_tabix = g_tabix + 1.
IF p_subtot_text-criteria = 'IN'.
READ TABLE it2 INTO wa2 INDEX g_tabix.
IF sy-subrc = 0.
p_subtot_text-display_text_for_subtotal = wa2-ebeln.
ENDIF.
ENDIF.
ENDFORM. "subtotal_text
Edited by: Keshav.T on Oct 14, 2011 3:04 PM
Hi ,
I am displying output data in ALV List. And I am sorting data and displayed Only SUBTOTAL. And if user want to expand it, than can do it.
I have used
wa_sort-spos = 1.
wa_sort-fieldname = 'EBELN'.
wa_sort-tabname = 'ITAB'.
wa_sort-subtot = 'X'.
wa_sort-expa = 'X'.
APPEND wa_sort TO it_sort.
Now, I need to sort data which is displaying only Subtotal without Expanding. How can I do that ?
Thanks,
2011 Oct 13 4:20 PM
2011 Oct 13 7:52 PM
Hi ,
When user run report , than Output displayed with Subtotals Only. And I want to sort this output. But this Output data for subtotal is not saved in any table . Its displayed because I pass parameter It_sort to ALV List Function Module.
So , How can I can sort This subtotal output data ? Plz anybody is having any Idea ?
Thanks,
2011 Oct 13 9:52 PM
Hi,
Use ALV GRID instead and the user can do further sorting on the output list.
2011 Oct 14 4:57 AM
wa_sort has a property up & down.Pass X to relevant property.
2011 Oct 14 7:07 AM
Hi ,
through this I can sort ( descending )detail data . But I need to sort these subtotal data .
suppose I have given one example below.
ebeln menge
100001 4
100001 6
100001 5
subtotal 100001 15
100002 2
100002 7
100002 8
subtotal 100002 17.
Now if I sort (decending) than its sorting only detail data means output will be
ebeln menge
100001 6
100001 5
100001 4
subtotal 100001 15
100002 8
100002 7
100002 2
subtotal 100002 17.
But I need to sort (descending) subtotal item means i should display like
ebeln menge
subtotal 100002 17
subtotal 100001 15
I hope now its more undestandable........
2011 Oct 14 7:39 AM
if you use
wa_sort-spos = 1.
wa_sort-fieldname = 'EBELN'.
wa_sort-tabname = 'ITAB'.
wa_sort-subtot = 'X'.
wa_sort-down = 'X
wa_sort-expa = 'X'.
APPEND wa_sort TO it_sort.it will give out put like
ebeln menge
subtotal 100002 17
subtotal 100001 15
2011 Oct 14 7:49 AM
Hi,
I dont see a standard method for just sorting the subtotals only, you can do some thing programatically if this is a necessary business reuirement.
TYPE-POOLS:slis.
TYPES:BEGIN OF ty,
ebeln TYPE ekpo-ebeln,
val TYPE i,
END OF ty.
DATA:it4 TYPE SORTED TABLE OF ty WITH NON-UNIQUE KEY ebeln.
DATA:it TYPE TABLE OF ty.
DATA:it1 TYPE TABLE OF ty.
DATA:it2 TYPE TABLE OF ty.
DATA:it3 TYPE TABLE OF ty.
DATA:wa TYPE ty,
wa2 TYPE ty,
i_fieldcat TYPE slis_t_fieldcat_alv,
i_sort TYPE slis_t_sortinfo_alv,
wa_sort TYPE slis_sortinfo_alv,
wa_lfl_fcat TYPE slis_fieldcat_alv.
START-OF-SELECTION.
wa-ebeln = '100009'.wa-val = '10'.APPEND wa TO it.wa-val = '10'.APPEND wa TO it.wa-val = '10'.APPEND wa TO it.
wa-ebeln = '100001'.wa-val = '4'.APPEND wa TO it.wa-val = '6'.APPEND wa TO it. wa-val = '5'.APPEND wa TO it.
wa-ebeln = '100006'.wa-val = '1'.APPEND wa TO it.wa-val = '1'.APPEND wa TO it. wa-val = '1'.APPEND wa TO it.
wa-ebeln = '100002'.wa-val = '2'.APPEND wa TO it.wa-val = '7'.APPEND wa TO it. wa-val = '8'.APPEND wa TO it.
SORT it BY ebeln.
APPEND LINES OF it TO it4.
LOOP AT it INTO wa.
COLLECT wa INTO it2.
ENDLOOP.
SORT it2 BY val DESCENDING.
LOOP AT it2 INTO wa2.
LOOP AT it4 INTO wa WHERE ebeln = wa2-ebeln.
APPEND wa TO it3.
ENDLOOP.
ENDLOOP.
wa_lfl_fcat-fieldname = 'EBELN'.
APPEND wa_lfl_fcat TO i_fieldcat.
wa_lfl_fcat-fieldname = 'VAL'.
wa_lfl_fcat-do_sum = 'X'.
APPEND wa_lfl_fcat TO i_fieldcat.
wa_sort-fieldname = 'EBELN'.
wa_sort-subtot = 'X'.
APPEND wa_sort TO i_sort .
DATA:l_repid TYPE sy-repid.
l_repid = sy-repid.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
i_callback_program = l_repid
it_fieldcat = i_fieldcat
it_sort = i_sort
TABLES
t_outtab = it3 "this itab holds values as you desired, but dont know why its not getting replicated in the output.
EXCEPTIONS
program_error = 1
OTHERS = 2.
2011 Oct 14 7:54 AM
Hi Suzie.
Here You have mentioned EBELN. But i need to sort based On MENGE . tHAN ITS WORK ? Or need to SORT For MENGE also..
Thanks....
2011 Oct 14 7:57 AM
Hi,
Execute the program in your system once and check. If you see it3 the data is as you needed and i have not given a sort to EBELN. But in display it sorts in ascending order by default. I think this happens internally
if you comment
* wa_sort-fieldname = 'EBELN'.
* wa_sort-up = ' '.
* wa_sort-down = ' '.
* wa_sort-subtot = 'X'.
* APPEND wa_sort TO i_sort .
you will understand
My bad:it makes sense "Without sorting how will the grouping for subtotal happen !!!" Thats why it happens internally
Kesav
Edited by: Keshav.T on Oct 14, 2011 12:33 PM
2011 Oct 14 7:58 AM
But I need to sort (descending) subtotal item means i should display like
ebeln menge
subtotal 100002 17
subtotal 100001 15
And why would someone want to do this? Standard ALV doesn't cater to this requirement.
Alternatively you can display the subtotal as the basic list(which you can SORT et al.) & based on some user interaction display the detailed list with the break down of the sub-total.
Hope you get the point.
BR,
Suhas
2011 Oct 14 8:15 AM
For time being this willl work, but there is a limit for field in in structure ty1. may be creating the internal table dynamically with field IN (n equal to the no of rows in internal table it2 )might help.
TYPE-POOLS:slis.
TYPES:BEGIN OF ty,
ebeln TYPE ekpo-ebeln,
val TYPE i,
END OF ty.
TYPES:BEGIN OF ty1,
in(1234) TYPE c,
ebeln TYPE ekpo-ebeln,
val TYPE i,
END OF ty1.
DATA:it4 TYPE SORTED TABLE OF ty WITH NON-UNIQUE KEY ebeln.
DATA:it TYPE TABLE OF ty.
DATA:it1 TYPE TABLE OF ty.
DATA:it2 TYPE TABLE OF ty.
DATA:it3 TYPE TABLE OF ty1.
DATA:wa TYPE ty,
wa2 TYPE ty,
wa3 TYPE ty1,
i_fieldcat TYPE slis_t_fieldcat_alv,
i_sort TYPE slis_t_sortinfo_alv,
wa_sort TYPE slis_sortinfo_alv,
wa_lfl_fcat TYPE slis_fieldcat_alv.
START-OF-SELECTION.
wa-ebeln = '100009'.
wa-val = '10'.APPEND wa TO it.wa-val = '10'.APPEND wa TO it.
wa-val = '10'.APPEND wa TO it.
wa-ebeln = '100001'.
wa-val = '4'.APPEND wa TO it.wa-val = '6'.APPEND wa TO it.
wa-val = '5'.APPEND wa TO it.
wa-ebeln = '100006'.
wa-val = '1'.APPEND wa TO it.wa-val = '1'.APPEND wa TO it.
wa-val = '1'.APPEND wa TO it.
wa-ebeln = '100002'.
wa-val = '2'.APPEND wa TO it.wa-val = '7'.APPEND wa TO it.
wa-val = '8'.APPEND wa TO it.
SORT it BY ebeln.
APPEND LINES OF it TO it4.
LOOP AT it INTO wa.
COLLECT wa INTO it2.
ENDLOOP.
SORT it2 BY val DESCENDING.
DATA:l_tabix TYPE i.
l_tabix = 0.
LOOP AT it2 INTO wa2.
l_tabix = l_tabix + 1.
LOOP AT it4 INTO wa WHERE ebeln = wa2-ebeln.
wa3-ebeln = wa-ebeln.
wa3-val = wa-val.
wa3-in = l_tabix.
APPEND wa3 TO it3.
ENDLOOP.
ENDLOOP.
sort it3 by in descending.
wa_lfl_fcat-fieldname = 'IN'.
wa_lfl_fcat-no_out = 'X'.
APPEND wa_lfl_fcat TO i_fieldcat.
clear wa_lfl_fcat.
wa_lfl_fcat-fieldname = 'EBELN'.
APPEND wa_lfl_fcat TO i_fieldcat.
clear wa_lfl_fcat.
wa_lfl_fcat-fieldname = 'VAL'.
wa_lfl_fcat-do_sum = 'X'.
APPEND wa_lfl_fcat TO i_fieldcat.
wa_sort-fieldname = 'IN'.
wa_sort-subtot = 'X'.
wa_sort-up = 'X'.
APPEND wa_sort TO i_sort .
DATA:l_repid TYPE sy-repid.
l_repid = sy-repid.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
i_callback_program = l_repid
it_fieldcat = i_fieldcat
it_sort = i_sort
TABLES
t_outtab = it3[]
EXCEPTIONS
program_error = 1
OTHERS = 2.
2011 Oct 14 9:15 AM
Hi Kechsav ,
Its really nice piece of coding.
Here I have added
wa_sort-expa = 'X'. So , its only Subtotal desplay and it can be expandable. Now problem is that There is not Subtotal text is displayed It shoul d be ebeln .
Means these subtotal of menge should be displayed with name of ebeln.
Thanks.
2011 Oct 14 10:01 AM
Try it with RS_TREE_LIST_DISPLAY. Its not possible the way you expect.
Kesav
2011 Oct 14 4:19 PM
Hi keshav ,
Thanks for needful coding . Its has been solved by Sutotal_text event.
And thanks to all fo your Comment.
2011 Oct 14 8:28 AM
Sort for EBELN as descending and MENGE ascending. it WILL solve your problem
2011 Oct 14 10:29 AM
Check this...It will work "Dont forget to diable the sort and sum buttons in the standard tool bar :)'
REPORT ytest_str11.
TYPE-POOLS:slis.
TYPES:BEGIN OF ty,
ebeln TYPE ekpo-ebeln,
val TYPE i,
END OF ty.
TYPES:BEGIN OF ty1,
in(1234) TYPE c,
ebeln TYPE ekpo-ebeln,
val TYPE i,
END OF ty1.
DATA:g_tabix TYPE i.
DATA:it4 TYPE SORTED TABLE OF ty WITH NON-UNIQUE KEY ebeln.
DATA:it TYPE TABLE OF ty.
DATA:it2 TYPE TABLE OF ty.
DATA:it3 TYPE TABLE OF ty1.
DATA:wa TYPE ty,
wa2 TYPE ty,
wa3 TYPE ty1,
i_fieldcat TYPE slis_t_fieldcat_alv,
i_sort TYPE slis_t_sortinfo_alv,
wa_sort TYPE slis_sortinfo_alv,
wa_lfl_fcat TYPE slis_fieldcat_alv,
i_alv_top_of_page TYPE slis_t_listheader,
i_events TYPE slis_t_event,
i_event TYPE slis_t_event,
wa_events TYPE slis_alv_event.
START-OF-SELECTION.
wa-ebeln = '100009'.
wa-val = '10'.APPEND wa TO it.wa-val = '10'.APPEND wa TO it.
wa-val = '10'.APPEND wa TO it.
wa-ebeln = '100001'.
wa-val = '4'.APPEND wa TO it.wa-val = '6'.APPEND wa TO it.
wa-val = '5'.APPEND wa TO it.
wa-ebeln = '100006'.
wa-val = '1'.APPEND wa TO it.wa-val = '1'.APPEND wa TO it.
wa-val = '1'.APPEND wa TO it.
wa-ebeln = '100002'.
wa-val = '2'.APPEND wa TO it.wa-val = '7'.APPEND wa TO it.
wa-val = '8'.APPEND wa TO it.
SORT it BY ebeln.
APPEND LINES OF it TO it4.
LOOP AT it INTO wa.
COLLECT wa INTO it2.
ENDLOOP.
SORT it2 BY val DESCENDING.
DATA:l_tabix(1234) TYPE c.
l_tabix = 0.
LOOP AT it2 INTO wa2.
l_tabix = l_tabix + 1.
SHIFT l_tabix LEFT DELETING LEADING space.
LOOP AT it4 INTO wa WHERE ebeln = wa2-ebeln.
wa3-ebeln = wa-ebeln.
wa3-val = wa-val.
wa3-in = l_tabix.
APPEND wa3 TO it3.
ENDLOOP.
ENDLOOP.
wa_lfl_fcat-fieldname = 'IN'.
wa_lfl_fcat-no_out = 'X'.
APPEND wa_lfl_fcat TO i_fieldcat.
CLEAR wa_lfl_fcat.
wa_lfl_fcat-fieldname = 'EBELN'.
APPEND wa_lfl_fcat TO i_fieldcat.
CLEAR wa_lfl_fcat.
wa_lfl_fcat-fieldname = 'VAL'.
wa_lfl_fcat-do_sum = 'X'.
APPEND wa_lfl_fcat TO i_fieldcat.
wa_sort-fieldname = 'IN'.
wa_sort-subtot = 'X'.
wa_sort-up = 'X'.
wa_sort-expa = 'X'.
APPEND wa_sort TO i_sort .
DATA:l_repid TYPE sy-repid.
l_repid = sy-repid.
DATA: l_s_event TYPE slis_alv_event.
l_s_event-form = 'SUBTOTAL_TEXT'.
l_s_event-name = 'SUBTOTAL_TEXT'.
APPEND l_s_event TO i_event.
data:lv_lines type i.
describe table it2 lines lv_lines.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
i_callback_program = l_repid
it_fieldcat = i_fieldcat
it_sort = i_sort
it_events = i_event
TABLES
t_outtab = it3[]
EXCEPTIONS
program_error = 1
OTHERS = 2.
*---------------------------------------------------------------------*
* FORM subtotal_text *
*---------------------------------------------------------------------*
* ........ *
*---------------------------------------------------------------------*
* --> P_TOTAL *
* --> P_SUBTOT_TEXT *
*---------------------------------------------------------------------*
FORM subtotal_text CHANGING
p_total TYPE any
p_subtot_text TYPE slis_subtot_text.
if g_tabix = lv_lines.
g_tabix = 0.
endif.
g_tabix = g_tabix + 1.
IF p_subtot_text-criteria = 'IN'.
READ TABLE it2 INTO wa2 INDEX g_tabix.
IF sy-subrc = 0.
p_subtot_text-display_text_for_subtotal = wa2-ebeln.
ENDIF.
ENDIF.
ENDFORM. "subtotal_text
Edited by: Keshav.T on Oct 14, 2011 3:04 PM
| User | Count |
|---|---|
| 3 | |
| 2 | |
| 2 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |