So what am I doing here.... firstly I check if the fieldcatalog was passed. If not then I create it on a base of internal table with usage of cl_salv_table and cl_salv_controller_metadata=>get_lvc_fieldcatalog. After I finally have the fieldcatalog I create result table with sort and filter criteria if they were passed. To do that I use class cl_salv_ex_util. At the end result table is transformed to xstring with method cl_salv_bs_tt_util=>if_salv_bs_tt_util~transform. So you're receiving at the end of the method an xstring file so you can do what you want with it, for example send via mail to the user, or save it on local PC (like in the example found at the end). The most important is that you can use this method in a background so you can prepare some jobs for your programs and send results of them to the users!
it_fieldcat type lvc_t_fcat optional -> field catalog for list viewer control
it_sort type lvc_t_sort optional -> alv control: table of sort criteria
it_filt type lvc_t_filt optional -> alv control: table of filter conditions
is_layout type lvc_s_layo optional -> alv control: layout structure
i_xlsx type flag optional -> create xlsx file?
In the method provided bellow I firstly create custom container object (cl_gui_custom_container) to place the chart in it, then I create chart engine (cl_gui_chart_engine), then using if_xml I create an xml data container which in fact can be written using simple concatenate statement but it's not nice to change and easy to mess.
So after we receive an xml with data then I will pass it to chart engine, then I will run the method prepared in previous part (Create a nice looking chart with CL_GUI_CHART_ENGINE - Part 2 - Customization ) to read the customization of the chart and I will pass it also to engine. Finally I will render the chart.
So first of all we need to download chart designer from SDN so you can google "sap chart designer" to get it. After you'll have it just run one of the versions available there (640 or 700) depending on your GUI version. All files which you'll find in the package are shown below, XML Format.pdf file will tell you how to prepare chart data depending on chart type.
i_dynnr type sy-dynnr -> subscreen number
1st) Add empty line after each part you want to separate and color it differently;
Adding empty lines will force you to delete all of them each time you'll do changes inside table displayed in grid and you'll have to do the calculation of position again, that's why today I will show you the second option.
IM_DISPLAY TYPE CHAR1 - Display only? (no selection)
IM_ELPEI TYPE TPRG-PRGBZ (OPTIONAL) - External date type
EX_EEIND TYPE RVDAT-EXTDATUM - External date
EX_ELPEI TYPE TPRG-PRGBZ - External date type
I_DYNNR TYPE SY-DYNNR - Current Screen Number
I_VARNAME TYPE RSVAR-VARIANT - Variant Name
I_VARTEXT TYPE VARIT-VTEXT - Program variant short text
When you use CL_GUI_ALV_GRID in edit mode or you change your internal table used to display data on ALV grid it may happen that after refreshing the grid using refresh_table_display your cursor or scroll goes to the begining of the grid. Users feels little lost in such situation but there is an easy solution for that.
data: is_stable type lvc_s_stbl.
is_stable-row = 'X'.
is_stable-col = 'X'.
is_stable = 'XX'.
is_stable = is_stable " With Stable Rows/Columns
* i_soft_refresh = i_soft_refresh " Without Sort, Filter, etc.
finished = 1
others = 2
if sy-subrc <> 0.
* message id sy-msgid type sy-msgty number sy-msgno
* with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
EDIT: Method of mine which can be found bellow doesn't have to be used to achieve your goal. To be honest I can't remember why I created separate version of it as only the cursor act a bit different than oryginal one. I must have had mind eclipse at the time :-) . Excuse me for that.
So to keep scroll position and current cell we will need to use following methods of CL_GUI_ALV_GRID:
get_scroll_info_via_id - gets current scroll information
get_current_cell - gets current cell, we will use that data to set the cursor at the end
get_selected_rows - gets selected rows
get_selected_cells_id - if we didn't select any rows, we check for the selected cell information
refresh_table_display - then simple refresh of grid
set_selected_cells_id - after refresh it's time to set back all information, so set selected cell
set_selected_rows - or set seleted rows (depanding what we received at the begining)
set_scroll_info_via_id - set scroll position back
set_current_cell_via_id - set cursor back.
There is no special coding here, just standard ALV grid methods used in proper order.
Method definition, Importing parameters:
I_SOFT TYPE CHAR01 DEFAULT 'X'
I_SET_CURRENT TYPE CHAR01 DEFAULT SPACE
I_SET_SELECTED TYPE CHAR01 DEFAULT SPACE
GRID TYPE REF TO CL_GUI_ALV_GRIDAdd a comment