Skip to Content

Business Scenario: Automate freight header pricing condition type on sales order at the header level.  Currently SAP doesn’t have the capability to automate header condition types.  What we mean by automate is, for example, item condition types, you can set those up with a condition record and when certain criteria is met the record is automatically inserted into the sales order.  Transaction VK11/VK12/VK13 allows you to enter in the condition record type and then create/change/display records for different condition types.

Solution: Put some custom code within the sales order user exit MV45AFZZ.  There are several places in which custom code can be placed in order to update the sales order header condition type.  One place the code can be put is the FORM userexit_save_document_prepare (which is the form that gets executed one time right before the sales document gets saved.  Another place and probably the best place to put it is in the FORM userexit_pricing_prepare_tkomk.  In our solution we have placed the code in the FORM userexit_pricing_prepare_tkomk.  Depending on the way the environment is setup you will either have to create an enhancement or you can just update the code directly.  In our example we are updating the code directly.  If you need to do an enhancement or would like assistance using other FORMS feel free to ask for pointers.

1. Go to SE38 and enter in MV45AFZZ and click on change.  (If it asks you for an object key that means you need to create an enhancement).

2. Go down to the FORM userexit_pricing_prepare_tkomk.

3. In our instance we only wanted to update the header freight condition type on the creation of the sales order.  In order to do this you need to start your custom code with an “if” statement that checks to make sure that t180-trtyp = ‘H’.  If it does, that means that it’s in creation mode.  The snippet of code I’m pasting is in relation to pulling information from a custom table to determine what the condition record should be and update the incoterms and payment terms along with the condition record.

4. Also note in the code that there is a global variable that is set, gv_update_pricing.  We had to do this in order for the new pricing to update automatically since the terms were being updated.  This code needs to be placed in the FORM userexit_new_pricing_vbkd of user exit MV45AFZB.  I’ve put the code, in order to update the pricing automatically, down below also.  And again this is only done when creating the sales order.

/wp-content/uploads/2014/12/codesnippet_2_622416.jpg

To report this post you need to login first.

9 Comments

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

  1. Jaume Guardiola Guerrero

    And what about automatic insertion of header condition type? Your sample is prety cool but a previous manual insertion for the header condition type is needed.

    I’m facing several problems while creating a new record in xkomv.

    Could you give me a solution?

    Thanks in advance.

    (0) 
    1. Tamara Robinson Post author

      Hi Jaume,

      The condition type can be setup as to be defaulted into the header. That is something that your functional consultant would need to do.  However, you can give it a try to where instead of just reading the XKOMV for the condition record you just insert the record into XKOMV and mark the parameter manual.  I have an example if you need it. 

      Thanks,

      Tamara

      (0) 
      1. Jaume Guardiola Guerrero

        Hello Tamara,

        You mean that I can customize the condition type ZF00 for being inserted with initial values into the header conditions? This would be perfect!

        I have tried to solve this issue coding the append into the xkomv internal table but the behavior of the condition type is not correct. I’ve found out that ZF00 becomes duplicated  into the header conditions and his amount cannot be modified (grey color)

        Could you give me any suggestion to fix it? Do you have any example to see how can I do it?

        Many thanks Tamara for your reply.

        This is my code in FORM USEREXIT_PRICING_PREPARE_TKOMK (MV45AFZZ):

        * Portes automáticos
           data wa_komv like xkomv.
           if t180trtyp eq ‘H’.
             clear wa_komv.
             read table xkomv into wa_komv with key kschl = ‘ZF00’.
             if sysubrc ne 0.
               select single * into corresponding fields of wa_komv
                 from t685a
                 where kappl eq ‘V’ and
                       kschl eq ‘ZF00’.
               select single * into corresponding fields of wa_komv
                 from t683s
                 where kvewe eq ‘A’ and
                       kappl eq ‘V’ and
                       kalsm eq ‘ZHASTI’ and
                       kschl eq ‘ZF00’.
               wa_komvkbetr = ‘10.00’. “valor de test
               wa_komvkmprs = ‘X’. “Cond.modificada manualmente
               wa_komvUPDKZ = ‘I’.
               append wa_komv to xkomv.
               move ‘D’ to v_recalc.
             endif.
           endif.

        (0) 
        1. Tamara Robinson Post author

          Hi Jaume,

          No you can’t customize the condition type ZF00 for being inserted with the initial values into the header condition.  What I meant was that if you go in and create a sales order manually and add your materials and then go to the header conditions you should automatically see ZF00 already there waiting for input.  If not then you can have a functional SD person configure it to automatically show up.

          For your code it sounds like the condition type ZF00 already exists and you are just trying to modify it?  If that’s the case then you don’t need to append, you just need to do a modify.  If you would like to insert the record then you need to do an append.  I’ve updated my code snippet above as I had to make some changes.  However, I’m putting a snippet of code that we put in to insert a record.

          /wp-content/uploads/2015/01/2015_01_09_175928_622415.png

          Hope this helps.

          Thanks,

          Tamara

          (0) 
          1. Jaume Guardiola Guerrero

            Hi Tamara,

            Perhaps I didn’t explain my issue properly due to my poor english level…

            Our goal is to automatically insert into the header conditions the condition type ZF00 (freights) before the insertion of any items, and after the customer is validated. The reason is that we have a freight cost by customer.

            Current situation is you have to go to header conditions and add the condition type ZF00.

            We want this to be automatic without going to the head screen.

            As per I see in you code, you need to have the condition type inserted before applying your code. This is not our case.

            Is there any way to reach our goal.

            Thanks a lot Tamara for your support.

            (0) 
            1. Tamara Robinson Post author

              Jaume,

              My apologies for the delay in this note as I was on vacation all last week.

              As long as your condition record is configured as a header condition record and a manual condition record then you should be able to append/insert that condition record.  Unfortunately, this is something I would have to see what your configuration looked like for your condition type.  I honestly don’t know if it’s possible to insert a condition type that doesn’t exist already as I’ve never tried it.

              Have you tried the code yet and it doesn’t work?  Could you please put a snippet of your code so I can see what you are currently doing?

              Thanks,

              Tamara

              (0) 
            2. Arindam Basu

              Hi Jaume,

              I also have similar requirement for my client…..can you please let us know how achieve the solution, if you done that already. Thanks in advance….

              (0) 

Leave a Reply