SAP OO ALV实现TOP-OF-PAGE页眉显示

不打扰是莪最后的温柔 提交于 2020-03-05 23:19:57
*&---------------------------------------------------------------------*
*& Report  YTEST_OOALV1_DEMO
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT  YTEST_OOALV1_DEMO MESSAGE-ID ZZ  .

DATA: IT_FLIGHT TYPE TABLE OF SFLIGHT.

DATA: OK_CODE LIKE SY-UCOMM,
      SAVE_OK LIKE SY-UCOMM.

DATA:  G_CONTAINER TYPE SCRFNAME VALUE 'CONTROL',
        O_DYNDOC_ID  TYPE REF TO CL_DD_DOCUMENT,
        O_SPLITTER   TYPE REF TO CL_GUI_SPLITTER_CONTAINER,
        O_PARENT_GRID TYPE REF TO CL_GUI_CONTAINER,
        O_PARENT_TOP TYPE REF TO CL_GUI_CONTAINER,
        O_HTML_CNTRL TYPE REF TO CL_GUI_HTML_VIEWER.
*----------------------------------------------------------------------*
*       CLASS LCL_EVENT_HANDLER DEFINITION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS LCL_EVENT_HANDLER DEFINITION .
  PUBLIC SECTION .
    METHODS:
*Event Handler for Top of page
    TOP_OF_PAGE FOR EVENT TOP_OF_PAGE
                          OF CL_GUI_ALV_GRID
                          IMPORTING E_DYNDOC_ID.
ENDCLASS.                    "LCL_EVENT_HANDLER DEFINITION


CLASS LCL_EVENT_HANDLER IMPLEMENTATION.
  METHOD TOP_OF_PAGE.
*   Top-of-page event
    PERFORM EVENT_TOP_OF_PAGE USING O_DYNDOC_ID.
ENDMETHOD.                    "TOP_OF_PAGE
"top_of_page
ENDCLASS. "LCL_EVENT_HANDLER IMPLEMENTATION



DATA: G_CUSTOM_CONTAINER TYPE REF TO CL_GUI_CUSTOM_CONTAINER,
      G_HANDLER TYPE REF TO LCL_EVENT_HANDLER."handler


START-OF-SELECTION.
  SELECT * FROM SFLIGHT UP TO 20 ROWS
                      INTO TABLE IT_FLIGHT.



END-OF-SELECTION.
  IF NOT IT_FLIGHT[] IS INITIAL.
    CALL SCREEN 100.
  ELSE.
    MESSAGE I002 WITH 'NO DATA FOR THE SELECTION'(004).
ENDIF.



MODULE STATUS_0100 OUTPUT.
  SET PF-STATUS 'STATUS'.
  SET TITLEBAR 'TITLE'.
  IF G_CUSTOM_CONTAINER IS INITIAL.
    PERFORM CREATE_AND_INIT_ALV.
  ENDIF.
ENDMODULE.                 " STATUS_0100  OUTPUT

MODULE USER_COMMAND_0100 INPUT.
  CASE SY-UCOMM.
  WHEN 'BACK'.
    LEAVE TO SCREEN 0.
  ENDCASE.
ENDMODULE.                 " USER_COMMAND_0100 INPUT


FORM CREATE_AND_INIT_ALV .
DATA: G_GRID TYPE REF TO CL_GUI_ALV_GRID.

    CREATE OBJECT G_CUSTOM_CONTAINER
      EXPORTING
        CONTAINER_NAME = G_CONTAINER.
* Create TOP-Document
    CREATE OBJECT O_DYNDOC_ID
      EXPORTING
        STYLE = 'ALV_GRID'.
* Create Splitter for custom_container
    CREATE OBJECT O_SPLITTER
      EXPORTING
        PARENT  = G_CUSTOM_CONTAINER
        ROWS    = 2
        COLUMNS = 1.

    CALL METHOD O_SPLITTER->GET_CONTAINER
      EXPORTING
        ROW       = 1
        COLUMN    = 1
      RECEIVING
        CONTAINER = O_PARENT_TOP.

    CALL METHOD O_SPLITTER->GET_CONTAINER
      EXPORTING
        ROW       = 2
        COLUMN    = 1
      RECEIVING
        CONTAINER = O_PARENT_GRID.

* Set height for g_parent_html
    CALL METHOD O_SPLITTER->SET_ROW_HEIGHT
      EXPORTING
        ID     = 1
        HEIGHT = 5.

    CREATE OBJECT G_GRID
      EXPORTING
        I_PARENT = O_PARENT_GRID.

    CREATE OBJECT G_HANDLER.
    SET HANDLER G_HANDLER->TOP_OF_PAGE FOR G_GRID.

*Calling the Method for ALV output
    CALL METHOD G_GRID->SET_TABLE_FOR_FIRST_DISPLAY
      EXPORTING
        I_STRUCTURE_NAME = 'SFLIGHT'
      CHANGING
        IT_OUTTAB        = IT_FLIGHT[].

    CALL METHOD O_DYNDOC_ID->INITIALIZE_DOCUMENT
      EXPORTING
        BACKGROUND_COLOR = CL_DD_AREA=>COL_TEXTAREA.
* Processing events
    CALL METHOD G_GRID->LIST_PROCESSING_EVENTS
      EXPORTING
        I_EVENT_NAME = 'TOP_OF_PAGE'
        I_DYNDOC_ID  = O_DYNDOC_ID.

ENDFORM."CREATE_AND_INIT_ALV


FORM EVENT_TOP_OF_PAGE USING DG_DYNDOC_ID TYPE REF TO CL_DD_DOCUMENT.
DATA : DL_TEXT(255) TYPE C.  "Text
  CALL METHOD DG_DYNDOC_ID->ADD_TEXT
    EXPORTING
      TEXT = 'Flight Details'
      SAP_STYLE = CL_DD_AREA=>HEADING
      SAP_FONTSIZE = CL_DD_AREA=>LARGE
      SAP_COLOR = CL_DD_AREA=>LIST_HEADING_INT.

    CALL METHOD DG_DYNDOC_ID->ADD_GAP
      EXPORTING
        WIDTH = 200.

    CALL METHOD O_DYNDOC_ID->ADD_PICTURE
      EXPORTING
        PICTURE_ID = 'ENJOYSAP_LOGO'.

* Add new-line CALL METHOD DG_DYNDOC_ID->NEW_LINE.
    CALL METHOD DG_DYNDOC_ID->NEW_LINE.
    CLEAR : DL_TEXT.


* program ID
    DL_TEXT = 'Program Name :'.
    CALL METHOD DG_DYNDOC_ID->ADD_GAP.

    CALL METHOD O_DYNDOC_ID->ADD_TEXT
      EXPORTING
        TEXT         = DL_TEXT
        SAP_EMPHASIS = CL_DD_AREA=>HEADING
        SAP_COLOR    = CL_DD_AREA=>LIST_HEADING_INT.

     CLEAR DL_TEXT.
     DL_TEXT = SY-REPID.

     CALL METHOD O_DYNDOC_ID->ADD_TEXT
        EXPORTING
          TEXT         = DL_TEXT
          SAP_EMPHASIS = CL_DD_AREA=>HEADING
          SAP_COLOR    = CL_DD_AREA=>LIST_NEGATIVE_INV.

* Add new-line
     CALL METHOD DG_DYNDOC_ID->NEW_LINE.
      CLEAR : DL_TEXT.
      CLEAR : DL_TEXT.
*   program ID
      DL_TEXT = 'User Name :'.

      CALL METHOD DG_DYNDOC_ID->ADD_GAP.
      CALL METHOD O_DYNDOC_ID->ADD_TEXT
        EXPORTING
          TEXT         = DL_TEXT
          SAP_EMPHASIS = CL_DD_AREA=>HEADING
          SAP_COLOR    = CL_DD_AREA=>LIST_HEADING_INT.

      CLEAR DL_TEXT.
      DL_TEXT = SY-UNAME.

      CALL METHOD O_DYNDOC_ID->ADD_TEXT
        EXPORTING
          TEXT         = DL_TEXT
          SAP_EMPHASIS = CL_DD_AREA=>HEADING
          SAP_COLOR    = CL_DD_AREA=>LIST_NEGATIVE_INV.
* Add new-line
      CALL METHOD DG_DYNDOC_ID->NEW_LINE.
      CLEAR : DL_TEXT.


* Run Date
      DL_TEXT = 'Run Date :'.
      CALL METHOD DG_DYNDOC_ID->ADD_GAP.
      CALL METHOD O_DYNDOC_ID->ADD_TEXT
        EXPORTING
          TEXT         = DL_TEXT
          SAP_EMPHASIS = CL_DD_AREA=>HEADING
          SAP_COLOR    = CL_DD_AREA=>LIST_HEADING_INT.

      CLEAR DL_TEXT.
* Move date
      WRITE SY-DATUM TO DL_TEXT.
      CALL METHOD O_DYNDOC_ID->ADD_TEXT
        EXPORTING
          TEXT         = DL_TEXT
          SAP_EMPHASIS = CL_DD_AREA=>HEADING
          SAP_COLOR    = CL_DD_AREA=>LIST_NEGATIVE_INV.

* Add new-line
      CALL METHOD DG_DYNDOC_ID->NEW_LINE.
      CLEAR : DL_TEXT.
*TimeDL_TEXT = 'Time :'.
       CALL METHOD DG_DYNDOC_ID->ADD_GAP.
       CALL METHOD O_DYNDOC_ID->ADD_TEXT
         EXPORTING
           TEXT         = DL_TEXT
           SAP_EMPHASIS = CL_DD_AREA=>HEADING
           SAP_COLOR    = CL_DD_AREA=>LIST_HEADING_INT.

       CLEAR DL_TEXT.
* Move time
       WRITE SY-UZEIT TO DL_TEXT.
       CALL METHOD O_DYNDOC_ID->ADD_TEXT
          EXPORTING
            TEXT         = DL_TEXT
            SAP_EMPHASIS = CL_DD_AREA=>HEADING
            SAP_COLOR    = CL_DD_AREA=>LIST_NEGATIVE_INV.
* Add new-line
       CALL METHOD DG_DYNDOC_ID->NEW_LINE.

       PERFORM DISPLAY.
ENDFORM.                    " EVENT_TOP_OF_PAGE

FORM DISPLAY.
*   Creating html control
  IF O_HTML_CNTRL IS INITIAL.
      CREATE OBJECT O_HTML_CNTRL
        EXPORTING
          PARENT = O_PARENT_TOP.
  ENDIF.
  CALL METHOD O_DYNDOC_ID->MERGE_DOCUMENT.
  O_DYNDOC_ID->HTML_CONTROL = O_HTML_CNTRL.
*   Display document
  CALL METHOD O_DYNDOC_ID->DISPLAY_DOCUMENT
    EXPORTING
      REUSE_CONTROL      = 'X'
      PARENT             = O_PARENT_TOP
    EXCEPTIONS
      HTML_DISPLAY_ERROR = 1.

  IF SY-SUBRC NE 0.
      MESSAGE I999 WITH 'Error in displaying top-of-page'(036).
  ENDIF.
ENDFORM.                    "TOP_OF_PAGE" display

在这里插入图片描述

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!