本文就介绍这种情况的:
效果
代码
REPORT ZLM_ALV01.
TYPE-POOLS: SLIS, ICON.
DATA:BEGIN OF STR_DATA,
CHECKBOX TYPE CHECKBOX,
CARRID LIKE SFLIGHT-CARRID,
CONNID LIKE SFLIGHT-CONNID,
FLDATE LIKE SFLIGHT-FLDATE,
PRICE LIKE SFLIGHT-PRICE,
CURRENCY LIKE SFLIGHT-CURRENCY,
END OF STR_DATA.
DATA: GT_DATA LIKE TABLE OF STR_DATA,
GS_DATA LIKE STR_DATA.
DATA:GS_LAYOUT TYPE SLIS_LAYOUT_ALV.
DATA:GT_FIELDCATALOG TYPE SLIS_T_FIELDCAT_ALV .
START-OF-SELECTION.
SELECT * FROM SFLIGHT INTO CORRESPONDING FIELDS OF TABLE GT_DATA.
CLEAR GT_FIELDCATALOG[].
CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
EXPORTING
I_PROGRAM_NAME = SY-REPID
I_INTERNAL_TABNAME = 'STR_DATA'
* I_STRUCTURE_NAME = ''
* I_CLIENT_NEVER_DISPLAY = 'X'
I_INCLNAME = SY-REPID
* I_BYPASSING_BUFFER = 'X'
CHANGING
CT_FIELDCAT = GT_FIELDCATALOG
EXCEPTIONS
INCONSISTENT_INTERFACE = 1
PROGRAM_ERROR = 2
OTHERS = 3.
IF GT_FIELDCATALOG[] IS INITIAL.
RETURN.
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 = 'CHECKBOX'.
<LS_FILEDCAT>-CHECKBOX = 'X'.
<LS_FILEDCAT>-EDIT = 'X'.
<LS_FILEDCAT>-SELTEXT_L = '选择'.
<LS_FILEDCAT>-SELTEXT_M = '选择'.
<LS_FILEDCAT>-SELTEXT_S = '选择'.
ENDIF.
* <LS_FILEDCAT>-JUST = 'R'.
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
TABLES
T_OUTTAB = GT_DATA
EXCEPTIONS
PROGRAM_ERROR = 1
OTHERS = 2.
IF SY-SUBRC <> 0.
* Implement suitable error handling here
ENDIF.
本位币左对齐了,如果想右对齐:
LOOP AT GT_FIELDCATALOG ASSIGNING <LS_FILEDCAT>.
<LS_FILEDCAT>-DDICTXT ='L'.
IF <LS_FILEDCAT>-FIELDNAME = 'CHECKBOX'.
<LS_FILEDCAT>-CHECKBOX = 'X'.
<LS_FILEDCAT>-EDIT = 'X'.
<LS_FILEDCAT>-SELTEXT_L = '选择'.
<LS_FILEDCAT>-SELTEXT_M = '选择'.
<LS_FILEDCAT>-SELTEXT_S = '选择'.
ENDIF.
<LS_FILEDCAT>-JUST = 'R'.
ENDLOOP.
可能执行中会dump。
报错:
需要设置: