How To Create SALV Reports Using Template

SALV (SAP List Viewer) is the OOP (Object Oriented Programming) approach for creating a powerful ALV. SALV can help you to create interactive and user friendly reports. It provides an enhanced user experience with features such as sorting, filtering, grouping, exporting, and more, without requiring extensive custom coding.

In today’s ABAP tutorial, I want to share ABAP source code to create SALV report by using object oriented approach. You can reuse this source code in your own projects.

Tutorial Objectives
1. Understand the importance of using SALV Template.
2. Understand the best way structuring your SALV report.
3. You know how to modify the SALV template based on your own needs.
Prerequisites
1. SAP System Access: SAP GUI, ECC.
2. Authorization: Developer role, TCODE: SE38

SALV reports are often preferred over traditional classical or ALV reports because of their simplicity and built in functionality. This tutorial introduces the SALV Report Template, a reusable framework that simplifies the creation of SALV reports for your own projects.

Why Do You Need To Have SALV Template?

I noticed that many developers (including myself) often find themselves repeating the same steps over and over again when creating a new ABAP reports.

For example, instead of starting from scratch, you commonly copy code from existing SALV reports. This approach comes from the need for SALV programming to include standard, repetitive code to set up the SALV framework, including: Declaring data objects for tables or structures, instantiating the SALV model and configuring basic settings and handling layouts, column properties, and events.

Well, it’s time to end this headache by having a template you can customize. Now you can minimize the repetitive setup tasks of the SALV report, allowing you to focus on the core logic of the report, such as validations, formulas, calculations and other business logic.

A standardized template can also help you to maintain a standard program structure in all of your SALV report program, instead of having 5 different methods for 5 different reports by 5 different developers. It ensures uniformity, consistency that will make the codebase easier to understand, maintain, and extend.

The ABAP SALV Template Structure

report z_salv_template.
include zsalvtempl_top. "1. Classes Definitions
include zsalvtempl_scr. "2. Selection Screens, Parameters, Select-options
include zsalvtempl_f01. "3. Classes Implementations

start-of-selection.
  data(o_alv) = new zcl_salv_report( ).
  o_alv->get_data( ).
  o_alv->display_alv( ).

The main SALV Template ABAP program (Z_SALV_TEMPLATE) is typically structured into three include programs, each serving a specific purpose:

1. ZSALVTEMPL_TOP: This include program serves as the central location for defining your main classes, its methods, and the event handler class definitions. It acts as the foundation of your SALV report template, encapsulating the structure and logic necessary for consistent and reusable code..

2. ZSALVTEMPL_SCR: This include program consists of your report selection screens, parameters, select-options and also the labels.

3. ZSALVTEMPL_F01: This last file is where you implement the classes for your SALV reports.

How To Implement The ABAP SALV Template?

Step 1. Visit ABAPGeeks GitHub repository for ABAP SALV Template Source Code

Step 2. Download the ZIP ABAP source code into your local system.

What’s In The ZIP Files?

1. Open the src folder.

2. This is the files name mapping.

Step 3. Copy the source code into a new ABAP program and adjust the code according to your own user specifications and logic.

Instructions on How To Modify The SALV Template

To Change the report structure, open ZSALVTEMPL_TOP include program and then go to line 33, there you can find the structure used for the report layout.

You might also need to change the references tables used for the selection screen parameters in line 1.

To change the selection screens parameters for your report, go to line 6 of ZSALVTEMPL_SCR include program.

To customize the GET_DATA method for defining the data source of your SALV report, navigate to line 261 in the ZSALVTEMPL_F01 include program. This is where you can add or modify the logic to fetch and prepare the data for your report.

So Let’s Recap!

By using a uniform template, you can streamline your development process. This allows you to focus primarily on the core logic of your report, rather than repeatedly setting up the same structure and configurations.

With the repetitive tasks of report creation already handled by the template, you can significantly reduce the time spent on setup, ensuring that your energy is spent on customizing the report’s functionality and meeting specific business requirements. This approach not only improves efficiency but also minimizes the chances of errors, as the standard template ensures consistency across all reports.

Download SALV Template Source Code

Click Here To Download the source code.

Feel free to use, modify, and distribute this source code in your projects, whether for personal, educational, or professional purposes. You are encouraged to adapt it to fit your specific requirements, integrate it into larger solutions, or even enhance its functionality.

You can also check SAP reference on Object Oriented Programming.

Share this tutorial with Fellow Geeks!

Other ABAP Tutorials

Leave a Reply

Your email address will not be published. Required fields are marked *