Most of the retail customers which are EDI trading partners of Lindt companies demand that EDI INVOIC messages are labelled with a unique and sequential Interchange Control Number (ICN) without gap. As already mentioned in a previous What SAP may have forgotten to integrate we do not use a full-blown EDI Adapter like Seeburger but just an “Add-On” (for more details contact http://www.resource.ch about their rEDI Adapter). This rEDI Adapter is highly versatile and does an excellent job for all kinds of EDI messages we employ but it had one major drawback: the generated ICNs were not part of the XML-EDI message and, therefore, could not be searched for in the XI monitoring.This became a dilemma as soon as INVOIC messages were rejected by customers (see Blog What SAP may have forgotten to integrate).
As a consequence I decided to use SAP standard means for generating document numbers (ICN = document number of an EDI message):
1. Use Number Range Objects (SNRO) to generate numbers.
2. Use ABAP Class mapping to incorporate the numbers as ICN into the EDI messages.
Defining Number Ranges for ICN Generation
As a prerequisite a number range object (SNRO) containing multiple number ranges is created. Each number range may be used for either all outbound messages or a certain message type (e.g. INVOIC) sent to an EDI partner.
The NR object ZEDICH_N06 defines 6-digit number ranges for multiple customers. The first customer (range = 00) has received already 1001 INVOIC messages, the second customer 146, the third one 1750 and so on.
Within the ABAP mapping class the correct NR object and number range are set in the CONSTRUCTOR method.
Implementation of Interface IF_MAPPING
In order to create an ABAP mapping class we need to implement method IF_MAPPING~EXECUTE as described e.g. in Michal Krawczyk‘s blog (The specified item was not found. and the SAP Online Help (ABAP Mappings).For maintenance reasons I split the sample coding of the Online Help into distinct methods (e.g. INIT_INPUT_STREAM, PARSE_DOCUMENT, INIT_OUTPUT_STREAM).
Methods PREPROCESSING and POSTPROCESSING enable the developer to do a pre-processing e.g. of the XML-IDoc stream and a post-processing of the XML-EDI stream. Here I will focus on the POSTPROCESSING method because our target is to add the new Interchange Control Number (ICN) into the XML-EDI stream.
Post-Processing of the XML-EDI Stream (Adding the ICN)
Method POSTPROCESSING is protected and needs to be re-defined to match the requirements of the customer. Method MAP_ICN is responsible for adding the ICN into the XML-EDI stream.
NOTE: Adding LOG-POINTs throughout the mapping class is quite useful when it comes to troubleshooting.
The coding of method MAP_ICN is split among the following 2 textareas corresponding to the 2 major functions being executed:
1. Get a new number (fm NUMBER_GET_NEXT) and generate the ICN according to the customer’s requirements.
2. Insert the ICN into the XML-EDI stream.
First we get a new number from the number range followed by a MODULO calculation (depending on the size of the number range object -> here: 6-digits). Then we use this number to generate the ICN.
The ICN may be identical to the NR number. However, some customers demand mnemonics for both supplier and customer as prefix. And others may have even more complicated “formulas” to generate the ICN.
NOTE: In case of TRADACOMS messages we would map the File Generation Number (FLGN) into the XML-EDI stream.
As you can see from the data elements (D_0020) we are mapping the ICN into an EDIFACT/EANCOM message. Instance attribute ME->MO_DOCUMENT (IF_IXML_DOCUMENT) is our handle to the XML-EDI stream. This instance attribute was created within method IF_MAPPING~EXECUTE.
Using method GET_ELEMENTS_BY_TAG_NAME (of IF_IXML_DOCUMENT) we specifically fetch the D_0020 data elements in the UNB and UNZ segment and overwrite their values with the generated ICN.
The ICN has now become an integral part of the XI message.
And by What SAP may have forgotten to integrate a little bit the ICN (and the XI-GUID) can be displayed within SAP R/3.
In this blog I wanted to demonstrate you how you can utilize SAP standard number ranges on SAP-PI in combination with ABAP class mapping in order to sequentially number your outbound EDI messages.
However, even more important I wanted to show you the simplicity and elegance of ABAP class mapping on SAP-PI which will be lost on a Java-only stack.