在同一 alv 屏幕中显示多个 table

Displaying multiple table in same alv screen

您好,很抱歉问了这个愚蠢的问题,因为我对 abap 编程还很陌生。 我试图在同一个 ALV 屏幕上显示多个显示器。我已经创建了自定义容器并正确命名,但仍然无法显示屏幕。

任何人都可以检查我下面的代码,让我知道我做错了什么。

Report Z1_TEST3 NO STANDARD PAGE HEADING.
TABLES: LIKP, LIPS, VEKP, VEPO.

TYPES: BEGIN OF ty_likp,
        vbeln TYPE likp-vbeln,
        vkorg TYPE likp-vkorg,
        vstel TYPE likp-vstel,
      END OF ty_likp,

       BEGIN OF ty_vekp,
         vbeln TYPE lips-vbeln,
         posnr TYPE lips-posnr,
         matnr TYPE lips-matnr,
         bpmng TYPE lips-bpmng,
         vrkme TYPE lips-vrkme,
         werks TYPE lips-werks,
         lgort TYPE lips-lgort,
       END OF ty_vekp,

       BEGIN OF ty_vepo,
         vbeln TYPE lips-vbeln,
         xchar TYPE vepo-xchar,
         vpmat TYPE lips-vpmat,
         brgew TYPE lips-brgew,
         ntgew TYPE lips-ntgew,
         gewei TYPE lips-gewei,
       END OF ty_vepo.

DATA: wa_likp TYPE ty_likp,
      wa_vekp TYPE ty_vekp,
      wa_vepp TYPE ty_vepo,
      it_likp TYPE STANDARD TABLE OF ty_likp,
      it_vekp TYPE STANDARD TABLE OF ty_vekp,
      it_vepo TYPE STANDARD TABLE OF ty_vepo.

DATA: wa_fcat_likp TYPE lvc_s_fcat,
      wa_fcat_vekp TYPE lvc_s_fcat,
      wa_fcat_vepo TYPE lvc_s_fcat,
      it_fcat_likp TYPE STANDARD TABLE OF lvc_s_fcat,
      it_fcat_vekp TYPE STANDARD TABLE OF lvc_s_fcat,
      it_fcat_vepo TYPE STANDARD TABLE OF lvc_s_fcat.

DATA: ob_custom1 TYPE REF TO cl_gui_custom_container,
      ob_custom2 TYPE REF TO cl_gui_custom_container,
      ob_custom3 TYPE REF TO cl_gui_custom_container,

      ob_grid1  TYPE REF TO cl_gui_alv_grid,
      ob_grid2  TYPE REF TO cl_gui_alv_grid,
      ob_grid3  TYPE REF TO cl_gui_alv_grid.

INITIALIZATION.

  SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.
  SELECT-OPTIONS s_vbeln FOR likp-vbeln.
  SELECTION-SCREEN END OF BLOCK b1.

CLASS delivery DEFINITION.

  PUBLIC SECTION.
    METHODS: get_likp,
             get_vekp,
             get_vepo,
             fieldcat_likp,
             fieldcat_vekp,
             fieldcat_vepo.

ENDCLASS.


CLASS delivery IMPLEMENTATION.

  METHOD get_likp.
    IF s_vbeln[] IS NOT INITIAL.
      SELECT vbeln vkorg vstel
        FROM likp INTO TABLE it_likp
        WHERE vbeln IN s_vbeln.

      IF sy-subrc = 0.
        SORT it_vekp BY vbeln.
      ELSE.
        MESSAGE 'Doesn''t exist' TYPE 'I'.
      ENDIF.

    ELSE.
      MESSAGE 'Please select a valid number' TYPE 'I'.
    ENDIF.
  ENDMETHOD.

  METHOD get_vekp.
    IF it_vekp IS NOT INITIAL.
      SELECT vbeln posnr matnr bpmng werks lgort
        FROM lips INTO TABLE it_vekp
        FOR ALL ENTRIES IN it_likp
        WHERE vbeln = it_likp-vbeln.

      IF sy-subrc = 0.
        SORT it_vekp BY vbeln.
        CALL METHOD: fieldcat_likp,
                     fieldcat_vekp,
                     fieldcat_vepo.
        CALL SCREEN 9000.
      ELSE.
        MESSAGE 'Doesn''t exist' TYPE 'I'.
      ENDIF.
    ENDIF.
  ENDMETHOD.

  METHOD get_vepo.
    IF it_vepo IS NOT INITIAL.
      SELECT vbeln xchar vpmat brgew ntgew gewei
        FROM lips INTO TABLE it_vepo
        FOR ALL ENTRIES IN it_likp
        WHERE vbeln = it_likp-vbeln.

      IF sy-subrc = 0.
        SORT it_vepo BY vbeln.
        CALL METHOD: fieldcat_likp,
                     fieldcat_vekp,
                     fieldcat_vepo.
        CALL SCREEN 9000.
      ELSE.
        MESSAGE 'Doesn''t exist' TYPE 'I'.
      ENDIF.
    ENDIF.
  ENDMETHOD.

  METHOD fieldcat_likp.
    CLEAR wa_fcat_likp.
    REFRESH it_fcat_likp.

    DATA: lv_row TYPE i VALUE 0.

    lv_row                 = 1 + lv_row.
    wa_fcat_likp-row_pos   = lv_row.
    wa_fcat_likp-fieldname = 'VBELN'.
    wa_fcat_likp-tabname   = 'IT_LIKP'.
    wa_fcat_likp-reptext   = 'Lieferung'.
    wa_fcat_likp-col_opt   = 'X'.
    APPEND wa_fcat_likp TO it_fcat_likp.
    CLEAR wa_fcat_likp.

    lv_row                 = 1 + lv_row.
    wa_fcat_likp-row_pos   = lv_row.
    wa_fcat_likp-fieldname = 'VKORG'.
    wa_fcat_likp-tabname   = 'IT_LIKP'.
    wa_fcat_likp-reptext   = 'Verkaufsorganisation'.
    wa_fcat_likp-col_opt   = 'X'.
    APPEND wa_fcat_likp TO it_fcat_likp.
    CLEAR wa_fcat_likp.

    lv_row                 = 1 + lv_row.
    wa_fcat_likp-row_pos   = lv_row.
    wa_fcat_likp-fieldname = 'VSTEL'.
    wa_fcat_likp-tabname   = 'IT_LIKP'.
    wa_fcat_likp-reptext   = 'Versandstelle'.
    wa_fcat_likp-col_opt   = 'X'.
    APPEND wa_fcat_likp TO it_fcat_likp.
    CLEAR wa_fcat_likp.

  ENDMETHOD.

  METHOD fieldcat_vekp.
    CLEAR wa_fcat_vekp.
    REFRESH it_fcat_vekp.

    DATA: lv_col TYPE i VALUE 0.

    lv_col                 = 1 + lv_col.
    wa_fcat_vekp-col_pos   = lv_col.
    wa_fcat_vekp-fieldname = 'POSNR'.
    wa_fcat_vekp-tabname   = 'IT_VEKP'.
    wa_fcat_vekp-reptext   = 'Position'.
    wa_fcat_vekp-col_opt   = 'X'.
    APPEND wa_fcat_vekp TO it_fcat_vekp.
    CLEAR wa_fcat_vekp.

    lv_col                 = 1 + lv_col.
    wa_fcat_vekp-col_pos   = lv_col.
    wa_fcat_vekp-fieldname = 'MATNR'.
    wa_fcat_vekp-tabname   = 'IT_VEKP'.
    wa_fcat_vekp-reptext   = 'Materialnummer'.
    wa_fcat_vekp-col_opt   = 'X'.
    APPEND wa_fcat_vekp TO it_fcat_vekp.
    CLEAR wa_fcat_vekp.

    lv_col                 = 1 + lv_col.
    wa_fcat_vekp-col_pos   = lv_col.
    wa_fcat_vekp-fieldname = 'BPMNG'.
    wa_fcat_vekp-tabname   = 'IT_VEKP'.
    wa_fcat_vekp-reptext   = 'Menge'.
    wa_fcat_vekp-col_opt   = 'X'.
    APPEND wa_fcat_vekp TO it_fcat_vekp.
    CLEAR wa_fcat_vekp.

    lv_col                 = 1 + lv_col.
    wa_fcat_vekp-col_pos   = lv_col.
    wa_fcat_vekp-fieldname = 'VRKMG'.
    wa_fcat_vekp-tabname   = 'IT_VEKP'.
    wa_fcat_vekp-reptext   = 'Mengeneinheit'.
    wa_fcat_vekp-col_opt   = 'X'.
    APPEND wa_fcat_vekp TO it_fcat_vekp.
    CLEAR wa_fcat_vekp.

    lv_col                 = 1 + lv_col.
    wa_fcat_vekp-col_pos   = lv_col.
    wa_fcat_vekp-fieldname = 'WERKS'.
    wa_fcat_vekp-tabname   = 'IT_VEKP'.
    wa_fcat_vekp-reptext   = 'Werks'.
    wa_fcat_vekp-col_opt   = 'X'.
    APPEND wa_fcat_vekp TO it_fcat_vekp.
    CLEAR wa_fcat_vekp.

    lv_col                 = 1 + lv_col.
    wa_fcat_vekp-col_pos   = lv_col.
    wa_fcat_vekp-fieldname = 'LGORT'.
    wa_fcat_vekp-tabname   = 'IT_VEKP'.
    wa_fcat_vekp-reptext   = 'Lagerort'.
    wa_fcat_vekp-col_opt   = 'X'.
    APPEND wa_fcat_vekp TO it_fcat_vekp.
    CLEAR wa_fcat_vekp.

  ENDMETHOD.

  METHOD fieldcat_vepo.
    CLEAR wa_fcat_vepo.
    REFRESH it_fcat_vepo.

    DATA: lv_col TYPE i VALUE 0.

    lv_col                 = 1 + lv_col.
    wa_fcat_vepo-col_pos   = lv_col.
    wa_fcat_vepo-fieldname = 'XCHAR'.
    wa_fcat_vepo-tabname   = 'IT_VEPO'.
    wa_fcat_vepo-reptext   = 'HU#'.
    wa_fcat_vepo-col_opt   = 'X'.
    APPEND wa_fcat_vepo TO it_fcat_vepo.
    CLEAR wa_fcat_vepo.

    lv_col                 = 1 + lv_col.
    wa_fcat_vepo-col_pos   = lv_col.
    wa_fcat_vepo-fieldname = 'VPMAT'.
    wa_fcat_vepo-tabname   = 'IT_VEPO'.
    wa_fcat_vepo-reptext   = 'Verpackungsmaterial'.
    wa_fcat_vepo-col_opt   = 'X'.
    APPEND wa_fcat_vepo TO it_fcat_vepo.
    CLEAR wa_fcat_vepo.

    lv_col                 = 1 + lv_col.
    wa_fcat_vepo-col_pos   = lv_col.
    wa_fcat_vepo-fieldname = 'BRGEW'.
    wa_fcat_vepo-tabname   = 'IT_VEPO'.
    wa_fcat_vepo-reptext   = 'Bruttogewicht'.
    wa_fcat_vepo-col_opt   = 'X'.
    APPEND wa_fcat_vepo TO it_fcat_vepo.
    CLEAR wa_fcat_vepo.

    lv_col                 = 1 + lv_col.
    wa_fcat_vepo-col_pos   = lv_col.
    wa_fcat_vepo-fieldname = 'NTGEW'.
    wa_fcat_vepo-tabname   = 'IT_VEPO'.
    wa_fcat_vepo-reptext   = 'Nettogewicht'.
    wa_fcat_vepo-col_opt   = 'X'.
    APPEND wa_fcat_vepo TO it_fcat_vepo.
    CLEAR wa_fcat_vepo.

    lv_col                 = 1 + lv_col.
    wa_fcat_vepo-col_pos   = lv_col.
    wa_fcat_vepo-fieldname = 'GEWEI'.
    wa_fcat_vepo-tabname   = 'IT_VEPO'.
    wa_fcat_vepo-reptext   = 'Gewichtseinheit'.
    wa_fcat_vepo-col_opt   = 'X'.
    APPEND wa_fcat_vepo TO it_fcat_vepo.
    CLEAR wa_fcat_vepo.

 ENDMETHOD.
ENDCLASS.

START-OF-SELECTION.
  DATA: delivery TYPE REF TO delivery.
  CREATE OBJECT delivery.
  CALL METHOD: delivery->get_likp,
               delivery->get_vekp,
               delivery->get_vepo.


MODULE status_9000 OUTPUT.
  SET PF-STATUS 'GUI_9000'.
  SET TITLEBAR 'TITLE_9000'.

  CREATE OBJECT ob_custom1
    EXPORTING
      container_name = 'CONTAINER1'.

  CREATE OBJECT ob_custom2
    EXPORTING
      container_name = 'CONTAINER2'.

  CREATE OBJECT ob_custom3
    EXPORTING
      container_name = 'CONTAINER3'.

  CREATE OBJECT ob_grid1
    EXPORTING
      i_parent = ob_custom1.

  CREATE OBJECT ob_grid2
    EXPORTING
      i_parent = ob_custom2.

  CREATE OBJECT ob_grid3
    EXPORTING
      i_parent = ob_custom3.

  CALL METHOD ob_grid1->set_table_for_first_display
    CHANGING
      it_fieldcatalog = it_fcat_likp
      it_outtab       = it_likp.

  CALL METHOD ob_grid2->set_table_for_first_display
    CHANGING
      it_fieldcatalog = it_fcat_vekp
      it_outtab       = it_vekp.

  CALL METHOD ob_grid3->set_table_for_first_display
    CHANGING
      it_fieldcatalog = it_fcat_vepo
      it_outtab       = it_vepo.

ENDMODULE.

MODULE user_command_9000 INPUT.

  IF sy-ucomm = 'BACK'
    OR sy-ucomm = 'EXIT'
    OR sy-ucomm = 'CANCEL'.

    FREE: ob_grid1, ob_grid2,ob_grid3, ob_custom1, ob_custom2,ob_custom3.
    REFRESH: it_likp, it_vekp,it_vepo.
    LEAVE TO SCREEN 0.
  ENDIF.

ENDMODULE.

您不能在一个容器中显示多个 GUI 控件(在您的例子中是 ALV)。但是你可以使用 "splitter container" 将一个容器分成几个(在网络中搜索许多引用 class CL_GUI_SPLITTER_CONTAINER 的示例) .