There are often instances when you would like to debug the transfer of accounting structures from Billing engine in CRM into R/3 Accounting via CRM middleware. One example, is if you have added a custom field in the CRM Billing Engine application and would like to have this field accessible before Accounting documents are posted. Since the transfer of the billing docs into R/3 occurs asynchronously, it's not quite easy to follow the data flow and debug synchronously. This blog helps you understand the data flow and helps debugging from CRM into R/3. The accounting sub-ledger can be FI-AP/AR or FI-CAX. Irrespective of the accounting module used, the data flow is the same and there are only some additional checks / logics, when FI-CAX is used.
CRM Billing Engine creates and persists Billing Due list items from CRM 1-Order (via Middleware) using the Billing engine adapter. Due List items could also be created from external (non-SAP) sources. A billing run is normally scheduled as a batch process to trigger the Billing process. The Billing process creates billing documents which are either split or combined (based on split criteria) and has a header/item structure similar to the 1-Order. The function module that gets triggered when the Billing document is saved is /1BEA/CRMB_BD_O_SAVE (assuming CRMB is the billing engine application). Billing Engine engine connects to other applications via so-called services and CRM Middleware is one of the service that Billing Engine is integrated into. Within the Save function module, there is an outbound trigger to CRM middleware.
Before you debug from Billing Engine, you have to set two session breakpoints as shown below:
- Class CL_SMW_MFLOW, method __OUTBOUND_HANDLER.
- Function Module CRM_UPLOAD_AFTER_MAP_HANDLER (do a find on variable lv_synchron).
Now, you can select one or more billing due list item(s), then click on "online collective billing". Depending on the split criteria, one or more billing document(s) are displayed. Once you hit the Save icon, you should land at your first breakpoint. At this point in time, you have to switch the values of the variables in_updatetask from 'X' to space and ch_header-debugmode from space to 'X' respectively. Now you can continue (F8). If you reach the same breakpoint again (in a different window), you can just hit F8.
The transfer of the billing documents into R/3 is held in the CRM middleware queue and can be debugged. In order to debug, open transaction SMW01, type the user name and select "Today" as send date and time and then F8. You should now see an entry with an execute icon status. If you select this entry and click on "Reprocess BDoc Message" icon, you should land at the second breakpoint. At this point in time, you have to switch the variable lv_synchron from space to 'X' in debugger. You can also check the value in gv_smof_erpsh-rfcdest. This contains the RFC destination to the R/3 system.
Note: In order to debug into R/3, you have to setup the RFC destination with a dialog user. If gv_smof_erpsh-rfcdest points to a RFC destination with a batch user, you can always copy the RFC destination into a different name with a dialog user (using transaction SM59) and switch the value of gv_smof_erpsh-rfcdest to the new RFC destination in debugger.
If you click F5 from the statement CALL FUNCTION 'CRM_UPLOAD_TRIGGER', you should see your debugger instance window switch from CRM to R/3. Now you can set a breakpoint at the inbound adapter function module BILL_DOC_INBOUND (using shift+F7 in old debugger) and continue. Within this adapter, you can see the middleware data is extracted into the accounting structures. Any additional fields that you might have passed in BAPI extension structures are also extracted. From this point onwards, you can debug into the accounting interface BAPI by setting a breakpoint in function module BAPI_ACC_DOCUMENT_POST. If at any point in time, you wish to cancel the debugging, just click on menu Debugging -> restart. The RFC connection will be closed, but you can launch SMW01 and repeat the debugging process by reprocessing the BDoc message again.
I hope this blog helped you to debug and analyze the data transfer from Billing Engine in CRM into R/3 Accounting. The process might look tedious, but once you become familiar, it doesn't take too much time to do it the next time.