How to Create ALV Report Using OOPS ABAP

How to Create ALV Report Using OOPS ABAP


ALV Using Factory Method

·        The class that is used for creating ALV report using the Object-oriented ABAP is CL_SALV_TABLE.

·        CL_SALV_TABLE uses the static method FACTORY to create the instance of ALV. This is known as Factory method design pattern.

·        After creating the instance, the instance method DISPLAY is used to display the ALV output.


Read : Difference Between Instance and Static method

The program below is used to explain how to create a simple ALV report using the Factory method.

Program:

*&---------------------------------------------------------------------*
*& Report ZTEST_ALV
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
REPORT ZTEST_ALV.

DATAlo_alv TYPE REF TO cl_salv_table.

START-OF-SELECTION.

SELECT FROM bkpf
  
INTO TABLE @DATA(it_bkpf)
  
UP TO 10 ROWS.
  
IF sy-subrc IS INITIAL.

    cl_salv_table
=>factory(
      
IMPORTING
        r_salv_table   
lo_alv    " Basis Class Simple ALV Tables
      
CHANGING
        t_table        
it_bkpf[]
    
).
*    CATCH cx_salv_msg. " ALV: General Error Class with Message

    lo_alv
->display( ).


  
ENDIF
.

The above program will fetch 10 records from BKPF table. The FACTORY method creates ALV table instance for IT_BKPF data. The DISPLAY method displays the internal table IT_BKPF in ALV format.

Queries

  • How to create ALV Report using Object Oriented Programming in ABAP
  • What are the methods used to create ALV report using OOPS
  • What is the Class name for OOPS ALV

1 Comments

  1. Super useful for understanding basic concepts ! thanks!

    ReplyDelete
Previous Post Next Post