OO ALV与FUNCTION ALV

2018-01-29  本文已影响0人  阿努比斯1117

OO ALV


image.png

OOALV中在AT SELECTION-SCREEN事件下使用SET_TABLE_FOR_FIRST_DISPLAY可以直接导出ALV,不用callscreen

*&---------------------------------------------------------------------*
*& Report ZMM004
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
REPORT ZMM004.

TABLES:T001.

DATA: BEGIN OF ITAB OCCURS 0,
      BUKRS LIKE T001-BUKRS,
      BUTXT LIKE T001-BUTXT,
      ORT01 LIKE T001-ORT01,
      END OF ITAB.

DATA:  GT_FIELDCAT   TYPE LVC_T_FCAT,
       GS_FIELDCAT   TYPE LVC_S_FCAT,
       GS_LAYOUT     TYPE LVC_S_LAYO,
       GT_EXCLUDE    TYPE UI_FUNCTIONS.

DATA: CON_SPLITTER TYPE REF TO CL_GUI_SPLITTER_CONTAINER,
      ALV_TABLES TYPE REF TO CL_GUI_ALV_GRID,
      CON_ALV_TABLES TYPE REF TO CL_GUI_CONTAINER.

DEFINE : ADD_FIELD.
  GS_FIELDCAT-FIELDNAME = &1.
  GS_FIELDCAT-COLTEXT = &2.
  APPEND GS_FIELDCAT TO GT_FIELDCAT.
END-OF-DEFINITION.

SELECTION-SCREEN BEGIN OF BLOCK T1 WITH FRAME .
SELECT-OPTIONS: S_BUKRS FOR T001-BUKRS.
SELECTION-SCREEN END OF BLOCK T1.

START-OF-SELECTION.

  PERFORM GET_AND_PROCESS_DATA.
  CALL SCREEN 2000.

END-OF-SELECTION.
*&---------------------------------------------------------------------*
*&      Form  GET_AND_PROCESS_DATA
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM GET_AND_PROCESS_DATA .

  SELECT BUKRS BUTXT ORT01
    INTO CORRESPONDING FIELDS OF TABLE ITAB
  FROM T001
  WHERE BUKRS IN S_BUKRS.

ENDFORM.
*&---------------------------------------------------------------------*
*&      Module  STATUS_2000  OUTPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE STATUS_2000 OUTPUT.
  SET PF-STATUS '2000'.
*  SET TITLEBAR 'xxx'.
  PERFORM SET_ALV_FIELDS.
  PERFORM SET_ALV_LAYOUT CHANGING GS_LAYOUT.

   CHECK CON_SPLITTER IS INITIAL.
  "創建容器
  CREATE OBJECT CON_SPLITTER
    EXPORTING
      PARENT  = CL_GUI_CONTAINER=>SCREEN0
      ROWS    = 1
      COLUMNS = 1.
  "創建ALV控件
  CON_ALV_TABLES = CON_SPLITTER->GET_CONTAINER( ROW = 1 COLUMN = 1 ).
  CREATE OBJECT ALV_TABLES
    EXPORTING
      I_PARENT = CON_ALV_TABLES.

  CALL METHOD ALV_TABLES->SET_TABLE_FOR_FIRST_DISPLAY
    EXPORTING
*     I_BUFFER_ACTIVE               =
*     I_BYPASSING_BUFFER            =
*     I_CONSISTENCY_CHECK           =
*     I_STRUCTURE_NAME              =
*     IS_VARIANT                    =
      I_SAVE                        = 'X'
*     I_DEFAULT                     = 'X'
      IS_LAYOUT                     = GS_LAYOUT
*     IS_PRINT                      =
*     IT_SPECIAL_GROUPS             =
 "     IT_TOOLBAR_EXCLUDING          = GT_EXCLUDE
*     IT_HYPERLINK                  =
*     IT_ALV_GRAPHICS               =
*     IT_EXCEPT_QINFO               =
*     IR_SALV_ADAPTER               =
    CHANGING
      IT_OUTTAB                     = ITAB[]
      IT_FIELDCATALOG               = GT_FIELDCAT
*     IT_SORT                       =
*     IT_FILTER                     =
    EXCEPTIONS
      INVALID_PARAMETER_COMBINATION = 1
      PROGRAM_ERROR                 = 2
      TOO_MANY_LINES                = 3
      OTHERS                        = 4.
  IF SY-SUBRC <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
               WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.

ENDMODULE.
*&---------------------------------------------------------------------*
*&      Form  SET_ALV_FIELDS
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM SET_ALV_FIELDS .
  ADD_FIELD 'BUKRS' '公司'.
  ADD_FIELD 'BUTXT' '名称'.
  ADD_FIELD 'ORT01' 'ORT01'.
ENDFORM.
*&---------------------------------------------------------------------*
*&      Form  SET_ALV_LAYOUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      <--P_GS_LAYOUT  text
*----------------------------------------------------------------------*
FORM SET_ALV_LAYOUT  CHANGING P_GS_LAYOUT TYPE LVC_S_LAYO.
  P_GS_LAYOUT-ZEBRA = 'X'.
  P_GS_LAYOUT-SMALLTITLE = 'X'.
  P_GS_LAYOUT-SEL_MODE = 'A'.
  P_GS_LAYOUT-GRID_TITLE = 'TEST'.
  P_GS_LAYOUT-CWIDTH_OPT = 'X'.
ENDFORM.

FUNCTION ALV


image.png
*&---------------------------------------------------------------------*
*& Report ZMM005
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
REPORT ZMM005.

TABLES:T001.

DATA: BEGIN OF ITAB OCCURS 0,
      BUKRS LIKE T001-BUKRS,
      BUTXT LIKE T001-BUTXT,
      ORT01 LIKE T001-ORT01,
      END OF ITAB.

DATA:  GT_FIELDCAT   TYPE LVC_T_FCAT,
       GS_FIELDCAT   TYPE LVC_S_FCAT,
       GS_LAYOUT     TYPE LVC_S_LAYO.

DEFINE : ADD_FIELD.
  GS_FIELDCAT-FIELDNAME = &1.
  GS_FIELDCAT-COLTEXT = &2.
  APPEND GS_FIELDCAT TO GT_FIELDCAT.
END-OF-DEFINITION.

SELECTION-SCREEN BEGIN OF BLOCK T1 WITH FRAME .
SELECT-OPTIONS: S_BUKRS FOR T001-BUKRS.
SELECTION-SCREEN END OF BLOCK T1.

START-OF-SELECTION.

  PERFORM GET_AND_PROCESS_DATA.
  PERFORM SET_ALV_DATAS.
  PERFORM DISPLAY_ALV.


END-OF-SELECTION.
*&---------------------------------------------------------------------*
*&      Form  GET_AND_PROCESS_DATA
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM GET_AND_PROCESS_DATA .

  SELECT BUKRS BUTXT ORT01
    INTO CORRESPONDING FIELDS OF TABLE ITAB
  FROM T001
  WHERE BUKRS IN S_BUKRS.

ENDFORM.
*&---------------------------------------------------------------------*
*&      Form  SET_ALV_DATAS
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM SET_ALV_DATAS .
  SET PF-STATUS 'PF_STATUS01'.

  ADD_FIELD 'BUKRS' '公司'.
  ADD_FIELD 'BUTXT' '名称'.
  ADD_FIELD 'ORT01' 'ORT01'.

    GS_LAYOUT-ZEBRA = 'X'.
    GS_LAYOUT-SMALLTITLE = 'X'.
    GS_LAYOUT-SEL_MODE = 'A'.
    GS_LAYOUT-GRID_TITLE = 'TEST'.
    GS_LAYOUT-CWIDTH_OPT = 'X'.
ENDFORM.
*&---------------------------------------------------------------------*
*&      Form  DISPLAY_ALV
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM DISPLAY_ALV .
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY_LVC'
 EXPORTING
*   I_INTERFACE_CHECK                 = ' '
*   I_BYPASSING_BUFFER                =
*   I_BUFFER_ACTIVE                   =
    I_CALLBACK_PROGRAM                = SY-REPID
*    I_CALLBACK_PF_STATUS_SET         = ' '
*   I_CALLBACK_USER_COMMAND           = ' '
*   I_CALLBACK_TOP_OF_PAGE            = ' '
*   I_CALLBACK_HTML_TOP_OF_PAGE       = ' '
*   I_CALLBACK_HTML_END_OF_LIST       = ' '
*   I_STRUCTURE_NAME                  =
*   I_BACKGROUND_ID                   = ' '
    I_GRID_TITLE                      = 'TEST'
*   I_GRID_SETTINGS                   =
    IS_LAYOUT_LVC                     = GS_LAYOUT
    IT_FIELDCAT_LVC                   = GT_FIELDCAT
*   IT_EXCLUDING                      =
*   IT_SPECIAL_GROUPS_LVC             =
*   IT_SORT_LVC                       =
*   IT_FILTER_LVC                     =
*   IT_HYPERLINK                      =
*   IS_SEL_HIDE                       =
*   I_DEFAULT                         = 'X'
*   I_SAVE                            = ' '
*   IS_VARIANT                        =
*   IT_EVENTS                         =
*   IT_EVENT_EXIT                     =
*   IS_PRINT_LVC                      =
*   IS_REPREP_ID_LVC                  =
*   I_SCREEN_START_COLUMN             = 0
*   I_SCREEN_START_LINE               = 0
*   I_SCREEN_END_COLUMN               = 0
*   I_SCREEN_END_LINE                 = 0
*   I_HTML_HEIGHT_TOP                 =
*   I_HTML_HEIGHT_END                 =
*   IT_ALV_GRAPHICS                   =
*   IT_EXCEPT_QINFO_LVC               =
*   IR_SALV_FULLSCREEN_ADAPTER        =
* IMPORTING
*   E_EXIT_CAUSED_BY_CALLER           =
*   ES_EXIT_CAUSED_BY_USER            =
  TABLES
    T_OUTTAB                          = ITAB
* EXCEPTIONS
*   PROGRAM_ERROR                     = 1
*   OTHERS                            = 2
          .
IF SY-SUBRC <> 0.
* Implement suitable error handling here
ENDIF.

ENDFORM.
上一篇下一篇

猜你喜欢

热点阅读