QQ群 :SAP干货铺, 群号:775662808
干货:
效果图:
code:
*&---------------------------------------------------------------------*
*& Report ZLM_ALV003
*&
*& sapliumeng
*&---------------------------------------------------------------------*
*&---------------------------------------------------------------------*
REPORT ZLM_ALV003.
CLASS LCL_MAIN DEFINITION.
PUBLIC SECTION.
DATA O_SALV TYPE REF TO CL_SALV_TABLE .
TYPES:
BEGIN OF TY_OUTPUT,
STATUS TYPE CHAR10,
FIELD1 TYPE CHAR30,
END OF TY_OUTPUT.
DATA: T_OUTPUT TYPE STANDARD TABLE OF TY_OUTPUT.
METHODS:
SELECT_DATA,
GENERATE_ALV.
ENDCLASS. "lcl_main DEFINITION
*
START-OF-SELECTION.
DATA: O_MAIN TYPE REF TO LCL_MAIN.
CREATE OBJECT O_MAIN.
O_MAIN->SELECT_DATA( ).
O_MAIN->GENERATE_ALV( ).
*
CLASS LCL_MAIN IMPLEMENTATION.
METHOD SELECT_DATA.
* INCLUDE: <ICON>.
DATA: LS_OUTPUT LIKE LINE OF T_OUTPUT.
DO 3 TIMES.
LS_OUTPUT-STATUS = ICON_GREEN_LIGHT.
LS_OUTPUT-FIELD1 = SY-UNAME.
APPEND LS_OUTPUT TO T_OUTPUT.
LS_OUTPUT-STATUS = ICON_YELLOW_LIGHT.
APPEND LS_OUTPUT TO T_OUTPUT.
LS_OUTPUT-STATUS = ICON_RED_LIGHT.
APPEND LS_OUTPUT TO T_OUTPUT.
LS_OUTPUT-STATUS = ICON_LED_GREEN.
APPEND LS_OUTPUT TO T_OUTPUT.
LS_OUTPUT-STATUS = ICON_LED_RED.
APPEND LS_OUTPUT TO T_OUTPUT.
LS_OUTPUT-STATUS = ICON_LED_YELLOW.
APPEND LS_OUTPUT TO T_OUTPUT.
ENDDO.
ENDMETHOD. "select_Data
METHOD GENERATE_ALV.
DATA: LO_FUNCTIONS TYPE REF TO CL_SALV_FUNCTIONS_LIST.
DATA: LO_FUNCTIONAL_SETTINGS TYPE REF TO CL_SALV_FUNCTIONAL_SETTINGS.
DATA: LO_TOOLTIPS TYPE REF TO CL_SALV_TOOLTIPS,
LV_VALUE TYPE LVC_VALUE.
DATA: LO_COLUMNS TYPE REF TO CL_SALV_COLUMNS.
DATA: LO_COLUMN TYPE REF TO CL_SALV_COLUMN_TABLE.
* INCLUDE: <ICON>.
*
* ALV Object
TRY.
CL_SALV_TABLE=>FACTORY(
IMPORTING
R_SALV_TABLE = O_SALV
CHANGING
T_TABLE = T_OUTPUT ).
CATCH CX_SALV_MSG. "#EC NO_HANDLER
ENDTRY.
* Functions
LO_FUNCTIONS = O_SALV->GET_FUNCTIONS( ).
LO_FUNCTIONS->SET_ALL( ABAP_TRUE ).
*... set the columns
LO_COLUMNS = O_SALV->GET_COLUMNS( ).
"lo_columns->set_optimize( abap_true ).
TRY.
LO_COLUMN ?= LO_COLUMNS->GET_COLUMN( 'STATUS' ).
LO_COLUMN->SET_ICON( IF_SALV_C_BOOL_SAP=>TRUE ).
LO_COLUMN->SET_LONG_TEXT( 'Hover for Tooltip' ).
LO_COLUMN->SET_ALIGNMENT( IF_SALV_C_ALIGNMENT=>CENTERED ).
LO_COLUMN->SET_OUTPUT_LENGTH( 20 ).
CATCH CX_SALV_NOT_FOUND. "#EC NO_HANDLER
ENDTRY.
*...Tooltips
LO_FUNCTIONAL_SETTINGS = O_SALV->GET_FUNCTIONAL_SETTINGS( ).
LO_TOOLTIPS = LO_FUNCTIONAL_SETTINGS->GET_TOOLTIPS( ).
TRY.
LV_VALUE = ICON_GREEN_LIGHT.
LO_TOOLTIPS->ADD_TOOLTIP(
TYPE = CL_SALV_TOOLTIP=>C_TYPE_ICON
VALUE = LV_VALUE
TOOLTIP = 'Everything is Processed' ). "#EC NOTEXT
CATCH CX_SALV_EXISTING. "#EC NO_HANDLER
ENDTRY.
TRY.
LV_VALUE = ICON_YELLOW_LIGHT.
LO_TOOLTIPS->ADD_TOOLTIP(
TYPE = CL_SALV_TOOLTIP=>C_TYPE_ICON
VALUE = LV_VALUE
TOOLTIP = 'Partially processed' ). "#EC NOTEXT
CATCH CX_SALV_EXISTING. "#EC NO_HANDLER
ENDTRY.
TRY.
LV_VALUE = ICON_RED_LIGHT.
LO_TOOLTIPS->ADD_TOOLTIP(
TYPE = CL_SALV_TOOLTIP=>C_TYPE_ICON
VALUE = LV_VALUE
TOOLTIP = 'Nothing Yet processed' ). "#EC NOTEXT
CATCH CX_SALV_EXISTING. "#EC NO_HANDLER
ENDTRY.
*... display the table
O_SALV->DISPLAY( ).
ENDMETHOD. "generate_alv
ENDCLASS. "lcl_main IMPLEMENTATION