1、先定義變量
DATA: W_EVENTS LIKE LINE OF IT_EVENTS,
IT_EVENTS TYPE SLIS_T_EVENT.
2、給變量賦值
" Display Header in ALV Report
CALL FUNCTION 'REUSE_ALV_EVENTS_GET'
EXPORTING
I_LIST_TYPE = 0
IMPORTING
ET_EVENTS = IT_EVENTS.
READ TABLE IT_EVENTS WITH KEY NAME = 'TOP_OF_PAGE' INTO W_EVENTS.
IF SY-SUBRC = 0.
MOVE 'HEADER' TO W_EVENTS-FORM.
MODIFY IT_EVENTS FROM W_EVENTS INDEX SY-TABIX.
ENDIF.
3、表頭子程序
"ALV上一行四列顯示
FORM header.
DATA: GT_TX_REMARK LIKE TLINE OCCURS 0 WITH HEADER LINE.
DATA:LR_CONTENT TYPE REF TO CL_SALV_FORM_ELEMENT
,LR_ROWS TYPE REF TO CL_SALV_FORM_LAYOUT_GRID
,LR_ROW TYPE REF TO CL_SALV_FORM_LAYOUT_FLOW
,LR_GRID_STATUS TYPE REF TO CL_SALV_FORM_LAYOUT_GRID
.
CREATE OBJECT LR_ROWS.
LR_CONTENT = LR_ROWS.
LR_ROW = LR_ROWS->ADD_ROW( ).
LR_GRID_STATUS = LR_ROW->CREATE_GRID( ).
"第二行是中英文說明
ADD 1 TO LI_ROW.
* , LC_Z1088 TYPE ZAUSP-Z1084 " 客戶型號
* , LC_Z1083 TYPE ZAUSP-Z1083 "公司型號
* LC_Z1089 TYPE ZAUSP-Z1089 "投產情況
IF SY-LANGU = '1' OR SY-LANGU = 'M'.
CONCATENATE '英文說明 : ' LC_MAKTX_EN INTO LC_INFO SEPARATED
BY SPACE.
ELSE.
CONCATENATE 'Description(EN) : ' LC_MAKTX_EN INTO LC_INFO SEPARATED
BY SPACE.
ENDIF.
LR_GRID_STATUS->CREATE_TEXT(
ROW = LI_ROW
COLUMN = 1
TEXT = LC_INFO ).
IF SY-LANGU = '1' OR SY-LANGU = 'M'.
CONCATENATE '客戶型號 :' LC_Z1088 INTO LC_INFO SEPARATED BY
SPACE.
ELSE.
CONCATENATE 'CUSTOM_MODEL :' LC_Z1088 INTO LC_INFO SEPARATED BY
SPACE.
ENDIF.
LR_GRID_STATUS->CREATE_TEXT(
ROW = LI_ROW
COLUMN = 3
TEXT = LC_INFO ).
"文本第二行
CLEAR GT_TX_REMARK.
READ TABLE GT_TX_REMARK INDEX 2.
LR_GRID_STATUS->CREATE_TEXT(
ROW = LI_ROW
COLUMN = 4
TEXT = GT_TX_REMARK-TDLINE ).
ENDFORM.
4、顯示ALV
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
I_CALLBACK_PROGRAM = G_REPID
IT_FIELDCAT = GT_FIELDCAT[]
I_CALLBACK_PF_STATUS_SET = G_STATUS
I_CALLBACK_USER_COMMAND = 'USER_COMMAND'
IS_LAYOUT = X_LAYOUT
IT_EVENTS = IT_EVENTS "此處的事件代碼就是顯示ALV表頭
IS_VARIANT = G_VARIANT
I_SAVE = G_SAVE " A = All => Standard & User
TABLES
T_OUTTAB = INTAB
EXCEPTIONS
PROGRAM_ERROR = 1
OTHERS = 2.