ALV Programming has undergone a major change over the last couple of years. First we had the function module approach - where the data to be displayed is passed to a function module like REUSE_ALV_LIST_DISPLAY. Then with the introduction of the OO concepts in 46C we had classes like CL_GUI_ALV_GRID and CL_GUI_ALV_TREE which changed ALV
Programming quite a bit. Most (almost all ?) ABAPers today use these classes to program their ALV.
If you were asked to name one improvement to this approach based on classes, what would that be? I would say that it is still a bit painful to create a screen and put a custom control container and then place this ALV Grid in that , all by myself. Especially when I want to create some test programs to answer the questions in the ABAP Forum :-)!
Wouldn't it be great if I could worry less about these and concentrate more on imporving the functionality of my ALV Grid?
This is precisely what you can do from Basis 640. You can now program an ALV in various modes (Fullscreen, Regular and List Mode), all using a single class (and without even having to create a screen ! ).
So without further ado, let me introduce you what's called the ALV Object Model. Now, what's that ?
START-OF-SELECTION.
CALL FUNCTION 'NAMETAB_GET'
EXPORTING
langu = sy-langu
tabname = tab_name
TABLES
nametab = dyntab. "dyntab now contains the field names
LOOP AT dyntab INTO wa_dyntab.
wa_fcat-fieldname = wa_dyntab-fieldname.
wa_fcat-ref_field = wa_dyntab-fieldname.
wa_fcat-ref_table = wa_dyntab-tabname.
APPEND wa_fcat TO i_fcat .
ENDLOOP.
CALL METHOD cl_alv_table_create=>create_dynamic_table
EXPORTING
it_fieldcatalog = i_fcat
IMPORTING
ep_table = dref.
ASSIGN dref->* TO .
SELECT the data from the table SPFLI. If you want a
different table, then just use a different value
than SPFLI in the data declarations part. Or better
still, use a PARAMETERS to take the name of the
table name as input from the selection-screen.
SELECT *
FROM (tab_name)
INTO TABLE
Instead of if_salv_c_bool_sap=>false, you can pass the
value if_salv_c_bool_sap=>true to this method to
see your ALV as a list.
TRY.
CALL METHOD cl_salv_table=>factory
EXPORTING
list_display = if_salv_c_bool_sap=>false
IMPORTING
r_salv_table = gr_table
CHANGING
t_table =