sap f11labz

Two ALV Grids in Single Screen using OOPs

In a report we can create two ALV grids in a single screen by using two Custom Container in one screen. Here we shall have a standard screen (like screen 0100 or 1000). We must not modify that screen. We shall create a custom screen (screen 9000 or 9001), since custom screen number starts from 9000.

After that we shall go to the LAYOUT of screen 9000. There we shall make two containers by drag and drop as following.

Now in PBO block we shall make custom PF status and custom title. Then after we shall create object for Container 1 and Container 2 which are referred to CL_GUI_CUSTOM_CONTAINER.

CREATE OBJECT ob_custom1
EXPORTING
container_name = 'CONTAINER1'.

CREATE OBJECT ob_custom2
EXPORTING
container_name = 'CONTAINER2'.

After that ALV Grid 1 and Grid 2 objects shall be created for Container 1 and 2. The Grids are referred to CL_GUI_ALV_GRID. Here we shall assign grid 1 for container 1 by exporting i_parent to the specific container. Similarly grid 2 for container 2 must be assigned by exporting i_parent to container 2.

CREATE OBJECT ob_grid1
EXPORTING
i_parent = ob_custom1.

CREATE OBJECT ob_grid2
EXPORTING
i_parent = ob_custom2.
After that Grid method SET_TABLE_FOR_FIRST_DISPLAY must be called with changing parameters. Here we have used field catalog (it_fieldcatalog) for selected custom fields and output table (it_outtab) for specific output table (Internal Table).
  CALL METHOD ob_grid1->set_table_for_first_display
    CHANGING
     it_fieldcatalog = it_fcat_ekko
      it_outtab       = it_ekko.
  CALL METHOD ob_grid2->set_table_for_first_display
    CHANGING
      it_fieldcatalog = it_fcat_ekpo
      it_outtab       = it_ekpo.

In the PAI block we shall validate the BACK, EXIT and CANCEL button by user command. Here 2 custom containers and 2 grids must be freed and internal tables must be refreshed. Then we shall leave to screen 0.
IF   sy-ucomm = 'BACK'     OR sy-ucomm = 'EXIT'     OR sy-ucomm = 'CANCEL'.   FREE: ob_grid1, ob_grid2, ob_custom1, ob_custom2.</div>   REFRESH: it_ekko, it_ekpo.   LEAVE TO SCREEN 0.   ENDIF.
Detailed Coding of the Requirement:*&---------------------------------------------------------------------*
*& Report  ZSR_TEST
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*REPORT  zsr_test NO STANDARD PAGE HEADING.TABLES: ekko, ekpo.TYPES: BEGIN OF ty_ekko,
ebeln TYPE ekko-ebeln,
bukrs TYPE ekko-bukrs,
lifnr TYPE ekko-lifnr,
sel   TYPE char1,
END OF ty_ekko,BEGIN OF ty_ekpo,
ebeln TYPE ekpo-ebeln,
ebelp TYPE ekpo-ebelp,
matnr TYPE ekpo-matnr,
werks TYPE ekpo-werks,
lgort TYPE ekpo-lgort,
sel   TYPE char1,
END OF ty_ekpo.DATA: wa_ekko TYPE ty_ekko,
wa_ekpo TYPE ty_ekpo,
it_ekko TYPE STANDARD TABLE OF ty_ekko,
it_ekpo TYPE STANDARD TABLE OF ty_ekpo.<b>"Field Catalog structure and Tables</b>
DATA: wa_fcat_ekko TYPE lvc_s_fcat,
wa_fcat_ekpo TYPE lvc_s_fcat,
it_fcat_ekko TYPE STANDARD TABLE OF lvc_s_fcat,
it_fcat_ekpo TYPE STANDARD TABLE OF lvc_s_fcat.DATA: <b>"Object for Custom Container</b>
ob_custom1 TYPE REF TO cl_gui_custom_container,
ob_custom2 TYPE REF TO cl_gui_custom_container,<b>"Object for GRIDs</b>
ob_grid1  TYPE REF TO cl_gui_alv_grid,
ob_grid2  TYPE REF TO cl_gui_alv_grid.

INITIALIZATION.

SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.
SELECT-OPTIONS s_ebeln FOR ekko-ebeln.
SELECTION-SCREEN END OF BLOCK b1.

*----------------------------------------------------------------------*
*       CLASS purchase DEFINITION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS purchase DEFINITION.

PUBLIC SECTION.
METHODS: get_ekko, <b>"Selection from EKKO</b>
get_ekpo, <b>"Selection from EKPO</b>
fieldcat_ekko, <b>"Fieldcatalog for Header Table</b>
fieldcat_ekpo. <b>"Fieldcatalog for Item Table</b>

ENDCLASS.                    "purchase DEFINITION

*----------------------------------------------------------------------*
*       CLASS purchase IMPLEMENTATION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS purchase IMPLEMENTATION.

METHOD get_ekko.
IF s_ebeln[] IS NOT INITIAL.
SELECT ebeln bukrs lifnr
FROM ekko INTO TABLE it_ekko
WHERE ebeln IN s_ebeln.

IF sy-subrc = 0.
SORT it_ekko BY ebeln.
ELSE.
MESSAGE 'PO doesn''t exist' TYPE 'I'.
ENDIF.

ELSE.
MESSAGE 'Please select a valid PO' TYPE 'I'.
ENDIF.
ENDMETHOD.                    "get_ekko

METHOD get_ekpo.
IF it_ekko IS NOT INITIAL.
SELECT ebeln ebelp matnr werks lgort
FROM ekpo INTO TABLE it_ekpo
FOR ALL ENTRIES IN it_ekko
WHERE ebeln = it_ekko-ebeln
AND bukrs = it_ekko-bukrs.

IF sy-subrc = 0.
SORT it_ekpo BY ebeln.
CALL METHOD: fieldcat_ekko,
fieldcat_ekpo.
CALL SCREEN 9000.
ELSE.
MESSAGE 'Item doesn''t exist' TYPE 'I'.
ENDIF.
ENDIF.
ENDMETHOD.                    "get_ekpo

METHOD fieldcat_ekko.
CLEAR wa_fcat_ekko.
REFRESH it_fcat_ekko.

DATA: lv_col TYPE i VALUE 0.

lv_col                 = 1 + lv_col.
wa_fcat_ekko-col_pos   = lv_col.
wa_fcat_ekko-fieldname = 'EBELN'.
wa_fcat_ekko-tabname   = 'IT_EKKO'.
wa_fcat_ekko-reptext   = 'Purchase Order'.
wa_fcat_ekko-col_opt   = 'X'.
APPEND wa_fcat_ekko TO it_fcat_ekko.
CLEAR wa_fcat_ekko.

lv_col                 = 1 + lv_col.
wa_fcat_ekko-col_pos   = lv_col.
wa_fcat_ekko-fieldname = 'BUKRS'.
wa_fcat_ekko-tabname   = 'IT_EKKO'.
wa_fcat_ekko-reptext   = 'Company Code'.
wa_fcat_ekko-col_opt   = 'X'.
APPEND wa_fcat_ekko TO it_fcat_ekko.
CLEAR wa_fcat_ekko.

lv_col                 = 1 + lv_col.
wa_fcat_ekko-col_pos   = lv_col.
wa_fcat_ekko-fieldname = 'LIFNR'.
wa_fcat_ekko-tabname   = 'IT_EKKO'.
wa_fcat_ekko-reptext   = 'Vendor'.
wa_fcat_ekko-col_opt   = 'X'.
APPEND wa_fcat_ekko TO it_fcat_ekko.
CLEAR wa_fcat_ekko.

ENDMETHOD.                    "fieldcat_ekko

METHOD fieldcat_ekpo.
CLEAR wa_fcat_ekpo.
REFRESH it_fcat_ekpo.

DATA: lv_col TYPE i VALUE 0.

lv_col                 = 1 + lv_col.
wa_fcat_ekpo-col_pos   = lv_col.
wa_fcat_ekpo-fieldname = 'EBELN'.
wa_fcat_ekpo-tabname   = 'IT_EKPO'.
wa_fcat_ekpo-reptext   = 'Purchase Order'.
wa_fcat_ekpo-col_opt   = 'X'.
APPEND wa_fcat_ekpo TO it_fcat_ekpo.
CLEAR wa_fcat_ekpo.

lv_col                 = 1 + lv_col.
wa_fcat_ekpo-col_pos   = lv_col.
wa_fcat_ekpo-fieldname = 'EBELP'.
wa_fcat_ekpo-tabname   = 'IT_EKPO'.
wa_fcat_ekpo-reptext   = 'Item'.
wa_fcat_ekpo-col_opt   = 'X'.
APPEND wa_fcat_ekpo TO it_fcat_ekpo.
CLEAR wa_fcat_ekpo.

lv_col                 = 1 + lv_col.
wa_fcat_ekpo-col_pos   = lv_col.
wa_fcat_ekpo-fieldname = 'MATNR'.
wa_fcat_ekpo-tabname   = 'IT_EKPO'.
wa_fcat_ekpo-reptext   = 'Material'.
wa_fcat_ekpo-col_opt   = 'X'.
APPEND wa_fcat_ekpo TO it_fcat_ekpo.
CLEAR wa_fcat_ekpo.

lv_col                 = 1 + lv_col.
wa_fcat_ekpo-col_pos   = lv_col.
wa_fcat_ekpo-fieldname = 'WERKS'.
wa_fcat_ekpo-tabname   = 'IT_EKPO'.
wa_fcat_ekpo-reptext   = 'Plant'.
wa_fcat_ekpo-col_opt   = 'X'.
APPEND wa_fcat_ekpo TO it_fcat_ekpo.
CLEAR wa_fcat_ekpo.

lv_col                 = 1 + lv_col.
wa_fcat_ekpo-col_pos   = lv_col.
wa_fcat_ekpo-fieldname = 'LGORT'.
wa_fcat_ekpo-tabname   = 'IT_EKPO'.
wa_fcat_ekpo-reptext   = 'Storage Location'.
wa_fcat_ekpo-col_opt   = 'X'.
APPEND wa_fcat_ekpo TO it_fcat_ekpo.
CLEAR wa_fcat_ekpo.

ENDMETHOD.                    "fieldcat_ekpo

ENDCLASS.                    "purchase IMPLEMENTATION

START-OF-SELECTION.
DATA: purchase TYPE REF TO purchase.
CREATE OBJECT purchase.
CALL METHOD: purchase->get_ekko,
purchase->get_ekpo.

*&---------------------------------------------------------------------*
*&      Module  STATUS_9000  OUTPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE status_9000 OUTPUT.
SET PF-STATUS 'GUI_9000'.
SET TITLEBAR 'TITLE_9000'.

<b>"Object creation for custom container 1 exporting the name</b>
CREATE OBJECT ob_custom1
EXPORTING
container_name = 'CONTAINER1'.

<b>"Object creation for custom container 2 exporting the name</b>
CREATE OBJECT ob_custom2
EXPORTING
container_name = 'CONTAINER2'.

<b>"Object creation for ALV Grid 1 exporting the parent container 1</b>
<b>"It means container 1 contains ALV grid 1 - header table</b>
CREATE OBJECT ob_grid1
EXPORTING
i_parent = ob_custom1.

<b>"Object creation for ALV Grid 2 exporting the parent container 2</b>
<b>  "It means container 2 contains ALV grid 2 - item table</b>
CREATE OBJECT ob_grid2
EXPORTING
i_parent = ob_custom2.

<b>*Calling the method to display the output table in ALV Grid 1. </b>
<b>*Here field catalog and output table are passed by changing parameter.</b>
<b>*Header table is passed here.</b>
CALL METHOD ob_grid1->set_table_for_first_display
CHANGING
it_fieldcatalog = it_fcat_ekko
it_outtab       = it_ekko.

<b>*Calling the method to display the output table in ALV Grid 2. </b>
<b>*Here field catalog and output table are passed by changing parameter.</b>
<b>*Item table is passed here.</b>
CALL METHOD ob_grid2->set_table_for_first_display
CHANGING
it_fieldcatalog = it_fcat_ekpo
it_outtab       = it_ekpo.

ENDMODULE.                 " STATUS_9000  OUTPUT
*&---------------------------------------------------------------------*
*&      Module  USER_COMMAND_9000  INPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE user_command_9000 INPUT.

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

FREE: ob_grid1, ob_grid2, ob_custom1, ob_custom2.
REFRESH: it_ekko, it_ekpo.
LEAVE TO SCREEN 0.
ENDIF.

ENDMODULE.                 " USER_COMMAND_9000  INPUT

The Output is as follows:

Selection Screen:

PO Item wise display:

Sandip Roy

Sandip Roy

Sandip is SAP ABAP consultant at Ericsson. When He is not working he can be found taking snaps @ the Himlayas

More Posts - Website

Add a Comment

HTML Snippets Powered By : XYZScripts.com