1. A method for calculating key performance indicators (KPI) within a manufacturing execution system, which comprises the steps of: defining a custom KPI set at engineering time; determining if the custom KPI set is valid, and if valid performing the following steps: automatically generating at the engineering time, through a software framework with support for code generation, a function code for calculating each custom KPI belonging to the custom KPI set; requesting, at runtime, a calculation of a given custom KPI belonging to the custom KPI set; and determining if a calculation request is valid, and if valid, at runtime, executing a calculation function code of the given custom KPI.