Example of Subtransaction.

Posted by Admin on 20-Jun-2011 08:17

1.       Please Write a program that contains sub transaction, Keep in mind that sub transaction should update a date field and if the input date is greater than today, transaction should be aborted by the program itself.

All Replies

Posted by rohit.ramak on 21-Jun-2011 04:00

DEFINE VARIABLE dtDate AS DATE        NO-UNDO.
DEFINE VARIABLE cState AS CHARACTER   NO-UNDO.

Main_TXN:
FOR FIRST customer EXCLUSIVE-LOCK :

    ASSIGN cState = customer.state.
    UPDATE cState.
    ASSIGN Customer.State = cState.


    FIND FIRST order OF customer EXCLUSIVE-LOCK NO-ERROR NO-WAIT.

    IF NOT avail order THEN UNDO Main_TXN, LEAVE Main_TXN.
    ELSE
    DO:
        ASSIGN dtDate = order.order-date.
        UPDATE dtDate.
        IF dtDate = ? OR dtDate > TODAY
            THEN UNDO Main_TXN, LEAVE Main_TXN.
        ASSIGN order.order-date = dtDate.
    END.
END.

This thread is closed