Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

ALV Traffic lights for subtotal

Former Member
0 Kudos

Hi,

How can I use "traffic lights" that depend on the subtotals of one field in one ALV?

Thank you

1 ACCEPTED SOLUTION

raymond_giuseppi
Active Contributor
0 Kudos

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

5 REPLIES 5

Former Member
0 Kudos

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

0 Kudos

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

raymond_giuseppi
Active Contributor
0 Kudos

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

0 Kudos

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

0 Kudos

Look at my sample using [link|] provided, add this coding in your report, put your own code in the evaluate_record FORM, this form will receive and update sub-total records, with the same structure than the detail records of the displayed internal table.

Regards,

Raymond