Skip to Content

Overview

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

image

  • 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

image

  • 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… image

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
      image

    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.

    To report this post you need to login first.

    13 Comments

    You must be Logged on to comment or reply to a post.

    1. Anonymous
      Kevin-
      This is a good one. This means, we don’t need multiple user exits but just one exit each for inbound and outbound and have all the logic inbuilt for various IDOC scenarios we have in the landscape.

      Thanks for bringing this to our attention.
      KK

      (0) 
      1. Kevin Wilson Post author
        I find it very useful when there is no overall IDoc user exit to be able to manipulate the data just before sending to MASTER_IDOC_DISTRIBUTE.
        Also, it’s great when you need to change data using some ABAP logic and only need it applied to certain partners.
        (0) 
        1. Gaurav Jain
          Hi,

          Very useful and nice blog…

          I also tried the same case for sending the invoice to third party system with modifing fields in E1EDKA1 segment.

          After activating user-exit, all my segments for which conversion rule is defines are blank. I also tried to debug but not able to reach the reason for that.

          If I deactivate the rules its workes fine…

          Can u plaease tell me the reason for that or any other steps to be consider.

          Thanks & Regards,
          Gaurav Jain

          (0) 
          1. Kevin Wilson Post author
            In BD79 you need to make sure that all the fields are mapped from source to target as described in my blog. I clicked the “Proposal” button but you can simply cut and paste all the fields from source to target if you wish. Obviously the field/s that you are changing do not need this mapping.

            Good Luck
            Thanks
            Kevin

            (0) 
              1. Afsar Ashraf
                Hi Gaurav,

                Please let me know whether you were able to solve this issue.

                I am also facing the same issue while sending the IDocs of message type GLMAST & COELEM.

                Waiting for reply..

                Thanks in advance,
                Afsar

                (0) 
                1. Martin Sommer
                  Hi Kevin and thanks for the excellent blog.

                  Afsar i faced the same problem: first i implemented the 1st include ZXKKCU01 and the segment contained no data after conversion.

                  I figured out that the enhancement attempts to call the 2nd include ZXKKCU02 after the 1st even the 2nd was not implemented. Consequence was that the segment data was not copied to the exporting param “receiver_set_new” of the 2nd include.

                  So i implemented the second include as well just to copy the data via “MOVE receiver_set TO receiver_set_new”.

                  The other way around: if ZXKKCU02 contained conversion routines i had to copy the data in the first include via “MOVE sender_set TO sender_set_new.”

                  Regards, Martin

                  (1) 
    2. Rhonda Wilcox
      Hello,

      I am planning to use a conversion rule along with the user exit for inbound cost centers and profit centers.  My question is:  How can I send a custom error message using the conversion rule if the idoc segment contains a certain value that I don’t want to load.  I would like to stop and fail the idoc with a custom message if one if the fields in the segment contains a certain value.

      Thank you for your help,
      Rhonda

      (0) 
      1. Kevin Wilson Post author
        Rhonda,

        I would not use this user exit for that type of functionality. In order to manipulate the EDIDS record you need access to the internal table IDOC_STATUS so that you can add your custom error.

        Why not create a custom process code and “wrapper” the function modules processing the cost and profit centers. Before calling the standard one check the segment for your value and change the status record accordingly. If the data is good then call the standard function.

        Thanks
        Kevin

        (0) 
    3. bart pelsmaekers
      I’ve got idocs from type PRCMAS coming in, containing profit centers. The profit center names are numeric, 4 long. As in SAP the field PRCTR is 10 long, a field conversion is necessary to add the leading zeroes.

      I’ve tried setting up a conversion rule for this idoc type, but it does not seem to work. In BD62 I added a conversion rule for idoc segment E1KEPCM.
      In BD79 I changed the conversion for field PRCTR. I selected rule type “Copy sender field”, and indicated conversion routine “ALPHA” (external –> internal).

      In BD55 I assigned the rule to the idoc type PRCMAS.

      but, after doing this, the idoc’s are created with PRCTR = ‘*’ instead of the profit center number. What am I doing wrong? Is adding leading zeroes possible this way, or should I use the user exit like you described?

      Kind Regards,

      Bart

      (0) 
    4. Alex Marius

      Hi,i have a question, maybe you have an idea, please.

      I have 3 systems(sons) that send to a fourth system(father). I implemented this method(thank u very much) and works when information come from sons to father. BUT! If i want to send from father to sons, how can i implement those user-exits to send to sons and make the conversion for every son?(example. father has company code 0000, son1 0001, son2 0002, son3 0003.)

      scenario 1: Sons send to father(conversion is done in father all 0001,0002,0003 become 0000). OK!

      scenario 2: Father sends to sons :'(. How can i tell him if the sends to 0001(0000->0001) or if he sends to 0002 (0000->0002)?

      Any idea? Thank u very much!

      (0) 
      1. Sanjana Lingras

        Hi Alex,

        I need help in the same scenario.

        I need help regarding SAP IDOC conversion rule. We have a conversion rule for the Instruction Key (DTAWS) field set for CREMAS IDOC to convert value of this field to value “20”. We have created this rule in BD79 for the field DATSW. Now we want this rule to be exempted for specific vendor code.

        Like for e.g. LIFNR = ‘23423423’ then rule should not be applied or DATWS field should not converted to value “20”.

        For this we can write special conversion routine and assign it in BD79.

        Also I have already tried using rule Copy Sender Field, I have put DATWS = 14 in sender field and in conditions I have put LIFNR NE  ‘23423423’. But this approach did not work.

        Can you please tell me in which user exit I can code this condition based conversion with some sample code? That will be really helpful for me.

        Can anybody help me for handling this scenario in special conversion routine and explain how the above scenario can be handled?

        Thanks,

        Sanjana

        (0) 
    5. E- Travel

      Hi Kevin,

      Thanks a million !!! I always used only the classic conversion routines inside the basic conversion rules because I didn’t know this user exit !

      This is more powerfull then the basic conversion rules for complex conversions.

      You simply saved my life 😉

      Best regards,

      Christophe

      (0) 

    Leave a Reply