# `Sp_beforeSave_sOpn` (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_sOpn`'`._

## Narrative

**Business context:** Outsourcing-arrivals — before-save delegator for the `发外到货` (outsourced-arrival) document. Wraps `sGuid` and forwards to `Sp_saveReturn_sOpn` to backwrite arrival quantities onto the upstream `工序发外` documents before the master save commits. Comment header: `发外到货存前反写数量`.

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

**Invocation:** No `gdsmodule` hook in the live DB. Called by dispatcher procs `Sp_Invalid_backwriting` and `Sp_delete_backwriting` to replay the writeback on invalidate/delete (each dispatcher contains 2 call sites covering different document codes that share this writer). Install script: `xly-src/script/标版/30100101/Sp_beforeSave_sOpn.sql`.

Flag: master-save coverage relies on dispatchers; the `发外到货` form-master is expected to wire its `sSaveProNameBefore` to this name but the slot is empty in this DB.
