# Business Logic — JBSbatKKAdChgTekkyoKjFinChsht.executeKK_T_ADCHG_DTL_KK_SELECT_042() [21 LOC]

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

## 1. Role

### JBSbatKKAdChgTekkyoKjFinChsht.executeKK_T_ADCHG_DTL_KK_SELECT_042()

This method performs a **single-record database read** against the address change detail table (`KK_T_ADCHG_DTL`), using the work case number (工事案件番号) as the lookup key. It is a private query helper that resolves to a specific SQL-keyed SELECT statement (`KK_SELECT_042`), retrieves the resulting row, and extracts the address change number (住所変更番号, `ADCHG_NO`) from the record.

The method plays a critical supporting role in the batch processing pipeline for **address change revocation work completion extraction** (住所変更中撤去工事完了抽出部品). It is invoked during the `execute()` method of `JBSbatKKAdChgTekkyoKjFinChsht`, which processes completed work records stored in the `KK_T_KJ_FIN_WK` work table. By looking up the address change detail associated with a given work case number, this method provides the address change number that the caller then uses as a foreign key to further query the parent address change table (`KK_T_ADCHG`) via `executeKK_T_ADCHG_KK_SELECT_021`.

**Design pattern**: Query/Delegate — the method follows a simple query-by-SQL-key pattern. It acts as a thin SQL abstraction layer: constructing a bind-variable list from input parameters, delegating the actual DB access to `JBSbatSQLAccess.selectBySqlDefine()`, and returning the business-relevant value from the result set.

## 2. Processing Pattern (Detailed Business Logic)

```mermaid
flowchart TD
    START(["executeKK_T_ADCHG_DTL_KK_SELECT_042(param)"])
    STEP1["Generate bind variable list<br/>JBSbatCommonDBInterface paramList = new JBSbatCommonDBInterface()"]
    STEP2["Bind param[0] value to paramList<br/>工事案件番号 Work Case Number"]
    STEP3["Execute DB access<br/>db_KK_T_ADCHG_DTL.selectBySqlDefine(paramList KK_SELECT_042)"]
    STEP4["Retrieve next record<br/>svInfo = db_KK_T_ADCHG_DTL.selectNext()"]
    COND{{svInfo == null?}}
    LOG_NO_MATCH["Log住所変更明細住所変更番号該当無し<br/>Log住所変更番号が取得できない処理をスキップします"]
    RETURN_NULL(["Return null"])
    LOG_WITH_MATCH["Log住所変更明細住所変更番号<br/>svInfo.getString(ADCHG_NO)"]
    RETURN_ADCHG(["Return svInfo.getString(ADCHG_NO)"])
    END_NODE(["Return Next"])

    START --> STEP1
    STEP1 --> STEP2
    STEP2 --> STEP3
    STEP3 --> STEP4
    STEP4 --> COND
    COND -- true --> LOG_NO_MATCH
    LOG_NO_MATCH --> RETURN_NULL
    RETURN_NULL --> END_NODE
    COND -- false --> LOG_WITH_MATCH
    LOG_WITH_MATCH --> RETURN_ADCHG
    RETURN_ADCHG --> END_NODE
```

## 3. Parameter Analysis

| No | Parameter Name | Type | Business Description |
|----|---------------|------|---------------------|
| 1 | `param` | `Object[]` | An array of bind variable values for the SQL SELECT query. Currently, it is expected to contain exactly one element: `param[0]` holds the **work case number** (工事案件番号, `kjfinwk_kojiakNo`) used to look up the address change detail record. |

**Instance fields read by this method:**

| Field | Type | Business Description |
|-------|------|---------------------|
| `db_KK_T_ADCHG_DTL` | `JBSbatSQLAccess` | SQL access handler for the address change detail table (`KK_T_ADCHG_DTL`). Used to execute the SQL query and retrieve results. |
| `super.logPrint` | `JBSbatCommonDBInterface` (debug logger) | Inherited debug logging utility. Used to write trace log entries for the address change number lookup result. |

## 4. CRUD Operations / Called Services

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

| CRUD | SC / CBS | SC Code | Entity / DB | Operation Description |
|------|----------|---------|-------------|----------------------|
| R | `db_KK_T_ADCHG_DTL.selectBySqlDefine` | (inferred batch DAO) | `KK_T_ADCHG_DTL` | Executes SQL key `KK_SELECT_042` to SELECT a record from the address change detail table, bound by work case number. |
| R | `db_KK_T_ADCHG_DTL.selectNext` | (inferred batch DAO) | `KK_T_ADCHG_DTL` | Retrieves the next row from the result set produced by the previous `selectBySqlDefine` call. |
| R | `svInfo.getString(ADCHG_NO)` | (inferred batch DAO) | `KK_T_ADCHG_DTL` | Extracts the `ADCHG_NO` (住所変更番号 / Address Change Number) column value from the retrieved record. |
| - | `JBSbatCommonDBInterface.setValue` | (framework) | - | Binds the work case number value to the parameter list for SQL execution. |
| - | `super.logPrint.printDebugLog` | (framework debug) | - | Writes debug log messages for traceability during batch execution. |

**Classification details:**
- The method performs exclusively **Read (R)** operations against the `KK_T_ADCHG_DTL` table.
- No Create, Update, or Delete operations are performed.
- The SQL key `KK_SELECT_042` is a private constant defined in the class itself (`KK_T_ADCHG_DTL_KK_SELECT_042 = "KK_SELECT_042"`), not a shared SC code. It maps to a predefined SQL statement that SELECTs from `KK_T_ADCHG_DTL` WHERE the work case number matches.

## 5. Dependency Trace

| # | Caller (Screen/Batch) | Call Chain (Full Path to this Method) | Terminal (SC / CRUD / Entity) |
|---|----------------------|--------------------------------------|-------------------------------|
| 1 | Batch: `JBSbatKKAdChgTekkyoKjFinChsht.execute()` | `execute()` -> `executeKK_T_ADCHG_DTL_KK_SELECT_042(new String[]{kjfinwk_kojiakNo})` | `selectBySqlDefine [R] KK_T_ADCHG_DTL`, `selectNext [R] KK_T_ADCHG_DTL`, `getString [R] ADCHG_NO` |

**Trace details:**
- The sole caller is the same class's `execute()` method (line 141).
- The caller invokes this method with the work case number from the `kjfinwk_kojiakNo` instance field (populated from the `KK_T_KJ_FIN_WK` work table).
- The returned address change number is used immediately afterward to call `executeKK_T_ADCHG_KK_SELECT_021()` to resolve the application number (申込番号) from the parent `KK_T_ADCHG` table.
- If no record is found (null or empty), the caller skips further address change processing.

## 6. Per-Branch Detail Blocks

### Block 1 — [SET/INIT] (L223)

> Initialize the bind variable list for SQL parameter binding. The method creates a `JBSbatCommonDBInterface` object to serve as a typed parameter list that holds bind variables for the SQL query.

| # | Type | Code |
|---|------|------|
| 1 | SET | `JBSbatCommonDBInterface paramList = new JBSbatCommonDBInterface()` // Create bind variable list container |
| 2 | SET | `JBSbatCommonDBInterface svInfo = null` // Initialize result record holder to null |

### Block 2 — [EXEC] (L225)

> Bind the work case number (工事案件番号) from the input parameter array into the bind variable list. The first element of `param` is cast to String and stored as the bind value.

| # | Type | Code |
|---|------|------|
| 1 | EXEC | `paramList.setValue(param[0].toString())` // Bind param[0] (work case number) into paramList [param[0] = kjfinwk_kojiakNo] |

### Block 3 — [EXEC] (L228)

> Execute the database SELECT query. The method delegates to the `db_KK_T_ADCHG_DTL` SQL access handler, passing the bind variable list and the SQL key `KK_SELECT_042`. This triggers a database query against the address change detail table.

| # | Type | Code |
|---|------|------|
| 1 | CALL | `db_KK_T_ADCHG_DTL.selectBySqlDefine(paramList, KK_T_ADCHG_DTL_KK_SELECT_042)` // Execute SQL SELECT against KK_T_ADCHG_DTL [SQL key = "KK_SELECT_042"] |

### Block 4 — [EXEC] (L230)

> Retrieve the next row from the result set. After the SQL query executes, `selectNext()` fetches the first (and expected only) record from the result set into the `svInfo` variable.

| # | Type | Code |
|---|------|------|
| 1 | EXEC | `svInfo = db_KK_T_ADCHG_DTL.selectNext()` // Get next record from result set |

### Block 5 — [IF/ELSE] (`svInfo == null`) (L232)

> Check whether a record was actually found in the address change detail table. If no matching record exists for the given work case number, log a debug message indicating that the address change number is not found, and return `null` to signal the caller to skip further processing.

**Block 5.1 — [IF-THEN] `svInfo == null` (L232)**

> No address change detail record found. Log the absence of the address change number and exit with null, allowing the caller to handle the missing data case.

| # | Type | Code |
|---|------|------|
| 1 | EXEC | `super.logPrint.printDebugLog("    住所変更明細.住所変更番号：該当無し")` // Debug log: Address change detail - Address change number: Not found (住所変更明細.住所変更番号：該当無し) |
| 2 | EXEC | `super.logPrint.printDebugLog("----住所変更番号が取得できない処理をスキップします")` // Debug log: Skips processing when address change number cannot be obtained (住所変更番号が取得できない処理をスキップします) |
| 3 | RETURN | `return null` // Return null to signal no matching record |

**Block 5.2 — [IF-ELSE] `svInfo != null` (L235)**

> A record was found. Log the address change number value extracted from the record and return it to the caller. The caller uses this value as a foreign key to look up the parent address change record.

| # | Type | Code |
|---|------|------|
| 1 | EXEC | `super.logPrint.printDebugLog("    住所変更明細.住所変更番号：" + svInfo.getString(ADCHG_NO))` // Debug log: Address change detail - Address change number: (value) [住所変更明細.住所変更番号：] |
| 2 | RETURN | `return svInfo.getString(ADCHG_NO)` // Return the address change number (住所変更番号) from the retrieved record |

## 7. Glossary

| Term | Type | Business Meaning |
|------|------|------------------|
| `KK_T_ADCHG_DTL` | DB Table | Address Change Detail table — stores detailed records of customer address changes (住所変更明細). |
| `KK_T_ADCHG` | DB Table | Address Change header table — stores the parent address change records associated with one or more detail records. |
| `KK_T_KJ_FIN_WK` | DB Table | Work Completion Work table — a staging/work table holding completed work case data to be processed by the batch. |
| `ADCHG_NO` | Field | Address Change Number (住所変更番号) — unique identifier for a record in the address change detail table. |
| `kjfinwk_kojiakNo` | Field | Work Case Number (工事案件番号) — internal tracking number for a work case, used as the primary lookup key to find associated address change records. |
| `kjfinwk_svc_kei_no` | Field | Service Contract Number (サービス契約番号) — identifier for the service contract line item. |
| `KK_SELECT_042` | SQL Key | SQL definition key for selecting from `KK_T_ADCHG_DTL` by work case number. Maps to a pre-configured SQL statement in the SQL definition configuration. |
| `KK_SELECT_021` | SQL Key | SQL definition key for selecting from `KK_T_ADCHG` by address change number — retrieves the parent record's application number (申込番号). |
| `JBSbatSQLAccess` | Class | Framework SQL access class — provides `selectBySqlDefine()` and `selectNext()` methods for executing parameterized SQL queries against configured database tables. |
| `JBSbatCommonDBInterface` | Class | Framework interface class used as a typed container for bind variables and result set values (provides `setValue()` and `getString()` methods). |
| 住所変更 (Chusho Henkou) | Japanese term | Address Change — a service contract modification where a customer's registered address is updated. |
| 住所変更明細 (Chusho Hencho Meisai) | Japanese term | Address Change Detail — the detailed breakdown of an address change operation, stored in `KK_T_ADCHG_DTL`. |
| 住所変更番号 (Chusho Henkou Bangou) | Japanese term | Address Change Number — the unique ID of an address change record. |
| 工事案件番号 (Kouji Anken Bangou) | Japanese term | Work Case Number — the internal reference number assigned to a work case (installation, removal, or modification job). |
| 中撤去 (Chu-Teru) | Japanese term | Mid-term Removal/Withdrawal — a type of service revocation process handled by this batch. |
| 工事完了抽出 (Kouji Kanryou Choushuu) | Japanese term | Work Completion Extraction — the batch process of extracting records where work has been completed, for further processing. |
| `param[0]` | Parameter | The work case number bound as the first (and only) bind variable for the SQL SELECT query. |
