States and Events

When a file was defined in its original Lawson 4GL development environment, its definition included states and events. When the original source code was generated for a program that used a file, that source code then include code that enabled the program to perform the events for the various valid states of the file’s records.

You can define states and events for each file in a product line. You can also define rules for each state and event in a file. For more information, see Database Rules.

State and Event Example

The Timerecord file belongs to the Payroll system and stores employees' time records. The Timerecord file has four states: Edit, Submitted, Approved, and History. The State field is Status. Its value can be 0, 1, 2, or 3. The value of the Status field determines the state of the record.

In the Edit state, the Add event lets you add an employee's time record. After the time record exists, you can change it (Change event), delete it (Delete event), or submit it for approval (Submit event). The Submit event is a function-type event. Time records in the Edit state have a Status of 0. When you submit a record for approval, the system updates the State field, Status, to 1. The record is now in the Submitted state.

In the Submitted state, you can reject the time record (Reject event), change it (Modify event), or approve it (Approve event). The Modify event is a change-type event. The Reject and Approve events are function-type events; they perform a set of rules on the Timerecord record. If the time record is approved, the system updates the State field, Status, to 2. The record is now in the Approved state.

The Approved state has a single event that processes and posts the time record. After you post the time record, the system updates the state field, Status, to 3. The record is now in the History state.

The History state has a single event that deletes time records from the file. Timerecord records remain in the History state until they are deleted (Delete event).