Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Error in BAPI_MATERIAL_SAVEDATA

Former Member
0 Kudos

Hello all.

Im trying to update a material using BAPI_MATERIAL_SAVEDATA, I have to update the field PLANTDATA-VARIANCE_KEY among others.

But the BAPI returns with the following error:

<i>Key fields for user data PLANTDATA and checkbox structure PLANTDATAX are different</i>

Here is my code


  LOOP AT it_data WHERE result EQ 1.

    CLEAR: header, w_mbew, return, return_msg.
    REFRESH: return_msg.

*- Header data
    header-material      = it_data-matnr.
    header-cost_view     = 'X'.
    header-purchase_view = 'X'.
    header-matl_type     = it_data-mtart.

*- Valuation View
    w_mbew-val_area    = it_data-werks.
    w_mbew-qty_struct  = ' '.
    w_mbew-plndprice1  = it_data-zplp1.
    w_mbew-price_unit  = it_data-peinh.
    w_mbew-price_ctrl  = it_data-vprsv.
    w_mbew-std_price   = it_data-stprs.
    w_mbew-moving_pr   = it_data-verpr.
    w_mbew-plndprdate1 = p_zldp1.

    w_mbewx-val_area    = it_data-werks.
    w_mbewx-qty_struct  = 'X'.
    w_mbewx-plndprice1  = 'X'.
    w_mbewx-price_unit  = 'X'.
    w_mbewx-price_ctrl  = 'X'.
    w_mbewx-std_price   = 'X'.
    w_mbewx-moving_pr   = 'X'.
    w_mbewx-plndprdate1 = 'X'.

* Plant data
    w_marc-plant         = it_data-werks.
    w_marc-variance_key  = it_data-awsls.

    w_marcx-plant        = 'X'.
    w_marcx-variance_key = 'X'.

    CALL FUNCTION 'BAPI_MATERIAL_SAVEDATA'
      EXPORTING
        headdata       = header
        plantdata      = w_marc
        plantdatax     = w_marcx
        valuationdata  = w_mbew
        valuationdatax = w_mbewx
      IMPORTING
        return         = return
      TABLES
        returnmessages = return_msg.

Any help will be rewarded...

1 ACCEPTED SOLUTION

RichHeilman
Developer Advocate
Developer Advocate
0 Kudos

Please try......



* Plant data    
w_marc-plant         = it_data-werks.   
w_marc-variance_key  = it_data-awsls.  
<b>w_marcx-plant        = it_data-werks. </b>   
w_marcx-variance_key = 'X'.   



The reason is that the PLANT field in the "X" structure is not a flag field, but the 4 character plant field which needs a valid plant.

Regards,

Rich Heilman

1 REPLY 1

RichHeilman
Developer Advocate
Developer Advocate
0 Kudos

Please try......



* Plant data    
w_marc-plant         = it_data-werks.   
w_marc-variance_key  = it_data-awsls.  
<b>w_marcx-plant        = it_data-werks. </b>   
w_marcx-variance_key = 'X'.   



The reason is that the PLANT field in the "X" structure is not a flag field, but the 4 character plant field which needs a valid plant.

Regards,

Rich Heilman