This solution only works for changing segment data within the current IDoc segment. Ie. You cannot query data that resides in another segment of the current Idoc but you can query data already residing in the database.
The solution is implemented in the user exit enhancement KKCD0001. This user exit is called after each Idoc is created on either the sender or receiver systems.
The function exits are EXIT_SAPFKCIM_001 for compression of sender segments or EXIT_SAPFKCIM_002 for receiver segments.
An example : I am going to put the bill of lading number in the AUGRU_BEZ field of the E1EDK01 segment of the INVOIC message type.
Procedure – Setting up the conversion rule
First we need to set up a dummy conversion rule for the required segment
- Define rule (BD62) – Create conversion rule name and link it to your required segment name. (PS: You can use transaction WE60 to check the documentation of your IDoc type to see what segments are expected.)
In our example we create a rule called BOLNR and link it to the IDoc segment E1EDK01
- Maintain Rule (BD79) – Enter the rule name (BOLNR) and click the change Icon. Here is where I click the Create proposal for rule button in order to get the segment data in to the user exit and subsequently out of the user exit. Save and Exit
- Map rule to partners (BD55) – Enter the message type (INVOIC) and enter. Enter the sender type and sender name. For outbound Idocs this is the logical system assigned to the client you are currently in. Enter the receiver type and number. VN is important to have for EDI partners, ALE goes from LS to LS and EDI goes from LS to LI / KU, …
Enter the segment type (E1EDK01) and the conversion rule name (BOLNR).
This is pretty useful stuff right here. You can turn on the conversion rule for that segment for specific partners only. Let’s say that you need this BOL number for an EDI partner X and not for Y then you can run partner X through the rule by putting and entry in BD55 and not for partner Y. (PS: Note that this is transportable and if you don’t have your production logical systems in your development environment then you will need to open QA and production to make this BD55 entry for their respective logical systems)
The following screendump shows that when an INVOIC Idoc is received with sender the DEV system client 100 and the receiver is bill to customer 1000025, and the segment is E1EDK01, the rule will be run…
Procedure – Setting up the user exit
EXIT_SAPFKCIM_001 is called (if activated see section below) during the processing in IDOC_SEGMENT_TRANSLATE. Ie. The function module ALE_IDOC_SERVICES_APPLY_OUT (always called) performs IDOC_CONVERT_FIELDS which calls IDOC_SEGMENT_TRANSLATE. If the Idoc segment and field have a conversion rule set-up the user exit described will be called.
The SAP help describes the user exits as follows:
For customer extensions, there are two customer exits for segment conversion. The exits are contained in the extension KKCD0001. Once activated, the customer exits are called for all segment conversions. It is recommended that you code a CASE statement within a customer exit, in which various cases can be accessed depending on the conversion rule (REPID). In the CASE statement you should have a WHEN OTHERS branch, in which the 'SENDER_SET' is assigned to the SENDER_SET_NEW' or the 'RECEIVER_SET' is assigned to the 'RECEIVER_SET_NEW'. SENDER_SET is a field like SDATA with all fields concatenated within itself. To reference it you need to assign the appropriate Idoc structure to SENDER_SET then you can address the fields based on this segment structure.
- Activate the user exit (CMOD) – Enter a new project (ZINVOIC) and create. Give the project a description and click Enhancment Assignments. Enter KKCD0001 and click components.
Double click on EXIT_SAPFKCIM_001.
Double click on zxkkcu01 in the include statement to begin coding.
When finished coding return to CMOD and activate project. In the code you will be working with the SENDER_SET and SENDER_SET_NEW combination.(NB: The first customer exit is accessed before the standard segment conversion (conversion according to defined rules))
- Activate the second user exit – The second customer exit is accessed after the standard segment conversion. You code the same way for this segment except that you will be working with the RECEIVER_SET and RECEIVER_SET_NEW combination.
- Example code – In include ZXKKCU01
data: e1edk01 type e1edk01. CASE repid. WHEN 'BOLNR'. move sender_set to e1edk01. * GET DELIVERY FROM INVOICE NUMBER select single vbelv into vbfa-vbelv from vbfa where vbeln = e1edk01-belnr and vbtyp_n = 'M' and vbtyp_v = 'J'. IF sy-subrc = 0. select single bolnr into e1edk01-augru_bez from likp where vbeln = vbfa-vbelv. ENDIF. * MOVE SENDER_SET to SENDER_SET_NEW --- NB move e1edk01 to sender_set_new. ENDCASE.
- Checking that it worked! – Run an Idoc based on the control record partners set up in BD55. Look at the status record 30 of the resulting IDoc and you should see that the message should read “Fields converted“
If no data appears in the segment check that you have assigned the SENDER_SET to SENDER_SET_NEW and that you have assigned RECEIVER_SET to RECEIVER_SET_NEW.