---
# Business Logic — JBSbatKKAdChgAddDataCst.getLogMsgKojiStop() [44 LOC]

| Field | Value |
|-------|-------|
| Fully Qualified Name | `eo.business.service.JBSbatKKAdChgAddDataCst` |
| Layer | Service Component (CC / Common Component) |
| Module | `service` (Package: `eo.business.service`) |

## 1. Role

### JBSbatKKAdChgAddDataCst.getLogMsgKojiStop()

This method acquires a structured log message containing the SYSID and service contract numbers associated with a residence change record (`adchgNo`). It is used to enrich batch processing log output during post-completion (completion/stop) processing (`KojiStop`), enabling operators to quickly identify which service contracts and system identifiers are involved in a given residence change operation. The method iterates through the residence change detail table (`KK_T_ADCHG_DTL`), filtering for service contract detail sub-type (`ADCHG_DTL_SBT_CD_SVC_KEI_NO = "01"`), and interprets each row based on the before-change (`CHBF_SKBT_NO`) and after-change (`CHAF_SKBT_NO`) service contract numbers. It handles three business scenarios per row: **addition** (`Tsuka` — service contract newly added), **cancellation/retention** (`Kaiyaku/Horyu` — service contract cancelled or retained), and **transfer** (`Hikiki` — service contract transferred, where the before and after numbers may be the same or different). The SYSID is extracted from the service contract header table (`KK_T_SVC_KEI`) only once, using the first valid service contract number encountered. Finally, it returns a single formatted log string containing the SYSID and all service contract numbers involved, enabling comprehensive audit trail logging.

## 2. Processing Pattern (Detailed Business Logic)

```mermaid
flowchart TD
    START(["getLogMsgKojiStop"])
    INIT["Initialize msgSvcKei, sysId"]
    SELECT["executeKK_T_ADCHG_DTL_KK_SELECT_003"]
    DBLOOP["db_KK_T_ADCHG_DTL.selectNext()"]
    CHECK_NULL["adchgDtl == null?"]
    BREAK["break"]
    EXTRACT["Extract motoSvcKeiNo, sakiSvcKeiNo"]
    BOTH_NULL["both null?"]
    CONTINUE["continue"]
    ONE_NULL["one null?"]
    ADD_BRANCH["moto null: use saki, append msg"]
    CANCEL_BRANCH["saki null: use moto, append msg"]
    BOTH_EXIST["both present: transfer"]
    SAME_CHECK["moto equals saki?"]
    APPEND_SAME["append same number msg"]
    APPEND_TRANSFER["append transfer msg with both numbers"]
    SET_MOTO["svcKeiNo = motoSvcKeiNo"]
    CHECK_SYSID["sysId empty?"]
    GET_SYSID["sysId = getSysId(svcKeiNo)"]
    RETURN["return SYSID + msgSvcKei"]
    END_NODE(["End"])

    START --> INIT --> SELECT --> DBLOOP
    DBLOOP --> CHECK_NULL
    CHECK_NULL -->|Yes| BREAK
    BREAK --> END_NODE
    CHECK_NULL -->|No| EXTRACT
    EXTRACT --> BOTH_NULL
    BOTH_NULL -->|Yes| CONTINUE
    CONTINUE --> DBLOOP
    BOTH_NULL -->|No| ONE_NULL
    ONE_NULL -->|Yes| ADD_BRANCH
    ADD_BRANCH --> BOTH_EXIST
    ONE_NULL -->|No| BOTH_EXIST
    BOTH_EXIST --> SAME_CHECK
    SAME_CHECK -->|Yes| APPEND_SAME
    SAME_CHECK -->|No| APPEND_TRANSFER
    APPEND_SAME --> SET_MOTO
    APPEND_TRANSFER --> SET_MOTO
    SET_MOTO --> CHECK_SYSID
    CHECK_SYSID -->|Yes| GET_SYSID
    GET_SYSID --> DBLOOP
    CHECK_SYSID -->|No| DBLOOP
    END_NODE --> RETURN
```

**CRITICAL — Constant Resolution:**
- `ADCHG_DTL_SBT_CD_SVC_KEI_NO = "01"` (Business meaning: Residence Change Detail Sub-Type — Service Contract). This constant is defined in `JKKTchishoMapperCC` and `JKKTchishoAddCC` as a static final string. It identifies rows in the residence change detail table that pertain to service contract line items.

## 3. Parameter Analysis

| No | Parameter Name | Type | Business Description |
|----|---------------|------|---------------------|
| 1 | `adchgNo` | `String` | Residence change number — the unique identifier for a residence change operation. This key is used to look up all related detail records in the `KK_T_ADCHG_DTL` table. It identifies a specific residence change event in the telecom billing system. |
| - | `db_KK_T_ADCHG_DTL` | `JBSbatCommonDBInterface` | Instance field — Database handle for the `KK_T_ADCHG_DTL` (Residence Change Detail) table. Used by `selectNext()` to iterate through queried records. |
| - | `ADCHG_DTL_SBT_CD_SVC_KEI_NO` | `String` (constant) | Residence change detail sub-type code for service contracts. Value = `"01"`. Used to filter the query to only service-contract-related detail rows. |

## 4. CRUD Operations / Called Services

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

| CRUD | SC / CBS | SC Code | Entity / DB | Operation Description |
|------|----------|---------|-------------|----------------------|
| R | `JBSbatKKAdChgAddDataCst.executeKK_T_ADCHG_DTL_KK_SELECT_003` | - | `KK_T_ADCHG_DTL` | Executes a database SELECT query on the residence change detail table, filtered by `adchgNo` and sub-type code `"01"` (service contract details). Sets up the cursor for iteration via `db_KK_T_ADCHG_DTL.selectNext()`. |
| R | `db_KK_T_ADCHG_DTL.selectNext` | - | `KK_T_ADCHG_DTL` | Iterates through the result set of the previously executed SELECT query, returning the next residence change detail row as a `JBSbatCommonDBInterface` object. Returns `null` when no more rows exist. |
| R | `JBSbatCommonDBInterface.getString` (CHBF_SKBT_NO) | - | `KK_T_ADCHG_DTL` | Reads the before-change service contract number (`CHBF_SKBT_NO`) from the current detail row. |
| R | `JBSbatCommonDBInterface.getString` (CHAF_SKBT_NO) | - | `KK_T_ADCHG_DTL` | Reads the after-change service contract number (`CHAF_SKBT_NO`) from the current detail row. |
| R | `JBSbatKKAdChgAddDataCst.getSysId` | - | `KK_T_SVC_KEI` | Delegates to `getSysId()` to look up the SYSID from the service contract header table using a service contract number. |
| R | `JBSbatKKAdChgAddDataCst.getSysId` (internal) | - | `KK_T_SVC_KEI` | Executes `db_KK_T_SVC_KEI.selectBySqlDefine()` with SQL define `KK_T_SVC_KEI_KK_SELECT_023` and reads `JBSbatKK_T_SVC_KEI.SYSID` from the result. |

## 5. Dependency Trace

The callers of `getLogMsgKojiStop` across the codebase are found to be commented-out calls in several batch information service classes. The method is defined in `JBSbatKKAdChgAddDataCst` and also has duplicate implementations in other batch classes that share the same batch processing pattern.

| # | Caller (Screen/Batch) | Call Chain (Full Path to this Method) | Terminal (SC / CRUD / Entity) |
|---|----------------------|--------------------------------------|-------------------------------|
| 1 | Batch: JBSbatKKAdChgAddDataCst | `JBSbatKKAdChgAddDataCst.getLogMsgKojiStop` (commented out in caller, L320) | `executeKK_T_ADCHG_DTL_KK_SELECT_003 [R] KK_T_ADCHG_DTL`, `getSysId [R] KK_T_SVC_KEI` |
| 2 | Batch: JBSbatKKPlaceNoChgRnkiInfCst | `JBSbatKKPlaceNoChgRnkiInfCst.getLogMsgKojiStop` (own copy, L853) | `executeKK_T_ADCHG_DTL_KK_SELECT_003 [R] KK_T_ADCHG_DTL`, `getSysId [R] KK_T_SVC_KEI` |
| 3 | Batch: JBSbatKKFmtcelSodUpdInfCst | `JBSbatKKFmtcelSodUpdInfCst.getLogMsgKojiStop` (own copy, L565) | `executeKK_T_ADCHG_DTL_KK_SELECT_003 [R] KK_T_ADCHG_DTL`, `getSysId [R] KK_T_SVC_KEI` |
| 4 | Batch: JBSbatKKSodUpdInfCst | `JBSbatKKSodUpdInfCst.getLogMsgKojiStop` (own copy, L1060) | `executeKK_T_ADCHG_DTL_KK_SELECT_003 [R] KK_T_ADCHG_DTL`, `getSysId [R] KK_T_SVC_KEI` |
| 5 | Batch: JBSbatKKSmtvlRnkiInfCst | `JBSbatKKSmtvlRnkiInfCst.getLogMsgKojiStop` (own copy, L518) | `executeKK_T_ADCHG_DTL_KK_SELECT_003 [R] KK_T_ADCHG_DTL`, `getSysId [R] KK_T_SVC_KEI` |

Note: All callers have the actual call to `getLogMsgKojiStop` commented out (prefixed with `//`), suggesting this method was prepared for future use or is part of an in-progress refactoring of batch completion logging.

## 6. Per-Branch Detail Blocks

**Block 1** — [SET] (L2399)

> Initialize local variables for building the log message.

| # | Type | Code |
|---|------|------|
| 1 | SET | `String msgSvcKei = ""` // Log message accumulator for service contract numbers |
| 2 | SET | `String sysId = ""` // SYSID placeholder, populated once during iteration |

**Block 2** — [CALL] (L2403)

> Query the residence change detail table for service contract sub-type records.

| # | Type | Code |
|---|------|------|
| 1 | CALL | `executeKK_T_ADCHG_DTL_KK_SELECT_003(new String[]{adchgNo, ADCHG_DTL_SBT_CD_SVC_KEI_NO})` // [-> ADCHG_DTL_SBT_CD_SVC_KEI_NO = "01"] — Residence change detail sub-type: Service Contract |

**Block 3** — [WHILE] (L2404) `while (true)`

> Iterate through all matching residence change detail records.

| # | Type | Code |
|---|------|------|
| 1 | EXEC | `JBSbatCommonDBInterface adchgDtl = db_KK_T_ADCHG_DTL.selectNext()` // Fetch next row from query result set |

**Block 4** — [IF] `(adchgDtl == null)` (L2406)

> Exit loop when no more records exist.

| # | Type | Code |
|---|------|------|
| 1 | CONTROL | `break` // End the while loop — all detail records processed |

**Block 5** — [SET] (L2408-L2410)

> Extract before-change and after-change service contract numbers from the current detail row.

| # | Type | Code |
|---|------|------|
| 1 | SET | `String motoSvcKeiNo = adchgDtl.getString(JBSbatKK_T_ADCHG_DTL.CHBF_SKBT_NO)` // [-> CHBF_SKBT_NO = "CHBF_SKBT_NO"] — Before-change service contract number |
| 2 | SET | `String sakiSvcKeiNo = adchgDtl.getString(JBSbatKK_T_ADCHG_DTL.CHAF_SKBT_NO)` // [-> CHAF_SKBT_NO = "CHAF_SKBT_NO"] — After-change service contract number |
| 3 | SET | `String svcKeiNo = null` // Intermediate variable for the effective service contract number |

**Block 6** — [IF] `(motoSvcKeiNo == null && sakiSvcKeiNo == null)` (L2412)

> Both numbers are null — skip this record. This represents a detail row where neither the before nor after service contract number is set (possibly a placeholder or orphaned record).

| # | Type | Code |
|---|------|------|
| 1 | CONTROL | `continue` // Skip to next iteration |

**Block 7** — [IF] `(motoSvcKeiNo == null || sakiSvcKeiNo == null)` (L2414)

> One of the numbers is null — this is an addition (`Tsuka`), cancellation (`Kaiyaku`), or retention (`Horyu`) operation.

**Block 7.1** — [IF] `(motoSvcKeiNo == null)` (L2416)

> Before-change is null, after-change has a value = Addition (`Tsuka`).

| # | Type | Code |
|---|------|------|
| 1 | SET | `svcKeiNo = sakiSvcKeiNo` // Effective number is the after-change number |
| 2 | EXEC | `msgSvcKei += " サービス契約番号:" + svcKeiNo` // [-> Japanese: "サービス契約番号:" = "Service contract number:"] |

**Block 7.2** — [ELSE] (L2418)

> After-change is null, before-change has a value = Cancellation or Retention (`Kaiyaku`/`Horyu`).

| # | Type | Code |
|---|------|------|
| 1 | SET | `svcKeiNo = motoSvcKeiNo` // Effective number is the before-change number |
| 2 | EXEC | `msgSvcKei += " サービス契約番号:" + svcKeiNo` // [-> Japanese: "サービス契約番号:" = "Service contract number:"] |

**Block 8** — [ELSE] (L2424)

> Both numbers are present = Transfer (`Hikiki`) operation.

**Block 8.1** — [IF] `(motoSvcKeiNo.equals(sakiSvcKeiNo))` (L2426)

> Before and after numbers are the same — this is a same-contract transfer (e.g., address change without contract number change).

| # | Type | Code |
|---|------|------|
| 1 | EXEC | `msgSvcKei += " サービス契約番号:" + motoSvcKeiNo` // [-> Japanese: "サービス契約番号:" = "Service contract number:"] — single number in msg |

**Block 8.2** — [ELSE] (L2429)

> Before and after numbers differ — this is a cancellation + new contract (`Hikiki: Kaiyaku + Shinki`).

| # | Type | Code |
|---|------|------|
| 1 | EXEC | `msgSvcKei += " サービス契約番号(転居元・先):" + motoSvcKeiNo + " / " + sakiSvcKeiNo` // [-> Japanese: "サービス契約番号(転居元・先):" = "Service contract number (pre/post-move):"] |

**Block 8.3** — [SET] (L2432) (within Block 8)

| # | Type | Code |
|---|------|------|
| 1 | SET | `svcKeiNo = motoSvcKeiNo` // Use before-change number for SYSID lookup |

**Block 9** — [IF] `("".equals(sysId))` (L2434)

> SYSID has not been obtained yet — fetch it from the service contract header table using the first valid service contract number encountered.

| # | Type | Code |
|---|------|------|
| 1 | SET | `sysId = getSysId(svcKeiNo)` // [-> Calls getSysId() which queries KK_T_SVC_KEI via KK_T_SVC_KEI_KK_SELECT_023] |

**Block 10** — [RETURN] (L2437)

> Build and return the final formatted log message.

| # | Type | Code |
|---|------|------|
| 1 | RETURN | `return " SYSID:" + sysId + msgSvcKei` // Prepend " SYSID:" to SYSID, then append all service contract number entries |

## 7. Glossary

| Term | Type | Business Meaning |
|------|------|------------------|
| `adchgNo` | Field | Residence change number — unique identifier for a residence change operation in the telecom billing system |
| `adchg_dtl_sbt_cd` | Field | Residence change detail sub-type code — classifies the type of detail record within a residence change (e.g., service contract details) |
| `ADCHG_DTL_SBT_CD_SVC_KEI_NO` | Constant | Residence change detail sub-type code for service contracts — value `"01"`, used to filter detail records that pertain to service contracts |
| `chbf_skbt_no` | Field | Before-change service contract number — the service contract number prior to the residence change operation |
| `chaf_skbt_no` | Field | After-change service contract number — the service contract number after the residence change operation |
| `motoSvcKeiNo` | Local variable | Before-change service contract number (Japanese: 元サービス契約番号) — extracted from `CHBF_SKBT_NO` column |
| `sakiSvcKeiNo` | Local variable | After-change service contract number (Japanese: 後サービス契約番号) — extracted from `CHAF_SKBT_NO` column |
| `svcKeiNo` | Local variable | Effective service contract number — resolved from before/after numbers depending on the operation type |
| SYSID | Field | System identifier — a unique system-level identifier for a service contract, stored in the `KK_T_SVC_KEI` table |
| KK_T_ADCHG_DTL | Table | Residence change detail table — stores line-level details of residence change operations, including before/after service contract numbers |
| KK_T_SVC_KEI | Table | Service contract table — stores service contract header records, including SYSID and other contract metadata |
| Tsuka (追加) | Business term | Addition — a service contract newly added during residence change (before null, after has value) |
| Kaiyaku (解約) | Business term | Cancellation — a service contract cancelled during residence change (before has value, after null) |
| Horyu (保留) | Business term | Retention — a service contract retained during residence change (before has value, after null) |
| Hikiki (引越) | Business term | Transfer — a service contract transferred during residence change (both before and after have values) |
| KojiStop (完工停止) | Business term | Completion stop — the post-completion processing phase in batch operations, where final log messages and status updates are generated |
| executeKK_T_ADCHG_DTL_KK_SELECT_003 | Method | Database select method for KK_T_ADCHG_DTL — queries residence change detail records with given adchgNo and sub-type code |
| KK_T_SVC_KEI_KK_SELECT_023 | Constant | SQL define name for SYSID lookup query on KK_T_SVC_KEI — value `"KK_SELECT_023"` |
