# `Sp_elematerials_BeforeUpdate` (procedure)

> 物料信息校验


- **Type:** PROCEDURE
- **Deterministic:** NO
- **SQL data access:** CONTAINS SQL

## Parameters

| # | Mode | Name | Type |
|---|---|---|---|
| 1 | IN | `sGuid` | `varchar(2000)` |
| 2 | IN | `sData` | `longtext` |
| 3 | IN | `sAllData` | `longtext` |
| 4 | IN | `sFormGuid` | `varchar(100)` |
| 5 | IN | `sLoginId` | `varchar(100)` |
| 6 | IN | `sBrId` | `varchar(100)` |
| 7 | IN | `sSuId` | `varchar(100)` |
| 8 | OUT | `sCode` | `int` |
| 9 | OUT | `sReturn` | `varchar(4000)` |

## Body

_Body is not pre-cached. To inspect: `mysql --defaults-file=~/.my.cnf -e 'SHOW CREATE PROCEDURE `Sp_elematerials_BeforeUpdate`'`._

## Narrative

**Business context:** 物料信息校验 (material-master pre-save guard). Two checks: (1) `paper`-class materials must have `dGramWeight > 0`, and (2) once a material has been referenced in any downstream document (期初/盘点/报价/工艺卡/销售订单/工单/采购订单/采购入库/材料出库/材料调整), key fields (`dGramWeight`, `sMaterialsUnit`, `sAuxiliaryUnit`, `iMetre`) can no longer be edited.

**What it does:** Walks `JSON_EXTRACT(sData, '$.elematerials')` per row. If `sMaterialsType='paper'` and `dGramWeight<=0`, aborts with `sEleMaterailsWeightError`. For `update`/`del` rows whose target `elematerials.sId` shows a changed weight/unit/spec/name, performs a sequence of `SELECT COUNT(1)` probes against 10 downstream tables (`mitmaterialsinitslave`, `mitmaterialscheckslave`, `QuoQuotationmaterials`, `mftproductmaterials`, `salsalesordermaterials`, `mftworkordermaterials`, `purpurchaseorderslave`, `purpurchaseinstoreslave`, `mitproductionmaterialsslave`, `mitmaterialsstoreadjustmentslave`); on first hit, aborts with `<BillName> + sEleMaterailsCantUpdate` and `sCode=-8`. Permission-bypass branch (commented out) would have skipped the check for users with `sftlogininfo.bBaseCnUpdat=1`.

**Invocation:** Status: appears orphaned via the standard hook channels — not bound to any `gdsmodule.sSaveProNameBefore`/`sSaveProName`, no form-master reference, no xly-src reference. Intra-DB reference is only `Sp_delete_backwriting` (which scans routine bodies for `_BeforeUpdate` naming patterns). The naming convention matches xly's pre-save validator slot for the 物料 (elematerials) form — likely intended as a tenant-override save guard that was never bound. Candidate for maintainer audit.
