Skip to Content

ALV OM Template Program


Over the years, my company has developed quite a few template programs for different activities. These allow development to start quickly, they remove the time it takes to code the same basic code over and over again, they provide consistency between applications, and they help new developers learn techniques from more experienced ones.

Now that we are in the middle of our R/3 4.6C to ECC 5.0 upgrade (WebAS 640), we wanted to update our most used template – our REUSE ALV report template.

The Old Template

Our old template program was based upon the set of REUSE function modules: REUSE_ALV_GRID_DISPLAY, REUSE_ALV_EVENTS_GET, and REUSE_ALV_COMMENTARY_WRITE. It also had functionality for working with ALV Grid Layout variants provided by function modules LVC_VARIANT_F4 and LVC_VARIANT_EXISTENCE_CHECK. This allows us to create reports with selection screens/variants that can also contain the grid variant. The REUSE function modules also work well Online/Interactive or for Batch Printing.

But one of the biggest problem with the template program approach (which we started doing about 8 years ago well before ABAP OO), is that the template program is copied and modified to add the necessary business logic. This creates the situation where the same code exists in many different programs. So not only did we want to recreate the existing functionality of our template program, but we wanted to also take an OO approach. Our goal was to recreate the functionality mostly as an ABAP OO Class. Then the final application could inherit from the base template class and just redefine the necessary methods. This would provide better maintainability over time. It also will allow us to add new features to the existing reports very easily.

The New Template

First of all you are welcome to download the complete source and documentation for this template from the following (I am only going to cover the more interesting parts in this weblog):
Download Content

First of all let’s have a look at the output that our template program will produce:

We will put in some very simple business logic (a select * from SFLIGHT) just so we can test that all the functionality works.

Dialog Program

Even though we wanted to go with as much of an ABAP OO approach as possible, we still need to support the ability to have select-options or parameters. The easiest way to do this is still to start with a dialog program. Therefore we still have a small template program that must be copied from. This is when the programmer can place their select-options/parameters and the hooks to their business logic (preferably in separate class methods).

report zesu_report_template_alv_om. tables: sflight. data: itab type table of sflight. data: keg_alv type ref to zcl_es_alv_om. selection-screen begin of block five with frame title text-017. parameter: variant like disvariant-variant. "ALV GRID VARIANT parameter: nodata1 as checkbox. "RUN ALV WITHOUT DATA selection-screen end of block five. at selection-screen on value-request for variant. keg_alv->f4_layouts( changing c_variant = variant ). initialization. create object keg_alv exporting i_repid = sy-repid. keg_alv->get_default_layout( changing c_variant = variant ). start-of-selection. keg_alv->auth_check( ). if nodata1 = 'X'. else. select * from sflight into table itab. * Perform to read data and do processing endif. keg_alv->set_report_title( 'Dialog Template'(t01) ). keg_alv->publish_alv( exporting i_variant = variant changing itab = itab ).

There isn’t all that much going on in the dialog program. We have the hooks into our class where all the real logic is. We also have hooks at the different events (on value-request and initialization).

Template Class

If you study the coding for the template class (available in full in the downloadable package), you will find an example of how to recreate all of the functionality of the Reuse ALV in the new ALV OM.

There are methods for creating the report header for instance. In the Reuse ALV you could just build HTML that would be used in interactive mode for the header. Now the ALV OM has its own meta data model for describing the header layout and content that is independent of the rendering output (HTML for interactive and ABAP List for background/printing).

There are also methods for adjusting the user interface (adding or taking away user events) and for registering and responding to ALV events (such as a double click on row). By default the event handlers are delivered empty.

This speaks to the power of using a class for the template. Now let’s assume that you have a basic report but you want to allow the user to double click on a row to forward navigate to the detailed transaction. You would inherit from the ALV Template class. You would then only need to redefine two methods. You could redefine the REGISTER_EVENTS method and uncomment the event you want registered. Then you redefine ON_DOUBLE_CLICK and add your specific logic. All the other processing of the class you inherited from is still in use. This will hopefully save our programming team lots of time as we develop custom reports.

You must be Logged on to comment or reply to a post.
    • I took your advise.  I have used the refactoring assistant in the past (I had a class that grew over time and eventually I decided to break it up).  Other than a small bug (it moved one method, but also left it in the subclass) that was easily fixed – it went great.  Thanks
      • If you want to update the example and the sample code, to reflect the refactoring, just let me know so that I can update the contents.
        thanks for this really well articulated example…
        • I have sent the updated code samples to Marilyn to include in the downloadable package.  However I would encourage everyone to use the Refactoring Assistant to make this change.  It is a great opportunity to try out this tool.  If you need help with the Refactoring Assistant, check out Thomas Ritter’s weblog Refactoring ABAP classes on the subject.

          I have asked that the original code sample also remain in the package as well.

          • Hi Thomas,

            nice to hear that you liked my suggestion. I think it is a good idea not to remove the original code sample. It is always cool to see how code evolves over time. Well, sometimes it is not… Do you know the saying “code that smells…” 😉


  • Hi Thomas,

    This is an excellent concept.But unfortunately, I am wondering, do you suggest any changes to this so that I can use it in our installation withWAS 6.2. Also, (may be it is a dumb question) how do I create the class from the downloaded content? In the sense, do I first create an ABAP report program with this code and then convert it using the class builder?


    • I am afraid that this example isn’t recreatable in 620.  This is an example of how to use the ALV Object Model (classes delivered by SAP).  The ALV OM is only available in Netweaver 04 and higher.

      As far as recreating this or any other class based example – I never start with a report and then convert.  I just create a class in the class builder and cut and paste in the code.  In 640 and higher you can directly edit the attribute and method areas and even cut and paste in the structure definition of the class.

      • Thanks once again Thomas.

        I read in your blog, that you used one template for your 4.6c version, which you upgraded to the ALV OM. Is it possible that I can use that old template, if it is ok with you?


        • I am afraid that because I don’t work for Kimball any longer, I no longer have access to that program. 

          However the old 4.6C version wasn’t really anything special.  It was just a shell of a program that already had the framework coded. It had forms for the call to the REUSE ALV function moduels and call back routines.  We took one of the SAP example applications for REUSE ALV and gutted the logic as our starting point. 

  • Hi Thomas,

    This tool can be useful to anyone.
    Do you know if there’s still a way to color an entire row in ALV OO like in ‘REUSE_ALV…’ functions. I checked and found out that this functionality is not available anymore 🙁 using ALV OO.


    • I didn’t have a chance to try out the theory, but after reading the online help, I think you would use the columns object (CL_SALV_COLUMNS_TABLE) by using the get_columns method.  In the Columsn object there is a method SET_COLOR_COLUMN.  Here is the help on it:
      Information about the color column
      The color column contains entries of the type LVC_T_SCOL. This type consists of the following fields:

      You use FNAME to control whether you assign a color to a row or cell:
      If FNAME is empty, you assign a color to the entire row.
      If FNAME contains the name of a column in your output table, you assign a color to the cell of the current row and corresponding column.
      This field is of the type LVC_S_COLO and consists of the following data:
      COL (Value = LVC_S_SCOL-COLOR-COL)
      Value for the color
      Value Name Description
      0 COL_BACKGROUND GUI-dependent
      1 COL_HEADING gray-blue 
      2 COL_NORMAL light gray
      3 COL_TOTAL yellow
      4 COL_KEY blue-green
      5 COL_POSITIVE green
      6 COL_NEGATIVE red
      7 COL_GROUP orange

      Intensity of background color
      1 dark
      0 light

      INV  (Value = LVC_S_SCOL-COLOR-INV)
      Background or text color (inverted)
      INV Text Background
      1 colored neutral
      0 black colored

      By default, key columns contain a specific color (COL_KEY) in the output table. You can only change this color if you set the NOKEYCOL field to ‘X’ and thus turn off the default color.

      Name of column that contains the color combination; Type LVC_FNAME

  • Hi Thomas,

    Your blog was of great help, thanks a lot.

    I needed some more info on ALV OM – I have the following scenario:
    I need to create multiple ALV grids/lists and no. of lists is dynamic. Also, each page should consist of only 1 list. I need to give navigation buttons on the 1st page, so that its easier to navigate through all the lists.

    Please let me know if there is a way to automatically generate these navigation buttons, provided the no. of lists is dynamic.

    Look forward to your reply.


    • Yes you can have multiple.  You could have separate screens with control containers and host separate instances of the ALV OM object or just “fake” it by resetting the instance on one screen and feeding in the new information.

      As far as navigation buttons – sure.  This would likely be normal dialog dynpro development.  You would create a screen with a container and your buttons and control the ready state and text of the button dynamically in your PBO/PAI.

  • Love the Object approach to the ALV.  The problem I have is trying to figure out how to do something simple like return the value that the user selects in a cell.  I’ve been able to get row and column but not the value.  Can anyone help with this?


    • I admist that I don’t know if there is a method of the Object Model that will read the cell value for you given the row, column.  I have never went looking for one because I just use the row column to read the data table I bound to the ALV directly.

        • Not sure I completely understand the question.  You can implement event handlers as local classes or global classes.  Are global classes what you are looking for?  If so I can send you some screen shots via email (you can drop me an email if you want – my address is available in my SDN business card) of exactly how to set that up.
          • Think I’ve figured it out.  I’m using an attribute to store the generic itab and accessing it via a field symbol and then able to pull the data from any event within the global object.  Next on my list is getting it to work with a container.

            Thanks for the help!!

  • In the traditional alv, you could change the column heading as well as set columns to be a checkbox etc.  How can you accomplish this with this OO grid?  I’ve seen the method that accesses the columns but have not figured this one out.
    • Have a look at the sample program, SALV_DEMO_TABLE_COLUMNS.  It has examples of the many different Cell Types – including Checkboxes.

          data: lr_columns type ref to cl_salv_columns_table,
                lr_column  type ref to cl_salv_column_table.

          lr_columns = gr_table->get_columns( ).

              lr_column ?= lr_columns->get_column( ‘CHECKBOX’ ).
              lr_column->set_cell_type( if_salv_c_cell_type=>checkbox ).
              lr_column->set_long_text( ‘CHECKBOX’ ).
            catch cx_salv_not_found.                          “#EC NO_HANDLER

    • Have a look at SALV_DEMO_TABLE_SELECTIONS (actually there are a lot of good demo applications in the package SALV_OBJECTS).  You use the SET_SELECTION_MODE method of the object CL_SALV_SELECTIONS.  Use the constants from IF_SALV_C_SELECTION_MODE.

      … §7 selections
        data: lr_selections type ref to cl_salv_selections,
              lt_rows       type salv_t_row,
              lt_column     type salv_t_column,
              ls_cell       type salv_s_cell.

        lr_selections = gr_table->get_selections( ).

      *… §7.1 set selection mode
        lr_selections->set_selection_mode( if_salv_c_selection_mode=>row_column ).

  • Users will need to be able to edit values within a grid cell or whole column.  I’ve looked over the salv objects package including the column and layout objects where I assumed a property could be set.  Is it possible to set columns or the grid as a whole to editable.


  • We have old programs coded with alv_grid, newer programs coded with REUSE_ALV_GRID_DISPLAY and now are looking at upgrading all these to cl_salv_table.

    To get the number of rows that are filtered for out row count (a standard user requirement), we use cl_gui_alv_grid->get_filtered_entries. For the REUSE_ALV_GRID_DISPLAY, it is REUSE_ALV_GRID_LAYOUT_INFO_GET.  What is it for cl_salv_table?  Or is there an alternative?


    Steve Oldner
    State of Louisiana

    • I don’t know as I’ve never needed this functionality.  I would have to look at the classes and documentation.  I’m traveling all this week, so it will be next week before I can have a look.
    • I’m afraid that I didn’t have any better luck finding a solution than you did.  I couldn’t find any way to return the number of filtered entries.  The ALV Object model abstracts several different implementation types and sometimes doesn’t expose all the functionality of every underlying implementation.  This may be a case where you must stick with CL_GUI_ALV_GRID directly if you must have the number of flitered entries.  You might also ask this question in the ABAP forums as someone else may have stumbled across the answer.
  • Context Menu on ALV,
    Is there a way to use context menu e.g if right click on selected (Multiple Rows) or colon I will like to be able to fire an event like delete a dataset.
    I lose the selected row when I double click on them can someone help with sample code or idea
    • Your question really isn’t directly related to the content of this blog.  I suggest that you just post your question in one of the ABAP forums.
  • Hi Thomas,

    Recently we downloaded this Class to use it as a generic framework for all ALV based requirements for our custom developments.

    We noticed a lot of the SALV model functionalities could not be leveraged out of this Class in our applications even if we tried to inherit it then Redefine its Methods simply because the ALV object is defined as Private and the object is not being passed through any of the Parameters. I believe its visibility should be Private so its ok but in that case how do we influence the behaviour of the ALV object in our applications for e.g. control different settings of the columns without having access to the ALV object itself?

    I also noticed in one of your comments above “I don’t believe a Logo is possible (remember we are abstracting all three kinds of ALV (list processing, full screen, and control based) with a single class in the ALV OM.  Therefore many features are designed to support the lowest common denominator.”

    So my question is did you only mean to create a basic ALV general class with this code for just displaying data i.e. a framework which can be reused by calling applications with ease? Are the applications meant to have access to functionalities provided by the SAP standard Class CL_SALV_TABLE through your Z class or we are missing something here?

    Your time is much appreciated.



    • Please note that I wrote this blog in 2005 – over 7 years ago – when I worked at Kimball International.  I’ve not seen this template program in question in quite a few years. Therefore my ability to answer specific questions about it is pretty limited.

      >how do we influence the behaviour of the ALV object in our applications

      In general if the attributes are private there should be some method which sets them.  This is how most of the control is done in the SALV.  But this is general statement about SALV.  Is there something particular in this class structure that you can’t access?

      >So my question is did you only mean to create a basic ALV general class with this code for just displaying data i.e. a framework which can be reused by calling applications with ease?

      Yes, this is just meant to be a generic framework which can be applied to many reports and provide the most commonly used features.

      >Are the applications meant to have access to functionalities provided by the SAP standard Class CL_SALV_TABLE through your Z class or we are missing something here?


      • Thanks Thomas. We solved the issue by creating a few more Protected SET & GET methods so that the calling applications could then redefine them if required.