Application Development Blog Posts
Learn and share on deeper, cross technology development topics such as integration and connectivity, automation, cloud extensibility, developing at scale, and security.
cancel
Showing results for 
Search instead for 
Did you mean: 
Former Member
0 Kudos

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.

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

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

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 ekes-xblnr 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 sy-subrc <> 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 sy-subrc = 0 AND lv_etens <> 0.
  45.   ADD 1 TO lv_etens.
  46. ENDIF.
  47. ls_uekes-ebeln    = lv_ebeln.        "Purchase order number you want to update 'EL00000002'
  48. ls_uekes-ebelp    = lv_ebelp.        "Position you want to update '00010' --> beware 5 digits
  49. ls_uekes-etens    = lv_etens.        "Counter in EKES
  50. ls_uekes-ebtyp    = 'AB'.            "Short form of the confirm category
  51. ls_uekes-xblnr    = lv_xblnr.        "The referenc sting
  52. ls_uekes-eindt    = lv_date.        "Delivery date of the confirmation
  53. ls_uekes-menge    = lv_menge.        "Quantety of the confirmation
  54. ls_uekes-ekpomeins = lv_ekpomeins.    "ISO UNIT
  55. ls_uekes-lpein    = '1'.
  56. ls_uekes-erdat    = sy-datum.        "Date when it was added
  57. ls_uekes-ezeit    = sy-uzeit.        "time when it was added
  58. ls_uekes-estkz    = '1'.
  59. ls_uekes-kzdis    = abap_true.
  60. ls_uekes-kz        = '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 sy-subrc = 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_eket-dabmg = lv_menge.
  86. APPEND ls_eket TO lt_eket.
  87. MODIFY eket FROM TABLE lt_eket.
  88. IF sy-subrc = 0.
  89.   CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
  90.     EXPORTING
  91.       wait  = 'X'
  92.     IMPORTING
  93.       return = ls_return.
  94. ENDIF.
4 Comments