How to find out who calls a function module in update task in CRM
In CRM, when saving a transaction(T_code CRMD_ORDER or CRM webui), there are function modules executed in update task. Sometimes, we get errors from these function modules. The typical sample is: SAPSQL_ARRAY_INSERT_DUPREC which happens in function modules like CRM_SERVICE_OS_UPD_SUB_DU.
Most of time, it happens because the same function module is executed twice with the same records to insert. If we know from where the function module is called, we can understand the whole logic more clearly and find out the reason why it runs in this way.
Normally, updates use database table VBMOD and VBDATA to record the update tasks. So we can use T-code SM13 to get information for the update function modules. But for CRMD_ORDER and CRM webui, we cannot find the update information in SM13. It is because both T-code CRMD_ORDER and CRM webui use ABAP Memory technology instead of VBMOD and VBDATA.
We can consider setting a breakpoint in the update function module. But when the breakpoint stops, it is already inside this function module. We still don’t know who call it.
Of couse, we can also set breakpoint in the command ‘CALL FUNCTION’ or ‘CALL FUNCTION IN UPDATE TASK’. It will stop at every ‘CALL FUNCTION’ statement. If we are lucky enough, we can find out quickly the line where the expected function module is called. But for me, I cannot say so.
Then, how can we locate quickly the place where the update function module is called? In this article, I will explain with a sample how I do.
How is the update information stored and retrieved
If we display program SAPMSSY0 in T-code SE38, we can find export to memory id statement. It writes %_vb_calls into ABAP memory with ID %%vbkey while %_vb_calls contains the update function modules information.
Let’s display program SAPMSSY4. We will see import from memory statement. Now the update information in the ABAP memory is imported to %_vb_calls.
I want to find out where the update function module CRM_SERVICE_OS_UPD_OST_DU is called.
steps in T-code CRMD_ORDER
1. Set breakpoint in line 575 of program SAPMSSY0 and line 31 of program SAPMSSY4.
2. Create a transaction, input values. Before clicking ‘save’ button, input /h and click Enter first.
3. Click ‘save’ button, it will go into debug mode. Check from menu ‘Settings’->’Change Debugger Profile/Settings’, make sure system debug is switch on since SAPMSSY0 and SAPMSSY4 are system programs.
4. Click F8, the breakpoint will stop at the line 575 of program SAPMSSY0. Double click the variant vb_func_name, the value now is, for example, CRM_ACTIVITY_H_UPDATE_DU.
5. From the callstack, if we double click on the previous program, we can see how FM CRM_ACTIVITY_H_UPDATE_DU is called in FM CRM_ORDER_TABLE_SAVE.
6. If we click F8, we can get all callstacks and notice that the variant VB_FUNC_NAME is the update function module name which is being called.
7. Of course, I just want to find out where FM CRM_SERVICE_OS_UPD_OST_DU is called. If I click F8 everytime, I have to stop many times. In order to make it fast, in step 5, I will set a condition for the breakpoint. Go to ‘Break/Watchpoints’ tab, click ‘new’ to create a condition.
8. The condition is VB_FUNC_NAME = ‘CRM_SERVICE_OS_UPD_OST_DU’.
9. Go back to ‘standard’ tab, click F8. This time, it will stop only when the update function module ‘CRM_SERVICE_OS_UPD_OST_DU’ is called. In this way, I can find out where the expected function module is called.
The entries of %_vb_calls change every time when we stop here. At the moment, its content is:
10. If we continue to click F8, finally, we will come to the line 31 of SAPMSSY4.
Content of %_vb_calls will be:
After this, system will loop %_vb_calls, execute the update function modules one by one.
steps in CRM webui
The steps in CRM webui are similiar to the ones in T-code CRMD_ORDER. For example, if I create an interaction record, all the steps will be:
1. Set breakpoint at line 575 of program SAPMSSY0 and line 31 of program SAPMSSY4. Please notice the breakpoints are ‘external breakpoint’.
2. Set breakpoint at method CL_ICCMP_BT_BUTTONBAR_IMPL->EH_ONSAVE.
3. Create an interaction record and click ‘save’ button.
4. Breakpoint will stop at line 575 of program SAPMSSY0. Also make sure system debug is switched on. Set condition VB_FUNC_NAME = ‘CRM_SERVICE_OS_UPD_OST_DU’, then click F8 to continue.
5. Breakpoint will stop when FM CRM_SERVICE_OS_UPD_OST_DU is called.
Good post, I have come this issue many times!.