How To Implement A Custom Contract Rejection
How To Implement A Custom Contract Rejection
Contract Rejection?
created by Abijith Chandra P on Jun 26, 2014 1:06 PM, last modified by Abijith Chandra P on Jun 26,
2014 1:58 PM
Version 3
inShare
Hi Friends,
We all know that in MM, a Contract is not a legal document. Hence standard SAP
transaction ME35K for releasing the Contract does not provide any provision for rejecting it. But in our
experience, we may have to face a situation from the client that, they want a provision for rejecting the
contract from ME35K (even after explaining the business purpose of a contract) from within a
workflow. Recently, I had to face such a situation where the client wants to reject the contract similar to
what they can do for a Purchase Order or for a Purchase Requisition in their respective workflows. We
tried our level best to defend, but they were adamant on their requirement.
I searched a lot in internet as well as on SDN, but was unable to find any standard solution for this. So I
came up with an idea that, we will build a custom rejection scenario in Contract approval process and
this is working well. This will not tamper the standard approval process and will not touch the
standard tables EKKO and EKPO. This was achieved with the help of a Z table for maintaining the
rejection details and some implicit enhancements built into the program RM06EF00.
I thought that sharing this will help others to tackle this situation. The step by step procedure for this is
explained below.
Step-1:
Create a Z table for storing the rejection details of a Contract, so that this can used later for giving
validations like Contract should not be changed during approval process etc. The table should contain
the following fields.
Since this is standard we can not change. So we need to copy this status into a Z one as ZFREI into
some dummy program ZABI_MM_TEST1. Then it is possible to add or delete application toolbar
items of ZFREI. Into the GUI StatusZFREI, I had added a new item called REJT and removed the
standard ones like FRGS, FRGR, PREV & FREI.
Step-3:
The new GUI Status need to be called from within the standard program RM06EF00, so that this will
overwrite the standard GUI Status FREI. Within the program RM06EF00, we can see that after
the START_OF_SELECTION event, the standard GUI Status is being set(in line no 176). After that,
we can see a perform frg_init, in which we will create an implicit enhancement and will set the custom
GUI Status ZFREI.
After this, the standard output of ME35K for a particular release code will be changed as below.
Step-4:
We had to write code for the rejection. This is done with another enhancement implementation. Under
the event AT USER-COMMAND, we can see a perform user_command. Inside this form routine, we
will be able find an enhancement spot called ES_SAPFM06L. Create an implementation for this spot
and write the code corresponding to rejection.
Since the release happens from a workflow, while coding in this enhancement we should write code to
insert values into table ZMMH005(created in step-1), trigger the
event SIGNIFICANTLYCHANGED of business object BUS2014 and another custom event of a
custom class if some rejection mails need to be send to the initiator through another custom
workflow.All these code is given below.
ENHANCEMENT 1 ZMM_ENH02. "active version
CASE sy-ucomm.
WHEN 'REJT'.
READ TABLE fekko WITH KEY hidk-ebeln BINARY SEARCH.
IF sy-subrc = 0.
DATA : objkey TYPE swo_typeid,
lt_input TYPE TABLE OF swr_cont,
wa_input LIKE LINE OF lt_input,
wa_zmmh005 TYPE zmmh005,
wa_ekko TYPE ekko,
wa_t16fw TYPE t16fW.
SELECT SINGLE * FROM ekko INTO wa_ekko WHERE ebeln = hidk-ebeln.
IF sy-subrc = 0.
SELECT SINGLE * FROM t16fw INTO wa_t16fw
WHERE frggr = wa_ekko-frggr AND otype = 'US' AND objid = sy-
uname.
IF sy-subrc = 0.
objkey = hidk-ebeln.
wa_input-element = 'ReleaseCode'.
wa_input-value = wa_t16fw-frgco.
APPEND wa_input TO lt_input.
*The following event is called so that the workitem
disappears from the agent's inbox.
CALL FUNCTION 'SAP_WAPI_CREATE_EVENT'
EXPORTING
object_type = 'BUS2014'
object_key = objkey
event = 'SIGNIFICANTLYCHANGED'
commit_work = 'X'
event_language = sy-langu
language = sy-langu
user = sy-uname
TABLES
input_container = lt_input.
IF sy-subrc = 0.
SELECT
SINGLE * FROM zmmh005 INTO wa_zmmh005 WHERE ebeln = hidk-ebeln.
IF sy-subrc = 0.
MOVE-CORRESPONDING wa_ekko TO wa_zmmh005.
wa_zmmh005-procstat = '08'.
MODIFY zmmh005 FROM wa_zmmh005.
COMMIT WORK.
ELSE.
MOVE-CORRESPONDING wa_ekko TO wa_zmmh005.
wa_zmmh005-procstat = '08'.
MODIFY zmmh005 FROM wa_zmmh005.
COMMIT WORK.
ENDIF.
*This event call is required only if you need to send a mail after the rejection of the
contract.
CALL METHOD zcl_mm_wf_contract_reject=>raise_event
EXPORTING
i_ebeln = hidk-ebeln
i_event = 'REJECT_INIT'.
In the above code the class zcl_mm_wf_contract_reject is created for triggering the custom workflow
for sending the rejection mail to the initiator. The workflow is configured to be triggered against
the REJECT_INIT event of the class.This is required only because, the business object BUS2014 does
not contain any event for rejection(such as in case of PO business object BUS2012,
REJECTION_START event).
Deatils on how to create a Z class for triggering a workflow can be learned from the following SCN
document.
Getting started with ABAP OO for Workflow ... using the IF_WORKFLOW interface
Step-5:
The entry that falls into the table ZMMH005, need to be updated while release happens. This can be
achieved by creating an implicit implementation in perform FRG_UPDATE before the existing
code(line no 103 in the performuser_command). The code to be written is given below:
ENHANCEMENT 2 ZMM_REJECTSTAT_CHANGE.
"Updating the contract rejection status table with proper process status while Release & Save and while
Release + Save
DATA : wa_zmmh005 TYPE zmmh005.
DATA : wa_t16fs type t16fs,
lv_char TYPE c,
lv_count type i,
lv_frgco type frgco,
lv_text TYPE char5,
lt_t16fw type TABLE OF t16fw,
wa_t16fw type t16fw.
SELECT * FROM t16fw INTO TABLE lt_t16fw WHERE frggr = ekko-frggr.
IF sy-subrc = 0.
DESCRIBE TABLE lt_t16fw lines lv_count.
lv_char = lv_count.
CONCATENATE 'FRGC' lv_char INTO lv_text.
CONDENSE lv_text.
Step-6:
The following piece of code can written in exit EXIT_SAPMM06E_012 of MM06E005 for preventing
any changes to the contract during approval process.
DATA: wa_zmmh005 TYPE zmmh005.
DATA: wa_ekko1 TYPE ekko.
DATA: wa_ekpo_app TYPE ekpo.
READ TABLE tekpo INTO wa_ekpo_app INDEX 1.
IF sy-subrc = 0.
IF sy-tcode = 'ME31K' OR sy-tcode = 'ME32K' OR sy-tcode = 'ME33K'.
SELECT
SINGLE * FROM zmmh005 INTO wa_zmmh005 WHERE ebeln = wa_ekpo_app-ebeln.
IF sy-subrc = 0.
IF wa_zmmh005-frgke = 'B'.
IF wa_zmmh005-procstat = '03'.
MESSAGE e000(zmm00).
ENDIF.
ENDIF.
ELSE.
SELECT SINGLE * FROM ekko INTO wa_ekko1 WHERE ebeln = wa_ekpo_app-
ebeln.
IF sy-subrc = 0.
IF wa_ekko1-frgke = 'B'.
IF wa_ekko1-procstat = '03'.
MESSAGE e000(zmm00).
ENDIF.
ENDIF.
ENDIF.
ENDIF.
ENDIF.
ENDIF.