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 and Rollback

dirk_niemeier
Explorer
0 Likes
2,606

Hi,

I'll use BAPI_MATERIAL_SAVEDATA to create new materials via JCo.

My proceeding :

1. call BAPI_STDMATERIAL_GETINTNUMBER to get a new number

2. call BAPI_MATERIAL_SAVEDATA to create new material

until here it works fine. When I stop my programm in debugger here and execute "mm02" the new material is locked. It seem that the material would be created.

3. call BAPI_TRANSACTION_ROLLBACK to undo work

after the rollback call the material still exists and the lock is cleared. It's the same behavour like calling BAPI_TRANSACTION_COMMIT.

When I don't use commit or rollback (close connection) the material will still exist too.

Isn't it be possible to rollback for BAPI_MATERIAL_SAVEDATA calls? Is the an explicit "BEGIN WORK" to set?

TIA

Dirk

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,838

Hi,

Actually when you execute MM02 and has the material locked, means the material already exists in database. Some thoughts:

1. In debugging mode, sometimes SAP do an automatic COMMIT. So you could try by not running it in debugging mode.

2. COMMIT command is coded at the FM so when a material is ok, it is directly created.

Regards,

Teddy

8 REPLIES 8
Read only

Former Member
0 Likes
1,839

Hi,

Actually when you execute MM02 and has the material locked, means the material already exists in database. Some thoughts:

1. In debugging mode, sometimes SAP do an automatic COMMIT. So you could try by not running it in debugging mode.

2. COMMIT command is coded at the FM so when a material is ok, it is directly created.

Regards,

Teddy

Read only

0 Likes
1,838

Hi Teddy,

< 2. COMMIT command is coded at the FM so when a material is ok, it is directly created.

this means, that the BAPI_MATERIAL_SAVEDATA doesn't support a rollback? No rollback when no error? I can't beleave this, because an error rollbacks automatically. Then the rollback function doesn't have any funktion anytime.

TIA

Dirk

Read only

0 Likes
1,838

Hi Dirk,

I used the same function modules in the same sequence. It is working fine for me.

first I used bapi_material_save_data

after that

if the message return type is not an error then

CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'

EXPORTING

WAIT = 'X'.

else.

CALL FUNCTION '`BAPI_TRANSACTION_ROLLBACK'.

ENDIF.

It is working perfectly fine for me. Check you conditions.

Read only

0 Likes
1,838

Hi NAVEEN KUMAR GUDURI,

you are right when you are only using this small code. But I have to insert a new material in an complex transaction of other activities in my program. There are a view other database actions (non SAP) to do and it is possible that this other action doesn't work. So I have to rollback the complete operation. And this is not possible, because the rollback doesn't work if no error in the small SAP call occures.

BTW I opend an service call on SAP and this is the answer :

-


the system behaviour you are experiencing is as designed.

The BAPI_MATERIAL_SAVEDATA can't execute the database changes in the

update task. It's correct, that the BAPI transaction model says there

something different, but the concept of the material master is much

older and we couldn't change this to make it compatible to the BAPI

transaction model. When the BAPI was added to the material master, we

extended the functionality of the ALE IDoc-type MATMAS. And in the ALE

it is not possible to save the database changes in update task.

And if you call the BAPI by RFC (like with the Java Connector), then

the system executes always a database commit at the end of the

executed function module. This means, that the database changes of the

BAPI are already fix and can't be removed by calling a ROLLBACK WORK

afterwards (e.g. by calling the function module

BAPI_TRANSACTION_ROLLBACK using the Java Connector).

-


regards,

Dirk

Read only

0 Likes
1,838

Hi Dirk,

So how is the decision? Do you change the program/design or find a workaround?

Regards,

Teddy

Read only

0 Likes
1,838

Hi Teddy,

I not sure this time. A other alternative ist to connect directly via JDBC. The MARA and MARC etc. tables are not really complicated. But I don't know what SAP will say when they get notice about that. Do you have an suggestion?

TIA

Dirk

Read only

0 Likes
1,838

Hi Dirk,

It is not suggested to directly go to the table. What I can think of are:

1. Has someone/program that will check the status of the several steps in the current program. If not all are successful, then he/she/it should complete the steps either manually (a person) or automatically (another program).

2. Change the logic in current program to run BAPI_MATERIAL_SAVEDATA at last.

3. Split current program to several programs so after BAPI_MATERIAL_SAVEDATA user could run another program for the next steps. If the next step unsuccessful, user can rectify the issue and re-run the program.

4. In current program, do a complete validation for all the steps so if the program decides to post, there is no error will happen.

Above are just a thought that might not be feasible in your case but could give you another alternatives.

Regards,

Teddy

Read only

Former Member
0 Likes
1,838

Commit or rollback is done from inside the FM BAPI_MATERIAL_SAVEDATA, infact from MATERIAL_MAINTAIN_DARK which is called from BAPI_MATERIAL_SAVEDATA. That's why if u call BAPI_TRANSACTION_ROLLBACK after th call of BAPI_MATERIAL_SAVEDATA it creates no impact to the database as data is already saved or ignored based on the commit /rollback executed inside the FM.