06-29-2011 1:07 PM
Hi,
How can I use "traffic lights" that depend on the subtotals of one field in one ALV?
Thank you
06-29-2011 1:34 PM
You may handle after_refresh event of class (cl_gui_alv_grid), In the method handle_after_refresh
- Check if flag to avoid recursive loop is not set
- Call method get_filtered_entries to get data displayed
- Call method get_subtotals to get subtotals (pointers on)
- Update subtotals or detail records
- Set the flag
- Call method refresh_table_display to redisplay data
- Clear the flag
Regards,
Raymond
Look at sample in my answer in
06-29-2011 1:33 PM
Hi Nuno Barros,
Please check the below link... it will guide you to fulfill your requirement..
http://wiki.sdn.sap.com/wiki/display/Snippets/ALVGRIDCOMPLETEEXAMPLEWITHTOOLBARBUTTONSUSINGCLASS.
http://www.erpgenie.com/sap/abap/controls/alvgrid.htm
http://wiki.sdn.sap.com/wiki/display/Snippets/TrafficlightsinALVdisplay
Or check this code...you may find it easy
*&----
*& Declaration part
*&----
TYPES: BEGIN OF t_lights,
matnr TYPE mard-matnr,
werks TYPE mard-werks,
lgort TYPE mard-lgort,
lights TYPE char4, "Variable is needs to be declared with length 4 char
END OF t_lights.
DATA: w_lights TYPE t_lights.
DATA: i_lights TYPE STANDARD TABLE OF t_lights.
FORM get_data .
SELECT matnr werks lgort
FROM mard
INTO CORRESPONDING FIELDS OF TABLE i_lights UP TO 10 ROWS.
"Just pass 1=red or 2=yellow or 3=green to lights fields ( HERE YOU CAN CHECK FOR YOUR CONDITION AND ASSIGN LIGHTS ACCORDIGLY)
LOOP AT i_lights INTO w_lights .
IF sy-tabix BETWEEN 1 AND 3.
w_lights-lights = '1'.
ELSEIF sy-tabix BETWEEN 4 AND 7.
w_lights-lights = '2'.
ELSEIF sy-tabix BETWEEN 8 AND 10.
w_lights-lights = '3'.
ENDIF.
MODIFY i_lights FROM w_lights INDEX sy-tabix TRANSPORTING lights.
ENDLOOP.
ENDFORM. " get_data
&----
*& Form build_layout
&----
FORM build_layout .
w_layout-colwidth_optimize = 'X'.
w_layout-zebra = 'X'.
w_layout-lights_fieldname = 'LIGHTS'.
w_layout-lights_tabname = 'I_LIGHTS'.
w_layout-lights_rollname = 'Hits'.
ENDFORM. " build_layout
&----
*& Form list_display
&----
FORM list_display .
DATA:
l_program TYPE sy-repid.
l_program = sy-repid.
CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
EXPORTING
i_callback_program = l_program
is_layout = w_layout
it_fieldcat = i_fieldcat
TABLES
t_outtab = i_lights
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.
ENDFORM. " list_display
Thanks
Shankar
06-30-2011 11:27 AM
Hi shankar,
Thanks for your answer but that doesn't answer my problem. I know already how to implement traffic lights for a simple ALV. My question here is how to implement these traffic lights for the subtotals of a certain field of the ALV. I suppose the solution should be done at the ALV level and not at the level of the table containing the data.
Nevertheless, thanks a lot for your time and for the promptitude of your answer.
Best regards, Nuno
06-29-2011 1:34 PM
You may handle after_refresh event of class (cl_gui_alv_grid), In the method handle_after_refresh
- Check if flag to avoid recursive loop is not set
- Call method get_filtered_entries to get data displayed
- Call method get_subtotals to get subtotals (pointers on)
- Update subtotals or detail records
- Set the flag
- Call method refresh_table_display to redisplay data
- Clear the flag
Regards,
Raymond
Look at sample in my answer in
06-30-2011 12:10 PM
Hi Raymond,
Your answer seems to point in the right direction. The problem is that I started learning ABAP only 2 weeks ago. Can you explain me better the solution you describe, namely the part of the "flag". I understood that the code you showed retrieves the subtotals information using get_subtotals method and saves this information in that 10 variables. Then, you reassign the subtotals info to the <total> and finally you refresh the displayed data. On the other side, I don't understand how am I able to read the subtotal values, interpret them (apply the condition for red, green or yellow) and finally include the traffic lights in the alv.
Thanks a lot, Nuno
07-01-2011 12:33 PM