This program demonstrates how to color individual cell in an ALV List. The same logic works for ALV grid also.
The ALV:
The Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111
|
REPORT ztest_sourav31. TYPE-POOLS: slis. TYPES: BEGIN OF x_sflight, sflight TYPE sflight. TYPES prop TYPE slis_t_specialcol_alv. TYPES END OF x_sflight. DATA: i_sflight TYPE STANDARD TABLE OF sflight, itab_sflight TYPE STANDARD TABLE OF x_sflight INITIAL SIZE 0, wa_prop TYPE slis_specialcol_alv, average TYPE s_seatsocc, layout TYPE slis_layout_alv, fieldcat TYPE slis_t_fieldcat_alv. FIELD-SYMBOLS: <wa> TYPE ANY, <field> TYPE ANY, <wa_sflight> TYPE x_sflight, <wa_fcat> TYPE slis_fieldcat_alv. START-OF-SELECTION. SELECT FROM sflight INTO TABLE i_sflight. CHECK sy-subrc = 0. SELECT AVG( seatsocc ) FROM sflight INTO average. CHECK sy-subrc = 0. END-OF-SELECTION. LOOP AT i_sflight ASSIGNING <wa>. APPEND INITIAL LINE TO itab_sflight ASSIGNING <wa_sflight>. DO. ASSIGN COMPONENT sy-index OF STRUCTURE <wa> TO <field>. IF sy-subrc = 0. IF sy-index = 9. IF <field> > average. wa_prop-fieldname = 'SFLIGHT-SEATSOCC'. wa_prop-color-col = '5'. wa_prop-color-int = '0'. wa_prop-color-inv = '0'. wa_prop-nokeycol = 'X'. APPEND wa_prop TO <wa_sflight>-prop. ELSE. wa_prop-fieldname = 'SFLIGHT-SEATSOCC'. wa_prop-color-col = '6'. wa_prop-color-int = '0'. wa_prop-color-inv = '0'. wa_prop-nokeycol = 'X'. APPEND wa_prop TO <wa_sflight>-prop. ENDIF. ENDIF. ELSE. EXIT. ENDIF. ENDDO. <wa_sflight>-sflight = <wa>. ENDLOOP. layout-coltab_fieldname = 'PROP'. CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE' EXPORTING i_program_name = 'ZTEST_SOURAV31' i_internal_tabname = 'ITAB_SFLIGHT' i_structure_name = 'SFLIGHT' i_client_never_display = 'X' CHANGING ct_fieldcat = fieldcat EXCEPTIONS inconsistent_interface = 1 program_error = 2 OTHERS = 3. IF sy-subrc <> 0.
ENDIF. LOOP AT fieldcat ASSIGNING <wa_fcat>. CONCATENATE 'SFLIGHT-' <wa_fcat>-fieldname INTO <wa_fcat>-fieldname. IF <wa_fcat>-cfieldname IS NOT INITIAL. CONCATENATE 'SFLIGHT-' <wa_fcat>-cfieldname INTO <wa_fcat>-cfieldname. ENDIF. ENDLOOP. CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY' EXPORTING i_callback_program = 'ZTEST_SOURAV31' is_layout = layout it_fieldcat = fieldcat TABLES t_outtab = itab_sflight EXCEPTIONS program_error = 1 OTHERS = 2. IF sy-subrc <> 0.
ENDIF.
|
No comments:
Post a Comment