How to identify what Input was Load, Unload or Complete
As the table PrdExec_Input_Event only contains information of the current events in running and stage positions that are load we need to look at the PrdExec_Input_Event_History table in order to identify what was the last event that was Load, Unload or Complete.
This table has key fields that will help us to identify the Unit, if the event was Load, Unload or Complete.
When an event is been Load the PrdExec_Input_Event_History gets one record where:
- Event_Id indicates what event is been load it.
- Event_Id_Updated is set to 1.
- Timestamp_Updated is set to 1.
- Unloaded field is set to 0.
- Unloaded_Update field is set to 0.
Event_Id | Unloaded_Updated | Event_Id_Updated | Timestamp_Updated | Unloaded |
---|---|---|---|---|
30069 | 0 | 1 | 1 | 0 |
When an event is been Unload the PrdExec_Input_Event_History gets two records where:
- On the first record Event_Id indicates what event is been Unload and on the second is Null.
- Event_Id_Updated is set to 0 on the first record and 1 on the second.
- Timestamp_Updated is set to 1 in the first record and 0 on the second.
- Unloaded field is set to 1 on the first record and 0 on the second.
- Unloaded_Update field is set to 1 on the 2 records.
Event_Id | Unloaded_Updated | Event_Id_Updated | Timestamp_Updated | Unloaded |
---|---|---|---|---|
30069 | 1 | 0 | 1 | 1 |
NULL | 1 | 1 | 0 | 0 |
When an event is been Complete the PrdExec_Input_Event_History gets one record where:
- Event_Id is set to null.
- Event_Id_Updated is set to 1.
- Timestamp_Updated is set to 1.
- Unloaded field is set to 0.
- Unloaded_Update field is set to 0.
Event_Id | Unloaded_Updated | Event_Id_Updated | Timestamp_Updated | Unloaded |
---|---|---|---|---|
NULL | 0 | 1 | 1 | 0 |
The following is a query example to help identify what event was running depending on a Line, Unit and input position:
SELECT Prod_Lines.PL_Desc_Local AS Line,
Prod_Units.PU_Desc_Local AS Unit,
PrdExec_Inputs.Input_Name,
PrdExec_Input_Positions.PEIP_Desc AS Position,
Events.Event_Id AS EventId,
Events.Event_Num AS [Even Number],
PrdExec_Input_Event_History.Unloaded AS Unload
FROM PrdExec_Inputs INNER JOIN
PrdExec_Input_Event_History ON PrdExec_Inputs.PEI_Id =
PrdExec_Input_Event_History.PEI_Id INNER JOIN
Prod_Units ON PrdExec_Inputs.PU_Id = Prod_Units.PU_Id INNER JOIN
Prod_Lines ON Prod_Units.PL_Id = Prod_Lines.PL_Id INNER JOIN
Events ON Prod_Units.PU_Id = Events.PU_Id INNER JOIN
PrdExec_Input_Positions ON PrdExec_Input_Event_History.PEIP_Id =
PrdExec_Input_Positions.PEIP_Id
WHERE (Prod_Lines.PL_Desc_Local = 'XXX') -- Line Name
AND (Prod_Units.PU_Desc_Local = 'YYY') -- Unit Name
AND (PrdExec_Inputs.Input_Name = 'ZZZ') -- Input Name
AND (PrdExec_Input_Positions.PEIP_Desc = 'Running') -- Position
AND (PrdExec_Input_Event_History.Unloaded_Updated = 1) -- This
indicates if the input was change or not
AND (PrdExec_Input_Event_History.Unloaded = 1) -- The change is
Unload.