Triggering an event using Function Module Enhancement

...Previous 

6.       Click on the Enhance button  on the top of the FM.

7.       Go to the end of the FM and click on the yellow line. Now go to Edit -> Enhancement Operations -> Create Enhancement.

8.       Now you would get a popup. Select ‘Code’.

9.       Now enter the details of the new enhancement.

10.       A new enhancement would be created ad the following code would be added to the end of the FM.

"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" A
*$*$-Start: (2)------------------------------------------------------------------$*$*
ENHANCEMENT 1 Z_IBPO_OQT_EVENTTRIGGER.
*
ENDENHANCEMENT.
*$*$-End:   (2)------------------------------------------------------------------$*$*
ENDFUNCTION.

11.        Now write the code to trigger the event of the business object inside this enhancement. This code would be executed when ever an OQT is saved.

Call the FM SAP_WAPI_CREATE. This FM accepts the business object name, Opportunity GUID and business object event name as input and triggers the BO event.

DATA: GUID1 type sweinstcou-objkey,
      rcode type SY-SUBRC,
      event_id type SWR_STRUCT-EVENT_ID.
GUID1 = lv_object_guid.
CALL FUNCTION 'SAP_WAPI_CREATE_EVENT'
  EXPORTING
    OBJECT_TYPE             = 'ZBO_TEST'
    OBJECT_KEY              = GUID1
    EVENT                   = 'OQTSaved'
*   COMMIT_WORK             = 'X'
*   EVENT_LANGUAGE          = SY-LANGU
*   LANGUAGE                = SY-LANGU
*   USER                    = SY-UNAME
*   IFS_XML_CONTAINER       =
 IMPORTING
   RETURN_CODE             = rcode
   EVENT_ID                = event_id
* TABLES
*   INPUT_CONTAINER         =
*   MESSAGE_LINES           =
*   MESSAGE_STRUCT          =
          .

12.       Save and activate the enhancement. Go to Function Module -> Activate Enhancement.

13.       Save the Function Module.

14.       Associate the Z business object ZBO_TEST -> OQTSaved event as a triggering event of a workflow and do the required processing. (BO creation and event association with the workflow is out of scope of this document).

15.   Execute the Opportunity transaction. On save of the OQT, the function module CRM_SVY_OPPORT_PAI would get triggered which would in turn trigger the business object event. This would trigger your workflow!

NOTE: This implementation can be used for save on any survey. Also enhancement of any function module can be done similarly. This approach might seem simple, but has vast implications so should be used with care. Also function module enhancement is only possible on SAP CRM 2007; older versions do not support it.

Conclusion

The issue of triggering a workflow from a Java save button was solved.

Please send us your feedback/suggestions at webmaster@SAPTechnical.COM 

HomeContribute About Us Privacy Terms Of Use • Disclaimer • SafeCompanies: Advertise on SAPTechnical.COM | Post JobContact Us  

Graphic Design by Round the Bend Wizards

footer image footer image