03-20-2010 4:40 AM
Hi,
Delivery quantity should be updated in the sales order item quantity, I have written the below shown code to achieve the functionality but it is not working, please check and let me know what else needs to be passed to the BAPI.
Include MV50AFZ1 exit : FORM userexit_save_document
data: w_vbelv type vbfa-vbelv,
w_quan type lfimg,
w_vbeln type BAPIVBELN-VBELN,
wa_INX type BAPISDH1X,
wa_item type BAPISDITM,
wa_schdl type bapischdl,
wa_schdlx type bapischdlx,
wa_order type U_16028, " Modified
wa_itemx type BAPISDITMX,
itab_inx type table of BAPISDITMX,
itab_schdl type table of bapischdl,
itab_schdlx type table of bapischdlx,
itab_item type table of BAPISDITM,
itab_order TYPE TABLE OF U_16028,
itab_return type table of BAPIRET2.
FIELD-SYMBOLS: <fs_lips> type LIPSVB, "Data type of XLIPS
<fs_order> type U_16028.
clear w_VBELV.
case sy-tcode.
when 'VL02N'.
select VBELV up to 1 rows from vbfa into w_VBELV
where vbeln = likp-VBELN
and vbtyp_n = 'J'
and vbtyp_v = 'C'.
ENDSELECT.
when 'VL01N'.
get PARAMETER ID 'AUF' FIELD w_VBELV.
endcase.
if w_VBELV is not initial.
select * from U_16028 into table itab_order where vbeln = w_vbelv.
if sy-subrc = 0.
loop at itab_order assigning <fs_order>.
READ TABLE xlips assigning <fs_lips> with key vgbel = <fs_order>-VBELN
posnr = <fs_order>-posnr.
if sy-subrc = 0.
wa_item-ITM_NUMBER = <fs_lips>-posnr.
wa_item-MATERIAL = <fs_lips>-matnr.
wa_item-TARGET_QTY = <fs_lips>-LFIMG. " Modified
wa_itemx-updateflag = 'U'.
wa_itemx-itm_number = <fs_lips>-posnr.
wa_itemx-TARGET_QTY = 'X'. " Modified
wa_itemx-MATERIAL = 'X'.
wa_schdl-itm_number = <fs_lips>-posnr.
wa_schdl-sched_line = <fs_order>-etenr.
wa_schdl-req_qty = <fs_lips>-LFIMG."
wa_schdlx-updateflag = 'U'.
wa_schdlx-itm_number = <fs_lips>-posnr.
wa_schdlx-sched_line = <fs_order>-etenr.
wa_schdlx-req_qty = 'X'.
APPEND: wa_item to itab_item,
wa_itemx to itab_inx,
wa_schdl to itab_schdl,
wa_schdlx to itab_schdlx.
clear: wa_item, wa_itemx, wa_schdl, wa_schdlx.
endif.
endloop.
if itab_item is not initial.
w_vbeln = w_VBELV.
wa_INX-UPDATEFLAG = 'U'.
CALL FUNCTION 'BAPI_SALESORDER_CHANGE'
EXPORTING
SALESDOCUMENT = w_vbeln
ORDER_HEADER_INX = wa_INX
TABLES
RETURN = itab_return
ORDER_ITEM_IN = itab_item
ORDER_ITEM_INX = itab_inx
SCHEDULE_LINES = itab_schdl
SCHEDULE_LINESX = itab_schdlx.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
wait = 'X'.
endif.
endif.
endif.
03-20-2010 5:07 AM
hi,
1. Are you using the BAPI inside the user exit userexit_save_document ?
2. What messages you are getting into the return table in the BAPI?
03-20-2010 6:24 AM
Hi,
1. yes i am using BAPI inside the user exit userexit_save_document .
2. I am getting message sales order changed successfully.
Regards,
Narayan
03-20-2010 11:34 AM
Hi,
I want to update the 'Delivery quantity' in the sales order item quantity, I have passed the below shown parameters to the BAPI_SALESORDER_CHANGE, but the quantity in is not working, please check and let me know what else needs to be passed to the BAPI.
I have written the code in Include MV50AFZ1 exit : FORM userexit_save_document
wa_item-itm_number = <fs_lips>-posnr.
wa_item-material = <fs_lips>-matnr.
wa_item-target_qty = <fs_lips>-lfimg.
wa_itemx-updateflag = 'U'.
wa_itemx-itm_number = <fs_lips>-posnr.
wa_itemx-target_qty = 'X'.
wa_itemx-material = 'X'.
wa_schdl-itm_number = <fs_lips>-posnr.
wa_schdl-sched_line = <fs_order>-etenr.
wa_schdl-req_qty = <fs_lips>-lfimg.
wa_schdlx-updateflag = 'U'.
wa_schdlx-itm_number = <fs_lips>-posnr.
wa_schdlx-sched_line = <fs_order>-etenr.
wa_schdlx-req_qty = 'X'.
APPEND: wa_item to itab_item,
wa_itemx to itab_inx,
wa_schdl to itab_schdl,
wa_schdlx to itab_schdlx.
clear: wa_item, wa_itemx, wa_schdl, wa_schdlx.
endif.
endloop.
if itab_item is not initial.
w_vbeln = w_VBELV.
wa_INX-UPDATEFLAG = 'U'.
CALL FUNCTION 'BAPI_SALESORDER_CHANGE'
EXPORTING
SALESDOCUMENT = w_vbeln
ORDER_HEADER_INX = wa_INX
TABLES
RETURN = itab_return
ORDER_ITEM_IN = itab_item
ORDER_ITEM_INX = itab_inx
SCHEDULE_LINES = itab_schdl
SCHEDULE_LINESX = itab_schdlx.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
wait = 'X'.
endif.
endif.
endif.
03-20-2010 9:00 PM
Doesn't this really foul up the sales order? SAP calculates open quantity for sales orders by calculating delivered quantities against schedule lines. If you have an order for 5 and you deliver 3 the sales order quantity should still be five.... and SAP will calculate 2 undelivered...
But I'm sure I don't understand what's going on in your shop....
You would need to get the item number form LIPS-vgbel or vgpos ? I've forgotten the field names. The item number on the delivery does not have to match the item number on the order, and infact, often does not. So, you need to get the item from the reference/prior/order document and item which is always stored in LIPS and VBRP (for billing).
03-21-2010 6:24 AM
Hi Narayanasamy,
BAPI to create/change should not be used in any Use Exits that are triggered while saving. As Unwanted Commits will create inconsistencies.
Regards
Srikanth M
03-21-2010 6:33 AM
Hi Srikanth,
Thanks for your suggestion, let's assume I haven't written explicit commit. How to achieve this functionality without using BAPI, If you have any other solution let me know.
Regards,
Narayan
03-23-2010 10:21 AM
Hi All,
If salse order item having multiple schedule line then it's not possible to updated the order quantity, that's the reason why it was not getting updated. I am closing the thread.
Thanks,
Narayan
06-08-2013 5:09 AM
Hi i am facing the same issue now....can u help me how did u solve it......only one line item order quantity is updated