My third question:
If I had a code like this:
Code:
DO TRANSACTION :
RUN doEverything.
END.
PROCEDURE doEverything:
FOR EACH tbl_a EXCLUSIVE-LOCK.
FIND FIRST tbl_b WHERE tbl_b.b_name = tbl_a.a_name
EXCLUSIVE-LOCK NO-ERROR.
IF AVAIL tbl_b THEN SET tbl_b.b_qty = tbl_b.b_qty + tbl_a.a_qty.
CREATE tbl_c.
SET tbl_c.c_name = tbl_a.a_name
tbl_c.c_trans = tbl_a.a_trans.
SET tbl_a.a_qty = tbl_a.a_qty + 1.
END.
END.
If my memory server me well, once I had an condition where tbl_c's creation failed because of it's UNIQUE index (I added record with same value so database reject it because it's already exist) because I hadn't check before creating tbl_c.
So if tbl_c's CREATE failed, the trasaction before and after (updating b and a) will be canceled, but why does the transaction for the next loop continuos? I wanted everything to be canceled. Not just current loop with error.
And what about this code below, is it differ from above?
Code:
DO TRANSACTION :
RUN doEverything.
END.
PROCEDURE doEverything:
DEF BUFFER bfr_a FOR tbl_a.
FOR EACH tbl_a NO-LOCK.
FIND FIRST tbl_b WHERE tbl_b.b_name = tbl_a.a_name
EXCLUSIVE-LOCK NO-ERROR.
IF AVAIL tbl_b THEN SET tbl_b.b_qty = tbl_b.b_qty + tbl_a.a_qty.
CREATE tbl_c.
SET tbl_c.c_name = tbl_a.a_name
tbl_c.c_trans = tbl_a.a_trans.
FIND FIRST bfr_a WHERE ROWID(bfr_a) EQ ROWID(tbl_a)
EXCLUSIVE-LOCK NO-ERROR.
IF AVAIL bfr_a THEN DO :
SET bfr_a.a_qty = bfr_a.a_qty + 1.
RELEASE bfr_a.
END.
END.
END.
My Regards
YoChan