2013 Aug 15 1:57 PM
Hi Experts,
I am using ALV grid report with the function module reuse_alv_grid_display. My Requirement is like below.
| BILLING DOC DATE | BILLING DOC NO | COUNT |
|---|---|---|
| 22.05.08 | 90000186 | - |
| 23.06.08 | 90000186 | 2 |
| 24.06.08 | 90000187 | - |
| 24.05.08 | 90000187 | - |
| 25.05.08 | 90000187 | 3 |
I have some 6 data dictionary fields like bill doc dill doc date. But I want to add another column which is A count and it is based on the no of billing document which are same.(Like above 90000186 has happened twice and so 2 in count and above it should be ' - ') How to achieve the same.
Regards,
Marina.
2013 Aug 15 9:09 PM
Eitan's suggestion is actually much better than the ones marked as "helpful". Eitan's option would work even if the users apply a sort/filter to the ALV report. What would happen to the other solutions in such case?
I'd question the need to have a dash in that column. It wouldn't even make sense when exporting to Excel, for example. Perhaps the users were misinformed on the ALV functionality. Otherwise why even bother with ALV, actually? Just do a plain list.
Also - have you tried Google 'ALV add count' before posting? There are many posts out there...
Hi Experts,
I am using ALV grid report with the function module reuse_alv_grid_display. My Requirement is like below.
| BILLING DOC DATE | BILLING DOC NO | COUNT |
|---|---|---|
| 22.05.08 | 90000186 | - |
| 23.06.08 | 90000186 | 2 |
| 24.06.08 | 90000187 | - |
| 24.05.08 | 90000187 | - |
| 25.05.08 | 90000187 | 3 |
I have some 6 data dictionary fields like bill doc dill doc date. But I want to add another column which is A count and it is based on the no of billing document which are same.(Like above 90000186 has happened twice and so 2 in count and above it should be ' - ') How to achieve the same.
Regards,
Marina.
2013 Aug 15 2:04 PM
Hello Marina,
you need to calculate the same inside the program and put the values in the new column count. ALV FM has nothing to do with this.
Regards
Animesh Sundriyal
2013 Aug 15 2:10 PM
sort itab by vbeln.
loop at itab into wa_itab.
v_idx = sy-tabix.
cnt = cnt + 1.
at end of vbeln.
wa_itab-count = cnt.
modify itab from wa_itab index v_idx transporting count.
clear cnt.
endat.
endloop.
pass itab to ALV FM. This will work may be with some little changes
Rgds
2013 Aug 15 2:13 PM
ok...i read your other requirement of putting '-' later. you can put another modify after the loop as i mentioned in my previous blog... so:
wa_itab-count = '-'.
modify itab from wa_itab transporting count where count is initial.
Rgds
2013 Aug 15 4:20 PM
Hi Sudhanshu,
Thanks for your answer. But one more doubt since i have declared count as integer it is not accepting '-'
How to sort out this issue?
Regards,
Marina.
2013 Aug 15 4:47 PM
since its not a Db field and just for run time display information. in fact it doesn't need any further calculation..you can have it as character type.
2013 Aug 15 2:29 PM
Hi,
You have to add one more column - count in your internal table .once your internal table is populated with data sort the table.
loop at internal table and with the help of event "at end of doc_no...endat" , you can populate the count field.
coding will be similar to this :
sort itab by doc_no.
loop at itab Assigning <wa_tab>.
counter = counter + 1.
at end of doc_no.
<wa_tab>-count = counter.
clear counter.
continue.
endat.
<wa_tab>-count = '_'.
endloop.
<wa_tab> is a field symbol of type your internal table structure.
hope this helps.
Regards,
Priyaranjan
2013 Aug 15 3:18 PM
Hi ,
Add a new integer column that will contain the number 1 .
In the field catalog for this field set the "sum" flag .
Add to the ALV sorting by billing document and also set the subtotal flag for that level.
regards .
2013 Aug 17 7:58 AM
| Billing Date | Billing Doc No | Counter |
|---|---|---|
| 22.03.2008 | 90000004 | - |
| 22.03.2008 | 90000005 | 2 |
| 23.03.2008 | 90000006 | - |
| 23.03.2008 | 90000007 | - |
| 23.03.2008 | 90000008 | 3 |
| 24.03.2008 | 90000009 | - |
| 24.03.2008 | 90000010 | 2 |
Hi Eitan,
Can you explain more on your solution. May be with an example. My Requirement is modified like below. As Jelena said there are issues when user tries to sort based on billing date or doc no.
Regards,
Marina.
2013 Aug 17 8:40 AM
Hi Marina,
Try like this
TYPE-POOLS: slis.
DATA: it_fieldcat TYPE slis_t_fieldcat_alv,
wa_fieldcat TYPE slis_fieldcat_alv,
it_list TYPE slis_t_listheader,
l_layout TYPE slis_layout_alv.
TYPES : BEGIN OF ty_itab,
a TYPE char10,
b TYPE vbfa-vbeln,
c TYPE char5,
END OF ty_itab.
DATA : wa_itab TYPE ty_itab,
it_itab TYPE TABLE OF ty_itab.
DATA : var TYPE i.
wa_itab-a = '22.03.2008'.
wa_itab-b = '90000004'.
APPEND wa_itab TO it_itab.
CLEAR wa_itab.
wa_itab-a = '22.03.2008'.
wa_itab-b = '90000005'.
APPEND wa_itab TO it_itab.
CLEAR wa_itab.
wa_itab-a = '23.03.2008'.
wa_itab-b = '90000006'.
APPEND wa_itab TO it_itab.
CLEAR wa_itab.
wa_itab-a = '23.03.2008'.
wa_itab-b = '90000007'.
APPEND wa_itab TO it_itab.
CLEAR wa_itab.
wa_itab-a = '23.03.2008'.
wa_itab-b = '90000008'.
APPEND wa_itab TO it_itab.
CLEAR wa_itab.
wa_itab-a = '24.03.2008'.
wa_itab-b = '90000009'.
APPEND wa_itab TO it_itab.
CLEAR wa_itab.
wa_itab-a = '24.03.2008'.
wa_itab-b = '90000010'.
APPEND wa_itab TO it_itab.
CLEAR wa_itab.
SORT it_itab BY a b.
LOOP AT it_itab INTO wa_itab.
var = var + 1.
at end of a.
wa_itab-c = var.
MODIFY it_itab FROM wa_itab TRANSPORTING c.
CLEAR var.
ENDat.
CLEAR wa_itab.
ENDLOOP.
LOOP AT it_itab INTO wa_itab.
if wa_itab-c is INITIAL.
wa_itab-c = '-'.
MODIFY it_itab FROM wa_itab TRANSPORTING c.
endif.
clear wa_itab-c.
endloop.
wa_fieldcat-fieldname = 'A'.
wa_fieldcat-seltext_m = 'BILLING DOC DATE'.
APPEND wa_fieldcat TO it_fieldcat.
CLEAR wa_fieldcat .
wa_fieldcat-fieldname = 'B'.
wa_fieldcat-seltext_m = 'BILLING DOC NO'.
* wa_fieldcat-do_sum = 'X'.
APPEND wa_fieldcat TO it_fieldcat.
CLEAR wa_fieldcat .
wa_fieldcat-fieldname = 'C'.
wa_fieldcat-seltext_m = 'COUNT'.
* wa_fieldcat-do_sum = 'X'.
APPEND wa_fieldcat TO it_fieldcat.
CLEAR wa_fieldcat .
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
* I_INTERFACE_CHECK = ' '
* I_BYPASSING_BUFFER = ' '
* I_BUFFER_ACTIVE = ' '
I_CALLBACK_PROGRAM = sy-repid
* I_CALLBACK_PF_STATUS_SET = ' '
* I_CALLBACK_USER_COMMAND = ' '
* I_CALLBACK_TOP_OF_PAGE = ' '
* I_CALLBACK_HTML_TOP_OF_PAGE = ' '
* I_CALLBACK_HTML_END_OF_LIST = ' '
* I_STRUCTURE_NAME =
* I_BACKGROUND_ID = ' '
* I_GRID_TITLE =
* I_GRID_SETTINGS =
* IS_LAYOUT =
IT_FIELDCAT = it_fieldcat
* IT_EXCLUDING =
* IT_SPECIAL_GROUPS =
* IT_SORT =
* IT_FILTER =
* IS_SEL_HIDE =
* I_DEFAULT = 'X'
* I_SAVE = ' '
* IS_VARIANT =
* IT_EVENTS =
* IT_EVENT_EXIT =
* IS_PRINT =
* IS_REPREP_ID =
* I_SCREEN_START_COLUMN = 0
* I_SCREEN_START_LINE = 0
* I_SCREEN_END_COLUMN = 0
* I_SCREEN_END_LINE = 0
* I_HTML_HEIGHT_TOP = 0
* I_HTML_HEIGHT_END = 0
* IT_ALV_GRAPHICS =
* IT_HYPERLINK =
* IT_ADD_FIELDCAT =
* IT_EXCEPT_QINFO =
* IR_SALV_FULLSCREEN_ADAPTER =
* IMPORTING
* E_EXIT_CAUSED_BY_CALLER =
* ES_EXIT_CAUSED_BY_USER =
TABLES
t_outtab = it_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.
2013 Aug 17 8:48 AM
2013 Aug 17 9:23 AM
hi,
i think this is your requirement.
REPORT ZFIELD_SORT.
TYPE-POOLS: SLIS.
TYPES : BEGIN OF TY_VBRP,
ERDAT TYPE ERDAT,
VBELN TYPE VBELN_VF,
END OF TY_VBRP,
BEGIN OF TY_OUTPUT,
ERDAT TYPE ERDAT,
VBELN TYPE VBELN_VF,
COUNT TYPE I,
END OF TY_OUTPUT.
DATA: IT_FIELDCAT TYPE SLIS_T_FIELDCAT_ALV,
WA_FIELDCAT TYPE SLIS_FIELDCAT_ALV,
it_sort TYPE SLIS_T_SORTINFO_ALV,
wa_sort TYPE SLIS_SORTINFO_ALV.
DATA : IT_VBRP TYPE STANDARD TABLE OF TY_VBRP,
WA_VBRP TYPE TY_VBRP,
IT_OUTPUT TYPE STANDARD TABLE OF TY_OUTPUT,
WA_OUTPUT TYPE TY_OUTPUT,
T_ERDAT TYPE ERDAT.
SELECT-OPTIONS : S_ERDAT FOR T_ERDAT.
SELECT ERDAT
VBELN
FROM VBRP
INTO TABLE IT_VBRP
WHERE ERDAT IN S_ERDAT.
SORT IT_VBRP BY VBELN.
IF IT_VBRP IS NOT INITIAL.
LOOP AT IT_VBRP INTO WA_VBRP.
WA_OUTPUT-ERDAT = WA_VBRP-ERDAT.
WA_OUTPUT-VBELN = WA_VBRP-VBELN.
WA_OUTPUT-COUNT = '1'.
APPEND WA_OUTPUT TO IT_OUTPUT.
CLEAR : WA_OUTPUT, WA_VBRP.
ENDLOOP.
ENDIF.
CLEAR WA_FIELDCAT .
WA_FIELDCAT-FIELDNAME = 'ERDAT'.
WA_FIELDCAT-SELTEXT_M = 'BILLING DOC DATE'.
APPEND WA_FIELDCAT TO IT_FIELDCAT.
WA_FIELDCAT-FIELDNAME = 'VBELN'.
WA_FIELDCAT-SELTEXT_M = 'BILLING DOC NO'.
*wa_fieldcat-do_sum = 'X'.
APPEND WA_FIELDCAT TO IT_FIELDCAT.
CLEAR WA_FIELDCAT .
WA_FIELDCAT-FIELDNAME = 'COUNT'.
WA_FIELDCAT-SELTEXT_M = 'COUNT'.
WA_FIELDCAT-DO_SUM = 'X'.
APPEND WA_FIELDCAT TO IT_FIELDCAT.
CLEAR WA_FIELDCAT .
CLEAR wa_sort.
wa_sort-SPOS ='2'.
wa_sort-FIELDNAME = 'VBELN'.
wa_sort-down = 'X'.
wa_sort-subtot = 'X'.
APPEND wa_sort to it_sort.
CLEAR wa_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_OUTPUT
EXCEPTIONS
PROGRAM_ERROR = 1
OTHERS = 2
.
IF SY-SUBRC <> 0.
ENDIF.
output.
2013 Aug 18 6:26 AM
Hi,
The principal is the same as "REUSE_ALV_GRID_DISPLAY" or "cl_gui_alv_grid" .
I can see that Sravan kilari demonstrate "REUSE_ALV_GRID_DISPLAY" .
So I choose to demonstrate using cl_salv_table .
Regards.
2013 Aug 15 9:09 PM
Eitan's suggestion is actually much better than the ones marked as "helpful". Eitan's option would work even if the users apply a sort/filter to the ALV report. What would happen to the other solutions in such case?
I'd question the need to have a dash in that column. It wouldn't even make sense when exporting to Excel, for example. Perhaps the users were misinformed on the ALV functionality. Otherwise why even bother with ALV, actually? Just do a plain list.
Also - have you tried Google 'ALV add count' before posting? There are many posts out there...
2013 Aug 16 6:51 AM
Hi ,
I have to admit that I did not think about sort/filter.
What drive me to this solution is cost .
I would not want to waste my time counting records......
About exporting to Excel: (I have to check it) maybe if I implement event “before_user_command” I can intercept
e_ucomm cl_gui_alv_grid=>mc_fc_call_xxl and clear the "One column" prior to the export to Excel.
regards .
2013 Aug 16 2:16 AM
2013 Aug 16 5:56 AM
Hi Marina,
Try like this
TYPE-POOLS: slis.
DATA: it_fieldcat TYPE slis_t_fieldcat_alv,
wa_fieldcat TYPE slis_fieldcat_alv,
it_list TYPE slis_t_listheader,
l_layout TYPE slis_layout_alv.
TYPES : BEGIN OF ty_itab,
b TYPE vbfa-vbeln,
a TYPE char8,
c TYPE char5,
END OF ty_itab.
DATA : wa_itab TYPE ty_itab,
it_itab TYPE TABLE OF ty_itab.
DATA : var TYPE i.
wa_itab-a = '22.05.08'.
wa_itab-b = '90000186'.
APPEND wa_itab TO it_itab.
CLEAR wa_itab.
wa_itab-a = '23.06.08'.
wa_itab-b = '90000186'.
APPEND wa_itab TO it_itab.
CLEAR wa_itab.
wa_itab-a = '24.06.08'.
wa_itab-b = '90000187'.
APPEND wa_itab TO it_itab.
CLEAR wa_itab.
wa_itab-a = '24.05.08'.
wa_itab-b = '90000187'.
APPEND wa_itab TO it_itab.
CLEAR wa_itab.
wa_itab-a = '25.05.08'.
wa_itab-b = '90000187'.
APPEND wa_itab TO it_itab.
CLEAR wa_itab.
SORT it_itab BY a b.
LOOP AT it_itab INTO wa_itab.
var = var + 1.
at end of b.
wa_itab-c = var.
MODIFY it_itab FROM wa_itab TRANSPORTING c.
CLEAR var.
ENDat.
CLEAR wa_itab.
ENDLOOP.
LOOP AT it_itab INTO wa_itab.
if wa_itab-c is INITIAL.
wa_itab-c = '-'.
MODIFY it_itab FROM wa_itab TRANSPORTING c.
endif.
clear wa_itab-c.
endloop.
wa_fieldcat-fieldname = 'A'.
wa_fieldcat-seltext_m = 'BILLING DOC DATE'.
APPEND wa_fieldcat TO it_fieldcat.
CLEAR wa_fieldcat .
wa_fieldcat-fieldname = 'B'.
wa_fieldcat-seltext_m = 'BILLING DOC NO'.
* wa_fieldcat-do_sum = 'X'.
APPEND wa_fieldcat TO it_fieldcat.
CLEAR wa_fieldcat .
wa_fieldcat-fieldname = 'C'.
wa_fieldcat-seltext_m = 'COUNT'.
* wa_fieldcat-do_sum = 'X'.
APPEND wa_fieldcat TO it_fieldcat.
CLEAR wa_fieldcat .
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
* I_INTERFACE_CHECK = ' '
* I_BYPASSING_BUFFER = ' '
* I_BUFFER_ACTIVE = ' '
I_CALLBACK_PROGRAM = sy-repid
* I_CALLBACK_PF_STATUS_SET = ' '
* I_CALLBACK_USER_COMMAND = ' '
* I_CALLBACK_TOP_OF_PAGE = ' '
* I_CALLBACK_HTML_TOP_OF_PAGE = ' '
* I_CALLBACK_HTML_END_OF_LIST = ' '
* I_STRUCTURE_NAME =
* I_BACKGROUND_ID = ' '
* I_GRID_TITLE =
* I_GRID_SETTINGS =
* IS_LAYOUT =
IT_FIELDCAT = it_fieldcat
* IT_EXCLUDING =
* IT_SPECIAL_GROUPS =
* IT_SORT =
* IT_FILTER =
* IS_SEL_HIDE =
* I_DEFAULT = 'X'
* I_SAVE = ' '
* IS_VARIANT =
* IT_EVENTS =
* IT_EVENT_EXIT =
* IS_PRINT =
* IS_REPREP_ID =
* I_SCREEN_START_COLUMN = 0
* I_SCREEN_START_LINE = 0
* I_SCREEN_END_COLUMN = 0
* I_SCREEN_END_LINE = 0
* I_HTML_HEIGHT_TOP = 0
* I_HTML_HEIGHT_END = 0
* IT_ALV_GRAPHICS =
* IT_HYPERLINK =
* IT_ADD_FIELDCAT =
* IT_EXCEPT_QINFO =
* IR_SALV_FULLSCREEN_ADAPTER =
* IMPORTING
* E_EXIT_CAUSED_BY_CALLER =
* ES_EXIT_CAUSED_BY_USER =
TABLES
t_outtab = it_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.
2013 Aug 19 3:09 PM
Just wanted to point out that for the Count column we can use either the initial value (1) in the table declaration (look up DATA... VALUE... in ABAP Help) or modify multiple rows with MODIFY ... WHERE ... instead of looping through the table.
2013 Aug 19 3:45 PM