Overview:
Sap adapter module IDOCFlatToXmlConvertor can be used to convert messages from IDoc flat file to XML format. Normally it’s added in the sender adapter so that the message gets converted to XML format.
In this blog, I’ll describe the approach of the journey of migrating from a custom solution to the standard bean IDOCFlatToXmlConvertor.
Existing Solution:
Existing solution to convert flat files to IDocs was created in SAP PI 7.0 system. As there was no standard bean to convert flat files to IDocs, we built a custom bean to do the flat file to IDoc conversion.
The solution relied on SAP IDoc metadata to be present on the ABAP stack on SAP PI system .
Our files can have some extra fields in the beginning 10 characters.
Some files can have segment type, others will have segment definitions.
The file can have data for multiple IDocs.
Files can be in ALE format ( i.e. control and data record is a single continuous string)
e.g. ALE file format
Non ALE format with segment type and leading DATA and CONTROL records
Non ALE-format with segment definition
Above are three examples files but the data could be in any combination of formats and segment type/segment definition information.
The drawback of the solution:
However, the solution was pretty robust and was being used by thousands of adapters ( 2000+ ).
Starting Getting Ready for Future
While doing migration from PI 7.0 system to PI 7.4 system, we had to code the adapter module again as the underlying Java APIs have modified. We decided not to try to switch to the standard bean as the standard bean doesn’t do the following:
Hence, we decided to create a custom pre-processing bean which will format the data required by the standard bean.
The plan is to replace the old bean by the combination of standard SAP_XI_IDOC/IDOCFlatToXmlConvertor module along with the new custom module
So functionally we will have the following situation
Old Bean = IdocPreProcessbean + SAP_XI_IDOC/IDOCFlatToXmlConvertor
Requirement for mass change of channels
As we have thousands of channels using this bean, the change will need to be done in mass.
We created a tool for making the change using the directory APIs so that we can make the change in mass and revert back to the old version speedily, if required. This blog from William Li can be accessed here which served as the foundation to build the tool.
Initial Version of the bean:
The first version if the bean was pretty lightweight. The thinking was:
Some hints here for converting the single line file to multi line format:
Control record maps to ABAP structure EDI_DC40 and has a length of 524 characters.
Data records map to structure EDIDD and has length 1065 characters.
Using this information, the single row ALE file can be converted to format expected by standard bean.
Roadblock:
The tests with the bean worked for single tests but when we started deploying the change to use the new bean in mass ( we took 10 channels as a pilot to test), it will require us to change thousands of communication channels.
There were two major issues:
Looking at an example segment type and segment definition screenshot, some files have E1EDKA1 whereas other files can have E2EDKA1003, E2EDKA1002, E2EDKA1001 or E2EDKA1.
This was the biggest roadblock as we can't automatically determine these attributes of the interface. In the old bean, the custom function module has access to all the metadata and can easily work with either segment type or segment definition of any release level. It was internally handled in ABAP function module IDX_IDOC_TO_XML.
Modification to solution:
In summary, we got a solution but it can’t be implemented as it’s not possible for us to do the change in mass as we can't identify file data attributes. So we decided to enhance the solution to cater for the roadblocks.
You can read the blog which I had written before about how to read IDoc metadata on Java stack. The link is here.
The solution relied on the following approach:
When we read the metadata with the current release level ( 740 ) , we get the below information.
Other release levels are created by the adapter module by decrementing the counter for segment definition.
This is required for the below reasons:
Module Configuration
Adapter configuration using old adapter module.
Adapter configuration using the new bean along with standard adapter module SAP_XI_IDOC/IDOCFlatToXmlConvertor.
As seen in the screen-print, the parameters are:
IdocPreProcessbean:
SourceJRA
TargetDestination
These are required to read IDoc metadata from the target ERP system. As we're not specifying any release level, it will read the metadata for the system's release level.
This can be verified by looking at the segment definition of the segment we were looking in WE31.
Parameters for the SAP_XI_IDOC/IDOCFlatToXmlConvertor bean:
SourceJRA
TargetDestination
SAPRelease
SegmentTypeProcessing
Now, these parameters can be supplied in mass.
For connection, these are fixed
SourceJRA
TargetDestination
SAPRelease : We use the current release level: 740
SegmentTypeProcessing: true , as we have already converted the segment definition to segment type in the custom bean.
Handling date and time:
As most of the interfaces are inbound to SAP, we converted them from classical scenarios to ICOs. This allowed us to use Idoc_AAE adapter on the receiver side. As Idoc_AAE adapter doesn't like date and time passed to it, it's blanked out.
In summary after the changes the implementation looked as below:
Libraries required to build the adapter module
Apart from normal libraries required for standard adapter module development, we'll need IDoc library as well.AP Java IDoc class library and SAP JCO libraries can be downloaded from service.sap.com/connectors .
Note about performance:
and realised that as we were appending Strings to existing String objects, it was consuming a lot of heap space. Then we realised that Strings are immutable in java and if an already existing String gets modified, a new Object gets created.
We could have used StringBuilder but decided to use StringBuffer as it is thread-safe.
2) The main objective of the bean was to make us future ready for eventual PO migration where we'll be forced to make the change. With the previous bean, we were making a call to PI ABAP stack for all messages.
With the new bean, call to ERP ABAP system to read IDoc metadata gets called only for the first message. Once the metadata gets cached, no calls to
ERP system are made and the metadata gets read locally from AS Java server cache. Of course, if the system restarts or someone deletes the metadata
manually, it'll again need to go and read metadata from ABAP stack of ERP system.
Standalone testing:
To speed up development and testing of the module, I did the testing from NWDS itself. The link I had for the IDoc library has the sample code for testing in Java SE environment.
As a summary, metadata can be read by creating a local JCO destination file and using in the code.
JCoDestination destination=JCoDestinationManager.getDestination(“NSP”);
IDocRepository iDocRepository = JCoIDoc.getIDocRepository(destination);
IDocSegmentMetaData rootMetaData = iDocRepository
.getRootSegmentMetaData(“Z_TEST”, “Z_TEST_EXT”,
“7.02”, “7.02”); } }
where Z_TEST : idoc type
Z_TEST_EXT : Extension Type
Github link is here. The code to read locally from NWDS JCO destination has been removed as I didn't want to deploy it to productive version.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
12 | |
12 | |
7 | |
5 | |
5 | |
4 | |
4 | |
3 | |
3 | |
3 |