Skip to Content
Technical Articles

How to update Standard fields of Purchase Order using User Exit MM06E005

Description:

In Purchasing, you normally use User Exit MM06E005 to update customer fields but in this post, i will show you how to update standard fields of Purchase Order or in Scheduling Agreement. We use small trick to update variables out side the EXIT, in the main program.

 

Step:

You do need to follow these steps below to achieve it:

  1. Create a project to use the User Exit (Tcode CMOD)
  2. Activate the Components
  3. Write the code (in  ZXM06U41)

 

Here i will give you a small example, which will update the Firm Zone field in Scheduling Agreement.

Scenarior:

The system uses “Firm zone” as a key field to determine which item vendor can ship. If delivery date falls  within Firm zone, the line item is treated as firm requirement, and vendor can only create ASN
for line item that marked as “Firm”. The firm zone should be relevant to JIT date range, which is  determined by creation profile.

However, in S/4HANA there is no standard function to link between
firm zone and creation profile. Therefore we need to use User Exit MM06E005 to update. Here i choose EXIT EXIT_SAPMM06E_016 (Export Data to Customer Subscreen for Purchasing Document Item (PBO)) to use.

 

Step by step:

  1. Use Tcode CMOD to create a project.

 

 

2. Activate the components (and create the subscreens)

 

3. Implement the code

We use the below trick to edit value in main program.

ASSIGN ('(SAPMM06E)EKPO') TO <LF_EKPO>.

 

Here is complete code

  DATA:
    LS_EKPO        TYPE EKPO,
    LW_FABHO       TYPE FABHO,
    LW_FABHO_DIV   TYPE P LENGTH 3 DECIMALS 2,
    LW_FABHO_ROUND TYPE ETFZ1.

  FIELD-SYMBOLS:
    <LF_EKPO> TYPE EKPO.

  CHECK SY-TCODE = 'ME31'
     OR SY-TCODE = 'ME31L'.

  ASSIGN ('(SAPMM06E)EKPO') TO <LF_EKPO>.
  LS_EKPO = <LF_EKPO>.
*
  IF LS_EKPO-ETFZ1 IS INITIAL.
    SELECT SINGLE FABHO
      INTO LW_FABHO
      FROM T163P
      WHERE ABUEB = LS_EKPO-ABUEB.

    IF SY-SUBRC = 0.
      LW_FABHO_DIV = LW_FABHO / 6.
      LW_FABHO_ROUND = ROUND( VAL = LW_FABHO_DIV
                              DEC = 0
                              MODE = 2 ).
      LS_EKPO-ETFZ1 = LW_FABHO +
                      LW_FABHO_ROUND.
      <LF_EKPO> = LS_EKPO.
    ENDIF.
  ENDIF.

 

Result:

Tcode ME32L, change Scheduling Agreement (additional data)

Before

 

Tcode ME32L

After:

Firmzone value has been changed

 

Hope you see this post is helpful. If you have any question, please leave your comment. Thank you.

 

6 Comments
You must be Logged on to comment or reply to a post.
  • This promotes bad programming practice:

    ASSIGN ('(SAPMM06E)EKPO') TO <LF_EKPO>.

    This is alright to read data from the global variables of a program,  but to write to it:

    <LF_EKPO> = LS_EKPO.

    Is dangerous and should never be done.

    Rich

    • That’s even the topic of the post to be blamed (“How to update Standard fields…” [using direct update]). A warning from the author is welcome, something like “in no event shall SAP be liable for any damages if a user exit is not used as intended ; use this “trick” at your own risk” 🙂

    • Thank you Richard,

      But you cannot change the global variables here. You can check it.

      And this statement

      <LF_EKPO> = LS_EKPO.

      was used in the case the structure is dynamic structure.

      • That will change the contents of the structure assigned to the field symbol.  And if it is not used to change the contents,  why is this article titled ”

        “How to update Standard fields of Purchase Order using User Exit MM06E005”

        No other statement in your code will affect the Ekpo structure.

        Also,  what do you mean by ‘dynamic’ structure ?  It’s a structure….. it doesn’t morph into something else during the processing of your routine.

        As I stated before,  this is bad programming practice and should not be promoted.

        Rich