2009年11月2日 星期一

ALV架構

呼叫前必須先完成TYPE-POOLS與ALV的欄位宣告
再程式輸出時呼叫CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'來完成


*&---------------------------------------------------------------------*
*& Report  ZBEN_TEST01
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT  ZBEN_TEST01 .
************************************************************************
* TYPES and TYPE-POOLS *
************************************************************************
TYPE-POOLS: SLIS.
************************************************************************
* Working Area & Internal Tables    *
************************************************************************
*ITAB
DATA: BEGIN OF GW_RPT,
    EBELN LIKE EKPO-EBELN,
    EBELP LIKE EKPO-EBELP,
  END OF GW_RPT.
DATA: GT_RPT LIKE GW_RPT OCCURS 0 WITH HEADER LINE.

*ALV
DATA: GT_FIELDCAT  TYPE SLIS_T_FIELDCAT_ALV,
  GT_SORTINFO  TYPE SLIS_T_SORTINFO_ALV,
  GT_EVENTS    TYPE SLIS_T_EVENT,
  G_REPID   TYPE SY-REPID,
  L_LAYOUT TYPE SLIS_LAYOUT_ALV,
  L_SELFIELD   TYPE SLIS_SELFIELD,
  SAV_SY_REPID TYPE SY-REPID,
  L_PRINT   TYPE SLIS_PRINT_ALV,
  GT_LIST_TOP_OF_PAGE TYPE SLIS_T_LISTHEADER.
DATA: BEGIN OF SELTAB OCCURS 0.
    INCLUDE STRUCTURE RSPARAMS.
DATA: END OF SELTAB.
************************************************************************
* Selection Screen *
************************************************************************
SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME.
PARAMETERS: P_EBELN LIKE EKKO-EBELN OBLIGATORY.
SELECTION-SCREEN END OF BLOCK B1.
************************************************************************
* START-OF-SELECTION Event *
************************************************************************
START-OF-SELECTION.
  PERFORM GET_DATA.
  PERFORM PROCESS_DATA.
  PERFORM PRINT_DATA.

************************************************************************
* END-OF-SELECTION Event    *
************************************************************************
END-OF-SELECTION.
*&---------------------------------------------------------------------*
*&   Form  GET_DATA
*&---------------------------------------------------------------------*
FORM GET_DATA.
  SELECT EBELN EBELP FROM EKPO
    INTO CORRESPONDING FIELDS OF TABLE GT_RPT
   WHERE EBELN = P_EBELN.
ENDFORM.     " GET_DATA
*&---------------------------------------------------------------------*
*&   Form  PROCESS_DATA
*&---------------------------------------------------------------------*
FORM PROCESS_DATA.
ENDFORM.     " PROCESS_DATA
*&---------------------------------------------------------------------*
*&   Form  PRINT_DATA
*&---------------------------------------------------------------------*
FORM PRINT_DATA.
  G_REPID = SY-REPID.
  PERFORM FIELDCAT_INIT USING GT_FIELDCAT[].
  PERFORM SORTINFO_INIT USING GT_SORTINFO[].
  PERFORM EVENTS_INIT   USING GT_EVENTS[].
  PERFORM LAYOUT_INIT   USING L_LAYOUT.
  PERFORM PRINT_INIT    USING L_PRINT.
  CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
   EXPORTING
    I_CALLBACK_PROGRAM    = G_REPID
    IT_FIELDCAT   = GT_FIELDCAT[]
    IT_SORT   = GT_SORTINFO[]
    IT_EVENTS     = GT_EVENTS
    IS_LAYOUT     = L_LAYOUT
    I_SAVE    = 'A'
    IS_PRINT = L_PRINT
   TABLES
    T_OUTTAB = GT_RPT.
  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.     " PRINT_DATA
*---------------------------------------------------------------------*
*    FORM fieldcat_inite    *
*---------------------------------------------------------------------*
FORM FIELDCAT_INIT USING IT_FIELDCATE TYPE SLIS_T_FIELDCAT_ALV.
  DATA: ST_FIELDCATE TYPE SLIS_FIELDCAT_ALV.
  ST_FIELDCATE-TABNAME = 'IT_RPT'.
  ST_FIELDCATE-FIELDNAME   = 'EBELN'.
  ST_FIELDCATE-SELTEXT_L   = '單號'.
  ST_FIELDCATE-OUTPUTLEN   = 10.
  ST_FIELDCATE-KEY = 'X'.
  APPEND ST_FIELDCATE TO IT_FIELDCATE.
  CLEAR  ST_FIELDCATE.
  ST_FIELDCATE-TABNAME = 'IT_RPT'.
  ST_FIELDCATE-FIELDNAME   = 'EBELP'.
  ST_FIELDCATE-SELTEXT_L   = '項次'.
  ST_FIELDCATE-OUTPUTLEN   = 10.
  ST_FIELDCATE-KEY = 'X'.
  APPEND ST_FIELDCATE TO IT_FIELDCATE.
  CLEAR  ST_FIELDCATE.
ENDFORM.
*---------------------------------------------------------------------*
*    FORM sortinfo_init     *
*---------------------------------------------------------------------*
FORM SORTINFO_INIT  USING IT_SORTINFOE TYPE SLIS_T_SORTINFO_ALV.
  DATA: ST_SORTE TYPE SLIS_SORTINFO_ALV.
ENDFORM.
*---------------------------------------------------------------------*
*    FORM events_init   *
*---------------------------------------------------------------------*
FORM EVENTS_INIT USING RT_EVENTS TYPE SLIS_T_EVENT.
  DATA: LS_EVENT TYPE SLIS_ALV_EVENT.
  CALL FUNCTION 'REUSE_ALV_EVENTS_GET'
   EXPORTING
    I_LIST_TYPE = 0
   IMPORTING
    ET_EVENTS   = RT_EVENTS.
  READ TABLE RT_EVENTS WITH KEY NAME = SLIS_EV_TOP_OF_PAGE
   INTO LS_EVENT.
  IF SY-SUBRC = 0.
    MOVE 'TOP_OF_PAGE' TO LS_EVENT-FORM.
    MODIFY RT_EVENTS FROM LS_EVENT INDEX SY-TABIX.
  ENDIF.
ENDFORM.
*---------------------------------------------------------------------*
*    FORM USER_COMMAND *
*---------------------------------------------------------------------*
FORM USER_COMMAND USING R_UCOMM LIKE SY-UCOMM
    RS_SELFIELD TYPE SLIS_SELFIELD.
  L_SELFIELD = RS_SELFIELD.
ENDFORM.
*&---------------------------------------------------------------------*
*&   Form  LAYOUT_INIT
*&---------------------------------------------------------------------*
FORM LAYOUT_INIT USING P_L_LAYOUT TYPE SLIS_LAYOUT_ALV.
  P_L_LAYOUT-ZEBRA  = 'X'.
ENDFORM.     " LAYOUT_INIT
*&---------------------------------------------------------------------*
*&   Form  PRINT_INIT
*&---------------------------------------------------------------------*
FORM PRINT_INIT USING  P_L_PRINT TYPE SLIS_PRINT_ALV.
ENDFORM.     " PRINT_INIT

沒有留言:

張貼留言