# `Sp_saveReturn_sMpa` (procedure)

> 新增领料申请反写


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

## Parameters

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

## Body

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

## Narrative

**Business context:** 生产执行 → MES单据 → 领料申请单据 / 补料申请单据 / 补版申请单据 — when a 领料申请 (or its 补料/补版 cousins) is saved, back-writes the requested material qty onto the source 生产工单 BOM row (`MftWorkOrderMaterials`) so the work-order's already-requested column stays accurate.

**What it does:** Splits `sGuid` into `p_t_sId`, looks up each line's `sSrcSlaveId` into `p_sSrcSlaveId_tmp`, sums the requested qty (with `iTag=1` zeroing the in-flight batch) into `t_data_temp`, then updates `MftWorkOrderMaterials` rows whose `sId = sSrcSlaveId` with the accumulated apply qty.

**Invocation:** Called by `Sp_beforeSave_sMpa` (`iTag=1`) and `Sp_afterSave_sMpa` (`iTag=2`). The beforeSave wrapper is bound on `gdsmodule.sSaveProNameBefore` for three forms under 生产执行 → MES单据 → 领料申请单据 (`101251240115016056026128440`), 补料申请单据 (`12012615914116395420093200`), and 补版申请单据 (`12012615914116395420566910`) — dispatched by `BusinessBaseServiceImpl`. `Sp_Invalid_backwriting` / `Sp_delete_backwriting` re-route to `Sp_beforeSave_sMpa` for these form ids on cancel/delete. No xly-src callers.
