Skip to Content
0
Nov 15, 2017 at 04:00 PM

BAPI_ALM_ORDER_MAINTAIN IT_SRULE ending with errors

2831 Views

Hello everyone

I am trying to update the Production order settlement rules using 'BAPI_ALM_ORDER_MAINTAIN'.

I need to change the quantity of the settlement rule but the BAPI always returns errors.

IWO_BAPI 402 Error when reading the settlement rule using the external number
IWO_BAPI2 113 Error during processing of BAPI methods

Here is a sample code use to test the BAPI.

  DATA: lt_srule    TYPE TABLE OF bapi_alm_order_srule,
        ls_srules   LIKE LINE OF lt_srule,
        lt_srule_up TYPE TABLE OF bapi_alm_order_srule_up,
        ls_srule_up LIKE LINE OF lt_srule_up,
        lt_methods  TYPE TABLE OF bapi_alm_order_method,
        ls_methods  LIKE LINE OF lt_methods,
        lt_return   TYPE STANDARD TABLE OF bapiret2,
        ls_return   TYPE bapiret2,
        ls_cobrb    TYPE cobrb.

  DATA: lv_aufnr  TYPE aufnr VALUE '000000501576'.

  SELECT * INTO ls_cobrb FROM cobrb
                        WHERE aufnr = lv_aufnr
                          AND lfdnr = '001'.    
    CLEAR ls_srules.
    ls_srules-objnr          = ls_cobrb-objnr.
    ls_srules-lfdnr          = ls_cobrb-lfdnr.
    ls_srules-equiv_number  = 0.     
    ls_srules-orderid        = ls_cobrb-aufnr.
    APPEND ls_srules TO lt_srule.

    ls_srule_up-equiv_number = 'X'.
    APPEND ls_srule_up TO lt_srule_up.
  ENDSELECT.

  CLEAR ls_methods.
  ls_methods-refnumber  = 1.
  ls_methods-objecttype = 'SRULE'.
  ls_methods-method     = 'CHANGE'.
  ls_methods-objectkey  = lv_aufnr.
  APPEND ls_methods TO lt_methods.

  CLEAR ls_methods.
  ls_methods-refnumber  = 1.
  ls_methods-objecttype = space.
  ls_methods-method     = 'SAVE'.
  ls_methods-objectkey  = lv_aufnr.
  APPEND ls_methods TO lt_methods.

  CALL FUNCTION 'BAPI_ALM_ORDER_MAINTAIN'
    TABLES
      it_methods  = lt_methods
      it_srule    = lt_srule
      it_srule_up = lt_srule_up
      return      = lt_return
    .

  READ TABLE lt_return INTO ls_return WITH KEY type = 'A'.
  CHECK sy-subrc <> 0.
  READ TABLE lt_return INTO ls_return WITH KEY type = 'E'.
  CHECK sy-subrc <> 0.

  CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
    EXPORTING
      wait = 'X'
    .