SAP Tech Pro

SAP Technical Blog

How to display multiple ALVs in a single screen using the class CL_SALV_TABLE

How to display multiple ALVs in a single screen using the class CL_SALV_TABLE

Do you have a requirement to show multiple sets of related data in a single screen using ALV? Then check out this article.

How to display multiple ALVs in a single screen using the class CL_SALV_

We can display multiple ALVs on a single screen using the ALV class CL_SALV_TABLE and the custom container class CL_GUI_CUSTOM_CONTAINER.

How to:

1) Create a program and a screen (Ex: 100) as shown below.

How to display multiple ALVs in a single screen using the class CL_SALV_TABLE

2) Place custom controls on the screen as per the requirement and name them accordingly. Name of the custom control is very important as we will be using the container name to instantiate the class CL_GUI_CUSTOM_CONTAINER.

How to display multiple ALVs in a single screen using the class CL_SALV_TABLE

3) Use below code in order to fetch the data and to display the data in ALV. Here important thing to notice in the code is that we need to instantiate the class CL_GUI_CUSTOM_CONTAINER and pass the object reference to the class CL_SALV_TABLE .

 


REPORT zstp_multiple_alvs_on_screen.

*&---------------------------------------------------------------------*
*& Report  ZSTP_ALV_PF_STATUS_HEADER
*&
*&---------------------------------------------------------------------*
*& SAPTechPro.com
*&
*&---------------------------------------------------------------------*

CLASS lcl_report DEFINITION.
  PUBLIC SECTION.

    DATA: o_salv TYPE REF TO cl_salv_table,              " ALV Reference
          i_sflight TYPE STANDARD TABLE OF sflight,
          i_scarr   TYPE STANDARD TABLE OF scarr,
          i_sflights TYPE STANDARD TABLE OF sflights.

* Methods to Fetch Data and Display Output
    METHODS: get_data,                             "Data Selection
             display_output,                       "Display Output
             display_alv                           "Display ALV
              IMPORTING
                 container_name TYPE c
               CHANGING
                 i_data           TYPE STANDARD TABLE.
  PRIVATE SECTION.
* Method to Set PF-Status
    METHODS: set_pf_status
                  CHANGING
                      co_salv TYPE REF TO cl_salv_table. " Default Pf Status

ENDCLASS.                    "lcl_report DEFINITION
*----------------------------------------------------------------------*
*       CLASS lcl_report IMPLEMENTATION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS lcl_report IMPLEMENTATION.

* Data selection
  METHOD get_data.
    SELECT * INTO TABLE i_sflight
           FROM sflight UP TO 50 ROWS.

    SELECT * INTO TABLE i_scarr
       FROM scarr UP TO 10 ROWS.

    SELECT * INTO TABLE i_sflights
   FROM sflights UP TO 10 ROWS.
  ENDMETHOD.                    "get_data

* Display ALV
  METHOD display_alv.

    DATA: lv_message TYPE REF TO cx_salv_msg, "Exception Class
          lo_container TYPE REF TO cl_gui_custom_container. "Custom Container

*   Instantiate the container
    CREATE OBJECT lo_container
      EXPORTING
        container_name              = container_name   " Name of the Screen CustCtrl Name to Link Container To
      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.
*    Raise exception
    ENDIF.

* Call Factory method which will give back the ALV object reference.
    TRY.
        CALL METHOD cl_salv_table=>factory
          EXPORTING
            r_container  = lo_container "****Pass container object to cl_salv_table***
          IMPORTING
            r_salv_table = o_salv
          CHANGING
            t_table      = i_data.
      CATCH cx_salv_msg INTO lv_message .
    ENDTRY.

*   Set PF status
    CALL METHOD set_pf_status
      CHANGING
        co_salv = o_salv.

* Display the ALV
    o_salv->display( ).
  ENDMETHOD.                    "display_ALV

* Display Output
  METHOD display_output.

*  Call ALV display method and pass the Container name and internal table
***Display ALV1***
    display_alv(
       EXPORTING
         container_name = 'CONTAINER1'
       CHANGING
         i_data           = i_sflight ).

***Display ALV2***
    display_alv(
       EXPORTING
         container_name = 'CONTAINER2'
       CHANGING
         i_data           = i_scarr ).

***Display ALV3***
    display_alv(
       EXPORTING
         container_name = 'CONTAINER3'
       CHANGING
         i_data           = i_sflights ).
  ENDMETHOD.                    "display_ALV

************************************************************************
*    Method Implementation
************************************************************************
* Setting the PF-Status
  METHOD set_pf_status.
    DATA: lo_functions TYPE REF TO cl_salv_functions_list.
* Default functions
    lo_functions = co_salv->get_functions( ).
    lo_functions->set_all( abap_true ).
  ENDMETHOD.                    "set_pf_status

ENDCLASS.                    "lcl_report IMPLEMENTATION

*&---------------------------------------------------------------------*
*&      Module  STATUS_0100  OUTPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE status_0100 OUTPUT.
  SET PF-STATUS 'STATUS'.
  SET TITLEBAR 'TITLE'.
ENDMODULE.                 " STATUS_0100  OUTPUT
*&---------------------------------------------------------------------*
*&      Module  USER_COMMAND_0100  INPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE user_command_0100 INPUT.
  IF sy-ucomm = 'BACK'.
    LEAVE TO SCREEN 0.
  ENDIF.
ENDMODULE.                 " USER_COMMAND_0100  INPUT


START-OF-SELECTION.

  DATA: lo_report TYPE REF TO lcl_report.
  CREATE OBJECT lo_report.
  lo_report->get_data( ).
  lo_report->display_output(  ).
  CALL SCREEN 100.

Output:

How to display multiple ALVs in a single screen using the class CL_SALV_TABLE

Add comment

Before Buying, Compare Prices at Topprice.in

Topprice.in