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 for BAPI and BDC

Former Member
0 Kudos
86

Hi,

recently i am doing material upload prog. i use BAPI to create and extent material, then i use BDC to fill a field inspection type in QM view.

but i am very confused that the result is variable. When i extent material cross plants. one material have extent all plants, but another just extent some> The code is as follow.

LOOP AT IT_MATMASTER.

  • transfer BAPI data

BAPIMATHEAD-MATERIAL = IT_MATMASTER-MATNR.

BAPIMATHEAD-IND_SECTOR = IT_MATMASTER-Mbrsh.

BAPIMATHEAD-MATL_TYPE = IT_MATMASTER-Mtart.

........

CALL FUNCTION 'BAPI_MATERIAL_SAVEDATA'

EXPORTING

headdata = BAPIMATHEAD

CLIENTDATA = BAPI_MARA

CLIENTDATAX = BAPI_MARAx

PLANTDATA = BAPI_MARc

PLANTDATAX = BAPI_MARcx

VALUATIONDATA = BAPI_MBEW

VALUATIONDATAX = BAPI_MBEWX

IMPORTING

RETURN = IT_RETURN

TABLES

MATERIALDESCRIPTION = IT_MATERIALDESC.

CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'.

commit work and wait. * create the material

  • extent material cross plants

LOOP AT IT_GOUJIAN where WERKS ne IT_MATMASTER-WERKS.

" it_goujian contains plants data

BAPI_MARC-PLANT = IT_GOUJIAN-WERKS.

BAPI_MARCX-PLANT = IT_GOUJIAN-WERKS.

BAPI_MBEW-VAL_AREA = IT_GOUJIAN-WERKS.

BAPI_MBEWX-VAL_AREA = IT_GOUJIAN-WERKS.

CALL FUNCTION 'BAPI_MATERIAL_SAVEDATA'

EXPORTING

headdata = BAPIMATHEAD

CLIENTDATA = BAPI_MARA

CLIENTDATAX = BAPI_MARAx

PLANTDATA = BAPI_MARc

PLANTDATAX = BAPI_MARcx

VALUATIONDATA = BAPI_MBEW

VALUATIONDATAX = BAPI_MBEWX

IMPORTING

RETURN = IT_RETURN

TABLES

MATERIALDESCRIPTION = IT_MATERIALDESC.

CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'.

commit work and wait.

ENDLOOP.

......

endloop.

as u see, the code is correct, the reason just before i can not control the process in SAP. although i use 'commit work and wait.' But sometimes it still dose not extent all plants in the table 'it_goujian'.

any help?? i expect ...

1 REPLY 1

Former Member
0 Kudos
45

Why do you need to use two bapi calls for processing same material? In fact the you could use <b>BAPI_MATERIAL_MAINTAINDATA_RT</b> where in the header you pass the material .. industry, etc.. and in the PLANTEXT, PLANTEXTX tables you can give multiple plants which you need to extend. This way, you can create a material and extend it to different plants in one shot.

And I feel you face problem is happening because of the 2 bapi calls with commit waits..

Cheers,

Thomas.

<b>Please mark points if helpful.</b>