CL_SALV_TABLE or CL_GUI_ALV_GRID which class is better to use in 2021 ?
Probably old abapers remember that more than decades ago that there was shift from the “old-fashioned” CL_GUI_ALV_GRID class & ‘REUSE*’ function modules towards new up-to-date & OOP style class CL_SALV_TABLE. At 2020 I decided to move backwards to CL_GUI_ALV_GRID. At the small article below I try to explain why I made that decision. And it is not related to nostalgia.
One of the reasons to use CL_SALV_TABLE was small amount of code compared to CL_GUI_ALV_GRID. Also, there was no need to create new screen & containers to display a grid. But then new syntax 7.40 was introduced and passing parameters to any method via structures & tables simplified drastically. I decided to fill a gap and just add nested screens functionality for CL_GUI_ALV_GRID.
Let’s jump to new syntax & display table data without annoying screen painter.
" Sample data
SELECT * INTO TABLE @DATA(lt_flight)
FROM sflight.
" Create ALV & pass table
NEW zcl_eui_alv( REF #( lt_flight ) )->show( ).
As I was mentioned earlier calling methods of CL_SALV_TABLE class is not the shortest and handiest available form of tuning a ALV GRID. Let’s try to pass parameters via structures (lvc_s_layo) & tables (lvc_t_fcat).
" Sample data
SELECT * INTO TABLE @DATA(lt_flight) FROM sflight.
" Create ALV & pass table
DATA(lo_alv) = NEW zcl_eui_alv(
ir_table = REF #( lt_flight )
" Set title
is_layout = VALUE lvc_s_layo( grid_title = `Demo title`
smalltitle = 'X' )
" Hot spot & totals by mask
it_mod_catalog = VALUE lvc_t_fcat( ( fieldname = 'CONNID' hotspot = 'X' )
( fieldname = 'SEATS*' do_sum = 'X' ) ) ).
" Show in full screen
lo_alv->show( ).
*No new API from my side for tuning an alv grid catalog & layout. Just small enhancements to change default field catalog (Not creating one from the scratch).
What about other parameters of CL_GUI_ALV_GRID? They are here in ZCL_EUI_ALV constructor’s parameters.
No comments:
Post a Comment