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

Autonomous database transaction

Torsten_
Product and Topic Expert
Product and Topic Expert
0 Likes
565

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

3 REPLIES 3
Read only

Former Member
0 Likes
512

Hi,,

refer

Hope this solves your purpose.

Award points if it helps.

-Gaurang

Read only

Torsten_
Product and Topic Expert
Product and Topic Expert
0 Likes
512

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

Read only

Torsten_
Product and Topic Expert
Product and Topic Expert
0 Likes
512

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.