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

Using Bapi Commit after Rollback

Former Member
0 Likes
2,586

Hi all,

I have a problem using the FM's BAPI_TRANSACTION_COMMIT and BAPI_TRANSACTION_ROLLBACK. In my case I submit several records for one employee using the FM HR_INFOTYPE_OPERATION with NOCOMMIT = 'X'. If an error occurs submitting any of these records I rollback all the records using BAPI_TRANSACTION_ROLLBACK. So far no problems. If I submit the next set of records for the next employee and this time call the commit, the records I previously rollbacked are commited as well! Does anyone know how I can prevent that rollbacked records are commited in a later phase?

My code looks like this:

CALL FUNCTION 'HR_INFOTYPE_OPERATION'

EXPORTING

infty = p_infty

number = p_pernr

subtype = p_subty

validitybegin = p_begda

validityend = p_endda

recordnumber = p_seqnr

record = p_infty_record

operation = p_operation

nocommit = 'X'

IMPORTING

return = bapireturn1.

Regards,

Ivo

14 REPLIES 14
Read only

Former Member
0 Likes
2,066

Not sure, but you could try a commit after the rollback.

Rob

Read only

0 Likes
2,066

I tried a commit after the rollback but that didn't work. The problem is that I want to submit seven records (containing hours worked each day of a week) for each employee and if an error occurs in any of these records I want to rollback all of the seven records. In this case I also need to rollback the successful created records. If the next set of seven records don't contain any errors I want to submit a commit just for these seven records. Now the rollbacked records are commited as well. It seems like these records are still somewhere in a buffer which need to be cleared......

Read only

0 Likes
2,066

Submit seven records with no_commit = 'X'. If everything is OK, resubmit them with a commit. Continue with the next group of seven records and so on..

Rob

Read only

0 Likes
2,066

Rob,

I tried your solution, when I call the BAPI with the nocommit='X', the program creates no records in the database. Whenever I add just one BAPI call to the program with a nocommit = space all the records that were previously created with the nocommit are still commited to the database. In this case I didn't use the FM's BAPI_TRANSACTION_ROLLBACK or BAPI_TRANSACTON_COMMIT.

Greets

Ivo

Read only

0 Likes
2,066

Hi ivo,

1. I am not sure, but this kind of bunching (either all or none)

2. will not work with HR_INFOTYPE_OPERATION

and neither bapi_rollback/commit will work.

3. We can either save/not save

one infotype at a time.

regards,

amit m.

Read only

Former Member
0 Likes
2,066

Hi,

This is strange. Each BAPI call has a separate LUW(Logical Unit of Work) & it doesnt overlap with call of COMMIT WORK of another BAPI.

Also since you are passing NOCOMMIT = 'X', the FM of HR_INFOTYPE_OPERATION has the logic to Rollback the changes if error.

I would suggest to retest the same.

Best regards,

Prashant

Read only

Former Member
0 Likes
2,066

Hi

I don't know the fm 'HR_INFOTYPE_OPERATION', but I suppose if u set the parameter NOCOMMIT, that fm doesn't force any COMMIT after posting the date.

So u shouldn't need any ROLLBACK.

Max

Read only

Former Member
0 Likes
2,066

Hi Ivo,

try without passing 'X' to nocommit.

Regards,

Vidya.

Read only

Former Member
0 Likes
2,066

Hi,

Are you sure that the COMMIT WORK of anothe BAPI is updating changes of the the BAPI for which you wanted to ROLLBACK Changes.

What i feel is the 1st ROLLBACK itself is called after COMMIT WORK, which possibly could be inside the FM.

Just checked the FM & other calls inside the FM's.

Please pass NOCOMMIT as Blank. This should solve the problem.

Best regards,

Prashant

Read only

Former Member
0 Likes
2,066

Vidya,

I tried submitting the FM HR_INFOTYPE_OPERATION without the NOCOMMIT = 'X', still no luck...

Read only

Former Member
0 Likes
2,066

Hi,

U can use the statement 'FREE MEMORY' after U roll back the error data.

Read only

0 Likes
2,066

I tried FREE MEMORY and DELETE FROM MEMORY ID 'PROPOSED_VALUES' to clear the rollbacked records from the memory. This doesn't work. Does anyone know any other statements to clear the memory? I think that would be the solution to the problem...

Read only

0 Likes
2,066

Seems that I found a solution to this problem. In order to use the FM HR_INFOTYPE_OPERATION in simulation mode, I use the parameter operation <b>'CHK'</b> (CHECK_RECORD). This way it's possible to check the validity of a set of records before adding them to the database with an operation insert or modify. If the FM returns an error in any of the records no rollback has to be performed. I just skip the modify/insert part and proceed to the next set of records.

Greets,

Ivo

Read only

0 Likes
2,066

In addition to this thread:

My colleague found a way to succesful clear the buffer by using the FM <b>HR_PSBUFFER_INITIALIZE</b>. This FM uses no parameters, it just refreshes the infotype buffers.