ABAP OOALV实现 TOP_OF_PAGE事件

  • Post author:
  • Post category:其他



相关类: CL_GUI_ALV_GRID , CL_GUI_SPLITTER_CONTAINER, CL_DD_DOCUMENT, CL_GUI_HTML_VIEWER


CL_GUI_CONTAINER


事    件: TOP_OF_PAGE

DATA: GO_SPLIT_LEFT         TYPE REF TO CL_GUI_SPLITTER_CONTAINER,
      GO_HEADER_LEFT        TYPE REF TO CL_GUI_CONTAINER,
      GO_ALVCONTAINER_LEFT  TYPE REF TO CL_GUI_CONTAINER,
      GREF_DOC_LEFT    TYPE REF TO CL_DD_DOCUMENT,
      GREF_VIEWER_LEFT TYPE REF TO CL_GUI_HTML_VIEWER.
DATA: GO_ALVGRID_LEFT  TYPE REF TO CL_GUI_ALV_GRID,
      GO_DOCKING       TYPE REF TO CL_GUI_DOCKING_CONTAINER.

CLASS LCL_EVENT_RECEIVER DEFINITION DEFERRED .
DATA EVENT_HANDLER_LEFT  TYPE REF TO LCL_EVENT_RECEIVER .

1.先初始化屏幕使用类

CL_GUI_SPLITTER_CONTAINER

将屏幕分为上下两屏,上面置入TOP_OF_PAGE的内容,下面置入ALV

  CREATE OBJECT GO_DOCKING
     EXPORTING
*      PARENT                =
       REPID                 = SY-REPID
       DYNNR                 = GC_SCREEN_0100
       SIDE                  = CL_GUI_DOCKING_CONTAINER=>DOCK_AT_BOTTOM
*      EXTENSION             = 50
*      STYLE                 =
*      LIFETIME              = lifetime_default
*      CAPTION               =
*      METRIC                      = 0
       RATIO                       = 90
*      NO_AUTODEF_PROGID_DYNNR     =
*      NAME                        =
     EXCEPTIONS
       CNTL_ERROR                  = 1
       CNTL_SYSTEM_ERROR           = 2
       CREATE_ERROR                = 3
       LIFETIME_ERROR              = 4
       LIFETIME_DYNPRO_DYNPRO_LINK = 5
       OTHERS                      = 6
      .
  IF SY-SUBRC <> 0.
   MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
              WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.
   CREATE OBJECT GO_SPLIT_LEFT 
     EXPORTING
       PARENT            = GO_DOCKING
       ROWS              = 2
       COLUMNS           = 1
*      NO_AUTODEF_PROGID_DYNNR =
*      NAME              =
    EXCEPTIONS
      CNTL_ERROR        = 1
      CNTL_SYSTEM_ERROR = 2
      OTHERS            = 3
      .
  IF SY-SUBRC <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
              WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.
   CALL METHOD GO_SPLIT_LEFT->GET_CONTAINER
    EXPORTING
      ROW       = 1
      COLUMN    = 1
    RECEIVING
      CONTAINER = GO_HEADER_LEFT. "放置top of pag的容器

  CALL METHOD GO_SPLIT_LEFT->GET_CONTAINER
    EXPORTING
      ROW       = 2
      COLUMN    = 1
    RECEIVING
      CONTAINER = GO_ALVCONTAINER_LEFT. " 放置alv的容器

  CALL METHOD GO_SPLIT_LEFT->SET_ROW_HEIGHT
    EXPORTING
      ID     = 1
      HEIGHT = 10.
  CREATE OBJECT GO_ALVGRID_LEFT  "将ALV置入底层容器
    EXPORTING
*      I_SHELLSTYLE      = 0
*      I_LIFETIME        =
      I_PARENT          = GO_ALVCONTAINER_LEFT
*      I_APPL_EVENTS     = SPACE
*      I_PARENTDBG       =
*      I_APPLOGPARENT    =
*      I_GRAPHICSPARENT  =
*      I_NAME            =
*      I_FCAT_COMPLETE   = SPACE
*      O_PREVIOUS_SRAL_HANDLER =
     EXCEPTIONS
       ERROR_CNTL_CREATE = 1
       ERROR_CNTL_INIT   = 2
       ERROR_CNTL_LINK   = 3
       ERROR_DP_CREATE   = 4
       OTHERS            = 5
      .
  IF SY-SUBRC <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
               WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.

2.实现TOP_OF_PAGE事件

*&---------------------------------------------------------------------*
*& 类声明
*&---------------------------------------------------------------------*
CLASS LCL_EVENT_RECEIVER DEFINITION .
  PUBLIC SECTION.

    METHODS:
      HANDLE_TOP_OF_PAGE_LEFT FOR EVENT TOP_OF_PAGE  OF CL_GUI_ALV_GRID
                            IMPORTING E_DYNDOC_ID,

ENDCLASS .
*&---------------------------------------------------------------------*
*& 类实现
*&---------------------------------------------------------------------*
CLASS LCL_EVENT_RECEIVER IMPLEMENTATION.

  METHOD HANDLE_TOP_OF_PAGE_LEFT.
    PERFORM FRM_TOP_OF_PAGE_LEFT USING E_DYNDOC_ID.
  ENDMETHOD.                    "handle_top_of_page

ENDCLASS .



FORM FRM_TOP_OF_PAGE_LEFT USING P_EREF_DOC TYPE REF TO CL_DD_DOCUMENT.
  DATA: LV_BACK TYPE SDYDO_KEY VALUE SPACE.
  DATA: LV_HTML TYPE STRING,
        M_P  TYPE I.
  DATA: L_LINE   TYPE I,
        L_LINE_S TYPE I,
        L_LINE_E TYPE I.

  LV_HTML = '<html><h3>凭证明细</h3>'.

  P_EREF_DOC->HTML_INSERT(
    EXPORTING
      CONTENTS = LV_HTML
    CHANGING
      POSITION = M_P
  ).

  IF GREF_VIEWER_LEFT IS INITIAL.
    CREATE OBJECT GREF_VIEWER_LEFT
      EXPORTING
        PARENT = GO_HEADER_LEFT.
  ENDIF.

  CALL FUNCTION 'REUSE_ALV_GRID_COMMENTARY_SET'
    EXPORTING
      DOCUMENT = GREF_DOC_LEFT
      BOTTOM   = SPACE.

  CALL METHOD GREF_DOC_LEFT->MERGE_DOCUMENT.
  CALL METHOD GREF_DOC_LEFT->SET_DOCUMENT_BACKGROUND
    EXPORTING
      PICTURE_ID = LV_BACK.
  GREF_DOC_LEFT->HTML_CONTROL = GREF_VIEWER_LEFT.
  CALL METHOD GREF_DOC_LEFT->DISPLAY_DOCUMENT
    EXPORTING
      REUSE_CONTROL = 'X'
      PARENT        = GO_HEADER_LEFT.

3. 把TOP_OF_PAG事件注册到ALV上面

CREATE OBJECT EVENT_HANDLER_LEFT.  
SET HANDLER EVENT_HANDLER_LEFT->HANDLE_TOP_OF_PAGE_LEFT
          FOR GO_ALVGRID_LEFT.

4.初始化DOCUMENT,实现TOP OF PAGE

    CREATE OBJECT GREF_DOC_LEFT.
    CALL METHOD GREF_DOC_LEFT->INITIALIZE_DOCUMENT.

    CALL METHOD GO_ALVGRID_LEFT->LIST_PROCESSING_EVENTS
      EXPORTING
        I_EVENT_NAME = 'TOP_OF_PAGE'
        I_DYNDOC_ID  = GREF_DOC_LEFT.



版权声明:本文为qq_40977705原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。