# `Sp_beforeSave_sPmd` (procedure)

> 生产领料存前反写数量


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

## Parameters

| # | Mode | Name | Type |
|---|---|---|---|
| 1 | IN | `sGuid` | `varchar(2000)` |
| 2 | IN | `sBrId` | `varchar(100)` |
| 3 | IN | `sSuId` | `varchar(100)` |
| 4 | OUT | `sCode` | `int` |
| 5 | OUT | `sReturn` | `varchar(4000)` |

## Body

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

## Narrative

**Business context:** 物料领用流程 / 生产领料单据 (also `1/1 新增生产补料`, `生产退料单据`) — before-save dispatcher for the material-issue family. Wraps `sGuid` and delegates to `Sp_saveReturn_sPmd` to backwrite issued/returned quantities onto the upstream work-order / material-request documents before the master save commits.

**What it does:** Normalises `sGuid` to a quoted-CSV form, then `CALL Sp_saveReturn_sPmd(sGuid, sBrId, sSuId, 1, @sCode, @sReturn)`.

**Invocation:** Hooked as `gdsmodule.sSaveProNameBefore` on three modules — `1/1 新增生产补料` (sId `192116810113315222184074940`), `生产领料单据` (`192116810113315226492535760`), `生产退料单据` (`192116810113315226622476570`). Also called by dispatcher procs `Sp_Invalid_backwriting` and `Sp_delete_backwriting`; the dispatcher additionally routes 生产补料, 来料入库, and 生产退料 form-guids into this same proc on invalidate/delete.
