# Business Logic — JBSbatKKAdChgPlaceNoChgRnki.getBfSvcKeiNo() [8 LOC]

| Field | Value |
|-------|-------|
| Fully Qualified Name | `eo.business.service.JBSbatKKAdChgPlaceNoChgRnki` |
| Layer | Service |
| Module | `service` (Package: `eo.business.service`) |

## 1. Role

### JBSbatKKAdChgPlaceNoChgRnki.getBfSvcKeiNo()

This method retrieves the **before-change service key number** (CHBF_SKBT_NO) for a service contract identified by the input `svcKeiNo`, from the address change detail table (`T_ADCHG_DTL`). It is part of the address-change batch processing system that handles residential address modifications for telecom service contracts. The method acts as a **data accessor** — it issues a database query against the address change detail table and returns the pre-change service key identifier associated with the specified service key number. If no matching address change record exists, it returns `null`, enabling the caller to gracefully handle the absence of historical change data. This method was added as part of defect tracking IKK-2013-0000707 (2013/04/03, Hoshino ADD END), indicating it supports a corrective or enhancement requirement for address change processing.

## 2. Processing Pattern (Detailed Business Logic)

```mermaid
flowchart TD
    START(["getBfSvcKeiNo(svcKeiNo)"])
    STEP1(["executeKK_T_ADCHG_DTL_KK_SELECT_023"])
    STEP2(["db_KK_T_ADCHG_DTL.selectNext"])
    COND{adchgDtlInf
!= null?}
    RET1(["return adchgDtlInf.getString(CHBF_SKBT_NO)"])
    RET2(["return null"])
    END_NODE(["Return / Next"])

    START --> STEP1
    STEP1 --> STEP2
    STEP2 --> COND
    COND -- true --> RET1
    COND -- false --> RET2
    RET1 --> END_NODE
    RET2 --> END_NODE
```

**Processing Summary:**
The method performs a simple two-step read pattern:

1. **Query Execution**: Invokes `executeKK_T_ADCHG_DTL_KK_SELECT_023` with the input `svcKeiNo` wrapped in a String array, which builds a parameter list and executes a SQL SELECT against the `T_ADCHG_DTL` table (address change detail table) using the `KK_SELECT_023` SQL define.
2. **Result Retrieval**: Calls `db_KK_T_ADCHG_DTL.selectNext()` to fetch the next row from the query result set.
3. **Null-Safe Return**: If a row is returned, extracts the `CHBF_SKBT_NO` (Before-Change Service Key Number) field and returns it. If no row exists, returns `null`.

## 3. Parameter Analysis

| No | Parameter Name | Type | Business Description |
|----|---------------|------|---------------------|
| 1 | `svcKeiNo` | `String` | Service key number — the unique identifier for a service contract line item. Used as the lookup key to find the corresponding address change detail record and retrieve the pre-change service key number. |

**Instance fields read:**

| No | Field Name | Type | Business Description |
|----|-----------|------|---------------------|
| 1 | `db_KK_T_ADCHG_DTL` | `JBSbatCommonDBInterface` | Database access interface for the `T_ADCHG_DTL` (Address Change Detail) table. Used to execute the SELECT query and retrieve result rows. |

## 4. CRUD Operations / Called Services

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

| CRUD | SC / CBS | SC Code | Entity / DB | Operation Description |
|------|----------|---------|-------------|----------------------|
| R | `JBSbatKKAdChgPlaceNoChgRnki.executeKK_T_ADCHG_DTL_KK_SELECT_023` | - | `T_ADCHG_DTL` | Executes a SQL SELECT via `KK_SELECT_023` on the Address Change Detail table, parameterized by `svcKeiNo` |
| R | `db_KK_T_ADCHG_DTL.selectNext` | - | `T_ADCHG_DTL` | Fetches the next row from the result set of the prior SELECT query |
| R | `JBSbatCommonDBInterface.getString` | - | - | Extracts the `CHBF_SKBT_NO` column value from the current row as a String |

**CRUD Classification:**
- Both operations are **Read (R)** — no data is created, updated, or deleted by this method.
- The method is a pure data accessor: it queries the address change detail table and returns a single field value from the result.

## 5. Dependency Trace

| # | Caller (Screen/Batch) | Call Chain (Full Path to this Method) | Terminal (SC / CRUD / Entity) |
|---|----------------------|--------------------------------------|-------------------------------|
| 1 | Batch: JBSbatKKAdChgPlaceNoChgRnki | `JBSbatKKAdChgPlaceNoChgRnki.execute` -> `getBfSvcKeiNo` | `executeKK_T_ADCHG_DTL_KK_SELECT_023 [R] T_ADCHG_DTL`, `selectNext [R] T_ADCHG_DTL`, `getString [R] CHBF_SKBT_NO` |

## 6. Per-Branch Detail Blocks

**Block 1** — [METHOD] `(method entry)` (L425)

> Entry point: `getBfSvcKeiNo(String svcKeiNo)` — a private method that queries the address change detail table for the "before" service key number.

| # | Type | Code |
|---|------|------|
| 1 | CALL | `executeKK_T_ADCHG_DTL_KK_SELECT_023(new String[]{svcKeiNo})` // Executes SQL SELECT on T_ADCHG_DTL using svcKeiNo as parameter [KK_SELECT_023] |
| 2 | SET | `adchgDtlInf = db_KK_T_ADCHG_DTL.selectNext()` // Retrieves the next result row from the query |

**Block 2** — [IF] `(adchgDtlInf != null)` (L428)

> Checks whether the address change detail query returned a matching record.

| # | Type | Code |
|---|------|------|
| 1 | RETURN | `adchgDtlInf.getString(JBSbatKK_T_ADCHG_DTL.CHBF_SKBT_NO)` // Returns the Before-Change Service Key Number (CHBF_SKBT_NO) from the matched record |

**Block 3** — [ELSE / FALLTHROUGH] `(adchgDtlInf == null)` (L431)

> Fallback when no matching address change detail record is found.

| # | Type | Code |
|---|------|------|
| 1 | RETURN | `null` // Returns null when no record exists — indicates no prior service key change history |

## 7. Glossary

| Term | Type | Business Meaning |
|------|------|------------------|
| `svcKeiNo` | Field | Service key number — the unique identifier for a telecom service contract line item |
| `CHBF_SKBT_NO` | Field | Before-Change Service Key Number — the original service key identifier before an address change operation |
| `CHAF_SKBT_NO` | Field | After-Change Service Key Number — the new service key identifier after an address change operation |
| `T_ADCHG_DTL` | Table | Address Change Detail Table — stores records of address modification operations on service contracts, including both pre-change and post-change identifiers |
| `KK_SELECT_023` | SQL Define | Named SQL query definition used to select address change detail records by service key number |
| `db_KK_T_ADCHG_DTL` | Field | Database access interface bound to the `T_ADCHG_DTL` table, used for executing SQL SELECT/INSERT/UPDATE/DELETE operations |
| `JBSbatCommonDBInterface` | Interface | Common database access interface providing generic `setValue()`, `selectBySqlDefine()`, `selectNext()`, and `getString()` methods for batch data access |
| `SVC_KEI_IDO_SBT_CD` | Field | Service Key Movement Type Code — classifies the type of service key change (e.g., address transfer, cancellation) |
| `ADCHG_DTL_SBT_CD` | Field | Address Change Detail Type Code — classifies the type of address change record |
| `KK` | Prefix | Internal naming convention prefix (Kokusa/Kei system) — used for table and class naming in the telecom batch processing subsystem |
| ADCHG | Abbreviation | Address Change — refers to the business process of modifying a customer's registered address for their service contract |
| IKK-2013-0000707 | Ticket | Defect/enhancement tracking ID — the method was added in response to this requirement on 2013/04/03 by developer Hoshino |
