RobertP
25th November 2013, 12:11
Hello gurus,

I'd like to know whether it is possible to use db.insert on a table without actually calling it in 'select for update"?

My situation is that whilst the main process is running (on the main table X) I want to insert data to 'log' table Z instead of sending to a report. The main process handles around 40 transactions. I want to avoid selecting table Z for update 40 times, if this can only be done once, with 40 db.inserts instead.

The main reason is performance.

Secondly, if it is possible, are there any related settings to manage? (e.g. db.retry.point or eflags)

Your input appreciated!

bhushanchanda
25th November 2013, 16:14
Hi,

Never required that, but you can try this:-

db.set.to.default(table_name)
db.insert(table_name,db.retry)

e.g.

db.set.to.default(ttcxyz001)
db.insert(ttcxyz001,db.retry)

I guess it should work. I would like to try this once I am back at my desk.

BaanInOhio
25th November 2013, 16:42
Not required. You can fill table fields and execute db.insert without locking the record. If on LN, you can use DAL2 instead of db.insert and have a dal2 script referenced by the log table that ensures that the index is unique.

Use the 'eflag' argument of db.insert (3rd) to handle exceptions:

db.insert(table, db.retry, db.skip.dupl) - disables error when trying to add a duplicate unique index.

db.insert(table, db.retry, db.return.error) - disables any error and returns the error code in a predefined variable = "e".

bhushanchanda
25th November 2013, 17:07
Yes,

As BaanInOhio said, its always better to add that 3rd command to avoid the errors.

So, I will modify my snippet a bit.

db.set.to.default(ttcxyz001)
db.insert(ttcxyz001,db.retry,db.skip.dupl)

RobertP
26th November 2013, 10:52
Thank you very much Bhushan and BaanInOhio!

This will come in handy for logging data in a table instead of sending to a report.