ALVレポートテンプレート

4829 ワード

最近、プロジェクトにレポートを書き続け、自分でテンプレート、フレームワークをまとめ、ダウンロードし、新しいレポートをアップロードするたびに、いくつかの方法を実現し、不要な重複労働を減らしました.
使用方法:
GET_を実現DATA、取数ロジックを完成する;
INIT_でFIELLDCATで定義されたマクロSET_FIELLDCATは、ヘッダーを設定し、2つのパラメータを受け入れ、1つ目はフィールド名、2つ目はヘッダー表示の名前である.
Z_という名前を自分で作る必要がありますALV_STATUSのGUI STATUS.
*&---------------------------------------------------------------------*

*& Report  ZALV_TEMPLATE

*&

*&---------------------------------------------------------------------*

* :

* :

* :

* :

* :

*----------------------------------------------------------------------*

* 

*

*----------------------------------------------------------------------*



REPORT  ZALV_TEMPLATE MESSAGE-ID ZCOMM.



TYPE-POOLS:SLIS.



TYPES:BEGIN OF TY_TAB,

  FIELDS TYPE C,  " 

  END OF TY_TAB.



DATA:IT_FIELDCAT TYPE SLIS_T_FIELDCAT_ALV,

G_LAYOUT TYPE SLIS_LAYOUT_ALV,

G_REPID LIKE SY-REPID VALUE SY-REPID.



DATA:IT_ITAB TYPE STANDARD TABLE OF TY_TAB.



SELECTION-SCREEN BEGIN OF BLOCK BLK WITH FRAME TITLE TEXT-001.

SELECTION-SCREEN END OF BLOCK BLK.



INITIALIZATION.



START-OF-SELECTION.

  PERFORM GET_DATA.

  IF IT_ITAB IS INITIAL.

    MESSAGE S000 DISPLAY LIKE 'E'.

  ELSE.

    PERFORM INIT_FIELDCAT.

    PERFORM INIT_LAYOUT.

    PERFORM OUTPUT.

  ENDIF.



*&---------------------------------------------------------------------*

*&      Form  GET_DATA

*&---------------------------------------------------------------------*

*        

*----------------------------------------------------------------------*

FORM GET_DATA.

ENDFORM.                    "GET_DATA



*&---------------------------------------------------------------------*

*&      Form  INIT_FIELDCAT

*&---------------------------------------------------------------------*

*        

*----------------------------------------------------------------------*

FORM INIT_FIELDCAT.

  DATA:LW_FIELDCAT TYPE SLIS_FIELDCAT_ALV.

  DEFINE SET_FIELDCAT.

    CLEAR LW_FIELDCAT.

    LW_FIELDCAT-FIELDNAME = &1.

    LW_FIELDCAT-SELTEXT_S = &2.

    LW_FIELDCAT-SELTEXT_M = LW_FIELDCAT-SELTEXT_S.

    LW_FIELDCAT-SELTEXT_L = LW_FIELDCAT-SELTEXT_S.

    APPEND LW_FIELDCAT TO IT_FIELDCAT.

  END-OF-DEFINITION.

ENDFORM.                    "INIT_FIELDCAT



*&---------------------------------------------------------------------*

*&      Form  INIT_LAYOUT

*&---------------------------------------------------------------------*

*        

*----------------------------------------------------------------------*

FORM INIT_LAYOUT.

  G_LAYOUT-DETAIL_POPUP = 'X'.  " 

  G_LAYOUT-F2CODE = '&ETA'.

  G_LAYOUT-ZEBRA = 'X'. " 

ENDFORM.                    "INIT_LAYOUT

*&---------------------------------------------------------------------*

*&      Form  OUTPUT

*&---------------------------------------------------------------------*

*        ALV

*----------------------------------------------------------------------*

FORM OUTPUT.

  G_REPID = SY-REPID.



  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

    EXPORTING

      I_CALLBACK_PROGRAM       = G_REPID

      IS_LAYOUT                = G_LAYOUT

      IT_FIELDCAT              = IT_FIELDCAT[]

      I_SAVE                   = 'A'

      I_CALLBACK_PF_STATUS_SET = 'PF_STATUS_SET'

      I_CALLBACK_USER_COMMAND  = 'USER_COMMAND'

    TABLES

      T_OUTTAB                 = IT_ITAB

    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.                    "OUTPUT

*&---------------------------------------------------------------------*

*&      Form  PF_STATUS_SET

*&---------------------------------------------------------------------*

*        GUI Status

*----------------------------------------------------------------------*

*      -->TR_EXTAB   text

*----------------------------------------------------------------------*

FORM PF_STATUS_SET USING TR_EXTAB TYPE SLIS_T_EXTAB.

  SET PF-STATUS 'Z_ALV_STATUS'.

ENDFORM.                    "PF_STATUS_SET



*&---------------------------------------------------------------------*

*&      Form  USER_COMMAND

*&---------------------------------------------------------------------*

*        

*----------------------------------------------------------------------*

*      -->UCOMM      text

*      -->SELFIELD   text

*----------------------------------------------------------------------*

FORM USER_COMMAND USING UCOMM LIKE SY-UCOMM SELFIELD TYPE SLIS_SELFIELD.

ENDFORM.                    "USER_COMMAND