In our functionality, a program was written to create sales order. A validation was done on sales price. If the sales price for an item is zero, an error was being thrown. This process is done under ttsbegin and ttscommit. Now the requirement is to save the details of sales orders which encounter this particular error. For this I have written a code which inserts a record in customized table just before the error is thrown. The issue is, after the error is thrown the record created is not available. How can I resolve this. The schenario is as below
The program is written under single ttsbegin and ttscommit. The code which I have written has overlap as
below
ttsbegin
ttsbegin
ttscommit
ttscommit.
However, if I remove the inner tts statements, The record which Is created is not available after the error is thrown, since the ttscommit is not being executed.
I appreciate your logic. Unfortunately, I cannot use your logic since our program is standard functionality. In-fact, the transaction is called under try catch.
try
{
ttsbegin;
program to create sales order;
ttscommit;
}
catch(exception::error)
{
error;
}
Maria,
The program is large. The code cannot be put in this post. So, I’ve given the the scenario.
I found table.ttscommit() method. This works fine, but the sales order is created. The sales order should not be created. Record should be created in customized table and the error should be thrown.
Nested transaction scopes won’t help you in any way - the outmost transaction will be used (and rollbacked), the inner transactions have almost no effect. You have several options:
Validate the price before entering any transaction. If the price is zero, log the error, otherwise call the logic creating orders. It’s important to be aware that price can be set to 0 after the validation succeeded, but it’s often acceptable, because it’s unlikely.
Use the transaction, but before throwing the error, save additional information (ItemId, for example) to a variable and use it in the catch block (i.e. after the transaction is rollbacked) to create the log record. This is what I would probably use in you situation.
First option is not valid for our functionality, because the client requirement is to throw error if sales price is zero.
Section option, I couldn’t use because the class where try catch used is a standard class. If I modify this class, it will affect for other functionality of ours.
Third option, suits my requirement. It works fine.