SALV Table 1 : Normal ALV Table Display

By | September 17, 2008 | SALV Table, SALV Tutorial, Tutorials | 69,311 | 4

SAP has introduced a new programming model to devleop Object Oriented ALV (OO ALV) using class CL_SALV family class. This class family is avaliable in the SAP Netweaver 04.

Some Background:

Prior to SAP Netweaver, we have so many different starting point to start the ALV. The starting point entirly depends of the flavour of ALV (Tabular, Tree, Hierarchical), Type of ALV (List or Grid) etc. If we want to use the Control framework, than we need to start the ALV by using the class CL_GUI_ALV_GRID. Moreover to this, we need to make different calles for TOP-OF-PAGE, END-OF-PAGE etc. To avoid this SAP has developed common model – which is entirely based on the object oriented.

These new ALV object oriented model has many advantages:

  • Simplified design: This Model uses a highly integrated object oriented design which provides the simplicity to programmers to develop the ALV.
  • Unified Object models: This model has only one main class which will get and set the parameters of entire layout.

Main Classes

These are the main classes for the different flavour of ALV:

ALV Flavour Class
Simple 2D table display CL_SALV_TABLE
Hierarchical ALV display CL_SALV_HIERSEQU_TABLE
Tree ALV using class CL_SALV_TREE

All Classes has static method FACTORY which will get back the instance of the ALV. Like for the simple table dispaly we must call the method CL_SALV_TABLE=>FACTORY to get the instance of the ALV.

In this post we will see how we can cretae a simple table output just by calling two methods.

Base Program

Code Snippet to generate ALV using class CL_SALV_TABLE

*&---------------------------------------------------------------------*
*& This code snippet will show how to use the CL_SALV_TABLE to
*&   generate the ALV
*&---------------------------------------------------------------------*
REPORT  ztest_oo_alv_main.
*
*----------------------------------------------------------------------*
*       CLASS lcl_report DEFINITION
*----------------------------------------------------------------------*
CLASS lcl_report DEFINITION.
*
  PUBLIC SECTION.
*
*   Final output table
    TYPESBEGIN OF ty_vbak,
           vbeln TYPE vbak-vbeln,
           erdat TYPE erdat,
           auart TYPE auart,
           kunnr TYPE kunnr,
           END   OF ty_vbak.
*
    DATAt_vbak TYPE STANDARD TABLE OF ty_vbak.
*
*   ALV reference
    DATAo_alv TYPE REF TO cl_salv_table.
*
    METHODS:
*     data selection
      get_data,
*
*     Generating output
      generate_output.
*
*$*$*.....CODE_ADD_1 - Begin..................................1..*$*$*
*
*    In this section we will define the private methods which can
*      be implemented to set the properties of the ALV and can be
*      called in the
*
*$*$*.....CODE_ADD_1 - End....................................1..*$*$*
*
ENDCLASS.                    "lcl_report DEFINITION
*
*
START-OF-SELECTION.
  DATAlo_report TYPE REF TO lcl_report.
*
  CREATE OBJECT lo_report.
*
  lo_report->get_data).
*
  lo_report->generate_output).
*
*----------------------------------------------------------------------*
*       CLASS lcl_report IMPLEMENTATION
*----------------------------------------------------------------------*
CLASS lcl_report IMPLEMENTATION.
*
  METHOD get_data.
*   data selection
    SELECT vbeln erdat auart kunnr
           INTO  TABLE t_vbak
           FROM  vbak
           UP TO 20 ROWS.
*
  ENDMETHOD.                    "get_data
*
*.......................................................................
  METHOD generate_output.
* New ALV instance
*   We are calling the static Factory method which will give back
*   the ALV object reference.
*
* exception class
    DATAlx_msg TYPE REF TO cx_salv_msg.
    TRY.
        cl_salv_table=>factory(
          IMPORTING
            r_salv_table o_alv
          CHANGING
            t_table      t_vbak ).
      CATCH cx_salv_msg INTO lx_msg.
    ENDTRY.
*
*$*$*.....CODE_ADD_2 - Begin..................................2..*$*$*
*
*    In this area we will call the methods which will set the
*      different properties to the ALV
*
*$*$*.....CODE_ADD_2 - End....................................2..*$*$*
*
*
* Displaying the ALV
*   Here we will call the DISPLAY method to get the output on the screen
    o_alv->display).
*
  ENDMETHOD.                    "generate_output
*
*$*$*.....CODE_ADD_3 - Begin..................................3..*$*$*
*
*    In this area we will implement the methods which are defined in
*      the class definition
*
*$*$*.....CODE_ADD_3 - End....................................3..*$*$*
*
*
ENDCLASS.                    "lcl_report IMPLEMENTATION

I had tried to build the report in the object oriented fashion. UML of that report is as follow. This design will give us flexibility to add more methods which will set and get the different properties of the O_ALV object. For example, if we need to change the Heading, we will add one private method SET_COLUMN_NAME and write our logic to change the O_ALV object. Than we will call that method just before calling the DISPLAY method. (We will cover this in next blogpost).

In the code snippet, I have tried to differential three section which can be changed easily. In next blog posts, I will use this program as the base program and provide the code snippet to add the new functionality. Like: Section of CODE_ADD_1 can be replaced with the code provided in the future blog post. You can download this base program code snippet from here.

Follow this link to get more information on SALV model: SAP List Viewer – New programming Model

Explore all SALV Table Display Tutorials

Find all SALV table Tutorials at Tutorials > SALV Table Display .

Like It? Share!!

Don't miss an Update

Get notified of the new post, right into your inbox

Naimesh Patel{272 articles}

I'm SAP ABAP Consultant for more than a decade. I like to experiment with ABAP especially OO. I have been SDN Top Contributor.
Follow :

Explore all of his 272 articles.

Load comments

4 Comments

  • Hello naimesh , a very useful and descriptive info you had posted.thanks for that.
    Here i had a query , if i want to set hotspot on row level of the slave table rather than cell level ,in this regard could you please guide me?

  • I am going to try this out today. Thanks!

  • Anonymous

    If in the GET_DATA method there is very big logic, where do you usually place it. can you write an include program in method?
    Thanks,

  • satya

    It is really good.it seems to very easy..

Comments on this Post are now closed. If you have something important to share, you can always contact me.

You seem to be new here. Subscribe to stay connected.