Wednesday, August 3, 2011

Adding functions to events using CRMV_EVENT

Another great tool to influence the system is adding Callback Functions in CRMV_EVENT. This is a totally different mechanism from last weeks' IC Event mechanism.
The similarity between the two is that both enable you to add custom coding to standard. The difference is that IC events occur because they are raised in specific coding (can be anytime), while the events available in CRMV_EVENT are always triggered from an operation on a oneorder object (where a oneorder object can be a salesorder, activity, service order, etc etc.).

The transaction
Let's take a look at the transaction CRMV_EVENT.

In the top there is a 'Read This Information' button, which actually contains valuable information.

In the next block, called Assignments, you can see 5 fields, where the last field is the Callback field. This field contains the functionmodule to be called, and the 4 fields above are the determination fields. So logically explained, if the situation occurs where the 4 fields are true, the funtion in the callback field is called.

In the next block, called Definitions, you can find the customizing of the Events, Objects etc which are used for the determination. Under normal circumstances, there is no need to adjust anything here, except in the Object Function / Callback option. Here, you are able to add a custom Z-function, which you can then use in the Assignments. I will show this later.

The last block called 'Checks' is a report that tells you which functions will be called for a specific transaction type or item type. This basically is a report that helps you determine which functions are raised.

Instead of adding entries to CRMV_EVENT as described here, it's probably better to add the callback function in transaction SM30 --> CRMV_EVENT_CUST, or via the IMG (SPRO-->CRM-->Transactions-->Basic Settings-->Edit Event Handler Table). The result will be the same, but this is probably a more upgrade-proof solution.

Let's say you want a certain field to be occupied with a certain value based on certain values in the transaction. You could then build a function where you first do a CRM_ORDER_READ (reads from the buffer, so pretty quick), followed by your logic and a CRM_ORDER_MAINTAIN to update the document. It is not recommended to add a commit in a function that is called by an event. Add this function to the object on event '78 Before Saving'.

The Attribute field
The attribute field can be used to filter on a specific attribute value. For instance, if you use object STATUS, you can add value E0004 as a value in the attribute field, so the function is only called if the status has been changed to 'E0004'. The attribute field cannot be used on all processing times (for instance not on the save).

Be careful
Events in CRMV_EVENTS is a powerful tool. You can implement all kind of logic. Be aware of performance though, because if you add a lot of logic on for instance time 1 (immediately), your logic will be processed on every change (not saved, but changed). Of course, there are examples where this is needed (take a look at what standard SAP has on time Immediately), but be cautious. Also, be aware of nesting your function (for instance if you implement a change of the document in your function and schedule your function on change of the document...).


  1. You should mention that customer-specific event callbacks should not be maintained in CRMV_EVENT, but rather in Customizing (SPRO > CRM > Transactions > Basic Settings > Edit Event Handler Table).

  2. Thanks Thomas, good contribution.
    You are perfectly right, I suppose the result is the same but probably more upgrade-proof. I will add it to the post.


  3. Thanks Thomas,

    You have given enough info to get understanding of CRM Events.

    Keep it up!


  4. Hi Thomas,

    The info was really handy.. Carry on.


  5. This post is from Pieter - Acorel not from Thomas. Thanks Pieter - Acorel for this post.

  6. What should be the parameters if I have to reject a document and the status should chnge to Rejected.

  7. This comment has been removed by the author.

  8. Ram, You might be able to find your answer in the information of the CRMV_EVENT transaction.
    Basically what happens, is that during processing of transactions, certain events are raised by the system automatically. You can trigger your (custom) function modules by adding them to the table using this transaction, allowing you to interfere in the standard processing.
    I am not sure if you can add your own events to the standard logic. This would probably require you to make a modification to the standard coding.

  9. This comment has been removed by the author.

  10. Hi Pieter, while creating the Z function module , How would i know that what are the importing parameter i have to use?
    I saw most of the FM contains, IV_HEADER, IV_ITEM, IV_OLD,IV_NEW, IV_Object function etc..

    1. I think this is the standard interface, but to be sure check the standard functions and debug your function to see where the function is called, and what parameters are passed.