Jul 3, 2026

A Aample Program Using BAPI_RESERVATION_CHANGE to Change Quantity and Storage Location

Storage location changes via this BAPI aren't as clean as quantity changes — SAP requires you to also populate MOVE_ITEM correctly or the storage location update silently gets ignored while quantity still updates fine. That's the part people usually miss and then spend an hour debugging why the reservation shows on the wrong bin/plant.

BAPI_RESERVATION_CHANGE requires you to explicitly flag every field you're changing in ITEMCONTROL — omitting the flag means the value in ITEMDATA is ignored even if populated.

For storage location changes specifically, you need MOVEMENT_ALLOWED context (goods movement not yet posted against that item) — if GI already happened against the reservation item, the BAPI will reject the storage location change via RETURN.

abap
REPORT zbapi_reservation_change.

DATA: lv_rsnum   TYPE rsnum VALUE '0000001234',  " your reservation number
      lv_rspos   TYPE rspos VALUE '0001'.        " reservation item number

DATA: lt_itemdata    TYPE STANDARD TABLE OF bapi2093_res_item,
      lt_itemcontrol TYPE STANDARD TABLE OF bapi2093_res_item_ctrl,
      lt_return      TYPE STANDARD TABLE OF bapiret2.

DATA: ls_itemdata    TYPE bapi2093_res_item,
      ls_itemcontrol TYPE bapi2093_res_item_ctrl.

* --- Optional but recommended: read current item first ---
DATA ls_resb TYPE resb.
SELECT SINGLE * FROM resb
  INTO ls_resb
  WHERE rsnum = lv_rsnum
    AND rspos = lv_rspos.

IF sy-subrc <> 0.
  WRITE: / 'Reservation item not found'.
  RETURN.
ENDIF.

* --- Fill ITEMDATA: the new values ---
ls_itemdata-res_item  = lv_rspos.
ls_itemdata-material   = ls_resb-matnr.
ls_itemdata-plant      = ls_resb-werks.
ls_itemdata-stge_loc   = 'STG2'.        " new storage location
ls_itemdata-entry_qnt  = '50'.          " new quantity
ls_itemdata-entry_uom  = ls_resb-meins.
APPEND ls_itemdata TO lt_itemdata.

* --- Fill ITEMCONTROL: flags telling SAP which fields to actually apply ---
ls_itemcontrol-res_item = lv_rspos.
ls_itemcontrol-stge_loc = abap_true.    " flag: storage location changed
ls_itemcontrol-entry_qnt = abap_true.   " flag: quantity changed
APPEND ls_itemcontrol TO lt_itemcontrol.

* --- Call the BAPI ---
CALL FUNCTION 'BAPI_RESERVATION_CHANGE'
  EXPORTING
    reservation = lv_rsnum
  TABLES
    itemdata    = lt_itemdata
    itemcontrol = lt_itemcontrol
    return      = lt_return.

* --- Check for errors before committing ---
READ TABLE lt_return TRANSPORTING NO FIELDS
  WITH KEY type = 'E'.
IF sy-subrc = 0.
  LOOP AT lt_return INTO DATA(ls_return) WHERE type CA 'EA'.
    WRITE: / ls_return-message.
  ENDLOOP.
ELSE.
  CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
    EXPORTING
      wait = abap_true.
  WRITE: / 'Reservation updated successfully'.
ENDIF.

 


No comments :