# `Sp_Calc_sMpa` (procedure) > 领料申请 - **Type:** PROCEDURE - **Deterministic:** NO - **SQL data access:** CONTAINS SQL ## Parameters | # | Mode | Name | Type | |---|---|---|---| | 1 | IN | `iFlag` | `int` | | 2 | IN | `iTmpCheck` | `int` | | 3 | IN | `sFormGuid` | `varchar(100)` | | 4 | IN | `sGuid` | `varchar(100)` | | 5 | IN | `sLoginId` | `varchar(100)` | | 6 | OUT | `sReturn` | `varchar(4000)` | | 7 | IN | `sBrId` | `varchar(100)` | | 8 | IN | `sSuId` | `varchar(100)` | | 9 | OUT | `sCode` | `int` | ## Body _Body is not pre-cached. To inspect: `mysql --defaults-file=~/.my.cnf -e 'SHOW CREATE PROCEDURE `Sp_Calc_sMpa`'`._ ## Narrative **Business context:** 生产执行 → MES单据 → 领料申请单据 / 补料申请单据 / 补版申请单据 — production material-pick-list audit / un-audit on `mitproductionapplymaster`/`mitproductionapplyslave`. Approving an apply locks the requested qty against the work-order, posts the picker KPI, and clears the matched semi-goods reservation. **What it does:** Validates `sGuid`, branches on `iFlag`. On `iFlag=1` flips `mitproductionapplymaster.bCheck=1` plus slave rows, writes a KPI row to `kpidetail`, `UPDATE MftWorkOrderMaterials` to back-write the applied qty onto the work-order's material slave, and `UPDATE sgdsemigoodsmatchbillmaterials` to consume the matched semi-goods reservation. `iFlag=0` reverses each. **Invocation:** Bound to `gdsmodule.sProcName` on three sibling modules under 生产执行 → MES单据: `领料申请单据`, `补料申请单据`, `补版申请单据` (all share `Sp_Check_sMpa` / `Sp_beforeSave_sMpa` too). Dispatched by Java `BusinessBaseServiceImpl.getPrcName(sFormGuid, …)` on the 审核/反审核 button — the three module slots share the same Sp_Calc but get differentiated downstream by the form sId. xly-src ships `script/标版/30100101/Sp_Calc_sMpa.sql` (install) and `script/标版/optimize/Sp_Calc_sMpa.sql` (perf patch).