直接上干货了:
如果字段比较多,当左右拖动滚动条的时候,某列一直显示,跟着滚动。
demo代码;
DATA:GT_DATA TYPE TABLE OF SPFLI.
DATA:GS_LAYOUT TYPE SLIS_LAYOUT_ALV.
DATA:GT_FIELDCATALOG TYPE SLIS_T_FIELDCAT_ALV .
DATA:LV_ALV_STRUCTURE TYPE DD02L-TABNAME VALUE 'ZLMS_ALV'.
START-OF-SELECTION.
SELECT * FROM SPFLI INTO TABLE GT_DATA.
CLEAR GT_FIELDCATALOG[].
CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
EXPORTING
I_STRUCTURE_NAME = LV_ALV_STRUCTURE
CHANGING
CT_FIELDCAT = GT_FIELDCATALOG
EXCEPTIONS
INCONSISTENT_INTERFACE = 1
PROGRAM_ERROR = 2
OTHERS = 3.
IF SY-SUBRC <> 0.
ENDIF.
FIELD-SYMBOLS <LS_FILEDCAT> LIKE LINE OF GT_FIELDCATALOG.
LOOP AT GT_FIELDCATALOG ASSIGNING <LS_FILEDCAT>.
<LS_FILEDCAT>-DDICTXT ='L'.
IF <LS_FILEDCAT>-FIELDNAME = 'CITYFROM' .
<LS_FILEDCAT>-FIX_COLUMN = 'X'.
<LS_FILEDCAT>-KEY = 'X'.
ENDIF.
ENDLOOP.
*
GS_LAYOUT-COLWIDTH_OPTIMIZE = 'X'.
GS_LAYOUT-ZEBRA = 'X'.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
I_GRID_TITLE = 'SAP干货铺测试'
IS_LAYOUT = GS_LAYOUT
IT_FIELDCAT = GT_FIELDCATALOG
* I_STRUCTURE_NAME = 'SPFLI'
TABLES
T_OUTTAB = GT_DATA
EXCEPTIONS
PROGRAM_ERROR = 1
OTHERS = 2.
IF SY-SUBRC <> 0.
* Implement suitable error handling here
ENDIF.
其他具体参数,自己查看下就行,比如左对齐,右对齐,合计,key颜色,长短文本,金额数量 参考字段参考表等等等的,自己去一个一个参数验证即可。