Skip to content
Call: +91-8779272083
Email: info@sapify.in
Enquiry Now
SAPifySAPify
  • Home
  • About Us
  • Courses
  • Blogs
  • Contact Us
  • My Account
0
No products in the cart.
SAPifySAPify
  • Home
  • About Us
  • Courses
  • Blogs
  • Contact Us
  • My Account
  • Home
  • ABAP
  • The OOPS ABAP ALV Code
ABAP

The OOPS ABAP ALV Code

  • 29 Jan, 2026
  • Com 0

In modern ABAP, the procedural function module approach is often replaced by the ALV Object Model (SALV). This approach is more robust, uses classes/methods, and requires significantly less code because the system handles the metadata (column headers) automatically.

The primary class used for this is CL_SALV_TABLE.

The OOPS ABAP ALV Code

REPORT z_simple_alv_oops.

* 1. Data Declaration

DATA: it_sflight TYPE TABLE OF sflight,

      lo_alv     TYPE REF TO cl_salv_table, ” Reference to the ALV Object

      lo_msg     TYPE REF TO cx_salv_msg.    ” Reference for Exception Handling

* 2. Data Retrieval

START-OF-SELECTION.

  SELECT * FROM sflight INTO TABLE it_sflight UP TO 100 ROWS.

* 3. Display ALV using Object Oriented Method

  IF it_sflight IS NOT INITIAL.

    TRY.

        ” Factory method creates the instance of the ALV object

        cl_salv_table=>factory(

          IMPORTING

            r_salv_table = lo_alv

          CHANGING

            t_table      = it_sflight ).

        ” Display the grid

        lo_alv->display( ).

      CATCH cx_salv_msg INTO lo_msg.

        ” Handle errors, like display issues

        MESSAGE lo_msg->get_text( ) TYPE ‘E’.

    ENDTRY.

  ELSE.

    MESSAGE ‘No data found.’ TYPE ‘I’.

  ENDIF.

Understanding the OO Logic

Unlike the procedural method where you pass parameters into a function, the OO approach treats the report as an object instance.

Component Description
cl_salv_table=>factory A static method that “manufactures” the ALV object. It automatically maps the fields of your internal table to the grid.
lo_alv This is the object reference (pointer). Once the factory creates it, lo_alv holds all the properties and methods of your report.
TRY…CATCH OOPS uses Exception Classes for error handling. If something goes wrong during object creation, the CATCH block prevents the program from crashing (dumping).
lo_alv->display( ) This is a method call. It tells the object to finally render the data on the user’s screen.

Why use OOPS for ALV?

Type Safety: The compiler catches more errors at design time compared to function modules.

Clean Syntax: You don’t have to manage long lists of “Exporting/Importing” parameters.

Extensibility: If you want to add a toolbar or double-click functionality, you simply fetch a “sub-object” (like lo_functions = lo_alv->get_functions( )) and trigger a method.

Share on:
Simple Editable ALV with Save Logic.

Leave a Reply Cancel reply

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

Search

Latest Post

Thumb
The OOPS ABAP ALV Code
29 Jan, 2026
Thumb
Simple Editable ALV with Save Logic.
29 Jan, 2026
Thumb
Editable ALV using the procedural approach
29 Jan, 2026

Categories

  • ABAP (3)
  • ALV (3)
sapify (2)

We are a dedicated SAP technical training platform committed to building industry-

Add: Mumbai, Maharashtra, India.
Call: +91-8779272083
Email: info@sapify.in

Online Platform

  • About
  • Course
  • Instructor

Links

  • Contact Us

Contacts

Enter your email address to register to our newsletter subscription

Icon-facebook Icon-instagram Icon-youtube Icon-linkedin2
Copyright 2026 SAPify | All Rights Reserved
SAPifySAPify