‎2007 May 16 2:58 PM
Hello,
I'll log some application information in a local table like this:
Here a pseudocode example:
funktion mainFunction{
"INSERT something"
log(count of inserted rows).
do something other
on error COMMIT eles ROLLBACK
}
function log(message){
insert message into log-table.
}In case of an error in the mainFunction the ROLLBACK will also rollback the log information.
In the ORACLE world I've solved the problem by using the PRAGMA autonomous_transaction
funktion mainFunction{
"INSERT something"
log(count of inserted rows).
do something other
on error COMMIT eles ROLLBACK
}
function log(message){
Pragma autonomous_transaction.
insert message into log-table.
COMMIT.
}The COMMIT in the log function has no effect to the insert in the mainFunction. IN case of an error and a rollback in the mainFunction the log entry is any longer in the log-table.
So on in the ORACLE world, but what can I do in SAP (with openSQL)
Torsten
‎2007 May 16 3:06 PM
‎2007 May 16 3:46 PM
Hi,
no this ref doesn't help.
funktion mainFunction{
try
"INSERT something"
log(count of inserted rows).
"INSERT something else"
log(log status message).
COMMIT
catch
ROLLBACK
}
function log(message){
insert message into log-table.
}Both inserts can only commited together (business logic / not technical view). In case an exception or error occurs by inserting the second one the catch branch will rollback all informtaion, also the log information.
The solution from your ref will mean:
function log(message){
insert message into log-table.
if sy-subrc ne 0.
rollback work.
exit.
endif.
}But this solution has the effect, that the first log entry also commit the first insert in the mainFunction. In case of an error by inserting the second one a rollback from the first insert isn't possible.
Torsten
‎2007 May 16 3:10 PM
I would be grateful for any other solution to log messages in an ABAP (BSP) application.
I've also find to write system logs (SM21) outof the application, but this is overkill I think.