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 based on grammar of a graphical editing tool; 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, the function code being generated just once for each said custom KPI resulting in a calculation function code, the calculation function code being compiled and compatible with runtime coding software and is runtime compiled programming; storing the calculation function code and the custom KPI; 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.