6 Columns with Active Background
6 Columns with Active Background
Active List Item Background

24OOP’s0409 – OOP’s ALV

 What is OOPS ALV?

OOPS ALV stands for Object-Oriented Programming ALV. Unlike the classical ALV, which uses a function module approach, OOPS ALV takes advantage of ABAP Objects, making the code more structured, reusable and maintainable. This new method is highly preferred for complex reports, as it offers better performance and flexibility.

With OOPS ALV, you can create interactive reports with features like:

– Sorting and filtering

– Interactive editing

– Exporting data to Excel

– Detailed drill-down reporting

 Key Components of OOPS ALV

 

To understand OOPS ALV better, here are the main classes involved in creating an ALV report:

  1. CL_SALV_TABLE: This is the main class used to display data in a simple ALV grid. It provides various methods to handle features like sorting, filtering and column settings.
  1. CL_GUI_CONTAINER: This class is used when you want to display the ALV output in a custom container, for example, within a screen.
  1. CL_GUI_ALV_GRID: This class is used when you need a more complex ALV, where the grid allows editing or more specific custom functionalities.
  1. CL_SALV_COLUMN: This class represents the columns of the ALV and you can use it to set properties such as column headers and alignment.

 Steps to Create a Simple OOPS ALV Report

Here’s a step-by-step guide to creating a basic OOPS ALV report using CL_SALV_TABLE:

  1. Data Declaration

First, declare the internal table and work area to store the data that you want to display.

TYPES: BEGIN OF ty_data,

         matnr TYPE matnr,

         maktx TYPE maktx,

         meins TYPE meins,

       END OF ty_data.

DATA: it_data TYPE TABLE OF ty_data,

      wa_data TYPE ty_data.

  1. Populate Data

Fill the internal table with some data. This can be from a database table or hardcoded for demonstration.

SELECT matnr maktx meins

  INTO TABLE it_data

  FROM mara

  UP TO 10 ROWS.

  1. Create ALV Object

Now, create an instance of the ALV object using the `CL_SALV_TABLE` class.

DATA: alv_table TYPE REF TO cl_salv_table.

TRY.

    cl_salv_table=>factory(

      IMPORTING r_salv_table = alv_table

      CHANGING  t_table      = it_data ).

CATCH cx_salv_msg INTO DATA(error).

    MESSAGE error TYPE ‘E’.

ENDTRY.

 

  1. Display the ALV

Finally, call the display method to show the data in ALV format.

alv_table->display( ).

This simple OOPS ALV report will display the material number, description and unit of measure from the MARA table in an interactive grid.

 Additional Features in OOPS ALV

Once you have a basic ALV report, you can enhance it with various features:

  1. Sorting and Filtering:

   You can enable sorting and filtering options for the user directly in the ALV grid without additional code.

  1. Setting Column Properties:

   Customize the properties of the columns (like headers or alignment) using the `CL_SALV_COLUMNS` and `CL_SALV_COLUMN` classes.

   Example:

   DATA: columns TYPE REF TO cl_salv_columns,

         column  TYPE REF TO cl_salv_column.

   columns = alv_table->get_columns( ).

   column  = columns->get_column( ‘MATNR’ ).

   column->set_short_text( ‘Material Number’ ).

  1. Export to Excel:

   OOPS ALV has built-in functionality for exporting the data to Excel, making reporting easy for users who need data outside SAP.

 Advantages of OOPS ALV

– Object-oriented ALV provides a cleaner, more structured code than the procedural approach, making it easier to maintain.

– Once written, the object classes can be reused in multiple reports or enhanced for specific use cases.

– OOPS ALV allows for advanced customization, including editable grids, embedded charts and interactive elements.

– It handles larger datasets more efficiently, especially when combined with in-memory technology in SAP HANA.

Author : Aniket Pawar, 9373518385                                                     

24OOP’s0409 – OOP’s ALV

 What is OOPS ALV?

OOPS ALV stands for Object-Oriented Programming ALV. Unlike the classical ALV, which uses a function module approach, OOPS ALV takes advantage of ABAP Objects, making the code more structured, reusable and maintainable. This new method is highly preferred for complex reports, as it offers better performance and flexibility.

With OOPS ALV, you can create interactive reports with features like:

– Sorting and filtering

– Interactive editing

– Exporting data to Excel

– Detailed drill-down reporting

 Key Components of OOPS ALV

 

To understand OOPS ALV better, here are the main classes involved in creating an ALV report:

  1. CL_SALV_TABLE: This is the main class used to display data in a simple ALV grid. It provides various methods to handle features like sorting, filtering and column settings.
  1. CL_GUI_CONTAINER: This class is used when you want to display the ALV output in a custom container, for example, within a screen.
  1. CL_GUI_ALV_GRID: This class is used when you need a more complex ALV, where the grid allows editing or more specific custom functionalities.
  1. CL_SALV_COLUMN: This class represents the columns of the ALV and you can use it to set properties such as column headers and alignment.

 Steps to Create a Simple OOPS ALV Report

Here’s a step-by-step guide to creating a basic OOPS ALV report using CL_SALV_TABLE:

  1. Data Declaration

First, declare the internal table and work area to store the data that you want to display.

TYPES: BEGIN OF ty_data,

         matnr TYPE matnr,

         maktx TYPE maktx,

         meins TYPE meins,

       END OF ty_data.

DATA: it_data TYPE TABLE OF ty_data,

      wa_data TYPE ty_data.

  1. Populate Data

Fill the internal table with some data. This can be from a database table or hardcoded for demonstration.

SELECT matnr maktx meins

  INTO TABLE it_data

  FROM mara

  UP TO 10 ROWS.

  1. Create ALV Object

Now, create an instance of the ALV object using the `CL_SALV_TABLE` class.

DATA: alv_table TYPE REF TO cl_salv_table.

TRY.

    cl_salv_table=>factory(

      IMPORTING r_salv_table = alv_table

      CHANGING  t_table      = it_data ).

CATCH cx_salv_msg INTO DATA(error).

    MESSAGE error TYPE ‘E’.

ENDTRY.

 

  1. Display the ALV

Finally, call the display method to show the data in ALV format.

alv_table->display( ).

This simple OOPS ALV report will display the material number, description and unit of measure from the MARA table in an interactive grid.

 Additional Features in OOPS ALV

Once you have a basic ALV report, you can enhance it with various features:

  1. Sorting and Filtering:

   You can enable sorting and filtering options for the user directly in the ALV grid without additional code.

  1. Setting Column Properties:

   Customize the properties of the columns (like headers or alignment) using the `CL_SALV_COLUMNS` and `CL_SALV_COLUMN` classes.

   Example:

   DATA: columns TYPE REF TO cl_salv_columns,

         column  TYPE REF TO cl_salv_column.

   columns = alv_table->get_columns( ).

   column  = columns->get_column( ‘MATNR’ ).

   column->set_short_text( ‘Material Number’ ).

  1. Export to Excel:

   OOPS ALV has built-in functionality for exporting the data to Excel, making reporting easy for users who need data outside SAP.

 Advantages of OOPS ALV

– Object-oriented ALV provides a cleaner, more structured code than the procedural approach, making it easier to maintain.

– Once written, the object classes can be reused in multiple reports or enhanced for specific use cases.

– OOPS ALV allows for advanced customization, including editable grids, embedded charts and interactive elements.

– It handles larger datasets more efficiently, especially when combined with in-memory technology in SAP HANA.

Author : Aniket Pawar, 9373518385