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

How to rollback batch input process?

Former Member
0 Likes
1,762

For example: I wanna post 10 documents, and all the posting should happen as a logical unit of work, i,e. either everything should be posted successfully or nothing should be posted. If error occured in the 7th record, i should rollback the posted 6 documents. How shall i do? It seems can't just use 'call transaction' clause.

6 REPLIES 6
Read only

Former Member
0 Likes
1,151

Hello Arthur,

There's a separate concept in SAP for handling scenarios precisely such as yours.

Please refer to the secion on <i>Programming Database Updates</i> at the follwoing link -

http://help.sap.com/saphelp_nw04/helpdata/en/d3/2e974d35c511d1829f0000e829fbfe/frameset.htm

The path at the above link would be : <i>The ABAP Programming Language --> Saving Data Externally --> Programming Database Updates</i>

Regards,

Anand Mandalika.

Read only

Former Member
0 Likes
1,151

hi,Anand

i've read the document you provided, but still have no idea about the detailed approach. could you specify it to me?

Read only

0 Likes
1,151

Hi,

How are you updating the documents ?

Regards,

Anand Mandalika.

Read only

0 Likes
1,151

Hello Arthur,

I'm afraid what you're seeking to accomplish is not possible.

And I don't think it makes too much sense. Let us say, you are

using a CALL TRANSACTION, then each CALL TRANSACTION is supposed

to be consistent and complete in itself.....and you cannot span

an LUW across multiple transactions....it is so much against the

concept of an LUW.

To give you a slightly non-technical explanation, you must first

ask yourself the question 'Why do we use BATCH INPUT'? Is it not

to just reduce the manual creation of all the documents in their

corresponding transactions?

Now in your case, let us assume that we have only 3 documents to

be posted and you have decided to post them yourself online, using

the relevant transactions. You finish successfull posting the first

two documents and then find that there's some error in the third one.

How are you going to roll back the previous two? You would have to

<i>delete</i> them.

So even in this case, you can only do a delete operation. Not a ROLLBACK.

By the way, I don't think your requirement makes much sense. Why should

the other documents be rolled back if something else fails ? They are quite

independent , right ?

Now if you really want to stick to this functionality, then the option that

is left for you is to find out if there are any Function Modules available to

do the DELETE operation.

Personally, if I were you, I would use the MESSAGES option for the CALL TRANSACTION

statement and display them to the user, so that he would know which transaction

had failed. He can then continue with the remaining documents after detecting the

error and correcting it.

Hope that is clear. Please do get back if you have further doubts. Else, please

reward points and mark the question as "answered".

Regards,

Anand Mandalika.

Read only

Former Member
0 Likes
1,151

Hi Arthur,

I don't really think that what you are trying to do is possible using a batch input process. This is because the batch input process (either submitting to the SM35 queue or using 'call transaction' from abap) calls the underlying SAP screen transaction, which has a 'COMMIT WORK' coded into it. So once a transaction/document has been posted, it will not really be possible to roll it back if subsequent postings fail.

I think that BAPIs are your best bet (if one exists for your desired document). As they do not have explicit 'COMMIT WORK' statements built in, you are then able to control whether all transactions should be comitted, or rolled back. So, you could call the BAPIs in sequence, checking the return structure from each call, and if any fail, execute a 'ROLLBACK WORK' which would roll back all updates.

This may not be exactly what you wanted to hear, but I believe its the best way to achieve what you are trying to do.

Cheers,

Brad

Read only

Former Member
0 Likes
1,151

I've faced such a problem before, but in more general manner.

The requirement was to provide the mechanism to control execution of sequences of interrelated "transactions" (batch inputs, BAPI's or simple function modules call's), which forms some business processes.

Indeed, there isn't any ROLLBACK TRANSACTION for CALL TRANSACTION, furthermore for some scenarios calling BAPI's with BAPI_TRANSACTION_COMMIT call at the end doesn't work(when following BAPI call depends on results of previous one). So requirement to extend SAP's transaction concept arise.

Object oriented programming in general and ABAP Objects in particular best suits for "Business Transaction"

implementation. Without going into details I'll provide conceptual description. "Business Transaction" is an abstraction that incapsulates all the data and behaviour needed for execution and "unexecution" of specific operation. "Unexecution" means necessary actions that restore enviroment' previous state. For example - posting and reversing documents.

I've defined the base class for business transaction abstraction, and concrete transactions, which implement business logic(by batch inputs, FM calls and so on), as base class specializations. For managing transaction sequences I make use of "composite" design pattern. So transaction sequences could be treated as separate transaction steps and could be used to form more complicated business processes.

Hope such general description helps in choosing the implementation approach.

Regards, Maxim.