# `Sp_Calc_sMaterialsBgd` (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(5000)` | | 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_sMaterialsBgd`'`._ ## Narrative **Business context:** 生产管理 → 生产单据 → 材料变更单 — material change-order audit / un-audit on `mftprocesschangemaster`. The 材料变更单 lets shop-floor users swap or re-spec the material attached to a 工单 (work order) mid-flight; auditing the change locks the new selection and propagates it into the downstream work-order material rows. **What it does:** Defaults the IN params, branches on `iFlag`. On `iFlag=1` it flips `mftprocesschangemaster.bCheck=1` with audit person/date, and `UPDATE mftworkordermaterials` to back-write the swapped material/qty onto the affected work-order slave rows; also re-evaluates `EleMaterialsStock` with `INSERT INTO EleMaterialsStock` to refresh the on-hand snapshot for the new material. `iFlag=0` reverses the slave back-write and re-evaluates stock. **Invocation:** Bound to `gdsmodule.sProcName` on `材料变更单` (sId `101251240115016119087978230`) under 生产管理 → 生产单据. Dispatched by Java `BusinessBaseServiceImpl.getPrcName(sFormGuid, …)` on the 审核/反审核 button. xly-src ships `script/标版/30100101/Sp_Calc_sMaterialsBgd.sql` (install) and `script/标版/optimize/Sp_Calc_sMaterialsBgd.sql` (perf patch) — verify which is deployed.