Application Development and Automation 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: 
Read only

BAPI_MATERIAL_SAVEDATA

Former Member
0 Likes
3,137

Hi,

There is an issue related to BAPI 'BAPI_MATERIAL_SAVEDATA'

When i run my program the above mentioned BAPI throws an error as ' The group data for the material & is locked by &' I have used a commit BAPI called 'BAPI_TRANSACTION_COMMIT' after the BAPI 'BAPI_MATERIAL_SAVEDATA' as-

CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'

EXPORTING

WAIT = ' '

IMPORTING

RETURN = l_return_commit.

still i get the error message.

Kindly suggest to this issue.Needs immediate reply.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
2,648

Hi,

the message The group data for the material & is locked by & indicates the material is being processed by user mentioned by locked by. once he logs out from this material then only u can create the material. its not the issue of commit or rollback.

CALL FUNCTION 'BAPI_MATERIAL_SAVEDATA'

EXPORTING

HEADDATA = HEADDATA

PLANTDATA = PLANTDATA

PLANTDATAX = PLANTDATAX

IMPORTING

RETURN = RETTAB.

APPEND RETTAB.

READ TABLE RETTAB WITH KEY TYPE = 'S'.

IF SY-SUBRC = 0.

CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'

EXPORTING

WAIT = 'X'.

REFRESH RETTAB.

ELSE.

REFRESH RETTAB.

CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'

  • IMPORTING

  • RETURN =

.

ENDIF.

Rgds

Siva

15 REPLIES 15
Read only

kanishakgupta1
Contributor
0 Likes
2,648

The same material or group data is already in use somewhere else.

Read only

Former Member
0 Likes
2,648

if there is any error , then commit work will fail. in this case you will see the same message.

First check the return messages before calling the Bapi commit, based on the message type you call the commit.

Read only

Former Member
0 Likes
2,649

Hi,

the message The group data for the material & is locked by & indicates the material is being processed by user mentioned by locked by. once he logs out from this material then only u can create the material. its not the issue of commit or rollback.

CALL FUNCTION 'BAPI_MATERIAL_SAVEDATA'

EXPORTING

HEADDATA = HEADDATA

PLANTDATA = PLANTDATA

PLANTDATAX = PLANTDATAX

IMPORTING

RETURN = RETTAB.

APPEND RETTAB.

READ TABLE RETTAB WITH KEY TYPE = 'S'.

IF SY-SUBRC = 0.

CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'

EXPORTING

WAIT = 'X'.

REFRESH RETTAB.

ELSE.

REFRESH RETTAB.

CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'

  • IMPORTING

  • RETURN =

.

ENDIF.

Rgds

Siva

Read only

0 Likes
2,648

Hi,

I am running the program, i didnt have any session opened to lock the material.But when i run the BAPI 'BAPI_MATERIAL_SAVEDATA'.The return message shows the error that its locked by a person(and its indicating the person id who runs the program). is there any problem will bapi,because when i re run the program anther material is getting lockes.To say in short the output is not consistent

Read only

0 Likes
2,648

Hi,

from user id find out the person, from him find out that whether he has opened any materials

which u are going to create or change.

If some other person is working on the material which ur creating or changing it will not allow to do any

thing on that material untill he closes.

Rgds

Siva

Edited by: siva prasad on Apr 28, 2009 1:54 PM

Read only

0 Likes
2,648

Hi Nicky Ben

i tried it just now....

in my case bapi is working perfectly ...

and i tried again with other sesion MM01 opened for same marerial..bapi return gave me error.....

'The group data for the material RKTEST200 is locked by ABAP1'...

so jst check some other user is using same tcode to change /create material...

Thnx

Rohit

Read only

0 Likes
2,648

actually its showing my id.Its saying the material is locked by me when i run that program and i have not opened any session related to it.

Read only

0 Likes
2,648

hey go to SM12(it is for unlocking tcodes) normally it is authorised one. check for your luck whether u were able to access it or not and check whether it is opened by you or not

if it is yes

refresh list

and once again try ecextuing the BAPI

if this is also not possible

close all your sessions

and open a new one and while opening just select delete alla other seesion and start this session

and then execute this. it will work for sure

cheers

s.janagar

Edited by: Janagar Sundaramoorthy Nadar on Apr 28, 2009 2:45 PM

Edited by: Janagar Sundaramoorthy Nadar on Apr 28, 2009 3:12 PM

Read only

Former Member
0 Likes
2,648

hi after bapi_material_savedata while use bapi_transaction_commit no need of passing any parameters.

just call function 'bapi_transaction_commit'.

thats it

still if it giving this error

just check whether MM01 is opened by you or some other users for the same key value

because this bapi can be used for creating as well as changing.

cheers

s.janagar

Read only

RahulKeshav
Active Contributor
0 Likes
2,648

Hi JK,

this error shows that somebody has already opened the transaction for creating or changing Material like MM01,MM02,...for the same material.....

Please close the other sessions before running BAPI.....

Thnx Rohit

Read only

Former Member
0 Likes
2,648

I give one sample code in two part

PART - I

  • Copy Materials from one Plant to Another

  • First run GETDATA AS CHECKBOX, "Tick to download materials data to local harddisk

  • Second run UPDDATA AS CHECKBOX. "Tick to update date to Materials Master

  • Check data in Excel before Second run

REPORT ZBAPIMM01 LINE-SIZE 255 NO STANDARD PAGE HEADING

LINE-COUNT 065(001).

TABLES: T001L, "Storage Locations

MARA, "General Material Data

MAKT, "Material Descriptions

MBEW, "Material Valuation

MARC. "Plant Data for Material

DATA: BAPI_HEAD LIKE BAPIMATHEAD,

BAPI_MAKT LIKE BAPI_MAKT, "Material Description

BAPI_MARA1 LIKE BAPI_MARA, "Client Data

BAPI_MARAX LIKE BAPI_MARAX,

BAPI_MARC1 LIKE BAPI_MARC, "Plant View

BAPI_MARCX LIKE BAPI_MARCX,

BAPI_MBEW1 LIKE BAPI_MBEW, "Accounting View

BAPI_MBEWX LIKE BAPI_MBEWX,

BAPI_RETURN LIKE BAPIRET2.

DATA: BEGIN OF INT_MAKT OCCURS 100.

INCLUDE STRUCTURE BAPI_MAKT.

DATA: END OF INT_MAKT.

DATA: BEGIN OF INT_MAT OCCURS 100,

WERKS(4), "Plant

MTART(4), "Material type

MATNR(18), "Material number

MATKL(9) , "Material group

MBRSH(1), "Industry sector

MEINS(3), "Base unit of measure

GEWEI(3), "Weight Unit

SPART(2), "Division

EKGRP(3), "Purchasing group

VPRSV(1), "Price control indicator

STPRS(12), "Standard price

PEINH(3), "Price unit

SPRAS(2), "Language key

MAKTX(40), "Material description

END OF INT_MAT.

SELECT-OPTIONS:

PLANT FOR MARC-WERKS OBLIGATORY MEMORY ID PLT,

MATERIAL FOR MARA-MATNR MEMORY ID MAT,

MATLTYPE FOR MARA-MTART MEMORY ID MTY,

DIVISION FOR MARA-SPART MEMORY ID DIV.

PARAMETERS: F_FILE LIKE RLGRAP-FILENAME

DEFAULT 'C:\DATA\ZMATERIAL.XLS' MEMORY ID F_FILE,

GETDATA AS CHECKBOX, "Tick to download materials data to local harddisk

UPDDATA AS CHECKBOX. "Tick to update date to Materials Master

IF GETDATA = 'X'.

PERFORM DOWNLOAD_DATA.

PERFORM DOWNLOAD_FILE.

ENDIF.

IF UPDDATA = 'X'.

PERFORM UPLOAD_FILE.

PERFORM UPDATE_MM.

ENDIF.

FORM DOWNLOAD_DATA.

SELECT * FROM MARC WHERE LVORM EQ ' '

AND WERKS IN PLANT

AND MATNR IN MATERIAL.

CLEAR MARA.

SELECT SINGLE * FROM MARA WHERE MATNR = MARC-MATNR.

CHECK MATLTYPE.

CHECK DIVISION.

CLEAR MBEW.

SELECT SINGLE * FROM MBEW WHERE MATNR = MARC-MATNR

AND BWKEY = MARC-WERKS.

CLEAR MAKT.

SELECT SINGLE * FROM MAKT WHERE SPRAS = 'EN'

AND MATNR = MARC-MATNR.

WRITE:/ MARC-WERKS, "Plant

MARA-MTART, "Material type

MARA-MATNR, "Material number

MARA-MATKL, "Material group

MARA-MBRSH, "Industry sector

MARA-MEINS, "Base unit of measure

MARA-GEWEI, "Weight Unit

MARA-SPART, "Division

MARC-EKGRP, "Purchasing group

MBEW-VPRSV, "Price control indicator

MBEW-STPRS, "Standard price

MBEW-PEINH, "Price unit

MAKT-SPRAS, "Language key

MAKT-MAKTX. "Material description

INT_MAT-WERKS = MARC-WERKS. "Plant

INT_MAT-MTART = MARA-MTART. "Material type

INT_MAT-MATNR = MARA-MATNR. "Material number

INT_MAT-MATKL = MARA-MATKL. "Material group

INT_MAT-MBRSH = MARA-MBRSH. "Industry sector

INT_MAT-MEINS = MARA-MEINS. "Base unit of measure

INT_MAT-GEWEI = MARA-GEWEI. "Weight Unit

INT_MAT-SPART = MARA-SPART. "Division

INT_MAT-EKGRP = MARC-EKGRP. "Purchasing group

INT_MAT-VPRSV = MBEW-VPRSV. "Price control indicator

INT_MAT-STPRS = MBEW-STPRS. "Standard price

INT_MAT-PEINH = MBEW-PEINH. "Price unit

INT_MAT-SPRAS = MAKT-SPRAS. "Language key

INT_MAT-MAKTX = MAKT-MAKTX. "Material description

APPEND INT_MAT.

CLEAR INT_MAT.

ENDSELECT.

ENDFORM.

Edited by: krupa jani on Apr 28, 2009 2:31 PM

Read only

Former Member
0 Likes
2,648

PART - II

FORM DOWNLOAD_FILE.

call function 'WS_DOWNLOAD'

EXPORTING

FILENAME = F_FILE

FILETYPE = 'DAT'

  • FILETYPE = 'WK1'

tables

data_tab = INT_MAT

EXCEPTIONS

FILE_OPEN_ERROR = 1

FILE_WRITE_ERROR = 2

INVALID_FILESIZE = 3

INVALID_TYPE = 4

NO_BATCH = 5

UNKNOWN_ERROR = 6

INVALID_TABLE_WIDTH = 7

GUI_REFUSE_FILETRANSFER = 8

CUSTOMER_ERROR = 9

OTHERS = 10.

IF SY-SUBRC = 0.

FORMAT COLOR COL_GROUP.

WRITE:/ 'Data Download Successfully to your local harddisk'.

SKIP.

ENDIF.

ENDFORM.

FORM UPLOAD_FILE.

call function 'WS_UPLOAD'

EXPORTING

FILENAME = F_FILE

FILETYPE = 'DAT'

  • FILETYPE = 'WK1'

tables

data_tab = INT_MAT

EXCEPTIONS

FILE_OPEN_ERROR = 1

FILE_WRITE_ERROR = 2

INVALID_FILESIZE = 3

INVALID_TYPE = 4

NO_BATCH = 5

UNKNOWN_ERROR = 6

INVALID_TABLE_WIDTH = 7

GUI_REFUSE_FILETRANSFER = 8

CUSTOMER_ERROR = 9

OTHERS = 10.

IF SY-SUBRC = 0.

FORMAT COLOR COL_GROUP.

WRITE:/ 'Data Upload Successfully from your local harddisk'.

SKIP.

ENDIF.

ENDFORM.

FORM UPDATE_MM.

LOOP AT INT_MAT.

  • Header

BAPI_HEAD-MATERIAL = INT_MAT-MATNR.

BAPI_HEAD-IND_SECTOR = INT_MAT-MBRSH.

BAPI_HEAD-MATL_TYPE = INT_MAT-MTART.

BAPI_HEAD-BASIC_VIEW = 'X'.

BAPI_HEAD-PURCHASE_VIEW = 'X'.

BAPI_HEAD-ACCOUNT_VIEW = 'X'.

  • Material Description

REFRESH INT_MAKT.

INT_MAKT-LANGU = INT_MAT-SPRAS.

INT_MAKT-MATL_DESC = INT_MAT-MAKTX.

APPEND INT_MAKT.

  • Client Data - Basic

BAPI_MARA1-MATL_GROUP = INT_MAT-MATKL.

BAPI_MARA1-BASE_UOM = INT_MAT-MEINS.

BAPI_MARA1-UNIT_OF_WT = INT_MAT-GEWEI.

BAPI_MARA1-DIVISION = INT_MAT-SPART.

BAPI_MARAX-MATL_GROUP = 'X'.

BAPI_MARAX-BASE_UOM = 'X'.

BAPI_MARAX-UNIT_OF_WT = 'X'.

BAPI_MARAX-DIVISION = 'X'.

  • Plant - Purchasing

BAPI_MARC1-PLANT = INT_MAT-WERKS.

BAPI_MARC1-PUR_GROUP = INT_MAT-EKGRP.

BAPI_MARCX-PLANT = INT_MAT-WERKS.

BAPI_MARCX-PUR_GROUP = 'X'.

  • Accounting

BAPI_MBEW1-VAL_AREA = INT_MAT-WERKS.

BAPI_MBEW1-PRICE_CTRL = INT_MAT-VPRSV.

BAPI_MBEW1-STD_PRICE = INT_MAT-STPRS.

BAPI_MBEW1-PRICE_UNIT = INT_MAT-PEINH.

BAPI_MBEWX-VAL_AREA = INT_MAT-WERKS.

BAPI_MBEWX-PRICE_CTRL = 'X'.

BAPI_MBEWX-STD_PRICE = 'X'.

BAPI_MBEWX-PRICE_UNIT = 'X'.

WRITE:/ BAPI_HEAD, BAPI_MARC1.

call function 'BAPI_MATERIAL_SAVEDATA'

exporting

HEADDATA = BAPI_HEAD

CLIENTDATA = BAPI_MARA1

CLIENTDATAX = BAPI_MARAX

PLANTDATA = BAPI_MARC1

PLANTDATAX = BAPI_MARCX

VALUATIONDATA = BAPI_MBEW1

VALUATIONDATAX = BAPI_MBEWX

IMPORTING

RETURN = BAPI_RETURN

TABLES

MATERIALDESCRIPTION = INT_MAKT

.

IF BAPI_RETURN-TYPE = 'E'.

WRITE:/ 'Error Message ', BAPI_RETURN.

ENDIF.

ENDLOOP.

ENDFORM.

Read only

RahulKeshav
Active Contributor
0 Likes
2,648

any break thru.....

Read only

Former Member
0 Likes
2,648

closed

Read only

0 Likes
2,648

Hey Jeevitha,

I am also facing the same problem. Did you find a solution for it? Please let me know if you did.