Application Development Blog Posts
Learn and share on deeper, cross technology development topics such as integration and connectivity, automation, cloud extensibility, developing at scale, and security.
cancel
Showing results for 
Search instead for 
Did you mean: 
joachimrees1
Active Contributor
37,097
In https://blogs.sap.com/2020/06/18/cleaning-up-my-adt-report-template-part-2-more-cleanabap/ I hinted that I could write a blog about my display_data method.

This is it.

Some years ago, I discovered cl_salv_table - and I liked it a lot (compared to CL_GUI_ALV_GRID), as I didn't have to care for a dynpro or a container.
Just give it your internal table and it will display it.

This is the simple call I have been using for that:
    DATA: lr_alv          TYPE REF TO cl_salv_table.
TRY.
CALL METHOD cl_salv_table=>factory
EXPORTING
list_display = if_salv_c_bool_sap=>false
IMPORTING
r_salv_table = lr_alv
CHANGING
t_table = ct_data.
##NO_HANDLER.
CATCH cx_salv_msg .
ENDTRY.
CALL METHOD lr_alv->display.

 

But some ALV-functions (like export I think) where missing.

This is solved with:
lr_functions = lr_alv->get_functions( ).
lr_functions->set_all( abap_true ).

Still, a function that is often important to me, was missing: saving (and retrieving) layouts.

This can be achieved with:
lr_layout = lr_alv->get_layout( ).
ls_key-report = sy-repid.
lr_layout->set_key( ls_key ).
lr_layout->set_default( abap_true ).
lr_layout->set_save_restriction( if_salv_c_layout=>restrict_none ).

With a little cleaning and writing things more compact, this is the current state of my display_data method:
  METHOD display_data.
TRY.
cl_salv_table=>factory( IMPORTING salv_table = data(alv)
CHANGING table = c_data ).
CATCH cx_salv_msg.
ENDTRY.

alv->get_layout( )->set_key( VALUE #( report = sy-repid ) ).
alv->get_layout( )->set_default( abap_true ).
alv->get_layout( )->set_save_restriction( if_salv_c_layout=>restrict_none ).
alv->get_functions( )->set_all( abap_true ).
CALL METHOD alv->display.
ENDMETHOD.

What do you think?

Have I missed some features, I could also add?
Could I write things more compact / elegant? How?

Is cl_salv_table even still the latest / best tool for easy-ALV-like displaying of an already existing internal table?!
(Wording brought to you by trying exclude the "Just write a CDS-view and slap a fiori-elements list on top of it" 😉 .
CDS-view + fiori-elements list is actually great and I am using it - I just don't want to discuss it here! )

Best
Joachim
13 Comments
Labels in this area