# `Sp_beforeSave_sPtr` (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_sPtr`'`._

## Narrative

**Business context:** 出库管理 / 成品领用单据 — before-save dispatcher reached for finished-goods issue documents. Targets `Sp_saveReturn_sPtr`. Body retains ~2.5K chars of commented-out legacy fallback SQL that aggregated `pitproductrejectslave.dProductQty` into `salchildproductapplyslave.dProductOutStoreQty`.

**What it does:** Declares unused `sDeliverSrc` local, normalises `sGuid` to a quoted-CSV form, then `CALL Sp_saveReturn_sPtr(sGuid, sBrId, sSuId, 1, @sCode, @sReturn)` (always — no `IF sGuid IS NOT EMPTY` guard, unlike sibling procs).

**Invocation:** **Not** hooked on any `gdsmodule` row directly. Reached only via dispatcher proc `Sp_delete_backwriting` when `sFormGuid = '101251240115015920999005840'` (resolves to `成品领用单据` in `gdsmodule`); **not** referenced by `Sp_Invalid_backwriting` — invalidate path does not replay this writeback.

Flag for maintainer audit: the dispatcher comment annotates this branch as `成品报废` but the actual form-guid `101251240115015920999005840` resolves to `成品领用单据` in `gdsmodule` — the proc's own doctype hint (`成品报废`, per the wiki header / commented legacy SQL targeting `pitproductrejectslave`) disagrees with the live form-guid mapping. Either the comment is stale or the dispatcher routes the wrong doctype.
