We have all needed methods and implicit enhancement is also created so we can create a program to call MB51. We have to create a structure for ALV and include in it type t_list from our class which I've called zab_mb51_call so you should be able to replace it with your own name fast. In my example I will add only few fields beside the one found in MB51, but you can choose as many as it's needed.
types: begin of t_alv. include type t_list. types: dispo like marc-dispo, ekgrp like marc-ekgrp, verid like blpk-verid, spart like mara-spart, bklas like mbew-bklas, rows type epsssrows, vendor_name type mepo_vendor, grtxt like t157e-grtxt, xabln like mkpf-xabln, bldat type mkpf-bldat, end of t_alv.
Selection-options which are the same as in MB51 should be coded with the same names so we can pass them to RM07DOCS by method call_mb51_static.
I used REUSE_ALV here just to be able to do it faster, but ALV OO can be used as well as SALV. If you copy the code bellow and you'll have problems with excel export, then you'll have ot remove it or install to your SAP abap2xlsx classes which I used in this function.
Program runs in following sequence:
If one of the additional select-options is used then it does preselection and manipulates select-options passed to MB51
Call of MB51
Import of results and additional selection done on a base of the result table
In attachments you'll find NUGG files for class and program.
I can already call MB51 from previously created method but still I need to add an implicit enhancement into RM07DOCS so I'll be able to export results from MB51 and leave the program without displaying them. Enhancement must be done at the end of form process_list.
I'll create a method to do the export inside MB51 with only one changing parameter, which will check if we're calling MB51 from our class and if yes then it will copy results of MB51 to memory and leave the program.
I've got method to get selection screen parameters to table so I can call MB51 by submitting program RM07DOCS. Of course if I do that without any changes of parameters then I would get not this list which I want (ALV kind) and MB51 would display its results on screen. That's why I need to export to memory some flags, first two must be set to be able to achieve form process_list in RM07DOCS and to get the output table for ALV, last one is my own flag which I will use in implicit enhancement to check if I should proceed with my own code and close MB51 after I'll get the results.
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'.
After submitting MB51 I'm importing results to table mt_list which is used then to move data into corresponding fields of ct_list.
import export to mt_list from memory id 'ZMB51_FULLLIST_EXPORT'.
As I have needed types I can start to create methods which I need. Firstly fast method the read select-option data from any program which will call our class. I will use here FM RS_REFRESH_FROM_SELECTOPTIONS . If you're thinking about it's restrictions to keep only 40 characters from screen parameters then please check your system as for some of the new versions this FM contains a table parameter of structure RSPARAMSL_255 which allows to store up to 255 characters.
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.
I've decided which way should I go, so now time to do it. I need to do following things to get what I desired:
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.
I prefer to create a class in which I will store all needed methods to call MB51 with selection-options filled and to get back the results.
I will need a type for the structure which will be used as a base type to all copy / move functions from MB51 to class and program. Bellow you'll find a type t_list which contains most of the fields which are available in MB51 (structure list in RM07DOCS). Just after t_list you'll find type tt_list which is just table type for t_list.
It think that some of you involved in MM or PP had already a request or need to add some fields to MB51 or to call it directly with ALV grid instead of old style view. I also had such request and it contained both needs - additional fields and direct display of ALV grid. So I started to dig and debug to see what is possible to do and these possibilities I found:
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
As promised today I'll put code for a method to reset the rejection of the Purchase requisition. Most of the code is the same like in the check method, in fact even the code is repeated again so you can use this one without checking if reset of rejection can be done or not.
I_BANFN TYPE EBAN-BANFN -> Purchase Requistion number
C_FACTORY TYPE REF TO IF_PURCHASE_REQ_FACTORY -> Purchase requisition factory
In the previous article I've shown how to check if we can reset the rejection of the purchase requisition. In the same way you can check if rejection is allowed or if release is allowed or if reset of release is allowed. To do that you'll have to replace following piece of code from previous example fo_releasable->is_reset_rej_allowed( )
with one of the following:
In next article I will show you how to reset the rejection of PR .
Working with Purchase Requisitions in ABAP is quite pleasant job, but sometimes it's not so easy like with other documents types. You cannot easily say if Requisition is rejected and can be reset by checking EBAN table. You have to use OO PR objects to be able to do so. Bellow you can find a method how to check if you can reset the rejection of the requisition done in the WF.
I_BANFN TYPE EBAN-BANFN ->Purchase Requisition Number
E_RESETABLE TYPE FLAG -> If rejection can be reset this parameter will be set to 'X'
CO_FACTORYTYPE REF TO IF_PURCHASE_REQ_FACTORY -> Purchase requisition factory
It may happen that you'll need to do select or loop on a base of the field which is kept in lower case, but you don't know exactly what's the value o field. In such case you may want to build a range of the possible values to be able to fulfill the task. Here is how to do it quite fast by doing FM:
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-subrceq 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-subrceq 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.