Hello Friends again,
Thought of preserving a solution evolved while helping a member in a recent discussion
To Control Order Release Authorizations using user-exit IWO10002 .
Order Releasing authorities at various levels will have their own limits for Releasing an Order (sometimes called DOP or Delegation Of Powers). Here we are discussing a situation where the Plan Costs should not go beyond the respective limits assigned to the users for Releasing an Order.
Create a Ztable (say ZPLANCOST) wtih TMG (Table Maintenance Generator to update the Table Entries)
Do not forget to enter the currency Reference fields as shown below.
Have the entries, UserIds vs the Allowed limit of Plan Costs for Release. like shown below
(The column heads User Name and Period value are coming from the data-elements we used in ztable.)
Put this code in include ZXWO1U02 of user-exit IWO10002.
DATA: v_stat TYPE char1. SELECT SINGLE iphas FROM afih INTO v_stat WHERE aufnr = caufvd_imp-aufnr. IF v_stat = '0'. DATA:v_cost TYPE bp_wpl, v_wrt TYPE bp_wpl, v_wrt01 TYPE bp_wpl, v_wrt02 TYPE bp_wpl, v_wrt03 TYPE bp_wpl, v_wrt04 TYPE bp_wpl, v_wrt05 TYPE bp_wpl, v_wrt06 TYPE bp_wpl, v_wrt07 TYPE bp_wpl, v_wrt08 TYPE bp_wpl, v_wrt09 TYPE bp_wpl, v_wrt10 TYPE bp_wpl, v_wrt11 TYPE bp_wpl, v_wrt12 TYPE bp_wpl. SELECT SINGLE cost FROM zplancost INTO v_cost WHERE uname = sy-uname. SELECT SINGLE wrt01 wrt02 wrt03 wrt04 wrt05 wrt06 wrt07 wrt08 wrt09 wrt10 wrt11 wrt12 FROM pmco INTO ( v_wrt01, v_wrt02, v_wrt03, v_wrt04, v_wrt05, v_wrt06, v_wrt07, v_wrt08, v_wrt09, v_wrt10, v_wrt11, v_wrt12 ) WHERE objnr = caufvd_imp-objnr AND wrttp = '01'. v_wrt = v_wrt01 + v_wrt02 + v_wrt03 + v_wrt04 + v_wrt05 + v_wrt06 + v_wrt07 + v_wrt08 + v_wrt09 + v_wrt10 + v_wrt11 + v_wrt12. ENDIF. IF v_wrt > v_cost. MESSAGE: 'Plan costs exceed your DOP limit, Order can not be released.' TYPE 'W' DISPLAY LIKE 'E'. SET SCREEN 3000. LEAVE SCREEN. ENDIF.
With this code in place, when the user ABCD_EFGH tries to release an Order (with CRTD status) where the Plan Cost is more than 5000 the system will throw below error (when clicked on REL flag).
Means the user ABCD_EFGH will not be able to release the Order.
We are talking about Plan costs, means we are talking about things after the Order is Saved. If someone tries to Release at the time of Order creation itself with excessive plan costs the code will not stop.
For this purpose put the following code also after the above code.
IF sy-tcode = 'IW31'. MESSAGE: 'Order can not be released while creating. Release Order thorugh ''IW32''.' TYPE 'W' DISPLAY LIKE 'E'. SET SCREEN 3000. LEAVE SCREEN. ENDIF.
This throws the error below in the status bar if some one tries toRelease the Order in IW31 itself..
Because we have TMG for Ztable, we will be able to maintain the Table entries in the Ztable (Add, Modify or Delete) in PRD client through SM30.
This solution evolved while my answering the discussion Using Permits to form Release Strategy The code in the present blog has been improvised to take care of more possibilities of Plan costs.
- I feel that one valuable thing in the above code is when a member studies and understands the code, he/she understands the table PMCO and its cost fields.
- These solutions often become significant not for their being able to directly applying and resolving issues, but for triggering ideas and adopting them to our own similar issues. So look for the applications in your own area which could make use of the above solution.
In another case, one of our scn friends wanted a solution ‘To stop Release of Refurbishment Order when its Plan cost exceeds 60% the Cost of New material’ . The solution code was worked-out, tested and given to him here: Restrict release of refurbishment order, if the Plan cost exceeds 60% or more than cost of new equipment.
Then there was a challenge. The case is :
Order was Created with Components and not released. Now in IW32, if user makes changes to components tab like altering quantities OR adding more component lines the, this will immediately not reflect on Plan costs. So Order will get Released if the new Plan Costs (to be after save) is more than the limit of the user. To take care of this the following code needs to be put after the above codes.
IF sy-tcode = 'IW32'. TYPES: BEGIN OF ty_resb, matnr TYPE resb-matnr, rspos TYPE resb-rspos, END OF ty_resb. DATA: it_resb TYPE STANDARD TABLE OF resb WITH HEADER LINE, wa_resb LIKE LINE OF it_resb, lines TYPE i, lines1 TYPE i. SELECT * FROM resb INTO TABLE it_resb WHERE aufnr = caufvd_imp-aufnr. DESCRIBE TABLE it_resb LINES lines. FIELD-SYMBOLS: <fs_resb> TYPE any. DATA: BEGIN OF i_resb OCCURS 0. INCLUDE STRUCTURE resb. DATA:END OF i_resb. ASSIGN ('(SAPLCOBC)resb_bt') TO <fs_resb>. i_resb = <fs_resb>. DESCRIBE TABLE i_resb LINES lines1. IF lines <> lines1. MESSAGE: 'First Save the Order before Release.' TYPE 'W' DISPLAY LIKE 'E'. SET SCREEN 3000. LEAVE SCREEN. ELSE. LOOP AT i_resb. READ TABLE it_resb INTO wa_resb WITH KEY rsnum = i_resb-rsnum rspos = i_resb-rspos. IF sy-subrc = 0. IF wa_resb-bdmng <> i_resb-bdmng. MESSAGE: 'First Save the Order before Release.' TYPE 'W' DISPLAY LIKE 'E'. SET SCREEN 3000. LEAVE SCREEN. ENDIF. ENDIF. ENDLOOP. ENDIF. ENDIF.
This code throws the error below in the taskbar if someone modifies the data in Components tab and tries to release a this point. (Code has taken care of Quantities and new lines, additional requirement if any to be addressed by you).
…And thus this post started very simple and evolved into a complete solution.