ALV OM Template Program
Introduction
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.
Hi Thomas,Thomas
thanks for this really well articulated example...
cheers,
Marilyn
I have asked that the original code sample also remain in the package as well.
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..." 😉
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?
Thanks
Ravi
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.
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?
Regards
Ravi
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.
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.
Thanks,
Victor
Information about the color column
The color column contains entries of the type LVC_T_SCOL. This type consists of the following fields:
FNAME
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.
COLOR
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
INT (Wert = LVC_S_SCOL-COLOR-INT)
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
NOKEYCOL
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.
Parameters
VALUE
required
Name of column that contains the color combination; Type LVC_FNAME
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.
Regards
Vicky
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.
Thanks
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.
Thanks for the help!!
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( ).
try.
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
endtry.
Thanks again!
... §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 ).
Thanks
Thanks
http://help.sap.com/saphelp_nw04/helpdata/en/80/e8eb40c4f8712ae10000000a155106/frameset.htm
nice Blog, thanks.
I have a questions. Is it possible to show an logo in the TOP_OF_PAGE? And how can I do this?
Kind Regards
Jens
Here is a link to the online help section that discussed the ALV OM Header and Footer areas:
http://help.sap.com/saphelp_nw70/helpdata/en/d3/6dee408a63732ae10000000a155106/frameset.htm
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?
Thanks,
Steve Oldner
State of Louisiana
Go figure...
Thanks,
Steve
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
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.
Regards,
Sougata.
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?
No.
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.
Cheers,
Sougata.