REPORT z_alv_line_color.
*---------------------------------------------------------------------*
* Example of ALV with Line color *
*---------------------------------------------------------------------*
* Author : Michel PIOUD *
* Email : mpioud@yahoo.fr HomePage : http://www.geocities.com/mpioud *
*---------------------------------------------------------------------*
* Macro definition
DEFINE m_fieldcat.
add 1 to ls_fieldcat-col_pos.
ls_fieldcat-fieldname = &1.
ls_fieldcat-ref_tabname = &2.
append ls_fieldcat to lt_fieldcat.
END-OF-DEFINITION.
TYPE-POOLS: slis. " ALV Global types
SELECTION-SCREEN :
SKIP, BEGIN OF LINE,COMMENT 5(27) v_1 FOR FIELD p_max. "#EC NEEDED
PARAMETERS p_max(2) TYPE n DEFAULT '30' OBLIGATORY. "#EC *
SELECTION-SCREEN END OF LINE.
TYPES:
BEGIN OF ty_vbak,
vkorg TYPE vbak-vkorg, " Sales organization
kunnr TYPE vbak-kunnr, " Sold-to party
vbeln TYPE vbak-vbeln, " Sales document
netwr TYPE vbak-netwr, " Net Value of the Sales Order
line_color(4), " Line color
END OF ty_vbak.
DATA:
* Data displayed
gt_vbak TYPE TABLE OF ty_vbak.
*---------------------------------------------------------------------*
INITIALIZATION.
v_1 = 'Maximum of records to read'. "#EC NOTEXT
*---------------------------------------------------------------------*
START-OF-SELECTION.
PERFORM f_read_data.
PERFORM f_fill_color.
PERFORM f_display_data.
*---------------------------------------------------------------------*
* Form f_read_data
*---------------------------------------------------------------------*
FORM f_read_data.
SELECT * INTO CORRESPONDING FIELDS OF TABLE gt_vbak
FROM vbak UP TO p_max ROWS.
ENDFORM. " F_READ_DATA
*--------------------------------------------------------------------*
* Form f_fill_color
*--------------------------------------------------------------------*
FORM f_fill_color.
DATA l_rnd_value TYPE integer2.
FIELD-SYMBOLS <vbak> TYPE ty_vbak.
LOOP AT gt_vbak ASSIGNING <vbak>.
* Random value
CALL FUNCTION 'RANDOM_I2'
EXPORTING
rnd_min = 0
rnd_max = 3
IMPORTING
rnd_value = l_rnd_value.
CASE l_rnd_value.
WHEN 0.
<vbak>-line_color = 'C100'. " Blue.
WHEN 1.
<vbak>-line_color = 'C300'. " Yellow.
WHEN 2.
<vbak>-line_color = 'C500'. " Green.
WHEN 3.
<vbak>-line_color = 'C600'. " Red.
ENDCASE.
ENDLOOP.
ENDFORM. " F_FILL_COLOR
*---------------------------------------------------------------------*
* Form f_display_data
*---------------------------------------------------------------------*
FORM f_display_data.
DATA:
ls_layout TYPE slis_layout_alv,
ls_fieldcat TYPE slis_fieldcat_alv,
lt_fieldcat TYPE slis_t_fieldcat_alv.
* Build the field catalog
m_fieldcat 'VKORG' 'VBAK'.
m_fieldcat 'KUNNR' 'VBAK'.
m_fieldcat 'VBELN' 'VBAK'.
m_fieldcat 'NETWR' 'VBAK'.
* Fill Layout - Name of the field with color
ls_layout-info_fieldname = 'LINE_COLOR'.
* Display the list
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
is_layout = ls_layout
it_fieldcat = lt_fieldcat
TABLES
t_outtab = gt_vbak.
ENDFORM. " F_DISPLAY_DATA
***************** END OF PROGRAM Z_ALV_LINE_COLOR *********************
유용하게 사용하겠습니다. 감사합니다^^