# Business Logic — JBSbatKKAdChgSmtvlRnki.getIdoRsvCourseChg() [15 LOC]

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

## 1. Role

### JBSbatKKAdChgSmtvlRnki.getIdoRsvCourseChg()

This method retrieves course change reservation records (コース変更予約情報) from the relocation reservation table (`KK_T_IDO_RSV`). It is a data-access helper method invoked during the address change smart-batch workflow (住所変更スマートバリー連携部品) when a customer relocates but retains their original service contract number. Specifically, when the transfer-from service contract number (`itnmSvcKeiNo`) matches the current service contract number (`svcKeiNo`), the calling `execute()` method queries this method to determine whether a course change reservation exists for that contract. The method prepares operational metadata (operation date) in the query parameter interface, executes a SQL define lookup (`KK_SELECT_080`) against the `KK_T_IDO_RSV` table, and returns the next row as a `JBSbatCommonDBInterface` — or `null` if no course change reservation exists. It implements a simple delegation/read pattern, acting as the data-access layer within the batch service.

## 2. Processing Pattern (Detailed Business Logic)

```mermaid
flowchart TD
    START(["getIdoRsvCourseChg (itnmSvcKeiNo)"]) --> SET_PARAMS["SET: paramList = new JBSbatCommonDBInterface"]
    SET_PARAMS --> SET1["SET: paramList.setValue(opeDate)"]
    SET1 --> SET2["SET: paramList.setValue(opeDate)"]
    SET2 --> SET3["SET: paramList.setValue(opeDate)"]
    SET3 --> SET4["SET: paramList.setValue(opeDate)"]
    SET4 --> SET5["SET: paramList.setValue(itnmSvcKeiNo)"]
    SET5 --> EXEC_SELECT["CALL: db_KK_T_IDO_RSV.selectBySqlDefine"]
    EXEC_SELECT --> EXEC_NEXT["CALL: db_KK_T_IDO_RSV.selectNext"]
    EXEC_NEXT --> RETURN["RETURN JBSbatCommonDBInterface"]
    RETURN --> END_NODE(["End"])
```

**Processing description:**
The method performs a straightforward sequential read. It creates a fresh `JBSbatCommonDBInterface` parameter object and populates it with four copies of the operational date (`opeDate`, an instance field of the class) followed by the input `itnmSvcKeiNo` (transfer-from service contract number). It then invokes the SQL access layer's `selectBySqlDefine` method using the SQL definition key `KK_SELECT_080` against the `KK_T_IDO_RSV` (relocation reservation) table. Finally, it calls `selectNext()` to retrieve the first matching row as a `JBSbatCommonDBInterface` result and returns it directly to the caller. There are no conditional branches, loops, or exception handling within this method itself — it delegates all error handling to the underlying `selectBySqlDefine`/`selectNext` infrastructure, which propagates exceptions up as `java.lang.Exception`.

## 3. Parameter Analysis

| No | Parameter Name | Type | Business Description |
|----|---------------|------|---------------------|
| 1 | `itnmSvcKeiNo` | `String` | Transfer-from service contract number (移転元サービス契約番号) — the original service contract number before a customer's relocation. Used as a query key to look up course change reservations associated with this contract. If no course change reservation exists for this contract, the method returns `null`. |

**Instance fields read by this method:**

| Name | Type | Business Description |
|------|------|---------------------|
| `opeDate` | (inferred: `String` or date type) | Operational date — a class-level field set by the batch framework, representing the processing date for this batch job execution |
| `db_KK_T_IDO_RSV` | `JBSbatSQLAccess` | Database access object for the `KK_T_IDO_RSV` (relocation reservation) table, injected by the framework |

## 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_IDO_RSV.selectBySqlDefine` | - | `KK_T_IDO_RSV` (relocation reservation) | Queries the relocation reservation table using SQL definition key `KK_SELECT_080` to find course change reservations matching the given transfer-from service contract number and operation date |
| R | `db_KK_T_IDO_RSV.selectNext` | - | `KK_T_IDO_RSV` (relocation reservation) | Fetches the next result row from the executed query as a `JBSbatCommonDBInterface` record containing course change reservation data (e.g., OLD/NEW EOHNT PPLAN TIKEI SKCD fields) |

**CRUD classification:**
- Both operations are **Read (R)** operations. The method does not create, update, or delete any records.
- `selectBySqlDefine` executes the SQL query defined by key `KK_SELECT_080` against the `KK_T_IDO_RSV` table, filtering by `itnmSvcKeiNo` (transfer-from service contract number) and `opeDate` (operational date).
- `selectNext` returns the first matching row from the result set, or `null` if no matching course change reservation exists.

## 5. Dependency Trace

| # | Caller (Screen/Batch) | Call Chain (Full Path to this Method) | Terminal (SC / CRUD / Entity) |
|---|----------------------|--------------------------------------|-------------------------------|
| 1 | Batch: `JBSbatKKAdChgSmtvlRnki.execute()` | `execute()` -> `getIdoRsvCourseChg(itnmSvcKeiNo)` | `selectBySqlDefine [R] KK_T_IDO_RSV`, `selectNext [R] KK_T_IDO_RSV` |

**Call context:** The `execute()` method of the same class calls `getIdoRsvCourseChg(itnmSvcKeiNo)` during the relocation processing flow. This occurs specifically when the transfer-from service contract number (`itnmSvcKeiNo`) equals the current service contract number (`svcKeiNo`), meaning the customer's contract number was retained during relocation. The method then uses the returned course change reservation data to determine pricing eligibility (specifically checking if both original and destination service plans use the TEGAKU/fixed-rate pricing plan).

## 6. Per-Branch Detail Blocks

**Block 1** — [SETUP] (L758)

> Initialize the parameter object for the database query. A fresh `JBSbatCommonDBInterface` is created to hold query parameters.

| # | Type | Code |
|---|------|------|
| 1 | SET | `paramList = new JBSbatCommonDBInterface()` |

**Block 2** — [SETUP] (L759)

> Set the operational date (opeDate) into the parameter object. The date is set four times, populating four separate parameter slots that are consumed by the SQL query's WHERE clause bindings.

| # | Type | Code |
|---|------|------|
| 1 | SET | `paramList.setValue(opeDate)` // Set operational date (1st slot) |
| 2 | SET | `paramList.setValue(opeDate)` // Set operational date (2nd slot) |
| 3 | SET | `paramList.setValue(opeDate)` // Set operational date (3rd slot) |
| 4 | SET | `paramList.setValue(opeDate)` // Set operational date (4th slot) |
| 5 | SET | `paramList.setValue(itnmSvcKeiNo)` // Set transfer-from service contract number |

**Block 3** — [EXEC] (L766)

> Execute the SQL query against the relocation reservation table. The SQL definition key `KK_SELECT_080` determines the query logic, filtering by the operational date and the transfer-from service contract number.

| # | Type | Code |
|---|------|------|
| 1 | CALL | `db_KK_T_IDO_RSV.selectBySqlDefine(paramList, KK_SELECT_080)` |

> Constant resolution: `KK_T_IDO_RSV_KK_SELECT_080 = "KK_SELECT_080"` — SQL definition key for course change reservation lookup query.

**Block 4** — [RETURN] (L769)

> Return the first matching course change reservation record, or `null` if none exists.

| # | Type | Code |
|---|------|------|
| 1 | RETURN | `return db_KK_T_IDO_RSV.selectNext()` |

## 7. Glossary

| Term | Type | Business Meaning |
|------|------|------------------|
| `itnmSvcKeiNo` | Field | Transfer-from service contract number (移転元サービス契約番号) — the original service contract number assigned to a customer before relocation |
| `opeDate` | Field | Operational date (運転日) — the batch processing date, used as a filter for finding reservation records active on the processing date |
| `KK_T_IDO_RSV` | Table | Relocation Reservation table (異動予約) — stores records of planned customer relocations, including course change reservations |
| `KK_SELECT_080` | SQL Key | SQL definition key for querying course change reservations from the `KK_T_IDO_RSV` table |
| `JBSbatCommonDBInterface` | Interface | Batch service database interface — a structured map-like object used to pass query parameters and receive result data across the batch framework |
| `JBSbatSQLAccess` | Class | Batch SQL access base class — provides database query methods like `selectBySqlDefine` and `selectNext` for batch service components |
| `selectBySqlDefine` | Method | Executes a SQL query using a predefined SQL key (e.g., `KK_SELECT_080`) with parameter bindings from a `JBSbatCommonDBInterface` |
| `selectNext` | Method | Fetches the next row from the result set of the most recently executed `selectBySqlDefine` query |
| Course Change Reservation | Business term | A reservation record indicating a customer's service plan/course change associated with a relocation (コース変更予約) — enables tracking of plan changes during address moves |
| Smart Batch (スマートバリー) | Business term | Address change smart-batch integration component — handles automated relocation notifications to KDDI when customers move homes (住所変更スマートバリー) |
| `itnsSvcKeiStat` | Field | Transfer-to service contract status (移転先サービス契約状態) — status code of the service contract after relocation |
| `JKKStrConst.CD00130_01` | Constant | Service code constant for NET service (IP/fiber service) — used to verify if the transfer-to service is a NET service |
| TEGAKU (定額制) | Business term | Fixed-rate pricing plan — a billing model where customers pay a flat monthly fee (定額) |
