# Business Logic — JBSbatKKAdChgFinAddRun.addAdchgDtl() [31 LOC]

| Field | Value |
|-------|-------|
| Fully Qualified Name | `eo.business.service.JBSbatKKAdChgFinAddRun` |
| Layer | Batch (Service layer within batch processing) |
| Module | `service` (Package: `eo.business.service`) |

## 1. Role

### JBSbatKKAdChgFinAddRun.addAdchgDtl()

This method registers a **detail record** into the address change (住所変更) header table `KK_T_ADCHG_DTL` during the batch confirmation processing for courier changes (コース変更確定バッチ処理). Specifically, when the address change batch job finalizes a confirmed address change request, it creates a detail record that captures the business execution date (`opeDate`) as the post-change identification number (変更後識別番号). The address change number (住所変更番号, `adchgNo`) is carried forward as the parent key, while the detail number is auto-generated from the database sequence `SEQ_ADCHG_DTL_NO`.

The detail type code is hardcoded to `"08"` (住所変更明細種別コード — address change detail type code), indicating this is a standard address change detail record. All other fields — such as the pre-change identification number, service contract anomaly code, billing address change flag, work remarks, audit timestamps, operator account, invalid flag, and operation dates — are left as `null` since this particular batch operation only needs to record the execution date and the structural parent-child link between the address change header and its detail record.

The method follows a simple builder-and-delegate pattern: it constructs a parameter array and then delegates the actual database insert to `executeKK_T_ADCHG_DTL_PKINSERT`, which maps the array elements to key-value pairs and performs a primary-key-based insert on the `KK_T_ADCHG_DTL` table. It is called from within the `execute()` method of the same class, specifically when processing confirmed address changes during the batch run.

## 2. Processing Pattern (Detailed Business Logic)

```mermaid
flowchart TD
    START(["addAdchgDtl adchgNo"])
    START --> GET_SEQ["Generate next sequence newAdchgDtlNo from SEQ_ADCHG_DTL_NO via JBSbatOracleSeqUtil.getFormatedNextSeq"]
    GET_SEQ --> BUILD_ARRAY["Build String array setParam with 22 elements"]
    BUILD_ARRAY --> MAP_PARAMS["Map params 0 to 21
[0] adchgNo
[1] newAdchgDtlNo
[2] ADCHG_DTL_SBT_CD 08
[3] CHG_TG_KEI_NO null
[4] CHBF_SKBT_NO null
[5] CHAF_SKBT_NO opeDate
[6] SVC_KEI_IDO_SBT_CD null
[7-21] audit null"]
    MAP_PARAMS --> EXEC_INSERT["Call executeKK_T_ADCHG_DTL_PKINSERT setParam"]
    EXEC_INSERT --> END_NODE(["Return void"])
```

**CRITICAL — Constant Resolution:**

| Constant | Resolved Value | Business Meaning |
|----------|---------------|------------------|
| `"08"` | `"08"` | ADCHG_DTL_SBT_CD — Address Change Detail Type Code (standard address change detail record) |
| `SEQ_ADCHG_DTL_NO` | `"SEQ_ADCHG_DTL_NO"` | Oracle database sequence for generating formatted 7-digit address change detail numbers |

- The method has **no conditional branches** — it executes a fixed linear flow regardless of input values.
- The hardcoded `"08"` type code is resolved directly from the source code string literal.
- The sequence format uses 7-digit padding (width = 7).
- `opeDate` is an instance field inherited from the parent batch class, representing the batch execution date.

## 3. Parameter Analysis

| No | Parameter Name | Type | Business Description |
|----|---------------|------|---------------------|
| 1 | `adchgNo` | `String` | Address Change Number (住所変更番号) — the parent key identifying an address change header record. This links the newly created detail record to its parent address change request in `KK_T_ADCHG_DTL`. |

**Instance fields read by this method:**

| No | Field Name | Type | Business Description |
|----|-----------|------|---------------------|
| 1 | `opeDate` | `String` | Operational execution date (変更後識別番号) — used as the post-change identification number. Inherited from the parent batch class; represents the batch processing date. |

## 4. CRUD Operations / Called Services

### Pre-computed evidence from code analysis graph:

| CRUD | SC / CBS | SC Code | Entity / DB | Operation Description |
|------|----------|---------|-------------|----------------------|
| R | `JBSbatOracleSeqUtil.getFormatedNextSeq` | JBSbatOracleSeq | SEQ_ADCHG_DTL_NO | Retrieves the next formatted 7-digit sequence number from the Oracle database sequence `SEQ_ADCHG_DTL_NO` for generating the detail number |
| C | `executeKK_T_ADCHG_DTL_PKINSERT` | JBSbatKKAdChgFinAddRun | KK_T_ADCHG_DTL | Inserts a new record into the address change detail table using primary keys (all fields set as key-value pairs) |

### Per-method analysis:

| CRUD | SC / CBS | SC Code | Entity / DB | Operation Description |
|------|----------|---------|-------------|----------------------|
| R | `JBSbatOracleSeqUtil.getFormatedNextSeq` | JBSbatOracleSeqUtil | SEQ_ADCHG_DTL_NO | Reads next sequence value from Oracle; generates a 7-digit zero-padded address change detail number |
| C | `executeKK_T_ADCHG_DTL_PKINSERT` | JBSbatKKAdChgFinAddRun | KK_T_ADCHG_DTL | Creates a new address change detail record by mapping 22 parameter values to column keys and inserting via primary key |

## 5. Dependency Trace

### Pre-computed evidence from code analysis graph:

No screen/batch entry points found within 8 hops. Direct callers found: 1 method.
Terminal operations from this method: `executeKK_T_ADCHG_DTL_PKINSERT` [C], `getFormatedNextSeq` [R]  # NOSONAR

| # | Caller (Screen/Batch) | Call Chain (Full Path to this Method) | Terminal (SC / CRUD / Entity) |
|---|----------------------|--------------------------------------|-------------------------------|
| 1 | Batch:JBSbatKKAdChgFinAddRun | `execute(inAdchgNo)` -> `addAdchgDtl(inAdchgNo)` | `executeKK_T_ADCHG_DTL_PKINSERT [C] KK_T_ADCHG_DTL` |

**Caller context:**
The `execute()` method of `JBSbatKKAdChgFinAddRun` calls `addAdchgDtl(inAdchgNo)` within the address change processing block (`if (!(isBlank(inAdchgNo) || isBlank(inAdchgUpdDtm)))`). The calling comment reads: "住所変更明細の登録処理 / コース変更確定バッチ処理用の確定時運用日付を保存する" (Address change detail registration processing / Stores the confirmation-time operational date for courier change confirmation batch processing).

## 6. Per-Branch Detail Blocks

**Block 1** — [SEQUENCE GENERATION] (L1538)

> Generates the next detail number for the address change detail record from the Oracle database sequence.

| # | Type | Code |
|---|------|------|
| 1 | SET | `newAdchgDtlNo = JBSbatOracleSeqUtil.getFormatedNextSeq(commonItem.getConnection(), "SEQ_ADCHG_DTL_NO", "", 7)` // Generates formatted 7-digit sequence number for address change detail |

**Block 2** — [ARRAY INITIALIZATION] (L1539–L1560)

> Builds a 22-element parameter array. Each element maps to a column in the `KK_T_ADCHG_DTL` table. Only 3 of the 22 fields have non-null values.

| # | Type | Code |
|---|------|------|
| 1 | SET | `setParam[0] = adchgNo` // 住所変更番号 (Address Change Number) |
| 2 | SET | `setParam[1] = newAdchgDtlNo` // 住所変更明細番号 (Address Change Detail Number) |
| 3 | SET | `setParam[2] = "08"` // [ADCHG_DTL_SBT_CD = "08"] 住所変更明細種別コード (Address Change Detail Type Code) |
| 4 | SET | `setParam[3] = null` // 変更対象契約番号 (Change Target Contract Number) |
| 5 | SET | `setParam[4] = null` // 変更前識別番号 (Pre-change Identification Number) |
| 6 | SET | `setParam[5] = opeDate` // 変更後識別番号 (Post-change Identification Number — batch execution date) |
| 7 | SET | `setParam[6] = null` // サービス契約異動種別コード (Service Contract Anomaly Type Code) |
| 8 | SET | `setParam[7] = null` // 請求書送付先変更有無 (Billing Address Change Flag) |
| 9 | SET | `setParam[8] = null` // 住所変更業務連絡備考 (Address Change Work Contact Remarks) |
| 10 | SET | `setParam[9] = null` // 登録年月日時刻分秒 (Registration Timestamp) |
| 11 | SET | `setParam[10] = null` // 登録オペレータアカウント (Registration Operator Account) |
| 12 | SET | `setParam[11] = null` // 更新年月日時刻分秒 (Update Timestamp) |
| 13 | SET | `setParam[12] = null` // 更新オペレータアカウント (Update Operator Account) |
| 14 | SET | `setParam[13] = null` // 削除年月日時刻分秒 (Deletion Timestamp) |
| 15 | SET | `setParam[14] = null` // 削除オペレータアカウント (Deletion Operator Account) |
| 16 | SET | `setParam[15] = null` // 無効フラグ (Invalid Flag) |
| 17 | SET | `setParam[16] = null` // 登録運用年月日 (Registration Operation Date) |
| 18 | SET | `setParam[17] = null` // 登録処理ID (Registration Process ID) |
| 19 | SET | `setParam[18] = null` // 更新運用年月日 (Update Operation Date) |
| 20 | SET | `setParam[19] = null` // 更新処理ID (Update Process ID) |
| 21 | SET | `setParam[20] = null` // 削除運用年月日 (Deletion Operation Date) |
| 22 | SET | `setParam[21] = null` // 削除処理ID (Deletion Process ID) |

**Block 3** — [DELEGATE INSERT] (L1561)

> Delegates the database insert to `executeKK_T_ADCHG_DTL_PKINSERT`, which maps the parameter array to column keys and performs a primary-key-based insert on `KK_T_ADCHG_DTL`.

| # | Type | Code |
|---|------|------|
| 1 | CALL | `executeKK_T_ADCHG_DTL_PKINSERT(setParam)` // Inserts address change detail record into KK_T_ADCHG_DTL table |

## 7. Glossary

| Term | Type | Business Meaning |
|------|------|------------------|
| `adchgNo` | Field | Address Change Number (住所変更番号) — unique identifier for an address change request/record |
| `adchgDtlNo` | Field | Address Change Detail Number (住所変更明細番号) — unique identifier for a detail record within an address change |
| `ADCHG_DTL_SBT_CD` | Field | Address Change Detail Type Code (住所変更明細種別コード) — classifies the type of address change detail; "08" indicates a standard detail record |
| `opeDate` | Field | Operational Execution Date (変更後識別番号) — the batch processing date used as the post-change identification number |
| `KK_T_ADCHG_DTL` | Entity/DB | Address Change Detail Table — stores detail-level records of address change requests |
| `SEQ_ADCHG_DTL_NO` | Constant | Database sequence for generating formatted 7-digit address change detail numbers |
| `CHG_TG_KEI_NO` | Field | Change Target Contract Number (変更対象契約番号) — identifies which contract is being changed |
| `CHBF_SKBT_NO` | Field | Pre-change Identification Number (変更前識別番号) — the identifier before the address change |
| `CHAF_SKBT_NO` | Field | Post-change Identification Number (変更後識別番号) — the identifier after the address change |
| `SVC_KEI_IDO_SBT_CD` | Field | Service Contract Anomaly Type Code (サービス契約異動種別コード) — codes for service contract status anomalies |
| `SKS_SHS_CHG_UM` | Field | Billing Address Change Flag (請求書送付先変更有無) — whether the billing invoice delivery address changed |
| `ADD_DTM` / `UPD_DTM` / `DEL_DTM` | Field | Registration/Update/Deletion Timestamp (登録年月日時刻分秒 / 更新年月日時刻分秒 / 削除年月日時刻分秒) — audit timestamps for CRUD operations |
| `ADD_OPEACNT` / `UPD_OPEACNT` / `DEL_OPEACNT` | Field | Registration/Update/Deletion Operator Account — audit fields tracking which operator performed each action |
| `MK_FLG` | Field | Invalid Flag (無効フラグ) — flag indicating if the record is marked as invalid |
| `ADD_UNYO_YMD` / `UPD_UNYO_YMD` / `DEL_UNYO_YMD` | Field | Registration/Update/Deletion Operation Date — operation-level date tracking |
| `ADD_TRN_ID` / `UPD_TRN_ID` / `DEL_TRN_ID` | Field | Registration/Update/Deletion Process ID — transaction IDs for audit trail |
| Address Change (住所変更) | Business term | Customer address change process — a core telecom service where a subscriber changes their registered address, requiring updates across multiple service contracts |
| Batch Confirmation (確定バッチ処理) | Business term | Batch processing job that finalizes pending changes; confirms and commits address change requests that were previously staged as tentative records |
| Courier Change (コース変更) | Business term | Change of the customer's service plan/courier package — a service modification in the telecom domain |
| JBSbatKKAdChgFinAddRun | Class | Address Change Final Addition Run — a batch service class that handles the finalization and registration of address change requests |
| `executeKK_T_ADCHG_DTL_PKINSERT` | Method | Primary-key-based insert for the KK_T_ADCHG_DTL table — maps parameter values to column keys and performs the database insert |
