QQ群 :SAP干货铺, 群号:775662808
所有群管理严格,严格禁止一切外来链接、招聘、广告等垃圾信息!
效果:carrid 列的第二行 设置为热键,CONNID 第三行设置为button
code:标签:Styles,cl,demo,CELLTYPE,LS,DATA,TYPE,SPFLI,SALV From: https://blog.51cto.com/u_15680210/5757907
*&---------------------------------------------------------------------*
*& Report ZLM_ALV004
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT ZLM_ALV004.
*
CLASS LCL_REPORT DEFINITION.
*
PUBLIC SECTION.
TYPES : BEGIN OF SPFLI_STRUC.
INCLUDE TYPE SPFLI.
TYPES : I_CELLTYPE TYPE SALV_T_INT4_COLUMN,
END OF SPFLI_STRUC.
DATA: GT_SPFLI TYPE STANDARD TABLE OF SPFLI_STRUC.
* ALV reference
DATA: O_ALV TYPE REF TO CL_SALV_TABLE.
METHODS:
GET_DATA, " data selection
GENERATE_OUTPUT. " Generating output
*
PRIVATE SECTION.
METHODS:
SET_COLUMNS. " Set columns
ENDCLASS. "lcl_report DEFINITION
*
*
START-OF-SELECTION.
DATA: LO_REPORT TYPE REF TO LCL_REPORT.
*
CREATE OBJECT LO_REPORT.
LO_REPORT->GET_DATA( ).
LO_REPORT->GENERATE_OUTPUT( ).
*
CLASS LCL_REPORT IMPLEMENTATION.
*
METHOD GET_DATA.
* data selection
SELECT *
FROM SPFLI
INTO CORRESPONDING FIELDS OF TABLE GT_SPFLI.
FIELD-SYMBOLS: <LFS_SPFLI> LIKE LINE OF GT_SPFLI.
DATA: LT_CELLTYPE TYPE SALV_T_INT4_COLUMN.
DATA: LS_CELLTYPE LIKE LINE OF LT_CELLTYPE.
LOOP AT GT_SPFLI ASSIGNING <LFS_SPFLI>.
CLEAR: LT_CELLTYPE.
* Only CARRID for 2nd record
IF SY-TABIX = 2.
LS_CELLTYPE-COLUMNNAME = 'CARRID'.
LS_CELLTYPE-VALUE = IF_SALV_C_CELL_TYPE=>HOTSPOT.
APPEND LS_CELLTYPE TO LT_CELLTYPE.
* Only CONNID for 3rd record
ELSEIF SY-TABIX = 3.
LS_CELLTYPE-COLUMNNAME = 'CONNID'.
LS_CELLTYPE-VALUE = IF_SALV_C_CELL_TYPE=>BUTTON.
APPEND LS_CELLTYPE TO LT_CELLTYPE.
* Entire 5th record
ELSEIF SY-TABIX = 5.
LS_CELLTYPE-COLUMNNAME = ".
LS_CELLTYPE-VALUE = IF_SALV_C_CELL_TYPE=>HOTSPOT.
APPEND LS_CELLTYPE TO LT_CELLTYPE.
ENDIF.
<LFS_SPFLI>-I_CELLTYPE = LT_CELLTYPE.
ENDLOOP.
ENDMETHOD. "get_data
*
METHOD GENERATE_OUTPUT.
* New ALV instance
DATA: LX_MSG TYPE REF TO CX_SALV_MSG.
TRY.
CL_SALV_TABLE=>FACTORY(
IMPORTING
R_SALV_TABLE = O_ALV
CHANGING
T_TABLE = GT_SPFLI ).
CATCH CX_SALV_MSG INTO LX_MSG.
ENDTRY.
*
* Setting up the Columns
ME->SET_COLUMNS( ).
* Displaying the ALV
O_ALV->DISPLAY( ).
ENDMETHOD. "generate_output
*
METHOD SET_COLUMNS.
*
*...Get all the Columns
DATA: LO_COLS TYPE REF TO CL_SALV_COLUMNS_TABLE.
LO_COLS = O_ALV->GET_COLUMNS( ).
*
* set the Column optimization
LO_COLS->SET_OPTIMIZE( 'X' ).
* Set the Cell Type
TRY.
LO_COLS->SET_CELL_TYPE_COLUMN( 'I_CELLTYPE' ).
CATCH CX_SALV_DATA_ERROR. "#EC NO_HANDLER
ENDTRY.
ENDMETHOD. "SET_COLUMNS
ENDCLASS. "lcl_report IMPLEMENTATION