# `Sp_System_ReplaceField_NEW` (procedure)

> 公式语言转换成sql


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

## Parameters

| # | Mode | Name | Type |
|---|---|---|---|
| 1 | IN | `sAllGuid` | `longtext` |
| 2 | IN | `sAllTbName` | `longtext` |
| 3 | IN | `sAllType` | `longtext` |
| 4 | IN | `sFormulaGuid` | `varchar(100)` |
| 5 | OUT | `sReturn` | `longtext` |
| 6 | IN | `sTmpValue` | `varchar(100)` |
| 7 | OUT | `sDetail` | `longtext` |
| 8 | IN | `sLoginId` | `varchar(100)` |
| 9 | IN | `sBrId` | `varchar(100)` |
| 10 | IN | `sSuId` | `varchar(100)` |
| 11 | OUT | `sCode` | `int` |
| 12 | IN | `sSlaveGuid` | `varchar(100)` |

## Body

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

## Narrative

**Business context:** 生产管理 → 工单/排产 — formula-language → SQL transpiler (label "公式语言转换成sql"). `_NEW` is the upgraded version of `Sp_System_ReplaceField` shipped by `script/标版/upgrade/20220321计算获取公式解析/`: same eight context-table convention (单据主/从/工序/材料/控制 + 基础产品/材料/工序/客户/供应商/机台/税率/销售员/付款), but adds an extra `sSlaveGuid` parameter so the formula can resolve slave-row scope alongside the master.

**What it does:** Loads `SysSystemSettings` (`CbxLanguage`, `CbxMaterialsUnit`, `CbxMachineUnit`, `NetConversionRate`, `CkxMinColorCalculation`) into a JSON env, reads language-specific labels from `gdsformconst`, then expands the formula stored in `eleformula` keyed by `sFormulaGuid`. For each `#{tableTag.column}` token, looks up the table+id mapping from `sAllGuid`/`sAllTbName`/`sAllType`, reads the column value, substitutes it into the SQL expression. Resulting dynamic SQL is run via PREPARE/EXECUTE; numeric result lands in `sReturn`, per-step trace into `sDetail`.

**Invocation:** Status: appears orphaned. No `gdsmodule` binding, no form-master, no other-proc match (only `Sp_CalcPlan_dHour` calls the `_Detail` sibling). xly-src has the upgrade install scripts (`upgrade/20220321计算获取公式解析/Sp_System_ReplaceField_NEW.sql` and `30100101/Sp_System_ReplaceField_NEW.sql`) but no caller. Likely the 2022 upgrade defined the new signature but the dispatch sites were never re-wired off the original `Sp_System_ReplaceField`. Candidate for maintainer audit.
