Event Handling Sequence Example
The following figure presents an overview of the database event handling process. The steps that follow use the example of two applications:
• The sending application is the Manufacturing application that, among its other functions, keeps track of the raw parts used in the manufacturing process.
• The receiving application is the Inventory control application that keeps track of supplies and orders them as necessary.
The following diagram illustrates the database event handling sequence:
The steps of the sequence are as follows:
1. You use the SQL create dbevent statement in the Terminal Monitor to create an event. For example, to create an event to be raised when supply of a part is low:
create dbevent part_low
2. You register the event in your receiving application. For example, to register the "part_low" event in the Inventory application:
register dbevent part_low
3. You place a raise dbevent statement after the appropriate code in your sending application. For example, to raise the "part_low" event in the Manufacturing application after an update that causes the quantity of a part to fall below 100:
update parts
set quantity = :quantity
where part_no = :part_no;
if quantity < 100 then
raise dbevent part_low;
endif;
4. When the supply of a part falls below 100, the raise dbevent statement is executed. The DBMS Server is notified that the "part_low" event has been raised. The server places the event into the event queue for the Inventory application.
5. An on dbevent activation block within the Inventory (receiving) application checks the event queue and extracts any events (for which it is registered) that have been raised.
6. An inquire_sql statement within the event activation block retrieves information about the event that has been raised. If it is the "part_low" event, the Inventory application takes the following actions:
• Calls the "reorder" procedure that generates a purchase order for the part
• Sends a mail message to the shop supervisor
The following is a sample of the 4GL code to accomplish steps 5 and 6:
on dbevent =
begin
inquire_sql (ename = dbeventname,
etime = dbeventtime);
if ename = 'part_low' then
callproc reorder;
call system 'mail/subject = "Part ' +
varchar(part_no) + ' was reordered at ' +
varchar(etime) + '." FOREMAN';
endif;
end
Last modified date: 08/28/2024