Thursday, 04 March 2021 20:26

Handy CL_GUI_ALV_GRID wrapper

Written by Birzhan Moldabayev
Rate this item
(0 votes)
“© 2020. SAP SE or an SAP affiliate company. All rights reserved.” “Used with permission of SAP SE”

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.

construcor

constructor


IT_TOOLBAR parameter is used mainly to avoid creating PF-STATUS. Creating it by copying was not so pleasant and fast thing to do.

other%20parameters

constructor parameters


The other most common used by me parameters of constructor are:

  • IT_FILTER
  • IT_SORT

They are used with popup( ) method, which can create nested screens for “drilldown” to a sum. Usually, to check calculated sum I try to show items which were used during calculation and display one alv grid upon another one.

drilldown%20to%20sum

drilldown to sum with LVC_T_SORT parameter supplied

In code it takes just to add popup( ) method call before show( ).

popup

popup( ) method


The show( ) method itself accepts an handler object, which should contain event handlers of CL_GUI_ALV_GRID class.

set%20handlers

set handlers

In handlers you could get access to instance of CL_GUI_ALV_GRID via sender reference or by calling get_grid( ) of ZCL_EUI_ALV class.


Also, could change default behavior in special PAI & PBO events


In conclusion:

Even at 2021 many reports still display a lot of information with grid controls in SAP gui. And I hope the ZCL_EUI_ALV will help you in this routine work.

PS:

Documentation to the entire EUI library https://bizhuka.github.io/eui.

EUI library located here https://github.com/bizhuka/eui. (Installation via abapgit)

A simple example will be available here SE38-> ZEUI_TEST_ALV

Read 189 times

Leave a comment

Make sure you enter all the required information, indicated by an asterisk (*). HTML code is not allowed.