How to use User Defined Types in ALV- Factory method

 How to use user defined types in ALV- Factory method



In traditional ALV, the field catalogue must be created before calling the REUSE_ALV_GRID_DISPLAY. In ALV OOPS using Factory method the field catalogue is not required. Check the example below

We have created a structure with some fields from BKPF and an internal table with the structure created.

We have created instance for ALV using the internal table without creating the field catalogue and calling display method to display ALV output.

The ALV created using Object oriented method is very simple when compared to traditional ALV. Also, it is reusable and improves performance.

You can also use new open SQL syntax using @DATA to create the internal table type.


*&---------------------------------------------------------------------*
*& Report ZTEST_ALV
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*

REPORT ztest_alv.

TYPESBEGIN OF ty_bkpf,
         bukrs 
TYPE bukrs,
         belnr 
TYPE belnr_d,
         gjahr 
TYPE gjahr,
         xblnr 
TYPE xblnr1,
       
END OF ty_bkpf.

DATAit_bkpf TYPE TABLE OF ty_bkpf.

DATAlo_alv TYPE REF TO cl_salv_table.

START-OF-SELECTION.

  
SELECT bukrs belnr gjahr xblnr
    
FROM bkpf
    
INTO TABLE it_bkpf
    
UP TO 10 ROWS.
  
IF sy-subrc IS INITIAL.

    cl_salv_table
=>factory(
      
IMPORTING
        r_salv_table   
lo_alv    
      
CHANGING
        t_table        
it_bkpf[]
    
).

    lo_alv
->display( ).

  
ENDIF.

Output:



Post a Comment

Previous Post Next Post