Skip to the lesson
CivOps AI Academy · M04Manufacturing Execution (MES): Routings, Interlocks, Genealogy and OEE on Your Own Spine
0%

Chapter 1 · Purpose, scope and standards

What an MES does and where it sits

A manufacturing execution system (MES) is the layer that makes a plan happen on the floor and writes down what really happened. This chapter says what it does, where it sits between the ERP and the machines, which standards give it a shape, and what this module leaves to others.

20 minISA-95 Level 311 MESA functions12 capabilities

By the end of this chapter you can

  • Say in one sentence what an MES executes, enforces and records.
  • Place the MES among the ISA-95 levels and name the standards the module follows.
  • Sort the eleven MESA functions into those this module builds and those other modules own.

Execute, enforce, record

An MES defines how products are made, dispatches orders to work centres, guides operators step by step, checks materials and qualifications, collects data from machines and people, builds the genealogy of every lot, captures downtime and OEE, and reports performance back to the ERP. Three verbs cover it: execute the work, enforce the rules while it is done, and record what happened in a form nobody can quietly change.

Tools in this class include Rockwell Plex and FactoryTalk ProductionCentre, Siemens Opcenter Execution, Critical Manufacturing, AVEVA MES, Dassault DELMIA Apriso, Parsec TrakSYS, Tulip and Sepasoft on Ignition. This module is the capstone of the library: the platform's direction is that the MES hub emerges from the other modules (scheduling, maintenance, documents, training, quality), and this module ties them together on the one shared spine.

Where it sits: ISA-95

ISA-95, published internationally as IEC 62264, divides a manufacturer into levels [1][2]. The business systems (ERP) are at Level 4, and the machines and their controls are below. Manufacturing operations management, the MES, sits at Level 3, between the two. That position explains what an MES does: it receives a schedule from above, turns it into work on the floor, and sends what was done back up.

ISA-95 levels and the MESFive stacked levels from Level 4 business planning at the top to Level 0 the physical process. The MES sits at Level 3. Arrows show the ERP exchange above it and machine data below it. Control and safety stay at Levels 1 and 2. Level 4 · Business planningERP: orders, plans, costsLevel 3 · Operations managementMES: execute, enforce, recordLevel 2 · Supervisory controlSCADA, HMI, DCS screensLevel 1 · Sensing and manipulatingPLCs, sensors, drivesLevel 0 · The physical processMachines, material, peopleSchedule in; performanceand material movements out(ISA-95 Part 5, B2MML)Counts, states and values in(OPC UA, Sparkplug B)Control and safety stayat Levels 1 and 2
The MES at Level 3. The plan comes down from the ERP, counts and states come up from the machines, and performance goes back to the ERP. Control logic and safety stay in the PLC and DCS at the levels below.

The standard has five parts. Parts 1 and 2 give the object models and terminology; Part 3 gives the Level 3 activity model, which is four categories of operation (production, maintenance, quality and inventory) crossed with eight activities; Part 4 describes the information that flows between those activities; and Part 5 defines the business-to-manufacturing (B2M) transactions between the ERP and the MES [3]. The module uses Parts 1 and 2 to name its equipment and material, and Part 5 for the ERP exchange in chapter 4.

StandardWhat the module takes from it
ISA-95 / IEC 62264 Parts 1 to 5Object models (Parts 1 and 2), the Level 3 activity model (Part 3), information flows (Part 4), B2M transactions (Part 5)
MESA-11 functional modelA checklist of eleven MES functions, used to inventory a plant today
B2MML (MESA)XML and JSON schemas that carry ISA-95 messages to the ERP
ISA-88 / IEC 61512Batch control: the physical and procedural models (procedure, unit procedure, operation, phase) and recipe types
ISO 22400-2Definitions of the manufacturing KPIs: OEE, availability, effectiveness, quality ratio, throughput
ISA-TR88.00.02 (PackML)A machine state model and tags for packaging lines
OPC UA (IEC 62541) and Eclipse Sparkplug BHow machine values reach the tag registry
21 CFR 211.188 and 211.192; 21 CFR 820Batch production records, and device history records under the QMSR (aligned to ISO 13485), where regulated

The eleven functions

The MESA model lists eleven functions an MES covers: resource allocation, scheduling, dispatching, document control, data collection, labour, quality, process management, maintenance, genealogy and performance analysis [1]. It is a checklist, not a design: use it to find out which of the eleven your plant does today, with what, and who does them.

The eleven MESA functionsEleven boxes in a grid. Green: resource allocation, dispatching, data collection, labour, process management, genealogy and performance analysis are built in this module. Cyan: scheduling (M03), document control (M06), quality (M08 and M09) and maintenance (M05) belong to other modules. Resource allocationequipment on each runSchedulingM03 owns itDispatchingthe dispatch listDocument controlM06 owns itData collectiontags and manual entryLabourclock on and off a runQualitygates here; M08 and M09Process managementsteps and parametersMaintenanceM05 owns itGenealogylot links and tracePerformance analysisOEE for each shiftbuilt in this modulebuilt elsewhere
The eleven functions, sorted. Seven are built here. Scheduling (M03), document control (M06), quality (M08 and M09) and maintenance (M05) are other modules' work, which this module reads from and writes to through the shared tables.

What is in and out of scope

The edge of the MES moduleInside: definitions and routings, dispatch and execution, data collection, genealogy, downtime and OEE, ERP exchange. Outside, with the owner: finite scheduling in M03, maintenance execution in M05, SPC in M09, laboratory testing in M10, and control logic and safety, which stay in the PLC or DCS. INSIDE THE MES MODULE (M04)Definitions, routingsDispatch, executionData collectionGenealogyDowntime and OEEERP exchangeOUTSIDE, WITH ITS OWNERFinite schedulingM03Maintenance executionM05SPC charts and capabilityM09Laboratory testingM10Control logic and safetystays in the PLC or DCS
The edge of the module. Everything on the right is real MES territory in a commercial product, and is kept out so each piece has one owner. The last box is the one that never moves.

Twelve capabilities, in three tiers

The specification groups the module's capabilities by tier. MVP is what every plant needs first; STD is what a standard MES also does; BIC is best in class.

CapabilityTierWhat it does
Product and process definitionMVPRoutings and master recipes with revisions and effectivity; operations with work centre, standard times, crew, instructions, required skills, parameters with limits and a bill of materials for each operation
DispatchingMVPRelease orders; dispatch lists per work centre from the schedule or by priority; operator job selection
Execution managementMVPStart, pause and complete operations; guided steps; interlocks for qualification, calibration, material scan and previous step
Material tracking and genealogyMVPConsume by scan or backflush, produce lots and serials, trace forward and backward in seconds
Downtime and OEEMVPA state model aligned to PackML, reason-coded downtime and micro-stoppages, OEE per ISO 22400
Data collectionSTDCounts and states from tags; manual fallback; parameters evaluated against limits
Labour trackingSTDClock on and off operations; setup, run and indirect time; crew size
In-process qualitySTDInspection triggers, automatic lot holds, quality gates at operation completion
Performance analysisSTDYield, scrap, cycle time, schedule adherence and ISO 22400 KPIs by line, shift and product
ERP integrationSTDProduction schedule in; performance and material movements out as B2MML messages through an outbox
Electronic batch and device history recordBICStep records with performer and verifier signatures, deviations linked to M08, review by exception
Process-industry batch (ISA-88)BICProcedural recipes, phase execution, recipe parameter downloads with read-back
Exercise · Place your plant on the models15 minutes

You need: Your Session 1 notes (docs/mes-inventory.md if you have started it), one routing from your plant, and a pen

Use one real line. Work on paper first; leave operator and customer names out of anything you save.

Outcome: A one-page placement of your plant on ISA-95 and MESA-11, with the three painful functions named and the control boundary written down.

Knowledge check

At which ISA-95 level does an MES sit?

Knowledge check

Which of these is outside the MES module's scope?

References

  1. SYMESTIC: the 11 core MES functions (MESA-11) and the ISA-95 Part 3 matrix. https://www.symestic.com/en-us/what-is/mesa-11
  2. Siemens: ISA-95 framework and layers. https://www.siemens.com/en-us/technology/isa-95-framework-layers/
  3. Automation World: the five parts of ISA-95. https://www.automationworld.com/products/software/article/13309288/the-five-parts-of-isa-95
  4. ISA: ISA-95 series of standards (enterprise-control system integration). https://www.isa.org/standards-and-publications/isa-standards/isa-95-standard

Chapter 2 · The data model

Definitions, orders and records: the fifteen tables

How production is stored decides what you can ever ask of it. Five tables say how a product is made, two say who is making it and where, and eight keep what happened. Everything points at the shared spine, so the MES never grows a second equipment list.

25 min15 tables3 groups2 pitfalls

By the end of this chapter you can

  • Name the fifteen mes_ tables and sort them into definitions, order and run, and records.
  • Explain how a product definition is approved, becomes effective and is superseded without being edited.
  • Say why equipment, items and people are keys to the spine and why measured values are typed columns.

Three groups of tables

Every table starts with the standard columns every platform table has: id, tenant_id, created_at, created_by, updated_at, updated_by, row_version, archived_at and ext. The module has no item master, machine list, lot table or people table of its own. Its keys go to core_item, core_equipment, core_lot, core_person and core_shift_instance, and to core_e_signature, core_uom, core_data_tag, core_reason_code, core_attachment, core_site and core_serial_unit. Its own tables share the prefix mes_.

The fifteen mes_ tablesThree groups. Definitions: product definition, operation definition, step, parameter and material. Order and run: production order, operation run and shift performance. Records: step record, parameter value, material consumption, material production, labour record, equipment state event and production count. All point at the spine tables for items, equipment, lots, people and shifts. DEFINITIONS · what to domes_product_definitionmes_operation_definitionmes_operation_stepmes_operation_parametermes_operation_materialORDER AND RUN · who, wheremes_production_ordermes_operation_runmes_shift_performancemes_shift_performance iscalculated from the recordsRECORDS · what happenedmes_step_recordmes_parameter_valuemes_material_consumptionmes_material_productionmes_labor_recordmes_equipment_state_eventmes_production_countThe spine: core_item · core_equipment · core_lot · core_person · core_shift_instance
The fifteen tables. Definitions say what to do; orders and runs say which order is done where and by whom; records keep what happened. mes_shift_performance is calculated from the records and written back.

The tables below give every column the module adds to the standard ones. Types are as in the specification: text, int, num (a decimal number), qty (a quantity, kept with its unit in a uom_id column), bool, ts (a timestamp with time zone), uuid and json (jsonb in Postgres). An arrow means a foreign key to that table, req means required (not null), and a list after a colon is the allowed values. This is what your agent builds from in Session 2.

Definitions: how a product is made

TableHoldsColumns
mes_product_definitionA routing or master recipe header, with revision and effectivitycode text req, unique; item_id → core_item req; revision text req; process_type text req: discrete, batch, continuous or mixed; status text req: draft, approved, effective, superseded or obsolete; effective_from ts; effective_to ts; approved_signature_id → core_e_signature
mes_operation_definitionAn operation (or ISA-88 unit procedure, operation or phase) within a definitionproduct_definition_id → mes_product_definition req; seq int req; code text req; name text req; work_center_id → core_equipment req; isa88_level text: none, unit_procedure, operation or phase; std_setup_min num; std_cycle_sec num; std_crew num; instruction_doc_ref uuid, a soft link to M06's doc_controlled_document; required_skill_ref uuid, a soft link to M07's trn_skill; quality_gate bool
mes_operation_stepA guided step: instruction, check, data entry, scan, signatureoperation_definition_id → mes_operation_definition req; step_no int req; step_type text req: instruction, check, data_entry, material_scan, signature, timer or equipment_check; text text req; media_attachment_id → core_attachment; requires_verification bool; parameter_key text
mes_operation_parameterA process parameter with limits, captured automatically or by handoperation_definition_id → mes_operation_definition req; key text req; name text req; data_tag_id → core_data_tag; uom_id → core_uom; target num; lsl num; usl num; capture text req: auto, manual or both; critical bool
mes_operation_materialThe bill of materials for one operation: inputs, outputs and by-productsoperation_definition_id → mes_operation_definition req; item_id → core_item req; qty_per qty req; uom_id → core_uom req; direction text req: input, output or byproduct; consumption text req: scan, backflush or manual; scrap_factor num

Order and run: who makes what, where

TableHoldsColumns
mes_production_orderAn order to produce, from the ERP, MRP, a scheduler or by handorder_no text req, unique; item_id → core_item req; product_definition_id → mes_product_definition req; site_id → core_site req; qty_planned qty req; uom_id → core_uom req; due_at ts; priority int; status text req: planned, released, in_progress, on_hold, completed, closed or cancelled; source text req: erp, mrp, aps or manual; external_ref text; output_lot_id → core_lot
mes_operation_runOne operation of one order on one piece of equipmentproduction_order_id → mes_production_order req; operation_definition_id → mes_operation_definition req; equipment_id → core_equipment; status text req: pending, ready, running, paused, complete or skipped; started_at ts; ended_at ts; qty_good qty; qty_scrap qty; qty_rework qty; lead_operator_id → core_person; shift_instance_id → core_shift_instance
mes_shift_performanceISO 22400 performance for one piece of equipment and one shift, calculatedequipment_id → core_equipment req; shift_instance_id → core_shift_instance req; planned_busy_min num; actual_run_min num; ideal_cycle_sec num; total_count qty; good_count qty; availability num; performance num; quality num; oee num

Records: what happened

TableHoldsColumns
mes_step_recordThe electronic batch or device history record of a step, with performer and verifieroperation_run_id → mes_operation_run req; operation_step_id → mes_operation_step req; entry json; performed_by → core_person req; performed_at ts req; verified_by → core_person; verified_at ts; performer_signature_id → core_e_signature; verifier_signature_id → core_e_signature; deviation_ref uuid, a soft link to M08's qms_quality_event
mes_parameter_valueA captured value with its specification evaluationoperation_run_id → mes_operation_run req; operation_parameter_id → mes_operation_parameter req; value_num num; value_text text; captured_at ts req; captured_by → core_person; source text req: tag or manual; in_spec bool
mes_material_consumptionMaterial consumed from a lot into a runoperation_run_id → mes_operation_run req; item_id → core_item req; lot_id → core_lot; serial_unit_id → core_serial_unit; qty qty req; uom_id → core_uom req; consumed_at ts req; consumed_by → core_person; verified_by_scan bool
mes_material_productionA lot or serial produced by a runoperation_run_id → mes_operation_run req; item_id → core_item req; lot_id → core_lot; serial_unit_id → core_serial_unit; qty qty req; uom_id → core_uom req; produced_at ts req
mes_labor_recordLabour time against a runperson_id → core_person req; operation_run_id → mes_operation_run; activity text req: direct, setup, indirect, training or break; started_at ts req; ended_at ts
mes_equipment_state_eventA state interval for one piece of equipment, with a reasonequipment_id → core_equipment req; state text req: running, idle, starved, blocked, planned_down, unplanned_down, changeover, micro_stop or offline; started_at ts req; ended_at ts; reason_code_id → core_reason_code; source text req: tag, manual or inferred; operation_run_id → mes_operation_run
mes_production_countA count increment, good and reject, by equipment and timeequipment_id → core_equipment req; operation_run_id → mes_operation_run; ts ts req; good qty req; reject qty; source text req: tag or manual

Two links are soft on purpose. instruction_doc_ref, required_skill_ref and deviation_ref are plain uuid columns with no foreign key, because the modules that own those tables (M06, M07 and M08) may not be installed yet; the module library's cross-module file adds the keys once both sides exist.

Definitions are versioned, never edited

A routing is a promise about how a product is made, so a change to it is a new revision, not an edit. A definition is a draft while it is being written, becomes approved only with an approval signature, becomes effective on a date (and the earlier effective revision of the same item becomes superseded on that date), and is never changed after that. An order records the definition it was made against, so a year later you can say exactly how a lot was made.

ISA-88 names four recipe types: general, site, master and control. For a batch process a mes_product_definition is the master recipe, and the control recipe is what one batch actually runs, which here is the order with its runs pinned to the effective revision. The isa88_level column marks an operation as a unit procedure, an operation or a phase; it is none for a discrete routing such as the seed's bracket.

Definition and order life cycleTop row: a product definition moves from draft to approved, effective and superseded. Bottom row: an order PO-1001 is planned, then released, which creates a run for OP10 that is ready and a run for OP20 that is pending. A PRODUCT DEFINITION (status)DrafteditableApprovedneeds a signatureEffectiveone per itemSupersededread-only historyThe move to effective sets effective_from and moves the earlier revision to superseded.AN ORDER THAT USES ITPO-1001plannedReleaseneeds an effectiverevisionRun OP10readyRun OP20pendingThe first operation is ready; the rest wait until the one before them is complete.
A definition and an order that uses it. Releasing PO-1001 needs an effective, signed revision, and creates one run per operation: the first is ready and the rest wait.

Regulated plants need this rule. For batch production, the US rules ask that a master record exists and that each batch record shows each step completed and checked [1]; for devices the QMSR asks for a device history record [2]. Where records are electronic, the electronic-signature rules apply [3]. Even where nothing is regulated, the habit is worth having: a revision you can point to ends arguments about what the instruction said on the day.

Rules this course adds

The specification names the tables and columns. This course adds rules inside the database so impossible rows cannot get in; ask your agent to add each, with a test.

  • One core_item has at most one mes_product_definition with status effective at a time (a partial unique index: a uniqueness rule that applies only to rows meeting a condition).
  • One piece of equipment has at most one mes_equipment_state_event with no ended_at, so it cannot be in two states at once.
  • One mes_operation_run for each order and operation; one operation for each definition and seq; one step for each operation and step_no; one mes_shift_performance for each equipment and shift.
  • lsl is not above usl; ended_at is not before started_at; a run's qty_good, qty_scrap and qty_rework are not negative.
  • Counts and consumptions may be negative, because that is how they are corrected: a row with the opposite sign that names the row it corrects in ext and carries a core_comment with the reason. The supervisor enters a count correction with source manual; the operator reverses a wrong scan while the run is still running; after a run is complete a wrong consumption becomes a deviation instead.
Exercise · Write one routing as rows15 minutes

You need: The routing from your Session 1 inventory, the column tables in this chapter, and your AI coding agent

Use the product you chose in Session 1. Do steps 1 to 5 on paper or in a text file; the agent comes in at step 6.

Outcome: A routing written as rows of the five definition tables, every work centre an existing spine equipment code, and every measured value a typed parameter with limits.

Knowledge check

Why does an order record the product definition it was made against?

Knowledge check

A machine appears in the MES with its own code and in core_equipment with another. What has gone wrong?

References

  1. eCFR: Title 21, Part 211, current good manufacturing practice for finished pharmaceuticals (subpart J holds the batch production records, sections 211.188 and 211.192). https://www.ecfr.gov/current/title-21/chapter-I/subchapter-C/part-211
  2. eCFR: Title 21, Part 820, Quality System Regulation and QMSR. https://www.ecfr.gov/current/title-21/chapter-I/subchapter-H/part-820
  3. eCFR: Title 21, Part 11, Electronic records; electronic signatures. https://www.ecfr.gov/current/title-21/chapter-I/subchapter-A/part-11
  4. ISA: ISA-95 series of standards (object models for equipment and material). https://www.isa.org/standards-and-publications/isa-standards/isa-95-standard

Chapter 3 · On the floor

Run the work: interlocks, records and genealogy

An order is released, an operator starts a run, and from then on the database, not a memory or a poster, decides what is allowed. This chapter follows one run from the dispatch list to a signed record and a lot that can be traced.

30 min9 interlocks3 status laddersTrace in under 1 second

By the end of this chapter you can

  • Follow an order from release to completion and say which status changes at each point.
  • Name the interlocks that stop an unqualified operator, an overdue gauge, a held lot and a step done out of order.
  • Explain signed step records, review by exception and how genealogy is built from consumption and production.

Release and dispatch

An order starts planned. The planner releases it, which is allowed only if its product definition is effective and signed, and releasing creates one run for each operation: the first is ready and the rest are pending. Releasing also writes an event, mes.production_order.released, to the outbox. The dispatch list for a work centre then shows one card for each ready run in the operator's area, ordered by priority and then due date, with a Start button only when the run is ready.

RecordStatuses, in orderWho or what moves it
mes_production_orderplanned, released, in_progress, completed, closed (also on_hold and cancelled)Planner releases; the first start makes it in_progress; completion of the last run makes it completed; review closes it
mes_operation_runpending, ready, running, paused, complete (also skipped)Release sets the first run ready; completing a run makes the next one ready; the operator starts, pauses and completes
mes_product_definitiondraft, approved, effective, superseded (also obsolete)Process engineer drafts; quality approves with a signature; effective date moves the earlier revision to superseded

The interlocks

An interlock is a rule that must be satisfied before an action is allowed. The module puts them in the database as triggers (rules that run on each insert or update), so no screen, route or script can skip one. If the database refuses an action, the route returns the rule's message to the operator. History is the one exception, and it is keyed to who inserts it, not to what a row says: a row marked ext imported_from skips the insert checks only when the importer account or the migration role that loads the seed inserts it, so the same marker on a row from an operator's route is ignored.

The interlocksThree columns of three rules each, the nine interlocks of the table below. To start: previous operation, qualification, calibration. When material is scanned: lot status, bill of materials, scan and quantity. For steps and completion: step order, completion, verification. TO START A RUNPrevious operationthe run before is completeQualificationtrn_qualification: qualifiedCalibrationlatest record not overdueWHEN MATERIAL IS SCANNEDLot statusreleased, not on holdBill of materialsitem is an input hereScan and quantityscanned, within qty_initialSTEPS AND COMPLETIONStep orderprevious step recordedCompletioninputs, values and signaturesVerificationverifier is not the performerEach rule is a trigger in the database: the screen shows its message, and no other route can skip it.
The interlocks, in the order work meets them. The nine interlocks of the table below: three at the start of a run, three when material is scanned, three for steps and completion.
InterlockThe ruleA seeded case that proves it
Previous operationThe run for the previous operation of the same order must be completeOP20 cannot start while OP10 of the same order is not complete
QualificationThe lead operator holds a trn_qualification for the operation's required skill with status qualified, and either no expires_at or one later than the startOPR-3 is refused on OP10 because the qualification expired on 31 January 2026; OPR-2 is refused on OP20 because SK-FORM is only in_training; OPR-1 may start both
CalibrationThe latest cmms_calibration_record for the run's equipment is not due before the start date and not fail or out_of_tolerance; no record means no requirementStarting with a date in 2031 is refused; with a date in 2026 it is allowed
Lot statusA consumed lot must be released, not on hold or in quarantineRAW-L3 is on_hold: scanning it is refused and leaves no row
Bill of materialsThe consumed item must be an input of that operationWIP-BLANK cannot be consumed in OP10; it is an output there
Scan and quantityA scan-mode input needs verified_by_scan true, and a lot cannot be consumed past its qty_initialRAW-L1 has 860 KG left (1000 less 80 and 60): consuming 900 more is refused
Step orderA step record needs the previous step_no already recorded, and the run must be runningA record for step 3 before step 2 is refused
CompletionEvery scan-mode input has a consumption, every critical parameter has a value, every out-of-spec critical value has a step record with a deviation, every signature step is signed (its step record's performer_signature_id is set)Completion without the signature is refused
VerificationThe verifier cannot be the person who performed the stepA test that sets a step's verifier to its performer is refused (an operator cannot verify at all: the role has no update right on step records)

Two notes on how the database applies them. A role can only update rows it can read, so the operator's rights must include reading the qualification and calibration tables the interlocks consult; if they do not, every start is refused or, worse, the check finds nothing. Running as the operator, the checks also see only the operator's area, which is one reason the first scope is a single area. And a refusal leaves no trace behind: a rejected scan creates no consumption row, which is why the dispatch list and the lot balances stay true.

Parameters and steps

The operator sees one step at a time, with large targets: an instruction, a scan box, a number box with its limits and a colour for in or out of specification, a signature button and a pause button. A measured value is stored in mes_parameter_value with in_spec set by the database from the limits, inclusive of both: with limits of 119.5 and 120.5, a value of 120.5 is in specification and 120.51 is not. An out-of-spec critical value publishes mes.parameter.out_of_spec, and the run cannot complete until a deviation is recorded against it.

Material in, lots out: genealogy

Scanning a lot into a run writes a row to mes_material_consumption. Completing a run writes the lot it made to mes_material_production, and a row to the spine's core_lot_genealogy with relation consumed_into: it says the parent lot went into the child lot. Follow those links forward and you find every lot that used a material; follow them backward and you find everything that went into a lot. A lot made by a run is numbered order number, a dash and the operation code (PO-1001-OP10), so it is readable and unique, and its status is released, because this course builds no inspection hold.

Lot genealogyRaw lot RAW-L1 was consumed into two intermediate lots, PO-0900-OP10 and PO-0901-OP10, each consumed into a finished lot at depth 2. A second chain shows RAW-L2 into PO-1001-OP10 into PO-1001-OP20. Arrows are labelled with the quantity consumed. Depth 0 · raw lotDepth 1 · intermediateDepth 2 · finishedRAW-L1RM-STRIP, 1000 KGPO-0900-OP1040 EA WIP-BLANKPO-0900-OP2038 EA FG-BRACKET80 KG40 EAPO-0901-OP1030 EA WIP-BLANKPO-0901-OP2030 EA FG-BRACKET60 KG30 EATHE ORDER YOU RUN IN SESSION 4RAW-L2RM-STRIP, 1000 KGPO-1001-OP1098 EA WIP-BLANKPO-1001-OP2094 EA FG-BRACKET200 KG98 EAForward from RAW-L1 reaches four lots; backward from PO-1001-OP20 reaches PO-1001-OP10 and RAW-L2.
Genealogy from the seed. RAW-L1 went into two intermediate lots and then two finished lots. The order PO-1001, which you run in Session 4, adds a second chain from RAW-L2. Arrows are labelled with the quantity consumed.

A trace is a recursive query: it follows the links level by level until none are left, returns each lot with its depth and the run that linked it, and refuses to loop. The module's target is a full forward and backward trace across three levels in under one second on seeded data, and you time it in Session 4 with EXPLAIN ANALYZE (the command that runs a query and reports how long it took).

Signed step records and review by exception

The step records of a run are the module's electronic batch record or device history record. Each has a performer and, where the step requires it, a verifier, each with their own electronic signature (core_e_signature) that names the meaning (performed, verified or reviewed) and a hash that changes if one character of the signed content changes. US rules ask that electronic signatures be unique to a person and linked to their record [1], and that batch records show each significant step [2].

Reading every record of every run does not scale. Review by exception means a person reads only the runs that need it: one with an out-of-spec value or a deviation. A clean run is approved in one action. The specification also names overrides; this course builds no way to override an interlock or skip a step, so there are none to flag, and if you ever add one it must be flagged in the record like the others. The rule that makes this honest is that every exception is flagged in the record, so none can hide in a run that looks clean.

Exercise · Write the rules page20 minutes

You need: Your Session 1 inventory, the interlock table in this chapter, and a text editor open on docs/mes-rules.md in your repository

Session 4 builds the triggers from this page, so write it as rules a developer could not misread. Keep to one page.

Outcome: A docs/mes-rules.md with each interlock, its message, its status moves, its lot numbering, its seeded test, and the sign-off of two people from the floor.

Knowledge check

OPR-2 holds the SK-FORM skill only as in_training and tries to start OP20, which requires it. What happens?

Knowledge check

A scan-mode input is recorded with verified_by_scan false. What should happen?

References

  1. eCFR: Title 21, Part 11, Electronic records; electronic signatures. https://www.ecfr.gov/current/title-21/chapter-I/subchapter-A/part-11
  2. eCFR: Title 21, Part 211, current good manufacturing practice for finished pharmaceuticals (batch production records are in subpart J). https://www.ecfr.gov/current/title-21/chapter-I/subchapter-C/part-211
  3. Siemens: ISA-95 framework and layers. https://www.siemens.com/en-us/technology/isa-95-framework-layers/
  4. SYMESTIC: the 11 core MES functions (MESA-11), including dispatching, labour and genealogy. https://www.symestic.com/en-us/what-is/mesa-11

Chapter 4 · States, OEE and the ERP

Measure it, connect it, cut over

Machines report counts and states, people give reasons, and the module turns both into one figure per shift. This chapter fixes the time base that makes the figure honest, sends the result to the ERP, and ends with the tests that say the old tool can go.

25 min9 machine statesOEE 0.7500 on the seed3 done-when tests

By the end of this chapter you can

  • Map machine states to the module's nine states and say when a short stop is a micro-stop.
  • Calculate availability, performance, quality and OEE from one time base, by hand, to two decimals.
  • Describe how messages reach the ERP through the outbox, and what must be migrated at cut-over.

Machines report; the module records

Counts, states and process values reach the module through the spine's tag registry (core_data_tag). OPC UA (IEC 62541) is the standard way for a machine or gateway to publish values [1]; MQTT with Sparkplug B is a light publish and subscribe scheme with an agreed layout for industrial data [2]. A tag collector machine account posts them: counts go to mes_production_count, state changes to mes_equipment_state_event and parameter values to mes_parameter_value with source tag. Where no tag exists, the supervisor enters the shift's states on the downtime screen and its counts in a counts box (an operator may enter counts for their own run), with source manual, and the performance job calculates from those rows exactly as it does from tag rows.

The feed is safe to repeat. Every message carries an id made by the sender, which the route keeps in the row's ext as message_id; a message whose id is already stored is skipped, and a simulator that posts a fixed feed twice leaves the same rows. A tap sent twice from a phone with a poor signal behaves the same way, so counts and downtime are never doubled.

States, reasons and micro-stops

The module has nine equipment states: running, idle, starved, blocked, planned_down, unplanned_down, changeover, micro_stop and offline. A packaging line's machine publishes the PackML state model (ISA-TR88.00.02), and the module maps it as follows.

Machine reports (PackML)The module storesNeeds a reason?
ExecuterunningNo
Idle, CompleteidleNo
Held, Stopped, Abortedunplanned_downYes, unless shorter than the micro-stop threshold
Suspendedstarved (blocked, where the machine says its output is full)Yes, unless shorter than the micro-stop threshold
Starting, Stopping, Resetting, Holding, Completing and the other transitional states (names ending in -ing)the state stored before them, unchangedNo new reason
Anything else that cannot be mappedofflineNo

In PackML, Held is a stop for a condition inside the machine, and Suspended is a wait for something outside it, such as no input or a full output. Machines differ, so read the state list of your own machine and write its mapping on the rules page; the table is a starting point.

A blocked, starved or unplanned_down stop shorter than 2 minutes is stored as micro_stop and needs no reason. Two minutes is this course's own threshold, written in docs/mes-rules.md where you may change it. Micro-stops matter because they are too short for anyone to log and too frequent to ignore, so they are where lost time can hide unnoticed. A longer stop appears on the downtime screen until someone gives it a reason from core_reason_code, which marks each reason planned or not.

OEE on one time base

OEE (overall equipment effectiveness) is availability times performance times quality. ISO 22400-2 defines the manufacturing KPIs, and names the same three factors as availability, effectiveness and quality ratio [3]. The danger is not the formula; it is mixing time bases, so that availability is measured against the shift, performance against the run, and nobody can reproduce the figure. The module fixes one base, written on the rules page, for every figure.

FigureDefinition used in this course
Planned busy timeThe shift's minutes less its planned_down minutes
Run timeThe minutes in state running
AvailabilityRun time ÷ planned busy time
PerformanceIdeal cycle (std_cycle_sec of the operation at that work centre, from the definition effective when the shift started) × total count ÷ run time in seconds
QualityGood count ÷ total count
OEEAvailability × performance × quality, calculated from unrounded values
One shift of CELL-BA timeline of the 480-minute shift on CELL-B on 2 March 2026, drawn to scale: changeover 30 minutes, running 180, unplanned down 15, running 120, planned down 30, running 90, starved 15. Below it three bars to the same scale: the shift 480 minutes, planned busy time 450 and run time 390. 06:0007:0008:0009:0010:0011:0012:0013:0014:00changeover 30 minrunning 180 minunplanned_down 15 minrunning 120 minplanned_down 30 minrunning 90 minstarved 15 minTHE TIME BASES, TO THE SAME SCALEShift: 480 minPlanned busy time: 450 min (the shift less 30 planned_down)Run time: 390 min (the three running intervals)
One shift of CELL-B, to scale. Changeover and starved time stay inside planned busy time; only planned_down comes out of it. Run time is the three green intervals.
Availability, performance, quality and OEEFour bars to scale against 100 percent: availability 0.8667, performance 0.9000, quality 0.9615, and OEE as their product, 0.7500. 100%Availability390 min run ÷ 450 min planned busy0.8667Performance45 s × 468 counted ÷ (390 min × 60)0.9000Quality450 good ÷ 468 counted0.9615OEEthe product, from unrounded values0.7500
The three factors and their product. 390 of 450 planned minutes ran (0.8667); the press made 468 pieces in the time it could have made 520 at its ideal cycle (0.9000); 450 of those 468 were good (0.9615). OEE is 0.7500.

The numbers a plant manager asks for

KPIDefinition
OEE (ISO 22400)Availability × performance (effectiveness) × quality ratio
First-pass yieldGood units without rework ÷ units started
Scrap rateScrap quantity ÷ total produced
Cycle time vs standardActual run time per unit ÷ ideal cycle time
Schedule attainmentQuantity produced to plan ÷ planned quantity
Trace timeSeconds to complete a full forward and backward trace of a lot

Talking to the ERP

The ERP owns orders and plans. The schedule comes in as production orders (source erp, with the ERP's number in external_ref). Performance and material movements go out as B2MML-style messages: B2MML is the MESA set of schemas that carries ISA-95 messages, and a run or lot message is named ProductionPerformance [4]. A message is never sent from the middle of an operation. The completion writes an event to core_event_outbox in the same database transaction as the record it describes, so either both exist or neither does.

ERP exchange through the outboxTop: the ERP sends the production schedule into mes_production_order. Bottom: a completed run writes an event to core_event_outbox in the same transaction; the ERP publisher turns it into a B2MML-style ProductionPerformance message for the ERP, which ignores a repeated event id. If the ERP does not answer, the row keeps its attempts and error and is tried again. IN · the scheduleERPowns orders and plansmes_production_ordersource erp, ext. refOUT · what happenedRun completeslot made, counts incore_event_outboxsame transactionERP publishera machine accountB2MML-style messageProductionPerformanceERPignores a repeat idNo answer: attempts and last_error are filled in, published_at stays empty, the next run tries again.
Schedule in, performance out. The ERP publisher is a machine account that reads unpublished outbox rows, posts each as a message and sets published_at. If the ERP is down the row keeps its attempts and last error and is tried again; the message carries the event id so the ERP can ignore a repeat.

Cut over and retire the old tool

MES history is rarely migrated whole. Migrate the open orders, the product definitions and the last 12 to 24 months of genealogy for the traceability obligations you have; leave the rest in an export you can still open. Rows brought in this way carry ext holding imported_from. When the importer account (or the migration role that loads the seed) inserts them, they skip the signature rule, the draft-only rule and the insert checks on history, so a definition can arrive already effective with its operations; the same marker on a row from any other role is ignored, so it can never open an interlock. An import sends nothing to the ERP. Imported history (completed runs, consumptions, productions and genealogy) can never be changed afterwards; imported open orders and definitions follow the normal rules. Before cut-over check that every operation points to a real work centre and every lot link resolves.

Run the old and the new side by side for at least a week, then check three things before you cancel. A lot traces forward and backward across three levels in under one second on seeded data. An unqualified operator is blocked from starting an operation that requires a skill. OEE for a seeded shift matches a hand calculation to two decimals.

Exercise · OEE and a trace, by hand20 minutes

You need: Paper or a spreadsheet, and the numbers below (they are the Session 2 seed for CELL-B on Monday 2 March 2026)

The shift runs 06:00 to 14:00. State intervals: changeover 06:00 to 06:30; running 06:30 to 09:30; unplanned_down 09:30 to 09:45; running 09:45 to 11:45; planned_down 11:45 to 12:15; running 12:15 to 13:45; starved 13:45 to 14:00. Counts: good 225 with reject 9, good 150 with reject 6, good 75 with reject 3. The ideal cycle for the operation at this press is 45 seconds. Lot links (consumed_into): RAW-L1 into PO-0900-OP10 (80 KG); PO-0900-OP10 into PO-0900-OP20 (40 EA); RAW-L1 into PO-0901-OP10 (60 KG); PO-0901-OP10 into PO-0901-OP20 (30 EA).

Outcome: Written sums for planned busy time, run time, availability, performance, quality and OEE, and two traces, each lot with its depth. If your time base is the one on the rules page you will reach an OEE of 0.7500, four lots forward from RAW-L1 (two at depth 1, two at depth 2) and, backward from PO-0901-OP20, PO-0901-OP10 at depth 1 and RAW-L1 at depth 2.

Knowledge check

In the course's time base, availability is:

Knowledge check

Why must OEE be calculated from unrounded factors?

References

  1. OPC Foundation: OPC UA. https://opcfoundation.org/about/opc-technologies/opc-ua/
  2. Eclipse Sparkplug specification. https://sparkplug.eclipse.org/
  3. ISO 22400-2:2014, Key performance indicators for manufacturing operations management: definitions and descriptions. https://www.iso.org/standard/54497.html
  4. Automation World: the five parts of ISA-95 (Part 5, business-to-manufacturing transactions). https://www.automationworld.com/products/software/article/13309288/the-five-parts-of-isa-95

Chapter 5 · 12 questions · 80% passes

Final assessment

Twelve questions across the element. Score 80% (10 of 12) to pass. Your LMS records your score and each answer; you can review the chapters and try again.

15 min12 questions≈ 15 minutesRetake allowed

Choose one answer for each question, then submit. You will see the right answer and why for every question.

1. Which three verbs describe what an MES does?
2. A schedule arrives from the ERP and performance goes back to it. Which ISA-95 level is the system in the middle?
3. Which MESA function does this module leave to another module (M03)?
4. How is the MES kept from building a second equipment hierarchy?
5. A product definition's status is effective. What is the right way to change a limit on one of its parameters?
6. Why is mes_parameter_value.in_spec set by the database from the limits and not typed by the operator?
7. An operator whose SK-FORM qualification has expired tries to start OP20. What stops the start?
8. RAW-L1 had 1000 KG, with 80 KG and 60 KG consumed. What happens if a run tries to consume 900 KG more?
9. What does review by exception mean?
10. A mes_production_count row was keyed wrongly. How is it corrected?
11. On CELL-B the shift is 480 minutes with 30 minutes planned_down and 390 minutes running. What is availability?
12. Why does an MES message to the ERP come from an outbox row written in the same transaction as the record?