Enhanced MB51 Part 4 - Call MB51
export no_list from m_flag to memory id 'MB51_NOLIST'.
export flag from m_flag to memory id 'MB51_FLAG'.
export flag from m_flag to memory id 'ZMB51_FULLLIST_EXPORT'.
- import export to mt_list from memory id 'ZMB51_FULLLIST_EXPORT'.
Enhanced MB51 Part 3 - Get selection parameters
i_progname type sy-repid
it_seltab type rsparams_tt
method get_selection_screen_criteria.
call function 'RS_REFRESH_FROM_SELECTOPTIONS'
exporting
curr_report = i_progname
tables
selection_table = it_seltab
exceptions
not_found = 1
no_report = 2
others = 3.
case sy-subrc.
when 0.
when 1.
"raise not_found.
when 2.
"raise no_report.
when others.
"raise other_error.
endcase.
endmethod.
Enhanced MB51 Part 2 - Structure for data
- Create a function group or class to be able to reuse the solution in other programs also
- Create implicit enhancement in MB51 to be able to export it's results and stop MB51 if it's called from outside
- Create a program with selection screen fields from MB51 + my own desired additional filters. This program should call standard MB51 and display some additional fields in ALV Grid.
Enhanced MB51 Part 1 - Goal and prerequisites
- Copy program RM07DOCS (MB51) to Z-one and to the changes there - but I don't like such solutions so I didn't want to do that way
- Create own program which selects data from MKPF and MSEG and display it like MB51 do - but this would be to time consuming to prepare same logic like in MB51 and in case of any changes in oryginal transaction I would need to adjust program again
- Do implicit enhancement in RM07DOCS to add missing fields to the field catalog and then fill them during the call of MB51 - this would solve the first part of the request but users will have to do additional two clicks to go to ALV grid which as you may know already is sometimes to much :) Nevertheless if someone of you would like to go this way then you should do two implicit enhancements in RM07DOCS:
Add a comment
Range to search in lower case fields
function z_ab_prep_val_for_case_search.
*"--------------------------------------------------------------------
*"*"Local Interface:
*" IMPORTING
*" VALUE(I_TEXT) TYPE CSEQUENCE
*" VALUE(I_SIGN) TYPE CHAR1
*" VALUE(I_OPTION) TYPE CHAR2
*" EXPORTING
*" REFERENCE(ER_RANGE) TYPE STANDARD TABLE
*"--------------------------------------------------------------------
field-symbols: <low> type any.
field-symbols: <sign> type any.
field-symbols: <opt> type any.
field-symbols: <line> type any.
field-symbols: <linenew> type any.
field-symbols: <lownew> type any.
field-symbols: <tab> type standard table.
data: f_times type i.
data: f_text type string.
data: f_textnew type string.
data: f_insidel type i.
data: f_insidel2 type i.
data: ft_data type ref to data.
"create temp table and assign it to FS
create data ft_data like er_range.
assign ft_data->* to <tab>.
f_text = i_text.
"get lenght
f_times = strlen( f_text ).
"translate to upper case so we have always same start
translate f_text to upper case.
"append initial line to range and put first value into table
append initial line to er_range assigning <line>.
check sy-subrc eq 0.
assign component 'LOW' of structure <line> to <low>.
check sy-subrc eq 0.
<low> = i_text. "all in uppercase
assign component 'SIGN' of structure <line> to <sign>.
check sy-subrc eq 0.
<sign> = i_sign.
assign component 'OPTION' of structure <line> to <opt>.
check sy-subrc eq 0.
<opt> = i_option.
translate <low> to upper case.
"create entries for each other combination of cases
do f_times times.
f_insidel2 = sy-index - 1.
loop at er_range assigning <line>.
assign component 'LOW' of structure <line> to <low>.
check sy-subrc eq 0.
if f_text+f_insidel2(1) ca '*+' and ( i_option eq 'CP' or i_option eq 'NP' ).
else.
append initial line to <tab> assigning <linenew>.
check sy-subrc eq 0.
assign component 'LOW' of structure <linenew> to <lownew>.
check sy-subrc eq 0.
assign component 'SIGN' of structure <linenew> to <sign>.
check sy-subrc eq 0.
<sign> = i_sign.
assign component 'OPTION' of structure <linenew> to <opt>.
check sy-subrc eq 0.
<opt> = i_option.
<lownew> = <low>.
f_textnew = <lownew>+f_insidel2(1).
translate f_textnew to lower case.
<lownew>+f_insidel2(1) = f_textnew.
endif.
endloop.
append lines of <tab> to er_range.
refresh <tab>[].
enddo.
endfunction.
Extend allowed runtime of a program
- Call commit work whenever you want to reset the counter of running time for your transaction (especially if you haven't done any update into database tables)
- If commit work doesn't work or you don't want to use it at the moment then you could use FM TH_REDISPATCH with the check_runtime parameter equal to 0.
- You could also you FM SAPGUI_PROGRESS_INDICATOR for the same purpose but keep in mind that showing indicator too often can slower your program.
Although it's nice to know this possibility my advice is to not to use it very often as the less time you have for program run the more optimized code you can provide, so it's really something that you use if you do not have other choice and you agreed that with your system admins.
Copy routing (create on a base of existing one)
Create XLSX/MHTML file from internal table in background
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?