In Error handling framework for ABAP proxies – Part 1 of this blog series, we discussed the design pattern for error handling in ABAP proxies by using the proxy framework classes and RTTS to dynamically create IDOCs. In this part we will take a deep dive in to the actual coding on how to achieve the same. If not already done, I strongly suggest that you take a look at Error handling framework for ABAP proxies – Part 1 before proceeding further.
In our design pattern, the first task is to identify the interface header details (Receiver, Sender, Message ID etc) before starting to process the data. This is achieved by using the method of class CL_PROXY_ACCESS as shown below
Once message header details are obtained, the corresponding IDOC type and message type are to be used for this interface can be obtained from our control table as shown below
Then using function module SWO_GET_FUNCTION_FROM_METHOD and table TBDBA we can obtain the underlying BAPI function module that is used for posting the IDOC data. Using function module RFC_GET_FUNCTION_INTERFACE_P, we can obtain the import, export and table signatures of the BAPI function module. Lastly, using function module IDOC_TYPE_COMPLETE_READ, we can obtain the segment information of the IDOC type that is being used.
At this point, we have the BAPI function module input signature and the segment definitions of the IDOC. One thing to note is that we cannot have more than one occurance of the same structure in the BAPI signatures, if an IDOC definiton has to be derived automatically out of it. In other words, the BAPI module signatures have to have unique structures, which means there is a one to one relationship between the BAPI function module signatures and the corresponding IDOC segments. This comes in handy when we have to dynamically frame IDOC data from the BAPI function module import or tables signature.
You can download the entire error handler class and control tables in SAPLink nugget format here.
Once you upload this code your system, you may use the class map below to understand the interaction between various methods.
Here is a sample code that can be used in the server proxy to dynamically create IDOCs in case of errors.
In the next part of this blog series, I will share a design framework for dynamic IDOC error handling tool (a better alternative to BD87) using ABAP WebDynpro.