# `Sp_SetUpSubjectAssociate` (procedure)


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

## Parameters

| # | Mode | Name | Type |
|---|---|---|---|
| 1 | IN | `sProInParam` | `varchar(10000)` |
| 2 | IN | `sMakePerson` | `varchar(100)` |
| 3 | IN | `sBrId` | `varchar(100)` |
| 4 | IN | `sSuId` | `varchar(100)` |
| 5 | OUT | `sReturn` | `varchar(1000)` |
| 6 | OUT | `sCode` | `int` |

## Body

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

## Narrative

**Business context:** 财务管理 → 凭证 / 科目设置 — generic-dispatch BtnEvent on the 科目 (subject / chart-of-accounts) grid. The button takes a set of `sissubject` rows already configured with `sSubject1..6` and `sThirdNo`, and propagates those values to every other `sissubject` row sharing the same `sFormId` (form-binding) that has the slot still empty. Effect: "apply this subject's account mapping to every other entry of the same business form".

**What it does:** Parses the standard `$.params[*].value[*].sId` JSON. For each `sId` it `SELECT ... INTO p_sFormId, p_sSubject1..6, p_sThirdNo FROM sissubject` then `UPDATE sissubject SET sSubject{1..6} = IF(IFNULL(sSubject{N},'')='', p_sSubject{N}, sSubject{N}), sThirdNo = IF(IFNULL(sThirdNo,'')='', p_sThirdNo, sThirdNo) WHERE sFormId = p_sFormId` (scoped to the calling `sBrId` / `sSuId`). If the source row has no `sFormId` it aborts with the localised `paramsErro` message from `Fun_Sis_GetConst`.

**Invocation:** Dispatched dynamically by `GenericProcedureCallServiceImpl.doGenericProcedureCall()` (POST `/procedureCall/doGenericProcedureCall`) — a 设置科目关联 toolbar button on the 科目 grid names `Sp_SetUpSubjectAssociate` as the action. xly-src ships `script/标版/30100101/Sp_SetUpSubjectAssociate.sql` and the original 2021-11-15 upgrade `script/标版/upgrade/20211115生成凭证/Sp_SetUpSubjectAssociate.sql`.
