Create confirmations entries with a Badi

I got the problem that I have to add a line for confirmation to migrated purchase order. So if you want to try this, you need a PO. Let us assume you got a PO (EL00000001) with one position (0010). As you can see there is no confirmation. We used material 990003038 and the standard plant 1000.

/wp-content/uploads/2015/06/po1_716135.png

Now, lets have a look into transaction MD04, using material 990003038 and the plant 1000. You should see something like this.

/wp-content/uploads/2015/06/po2_716136.png

Now we want to add the confirmation. If you add it by hand:

/wp-content/uploads/2015/06/po3_716137.png

ATTENTION: In this tutorial a table will be updated with the MODIFY command. Please stop here if the command is not clear and read this. You may damage the system if you do something wrong.

First of all I’ll present you the tables we need.

EKKO – EinKauf KOpf – Header PO (yes, German is my mother tongue)

EKPO – EinKauf POsition – Position PO

EKES – Vendor Confirmations

EKET – Scheduling Agreement Schedule Lines

First I’ll create another PO (EL00000002) with the same position (0010).

So here is the program I used:

  1. DATA:  lt_uekes    TYPE TABLE OF uekes,
  2.       ls_uekes    LIKE LINE OF  lt_uekes,
  3.       lt_uekes_out TYPE TABLE OF uekes,
  4.       lv_etens    TYPE          etens.
  5. DATA: lv_date TYPE eindt.
  6. DATA: lv_ebelp TYPE ebelp VALUE ’10’.
  7. DATA: lv_ebeln TYPE ebeln VALUE ‘EL00000002’.
  8. DATA: lv_xblnr TYPE ekesxblnr VALUE ‘REFERENCE’.
  9. DATA: lv_data_char10 TYPE char10 VALUE ‘01.07.2015’.
  10. DATA: lv_menge TYPE bbmng VALUE ‘5’.
  11. DATA: lv_ekpomeins TYPE bstme VALUE ‘PC’.
  12. DATA: ls_return TYPE bapiret2.
  13. DATA: ls_eket TYPE eket.
  14. DATA: lt_eket TYPE STANDARD TABLE OF eket.
  15. “Just make sure the the format is right.
  16. CALL FUNCTION ‘CONVERSION_EXIT_ALPHA_INPUT’
  17.   EXPORTING
  18.     input  = lv_ebeln
  19.   IMPORTING
  20.     output = lv_ebeln.
  21. CALL FUNCTION ‘CONVERSION_EXIT_ALPHA_INPUT’
  22.   EXPORTING
  23.     input  = lv_ebelp
  24.   IMPORTING
  25.     output = lv_ebelp.
  26. “Change the date to internal format
  27. CALL FUNCTION ‘CONVERT_DATE_TO_INTERNAL’
  28.   EXPORTING
  29.     date_external            = lv_data_char10
  30.   IMPORTING
  31.     date_internal            = lv_date
  32.   EXCEPTIONS
  33.     date_external_is_invalid = 1
  34.     OTHERS                  = 2.
  35. IF sysubrc <> 0.
  36. * Implement suitable error handling here
  37. ENDIF.
  38. “Check if there is already a ekes entry. If so you have to increase ETENS by one.
  39. “ETENS is an incremental counter in the table.
  40. SELECT MAX( etens ) INTO lv_etens
  41.   FROM ekes
  42.   WHERE ebeln = lv_ebeln
  43.     AND ebelp = lv_ebelp.
  44. IF sysubrc = 0 AND lv_etens <> 0.
  45.   ADD 1 TO lv_etens.
  46. ENDIF.
  47. ls_uekesebeln    = lv_ebeln.        “Purchase order number you want to update ‘EL00000002’
  48. ls_uekesebelp    = lv_ebelp.        “Position you want to update ‘00010’ –> beware 5 digits
  49. ls_uekesetens    = lv_etens.        “Counter in EKES
  50. ls_uekesebtyp    = ‘AB’.            “Short form of the confirm category
  51. ls_uekesxblnr    = lv_xblnr.        “The referenc sting
  52. ls_uekeseindt    = lv_date.        “Delivery date of the confirmation
  53. ls_uekesmenge    = lv_menge.        “Quantety of the confirmation
  54. ls_uekesekpomeins = lv_ekpomeins.    “ISO UNIT
  55. ls_uekeslpein    = ‘1’.
  56. ls_uekeserdat    = sydatum.        “Date when it was added
  57. ls_uekesezeit    = syuzeit.        “time when it was added
  58. ls_uekesestkz    = ‘1’.
  59. ls_uekeskzdis    = abap_true.
  60. ls_uekeskz        = ‘I’.            “I is for Insert, U for Update
  61. APPEND ls_uekes TO lt_uekes.
  62. CALL FUNCTION ‘ME_CONFIRMATION_UPDATE’
  63.   EXPORTING
  64.     i_ebeln = lv_ebeln                “Purchase order number is the key for the FuMo(FUBA)
  65.   TABLES
  66.     xekes  = lt_uekes.
  67. IF sysubrc = 0.
  68.   “You have to call the commit, because you want to find an EKET entry
  69.   “I you don’t do this the next select will fail
  70.   CALL FUNCTION ‘BAPI_TRANSACTION_COMMIT’
  71.     EXPORTING
  72.       wait  = ‘X’
  73.     IMPORTING
  74.       return = ls_return.
  75. ENDIF.
  76. “Okay now EKES is ready, but the will be no update to md04 if you dont update EKET.
  77. “I couldn’t find a FuMo(FUBA) which will do the update for me.
  78. “If somebody got a better solution please mail me nikolaus.harrich@cnt-online.at
  79. “But beware and think about what you do here.
  80. SELECT SINGLE *
  81.   FROM eket
  82.   INTO ls_eket
  83.   WHERE ebeln  = lv_ebeln AND
  84.         ebelp  = lv_ebelp.
  85. ls_eketdabmg = lv_menge.
  86. APPEND ls_eket TO lt_eket.
  87. MODIFY eket FROM TABLE lt_eket.
  88. IF sysubrc = 0.
  89.   CALL FUNCTION ‘BAPI_TRANSACTION_COMMIT’
  90.     EXPORTING
  91.       wait  = ‘X’
  92.     IMPORTING
  93.       return = ls_return.
  94. ENDIF.
To report this post you need to login first.

4 Comments

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

  1. sampath kumar

    hi,

    thanks for

    First of all I’ll present you the tables we need.

    EKKO – EinKauf KOpf – Header PO (yes, German is my mother tongue)

    EKPO – EinKauf POsition – Position PO

    but why in heading you used badi? please change that header.

    kindly explain the fuctional in this scenerio…

    thanks,

    sampath kumar.

    (0) 
    1. Nikolaus Harrich Post author

      Hello Sampath,

      you are right the tables are not used in the badi.

      But I want to mention it, because you need this table to find the correct PO.

      best regards,

      Nikolaus

      (0) 
  2. Rudra Roy

    Hi Nikolaus,

    FM ME_CONFIRMATION_UPDATE is update FM module and it updates the EKES table directly anyway . It’s a very low level one. Also you are updating EKET directly. These two steps in together can lead to database inconsistencies.

    Did you try BAPI_PO_CHANGE? Or Maybe IDOC_INPUT_ORDRSP can be useful.

    Kind regards,

    R

    (0) 
    1. Nikolaus Harrich Post author

      Hello Roy,

      As you can see I used ME_CONFIRMATION_UPDATE at line 75. But the problem is that you are only able to update EKES, but not EKET.

      I didn`t manage to get BAPI_PO_CHANGE working to update the confirmation. As I said Im open for better solutions anyway. I would be pleased to see examples.

      Br,

      Nikolaus

      (0) 

Leave a Reply