Sunday, June 4, 2017

Adding a debit memo line to a repair order

Repair orders appear to look like normal sales orders in SAP and can be viewed and changed via VA03/VA02 as usual. However, when you want to change a line, then you need to click on the repair line and hit the repair button at the bottom of the screen.

If you want to change this line programatically, then you need to jump through a few more hoops as you cannot use the usual BAPIs to add or edit one of these lines. Below is the code to add a debit memo to the repair line;

  "Open the sales order for manipulation
  call function 'SD_SALES_DOCUMENT_READ'
      document_number            = ls_vbak-vbeln
      status_buffer_refresh      = 'X'
      requisition_buffer_refresh = 'X'.

  "Update our line item
  refresh lt_itemkom.
  clear lt_itemkom.
  lt_itemkom-posnr = '900003'.
  lt_itemkom-updkz = 'I'.
  lt_itemkom-vkgru = '109'. "Debit memo
  lt_itemkom-menge = ls_vbap-kwmeng.
  lt_itemkom-matnr_g = ls_vbap-matnr.
  lt_itemkom-arktx_g = ls_vbap-arktx.
  append lt_itemkom.

  perform repairitems_generate(sapfv45p) tables lt_itemkom
                                         using  ls_vbap-uepos.

  "Save the order again
  call function 'SD_SALES_DOCUMENT_SAVE'
      synchron                   = 'X'
      status_buffer_refresh      = 'X'
      requisition_buffer_refresh = 'X'.

  commit work and wait.

No comments:

Post a Comment