Sep 19, 2016

Colors in ALV List Using Function Module 'REUSE_ALV_LIST_DISPLAY'

By Haritha
From saptechnical.com


Colors in ALV List Using Function Module 'REUSE_ALV_LIST_DISPLAY'

Column and Row are colored with a coded color ‘Cxyz’.
    Where C: Color (coding must begin with C)
                 X: Color Number
                 Y: Bold
                 Z: Inverse.

The Selection Screen will be as follows.



In the Selection screen if we enter only the Column Number and color the whole column will be colored as follows.



In the Selection screen if we enter only the row Number and color, the whole column will be colored as follows.


 
 In the Selection screen if we enter both the Row number and the Column Number then that particular cell will be colored as follows (this color is not picked from selection screen, it is already written in the program itself)






Source Code:

REPORT yalvcol_list.

TABLESspfli.

TYPE-POOLSslis.

PARAMETERSp_col      TYPE i,
            p_row      
TYPE i,
            p_color
(4TYPE c.

DATA:
  t_fieldcat      
TYPE slis_t_fieldcat_alv,
  fs_fieldcat     
LIKE LINE OF t_fieldcat,
  fs_layout       
TYPE slis_layout_alv,
  w_color
(4) ,
  w_row           
TYPE i,
  w_fieldname
(20),
  w_prog          
TYPE sy-repid.

DATA:
  
BEGIN OF t_spfli OCCURS 0,
    
color(4),
    
checkbox ,
    cell     
TYPE slis_t_specialcol_alv,
    carrid   
TYPE spfli-carrid,
    connid   
TYPE spfli-connid,
    cityfrom 
TYPE spfli-cityfrom,
    cityto   
TYPE spfli-cityto,
    distance 
TYPE spfli-distance,
  
END OF t_spfli.

DATA:
fs_cell 
LIKE LINE OF t_spfli-cell.

SELECT *
FROM spfli
INTO CORRESPONDING FIELDS OF TABLE t_spfli.

w_color 
p_color.

t_spfli
-color p_color.
IF p_col IS INITIAL AND p_row GT 0.
  
MODIFY t_spfli INDEX p_row TRANSPORTING color.
ENDIF.

fs_fieldcat
-fieldname 'CARRID'.
fs_fieldcat
-ref_tabname 'SPFLI'.
fs_fieldcat
-col_pos 1.
fs_fieldcat
-key 'X'.
fs_fieldcat
-hotspot 'X'.
APPEND fs_fieldcat TO t_fieldcat.

CLEAR fs_fieldcat .
fs_fieldcat
-fieldname 'CONNID'.
fs_fieldcat
-ref_tabname 'SPFLI'.
fs_fieldcat
-col_pos 2.
fs_fieldcat
-key 'X'.
fs_fieldcat
-hotspot 'X'.
APPEND fs_fieldcat TO t_fieldcat.

CLEAR fs_fieldcat .
fs_fieldcat
-fieldname 'DISTANCE'.
fs_fieldcat
-ref_tabname 'SPFLI'.

fs_fieldcat
-col_pos 3.
fs_fieldcat
-key ' '.
fs_fieldcat
-edit 'X'.
APPEND fs_fieldcat TO t_fieldcat.

CLEAR fs_fieldcat.
fs_fieldcat
-fieldname 'CITYFROM'.
fs_fieldcat
-ref_tabname 'SPFLI'.
fs_fieldcat
-col_pos 4.
fs_fieldcat
-key ' '.
APPEND fs_fieldcat TO t_fieldcat.

LOOP AT t_fieldcat INTO fs_fieldcat.
  
IF fs_fieldcat-col_pos EQ p_col.
    fs_fieldcat
-emphasize p_color.
    w_fieldname 
fs_fieldcat-fieldname.
    
IF p_row IS INITIAL AND p_col GT 0.
      
MODIFY t_fieldcat FROM fs_fieldcat TRANSPORTING emphasize.
    
ENDIF.
  
ENDIF.
ENDLOOP.

fs_cell
-fieldname w_fieldname .
fs_cell
-color-col 6.
fs_cell
-nokeycol 'X'.
APPEND fs_cell TO t_spfli-cell.

IF p_row IS NOT INITIAL AND p_col IS NOT INITIAL.
  
MODIFY t_spfli INDEX p_row TRANSPORTING cell.
ENDIF.

fs_layout
-info_fieldname 'COLOR'.
fs_layout
-box_fieldname 'CHECKBOX'.
fs_layout
-coltab_fieldname 'CELL'.
fs_layout
-f2code '&ETA'.

w_prog 
sy-repid.
CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
  
EXPORTING
    i_callback_program 
w_prog
    is_layout          
fs_layout
    it_fieldcat        
t_fieldcat
  
TABLES
    t_outtab           
t_spfli
  
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.

No comments :