我写的一个测试程序,看看这样行不,可别见笑呀。
*&---------------------------------------------------------------------*
*& Report ZTEST_TTEST_ALV
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT ZTEST_TTEST_ALV.
TYPE-POOLS: SLIS.
TYPES:
BEGIN OF TYP_VALUE,
TITLE TYPE CHAR40,
WAERS TYPE BSID-WAERS,
DMBTR TYPE BSID-DMBTR,
END OF TYP_VALUE.
CONSTANTS:
CNS_H TYPE CHAR1 VALUE 'H',
CNS_S TYPE CHAR1 VALUE 'S',
CNS_STATUS TYPE SLIS_FORMNAME VALUE 'SET_PF_STATUS_ALV',
CNS_TOPPG TYPE SLIS_FORMNAME VALUE 'SET_TOP_OF_PAGE_ALV'.
DATA:
GT_VALUE TYPE TABLE OF TYP_VALUE,
GS_VALUE TYPE TYP_VALUE,
GT_TOTAL TYPE TABLE OF TYP_VALUE,
GS_TOTAL TYPE TYP_VALUE,
GW_DMBTR(16) TYPE P DECIMALS 3,
GT_EVENT TYPE SLIS_T_EVENT ,
GS_EVENT LIKE LINE OF GT_EVENT,
GT_FIELDCAT TYPE SLIS_T_FIELDCAT_ALV ,"ALV項目部テーブル
GS_FIELDCAT LIKE LINE OF GT_FIELDCAT, "ALV項目部テーブルヘッダ
GT_TITLE TYPE SLIS_T_LISTHEADER, "ALVヘッダー内部テーブル
GS_TITLE LIKE LINE OF GT_TITLE. "ALVヘッダ内部テーブルヘッダ
DATA:
LAYOUT TYPE SLIS_LAYOUT_ALV ,
I_GRID_TITLE TYPE LVC_TITLE,
TEM_GRID TYPE REF TO CL_GUI_ALV_GRID.
*----------------------------------------------------------------------*
* CLASS LCL_EVENT_RECEIVER DEFINITION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS LCL_EVENT_RECEIVER DEFINITION.
PUBLIC SECTION.
METHODS:
HANDLE_MODIFY
FOR EVENT DATA_CHANGED_FINISHED OF CL_GUI_ALV_GRID
IMPORTING E_MODIFIED ET_GOOD_CELLS.
ENDCLASS. "LCL_EVENT_RECEIVER DEFINITION
*----------------------------------------------------------------------*
* CLASS LCL_EVENT_RECEIVER IMPLEMENTATION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS LCL_EVENT_RECEIVER IMPLEMENTATION.
METHOD HANDLE_MODIFY.
DATA STBL TYPE LVC_S_STBL.
* 稳定刷新
STBL-ROW = 'X'." 基于行的稳定刷新
STBL-COL = 'X'." 基于列稳定刷新
CALL METHOD TEM_GRID->REFRESH_TABLE_DISPLAY
EXPORTING
IS_STABLE = STBL.
ENDMETHOD. "HANDLE_MODIFY
ENDCLASS. "LCL_EVENT_RECEIVER IMPLEMENTATION
START-OF-SELECTION.
PERFORM FRM_SET_VALUE.
PERFORM SET_OUTPUT_FIELDCAT USING:
'TITLE' TEXT-L14 SPACE 'L' SPACE SPACE SPACE SPACE,
'WAERS' TEXT-L01 SPACE 'L' SPACE SPACE SPACE SPACE,
'DMBTR' TEXT-L02 SPACE 'L' 'WAERS' SPACE 'X' 'X'.
PERFORM SET_LAYOUT.
PERFORM FRM_SET_EVENT.
PERFORM SET_TOP_OF_PAGE_ALV.
* ALV GridControl 全画面
PERFORM DISPLAY_ALV.
*&---------------------------------------------------------------------*
*& Form SET_OUTPUT_FIELDCAT
*&---------------------------------------------------------------------*
* 輸出固定列の定義
*----------------------------------------------------------------------*
* -->PU_FIELDNAME フィールドネーム
* -->PU_SELTEXT_L フィールドテキスト
* -->PU_NO_OUT アウトプット
* -->PU_JUST 左詰
* -->PU_CUR 通貨コード
* -->PU_DECIMALS 小数点以下のN桁
* -->PU_EDIT 編集
* -->PU_DOSUM 集計
*----------------------------------------------------------------------*
FORM SET_OUTPUT_FIELDCAT USING PU_FIELDNAME TYPE CHAR30
PU_SELTEXT_L TYPE CHAR100
PU_NO_OUT TYPE CHAR1
PU_JUST TYPE CHAR1
PU_CUR TYPE CHAR30
PU_DECIMALS
PU_EDIT
PU_DOSUM.
IF PU_CUR <> SPACE.
GS_FIELDCAT-CFIELDNAME = PU_CUR.
ENDIF.
IF PU_DECIMALS <> 0.
GS_FIELDCAT-DECIMALS_OUT = PU_DECIMALS.
ENDIF.
GS_FIELDCAT-FIELDNAME = PU_FIELDNAME.
GS_FIELDCAT-SELTEXT_L = PU_SELTEXT_L.
GS_FIELDCAT-NO_OUT = PU_NO_OUT.
GS_FIELDCAT-JUST = PU_JUST.
GS_FIELDCAT-EDIT = PU_EDIT.
GS_FIELDCAT-DO_SUM = PU_DOSUM.
APPEND GS_FIELDCAT TO GT_FIELDCAT.
CLEAR GS_FIELDCAT.
ENDFORM. " SET_OUTPUT_FIELDCAT
*&---------------------------------------------------------------------*
*& Form DISPLAY_ALV
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM DISPLAY_ALV .
DATA: LW_CPROG TYPE SY-CPROG. "呼出プログラム
LW_CPROG = SY-CPROG.
* ALV GridControl 全画面
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
I_CALLBACK_PROGRAM = LW_CPROG "プログラム
IT_FIELDCAT = GT_FIELDCAT "項目属性
I_SAVE = 'A' "自動保存
I_CALLBACK_PF_STATUS_SET = CNS_STATUS "GUIステータス
I_CALLBACK_TOP_OF_PAGE = CNS_TOPPG "トップページ
IT_EVENTS = GT_EVENT
IS_LAYOUT = LAYOUT
I_GRID_TITLE = I_GRID_TITLE "タイトル
TABLES
T_OUTTAB = GT_VALUE "出力テーブル
EXCEPTIONS
PROGRAM_ERROR = 1
OTHERS = 2.
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID
TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
ENDFORM. " DISPLAY_ALV
*&---------------------------------------------------------------------*
*& Form SET_PF_STATUS_ALV
*&---------------------------------------------------------------------*
* ALV GUI ステータスの設定
*----------------------------------------------------------------------*
FORM SET_PF_STATUS_ALV USING PU_EXTAB TYPE SLIS_T_EXTAB.
* ALV GUI ステータス
SET PF-STATUS 'STANDARD'.
ENDFORM. " SET_PF_STATUS_ALV
*&---------------------------------------------------------------------*
*& Form SET_TOP_OF_PAGE_ALV
*&---------------------------------------------------------------------*
* TOP OF PAGE
*----------------------------------------------------------------------*
FORM SET_TOP_OF_PAGE_ALV .
* 初期化
CLEAR GS_TITLE.
REFRESH GT_TITLE.
* ローカル変数の定義
DATA:
LW_LOW TYPE CHAR6,
LW_YEAR TYPE CHAR6, "年
LW_OPTRG TYPE CHAR20. "輸出範囲
LW_YEAR = SY-DATUM+0(4) + 3.
CONDENSE LW_YEAR.
LW_YEAR+4(2) = SY-DATUM+4(2).
LW_LOW = SY-DATUM+0(6).
CONCATENATE LW_LOW '~' LW_YEAR INTO LW_OPTRG.
PERFORM CREATE_TITLE USING :
CNS_H SPACE TEXT-H01 , "タイトル
CNS_S TEXT-H02 '1000'. "会社コード
PERFORM CREATE_TITLE USING :
CNS_S TEXT-H04 LW_OPTRG. "年月
* 汎用モジュールを呼び出して画面タイトルテキストを出力する
CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
EXPORTING
IT_LIST_COMMENTARY = GT_TITLE.
ENDFORM. " SET_TOP_OF_PAGE_ALV
*&---------------------------------------------------------------------*
*& Form CREATE_TITLE
*&---------------------------------------------------------------------*
* タイトル
*----------------------------------------------------------------------*
* -->PU_TYPE タイプ
* -->PU_KEY キー
* -->PU_INFO 情報
*----------------------------------------------------------------------*
FORM CREATE_TITLE USING PU_TYPE TYPE CHAR1
PU_KEY TYPE CHAR20
PU_INFO .
GS_TITLE-TYP = PU_TYPE. "ヘッダー
GS_TITLE-KEY = PU_KEY. "キー
GS_TITLE-INFO = PU_INFO.
APPEND GS_TITLE TO GT_TITLE.
ENDFORM. " CREATE_TITLE
*&---------------------------------------------------------------------*
*& Form SET_LAYOUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM SET_LAYOUT .
DATA: TITLE(50) TYPE C.
LAYOUT-COLWIDTH_OPTIMIZE = 'X'. "OPTIMIZE
TITLE = '配件周生产计划 明细表'.
WRITE TITLE TO TITLE CENTERED.
I_GRID_TITLE = TITLE. "ALV TITLE
I_GRID_TITLE = I_GRID_TITLE .
ENDFORM. " SET_LAYOUT
*&---------------------------------------------------------------------*
*& Form FRM_SET_VALUE
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM FRM_SET_VALUE .
GS_VALUE-TITLE = 'Japanese (Export.) class'.
GS_VALUE-WAERS = 'CNY'.
GS_VALUE-DMBTR = '1088880'.
APPEND GS_VALUE TO GT_VALUE.
CLEAR GS_VALUE.
GS_VALUE-TITLE = 'Japanese (Export.) class'.
GS_VALUE-WAERS = 'JPY'.
GS_VALUE-DMBTR = '10999909'.
APPEND GS_VALUE TO GT_VALUE.
CLEAR GS_VALUE.
GS_VALUE-TITLE = 'Japanese (Export.) class'.
GS_VALUE-WAERS = 'USD'.
GS_VALUE-DMBTR = '10666609'.
APPEND GS_VALUE TO GT_VALUE.
CLEAR GS_VALUE.
GS_VALUE-TITLE = 'Japanese (Export.) class'.
GS_VALUE-WAERS = 'JPY'.
GS_VALUE-DMBTR = '1009'.
APPEND GS_VALUE TO GT_VALUE.
CLEAR GS_VALUE.
GS_VALUE-TITLE = 'Japanese (Export.) class'.
GS_VALUE-WAERS = 'HKD'.
GS_VALUE-DMBTR = '1009'.
APPEND GS_VALUE TO GT_VALUE.
CLEAR GS_VALUE.
GS_VALUE-TITLE = 'Japanese (Export.) class'.
GS_VALUE-WAERS = 'JPY'.
GS_VALUE-DMBTR = '1009'.
APPEND GS_VALUE TO GT_VALUE.
CLEAR GS_VALUE.
GS_VALUE-TITLE = 'KOREA (Export.) class'.
GS_VALUE-WAERS = 'CNY'.
GS_VALUE-DMBTR = '2800'.
APPEND GS_VALUE TO GT_VALUE.
CLEAR GS_VALUE.
GS_VALUE-TITLE = 'KOREA (Export.) class'.
GS_VALUE-WAERS = 'JPY'.
GS_VALUE-DMBTR = '2090'.
APPEND GS_VALUE TO GT_VALUE.
CLEAR GS_VALUE.
GS_VALUE-TITLE = 'KOREA (Export.) class'.
GS_VALUE-WAERS = 'USD'.
GS_VALUE-DMBTR = '2090'.
APPEND GS_VALUE TO GT_VALUE.
CLEAR GS_VALUE.
GS_VALUE-TITLE = 'KOREA (Export.) class'.
GS_VALUE-WAERS = 'JPY'.
GS_VALUE-DMBTR = '2090'.
APPEND GS_VALUE TO GT_VALUE.
CLEAR GS_VALUE.
GS_VALUE-TITLE = 'KOREA (Export.) class'.
GS_VALUE-WAERS = 'HKD'.
GS_VALUE-DMBTR = '2090'.
APPEND GS_VALUE TO GT_VALUE.
CLEAR GS_VALUE.
GS_VALUE-TITLE = 'KOREA (Export.) class'.
GS_VALUE-WAERS = 'JPY'.
GS_VALUE-DMBTR = '2090'.
APPEND GS_VALUE TO GT_VALUE.
ENDFORM. " FRM_SET_VALUE
*&---------------------------------------------------------------------*
*& Form FRM_SET_EVENT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM FRM_SET_EVENT .
CALL FUNCTION 'REUSE_ALV_EVENTS_GET'
EXPORTING
I_LIST_TYPE = 0
IMPORTING
ET_EVENTS = GT_EVENT
EXCEPTIONS
LIST_TYPE_WRONG = 1
OTHERS = 2.
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID
TYPE SY-MSGTY
NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
READ TABLE GT_EVENT INTO GS_EVENT WITH KEY NAME = SLIS_EV_TOP_OF_PAGE.
IF SY-SUBRC = 0 .
GS_EVENT-FORM = 'SET_TOP_OF_PAGE_ALV'.
APPEND GS_EVENT TO GT_EVENT.
ENDIF.
READ TABLE GT_EVENT INTO GS_EVENT WITH KEY NAME = SLIS_EV_END_OF_LIST.
IF SY-SUBRC = 0.
GS_EVENT-FORM = 'ALV_END_OF_LIST'.
APPEND GS_EVENT TO GT_EVENT.
ENDIF.
GS_EVENT-NAME = 'CALLER_EXIT'.
GS_EVENT-FORM = 'FM_BUTTON'.
APPEND GS_EVENT TO GT_EVENT.
ENDFORM. " FRM_SET_EVENT
*&---------------------------------------------------------------------*
*& Form FM_BUTTON
*&---------------------------------------------------------------------*
* ENTER 事件
*----------------------------------------------------------------------*
* -->E_GRID text
*----------------------------------------------------------------------*
FORM FM_BUTTON USING E_GRID TYPE SLIS_DATA_CALLER_EXIT.
CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR'
IMPORTING
E_GRID = TEM_GRID.
* 設定 ENTER 事件
CALL METHOD TEM_GRID->REGISTER_EDIT_EVENT
EXPORTING
I_EVENT_ID = CL_GUI_ALV_GRID=>MC_EVT_ENTER
EXCEPTIONS
ERROR = 1
OTHERS = 2.
DATA: GT_EVENT_RECEIVER TYPE REF TO LCL_EVENT_RECEIVER .
CREATE OBJECT GT_EVENT_RECEIVER.
SET HANDLER GT_EVENT_RECEIVER->HANDLE_MODIFY FOR TEM_GRID.
ENDFORM. "FM_BUTTON