4GL triggers - DELETE

martilan

New Member
Hello,

I have a code similar to this:


ON DELETE OF Orders
DO:
...
END.


CREATE Orders.
ASSIGN Orders.OrderID = "000000001"
ASSIGN Orders.Amount = 100.
...
RELEASE Orders.

FOR FIRST Orders WHERE
Orders.OrderID = "000000001"
EXCLUSIVE-LOCK:
...
ASSIGN Orders.Amount = 200.
...
DELETE Orders.
END.

Can I somehow access the original amount (which was 100) in the DELETE trigger (like it is possible for example with the WRITE trigger where we can access the old buffer)?

Thanks!
 

Cringer

ProgressTalk.com Moderator
Staff member
Surely the new value has to be written before the delete happens? So I'd be looking at the wirte trigger to capture that.
 
Hello,

I have a code similar to this:


ON DELETE OF Orders
DO:
...
END.


CREATE Orders.
ASSIGN Orders.OrderID = "000000001"
ASSIGN Orders.Amount = 100.
...
RELEASE Orders.

FOR FIRST Orders WHERE
Orders.OrderID = "000000001"
EXCLUSIVE-LOCK:
...
ASSIGN Orders.Amount = 200.
...
DELETE Orders.
END.

Can I somehow access the original amount (which was 100) in the DELETE trigger (like it is possible for example with the WRITE trigger where we can access the old buffer)?

Thanks!
I would use local vars or temp-tables.
 

martilan

New Member
Thanks for your responses!
I wouldn't want to change the code where the Orders records are created because there are many places in code where this is done, so I just wanted to add the triggers to capture the field changes. I don't think that I could use the WRITE trigger because this will not be fired if there's no RELEASE statement before the Orders record is deleted. Maybe I could use the ASSIGN trigger for that to store the original values in some temp-table but I would have to add an ASSIGN trigger for each field I want to track, so I was wondering if it's possible to easily get to the original value in the DELETE trigger somehow.
 

Cringer

ProgressTalk.com Moderator
Staff member
I get that your example is a trivial one to illustrate a point, but any code where a record is updated and deleted within the same transaction is asking for this sort of confusion. I've adapted your code to use proper transaction scoping with named buffers (and changed it to match my available data structures), and you get the expected behaviours and everything is logged as you expect.

Code:
ON write OF EntryHeader
DO:
message 'write' EntryHeader.customer-ref entryheader.booking-no
    view-as alert-box info buttons ok.
END.

ON DELETE OF EntryHeader
DO:
message 'delete' EntryHeader.customer-ref entryheader.booking-no
    view-as alert-box info buttons ok.
END.

define buffer bentryheader for entryheader.

do for bentryheader transaction:
    CREATE bentryheader.
    assign 
        bentryheader.warehouse = 'jp'
        bentryheader.trx-type = 'jp'
        bentryheader.trx-no = 1
        bentryheader.customer-ref = "000000001"
        bentryheader.booking-no = 100.
end.

do for bentryheader transaction:
    FOR FIRST bEntryHeader WHERE
        bentryheader.warehouse eq 'jp'
        and bentryheader.trx-type eq 'jp'
        and bentryheader.trx-no eq 1
    EXCLUSIVE-LOCK:
    
        ASSIGN bEntryHeader.booking-no = 200.
    end. 
end. 
do for bentryheader transaction:
    FOR FIRST bEntryHeader WHERE
        bentryheader.warehouse eq 'jp'
        and bentryheader.trx-type eq 'jp'
        and bentryheader.trx-no eq 1
    EXCLUSIVE-LOCK:
    
        DELETE bEntryHeader.
    end. 
end.
 

martilan

New Member
Thanks, Cringer.
I'll try to use the correct transaction scoping as you described in your example. However, I was also looking for a way how to create the DELETE trigger, so that when someone later adds a code where he makes some changes to the Orders table, the trigger would still work in all possible scenarios as expected (even if he updates and then deletes the record in the same transaction as in my example).
 
Top