Quantcast
Channel: SCN : All Content - ABAP Development
Viewing all articles
Browse latest Browse all 8332

Line item doesn't get inserted using BAPI 'BAPI_SALESORDER_CHANGE'

$
0
0

Hello Experts,

 

I've a requirement where I need to change matnr, quantity and net value at item level. After some research I found that I need to delete the current line item first and then add new line item (please correct me if I'm wrong here). Therefore, I'm trying to do this and as first step I'm also able to delete the first line item (at item level) but new line item is not getting saved on the sales order and I'm keep getting error (refer to the screen shot).

Item_in-error.jpg

 

For reference here is my code

*****************************************************************************************************************************************************************

constants:     c_delete      type c value 'D',

                      c_insert      type c value  'I',

                     c_x             type c value 'X',


     lwa_order_header_inx-updateflag = c_update.

*   Update PO number

    lwa_order_header_in-purch_no_c = lw_zrerate_dtl-zvbeln_pr.

      lwa_order_header_inx-purch_no_c = c_x.

*   Update billing block

    lwa_order_header_in-bill_block = 'Y5'.

    lwa_order_header_inx-bill_block = c_x.

 

*   Update item details

    refresh: li_order_items, li_order_items_inx.

    clear: lwa_order_items, lwa_order_items_inx.

    "check if matnr has been changed.

     lwa_order_items-itm_number = lw_zrerate_dtl_str-posnr. "Delete line item

       append lwa_order_items to li_order_items.

     lwa_order_items_inx-updateflag = c_delete.

     lwa_order_items_inx-itm_number = lw_zrerate_dtl_str-posnr.

       append lwa_order_items_inx to li_order_items_inx.

       clear: lwa_order_items, lwa_order_items_inx.

 

lwa_order_items-itm_number = lw_zrerate_dtl_str-posnr.  "Insert line item

lwa_order_items-target_qty = lw_zrerate_dtl_str-kwmeng.

lwa_order_items-material = lw_zrerate_dtl_str-matnr.

lwa_order_items-net_weight = lw_zrerate_dtl_str-ntgew.

lwa_order_items-untof_wght = lw_zrerate_dtl_str-gewei.

lwa_order_items-item_categ = WA_VBAP-PSTYV.

lwa_order_items-cust_mat35 = WA_VBAP-KDMAT.

lwa_order_items-short_text = WA_VBAP-ARKTX.

lwa_order_items-matl_group = WA_VBAP-MATKL.

lwa_order_items-ref_doc    = WA_VBAP-VGBEL.

lwa_order_items-ref_doc_it = WA_VBAP-VGPOS.

lwa_order_items-bill_rel   = WA_VBAP-FKREL.

lwa_order_items-plant      = WA_VBAP-WERKS.

lwa_order_items-CURRENCY   = WA_VBAP-WAERK.

lwa_order_items-prod_hiera = WA_VBAP-PRODH.

lwa_order_items-division   = WA_VBAP-SPART.

lwa_order_items-SALES_UNIT = WA_VBAP-VRKME.

lwa_order_items-SALQTYNUM  = WA_VBAP-UMVKZ.

lwa_order_items-SALQTYDEN  = WA_VBAP-UMVKN.

lwa_order_items-GROSS_WGHT = WA_VBAP-BRGEW.

lwa_order_items-NET_WEIGHT = WA_VBAP-NTGEW.

lwa_order_items-UNTOF_WGHT = WA_VBAP-GEWEI.

lwa_order_items-mat_entrd  = WA_VBAP-MATWA.

lwa_order_items-max_pl_dlv = WA_VBAP-ANTLF.

lwa_order_items-ORDER_PROB = WA_VBAP-AWAHR.

lwa_order_items-CREATED_BY = WA_VBAP-ERNAM.

lwa_order_items-MAT_PR_GRP = WA_VBAP-KONDM.

lwa_order_items-PRC_GROUP1    = WA_VBAP-MVGR1.

lwa_order_items-PRC_GROUP2 = WA_VBAP-MVGR2.

lwa_order_items-PRC_GROUP3 = WA_VBAP-MVGR3.

lwa_order_items-PRC_GROUP4 = WA_VBAP-MVGR4.

lwa_order_items-PRC_GROUP5 = WA_VBAP-MVGR5.

"lwa_order_items-VAL_CONTR  = WA_VBAP-VAL_CONTR.

lwa_order_items-TARGET_QU  = WA_VBAP-ZIEME.

lwa_order_items-TRG_QTY_NO = WA_VBAP-UMZIZ.

lwa_order_items-TRGQTY_DEN = WA_VBAP-UMZIN.

 

lwa_order_items-purch_no_s = WA_VBAPKOM-BSTKD_E.

lwa_order_items-poitm_no_s = WA_VBAPKOM-POSEX_E.

lwa_order_items-comp_quant = '1'.

"lwa_order_items-target_Val = BAPICUREXT =

lwa_order_items-currency   = 'CAD'.

lwa_order_items-sales_dist = WA_VBAPKOM-BZIRK.

lwa_order_items-purch_no_c = WA_VBAPKOM-BSTKD.

lwa_order_items-purch_date = WA_VBAPKOM-BSTDK.

lwa_order_items-po_method  = WA_VBAPKOM-BSARK.

lwa_order_items-pmnttrms   = WA_VBAPKOM-ZTERM.

lwa_order_items-EXCHG_RATE = WA_VBAPKOM-KURSK.

lwa_order_items-price_date = WA_VBAPKOM-PRSDT.

lwa_order_items-bill_date  = WA_VBAPKOM-FKDAT.

lwa_order_items-serv_date  = WA_VBAPKOM-FBUDA.

lwa_order_items-ACCNT_ASGN = WA_VBAPKOM-KTGRD.

lwa_order_items-REF_1      = WA_VBAPKOM-IHREZ.

lwa_order_items-PMTGAR_PRO = WA_VBAPKOM-ABSSC.

lwa_order_items-SHIP_TYPE  = WA_VBAPKOM-VSART.

  append lwa_order_items to li_order_items.

lwa_order_items_inx-itm_number = lw_zrerate_dtl_str-posnr.

lwa_order_items_inx-updateflag = c_update. "c_x

lwa_order_items_inx-material = c_x.

lwa_order_items_inx-net_weight = c_x.

lwa_order_items_inx-target_qty = c_x.

lwa_order_items_inx-untof_wght = c_x.

  append lwa_order_items_inx to li_order_items_inx.

  clear: lwa_order_items, lwa_order_items_inx.

 

 

 

    CALL FUNCTION 'BAPI_SALESORDER_CHANGE'

      EXPORTING

        salesdocument               = lw_zrerate_dtl-zvbeln_pr

        order_header_in             = lwa_order_header_in

        order_header_inx            = lwa_order_header_inx

*       SIMULATION                  =

*       BEHAVE_WHEN_ERROR           = ' '

*       INT_NUMBER_ASSIGNMENT       = ' '

        LOGIC_SWITCH                = l_logic_switch

*       NO_STATUS_BUF_INIT          = ' '

      tables

        return                      = li_return

        order_item_in               = li_order_items

        order_item_inx              = li_order_items_inx.

 

  loop at li_return into lwa_return where type eq c_success.

    lv_updated = c_x.

*   Update BAPI

    call function 'BAPI_TRANSACTION_COMMIT'

      importing

        return = lwa_return.

*   Move error message to error log table if bapi cannot be updated

    if lwa_return is not initial.

     " message i025 with lv_vbeln.

    endif.

    clear: lwa_return.

    exit.

  endloop.

 

*****************************************************************************************************************************************************************

 

Can somebody tell me what mistake I'm making and how to rectify it? Also beside using this BAPI can I use anything else to update detail at item level?

 

Many thanks in advance.


Viewing all articles
Browse latest Browse all 8332

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>