# Business Logic — JBSbatKKCourseChgeTstaDayChsht.selectIdoRsv() [67 LOC]

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

## 1. Role

### JBSbatKKCourseChgeTstaDayChsht.selectIdoRsv()

This method performs the **move reservation search** (異動予約の検索処理) — it queries the database to retrieve reservation records for a service change/move operation associated with a given order detail number (`mskmDtlNo`). The method executes a targeted SQL SELECT against the `KK_T_IDO_RSV` (Move Reservation) table, using the order detail number and the first day of the next operating month as search criteria. It iterates over all matching reservation records in the result set, extracting four key fields: the service contract detail number, registration timestamp, move reservation number, and last-update timestamp. The extracted values are written to the output interface map (`outmap`) for downstream consumption, and the method returns only the service contract detail number (`svcKeiUcwkNo2`). The method uses a **delegation pattern** — it delegates the actual SQL execution to the internal `executeKK_T_IDO_RSV_KK_SELECT_013` helper method, which sets up bind parameters and invokes `selectBySqlDefine` on the `db_KK_T_IDO_RSV` entity mapper. The result is then consumed iteratively via `selectNext()`. This method serves as a shared utility within the batch service, called by `execute()` in the same class to supply move reservation data during course-change processing.

## 2. Processing Pattern (Detailed Business Logic)

```mermaid
flowchart TD
    START(["selectIdoRsv outmap mskmDtlNo"])
    INIT["Initialize: svcKeiUcwkNo2, geneAddDtm2, idoRsvNo2, updDtm2 empty, iDoRsvMap_013 null"]
    WHERE["Build whereParam array: mskmDtlNo plus getOpedateNextMonthFst"]
    EXEC["executeKK_T_IDO_RSV_KK_SELECT_013 whereParam"]
    FETCH["Fetch next record: iDoRsvMap_013 = db_KK_T_IDO_RSV.selectNext()"]
    CHECK_NULL{iDoRsvMap_013 == null?}
    SET_EMPTY["Set all fields to empty string"]
    WHILE_LOOP{while iDoRsvMap_013 != null?}
    EXTRACT["Extract fields: svcKeiUcwkNo2, geneAddDtm2, idoRsvNo2, updDtm2 via Rtrim getString, then selectNext"]
    SET_OUT["Set output: outmap.setString SVC_KEI_UCWK_NO2, GENE_ADD_DTM2, IDO_RSV_NO2, UPD_DTM2"]
    CHECK_DEBUG{chkLogLevel DEBUG?}
    LOG["Print debug logs: idoRsvNo2, svcKeiUcwkNo2, geneAddDtm2, updDtm2"]
    RETURN["return svcKeiUcwkNo2"]
    END_NODE(["End"])
    START --> INIT
    INIT --> WHERE
    WHERE --> EXEC
    EXEC --> FETCH
    FETCH --> CHECK_NULL
    CHECK_NULL -->|Yes| SET_EMPTY
    CHECK_NULL -->|No| WHILE_LOOP
    SET_EMPTY --> SET_OUT
    WHILE_LOOP -->|Yes| EXTRACT
    EXTRACT --> WHILE_LOOP
    WHILE_LOOP -->|No| SET_OUT
    SET_OUT --> CHECK_DEBUG
    CHECK_DEBUG -->|Yes| LOG
    CHECK_DEBUG -->|No| RETURN
    LOG --> RETURN
    RETURN --> END_NODE
```

## 3. Parameter Analysis

| No | Parameter Name | Type | Business Description |
|----|---------------|------|---------------------|
| 1 | `outmap` | `JBSbatServiceInterfaceMap` | Output interface object — a key-value map into which the method writes the four extracted move reservation fields (service contract detail number, registration timestamp, move reservation number, update timestamp). Downstream processes read from this map to consume the search results. |
| 2 | `mskmDtlNo` | `String` | Order detail number — the unique identifier of an order detail line item. Used as the primary search key to locate move reservation records associated with a specific order. Values correspond to customer order line entries in the billing/ordering system. |

**External state read by this method:**
- `db_KK_T_IDO_RSV` — Entity mapper for the `KK_T_IDO_RSV` (Move Reservation) table. Provides `selectBySqlDefine` and `selectNext` operations for SQL-based data retrieval.
- `super.logPrint` — Logging utility inherited from parent class. Provides `chkLogLevel` and `printDebugLog` methods for conditional debug output.
- `getOpedateNextMonthFst()` — Internal method (same class) that computes the first day of the next operating month. Used as a secondary search criterion.

## 4. CRUD Operations / Called Services

| CRUD | SC / CBS | SC Code | Entity / DB | Operation Description |
|------|----------|---------|-------------|----------------------|
| R | `executeKK_T_IDO_RSV_KK_SELECT_013` | KK_T_IDO_RSV_SELECT | KK_T_IDO_RSV | Executes SQL SELECT on the Move Reservation table using bind parameters (order detail number and next-month first-day). Delegates to `db_KK_T_IDO_RSV.selectBySqlDefine`. |
| R | `db_KK_T_IDO_RSV.selectNext` | KK_T_IDO_RSV_SELECT | KK_T_IDO_RSV | Iteratively fetches the next record from the SQL result set returned by the previous `selectBySqlDefine` call. |
| R | `JBSbatKK_T_SVC_KEI_UCWK.getString` (via iDoRsvMap_013) | KK_T_IDO_RSV_SELECT | KK_T_IDO_RSV (svc_kei_ucwk_no, gene_add_dtm) | Extracts service contract detail number and registration timestamp from the result set via column name constants `SVC_KEI_UCWK_NO` and `GENE_ADD_DTM`. |
| R | `JBSbatKK_T_IDO_RSV.getString` (via iDoRsvMap_013) | KK_T_IDO_RSV_SELECT | KK_T_IDO_RSV (ido_rsv_no, upd_dtm) | Extracts move reservation number and update timestamp from the result set via column name constants `IDO_RSV_NO` and `UPD_DTM`. |
| U | `JBSbatKKIFM151.setString` (on outmap) | KK_T_IDO_RSV_SELECT | - | Writes the four extracted values into the output interface map under keys `SVC_KEI_UCWK_NO2`, `GENE_ADD_DTM2`, `IDO_RSV_NO2`, and `UPD_DTM2`. |
| - | `JBSbatStringUtil.Rtrim` | - | - | Right-trims whitespace from extracted string values to normalize field data. |
| - | `JBSbatLogUtil.chkLogLevel` | - | - | Checks whether debug-level logging is enabled. Conditional gate for debug output. |
| - | `JBSbatLogUtil.printDebugLog` | - | - | Writes debug log entries for each of the four move reservation fields when debug mode is active. |

## 5. Dependency Trace

| # | Caller (Screen/Batch) | Call Chain (Full Path to this Method) | Terminal (SC / CRUD / Entity) |
|---|----------------------|--------------------------------------|-------------------------------|
| 1 | Batch: JBSbatKKCourseChgeTstaDayChsht.execute | `execute()` -> `selectIdoRsv(outmap, mskmDtlNo)` | `executeKK_T_IDO_RSV_KK_SELECT_013 [R] KK_T_IDO_RSV`, `selectNext [R] KK_T_IDO_RSV`, `setString [U] -` |

**Notes:** The only direct caller is `execute()` in the same class (`JBSbatKKCourseChgeTstaDayChsht`). No screen/batch entry points (KKSV*) were found within 8 hops. This method is an internal batch service utility consumed by the class's main execution flow.

## 6. Per-Branch Detail Blocks

**Block 1** — INIT (L1650)

> Initialize all local variables to empty strings and null.

| # | Type | Code |
|---|------|------|
| 1 | SET | `svcKeiUcwkNo2 = ""` // Service contract detail number 2 |
| 2 | SET | `geneAddDtm2 = ""` // Registration year/month/day 2 |
| 3 | SET | `idoRsvNo2 = ""` // Move reservation number 2 |
| 4 | SET | `updDtm2 = ""` // Update year/month/day time/second 2 |

**Block 2** — INIT (L1657)

> Declare the SQL result holder variable.

| # | Type | Code |
|---|------|------|
| 1 | SET | `iDoRsvMap_013 = null` // SQL execution result holder (move reservation retrieval) |

**Block 3** — EXEC (L1660)

> Build the WHERE parameter array with the order detail number and the first day of next operating month.

| # | Type | Code |
|---|------|------|
| 1 | SET | `whereParam = { mskmDtlNo, getOpedateNextMonthFst() }` // Operating month next-month first-day |

**Block 4** — CALL (L1663)

> Execute the SQL SELECT on the Move Reservation table.

| # | Type | Code |
|---|------|------|
| 1 | CALL | `executeKK_T_IDO_RSV_KK_SELECT_013(whereParam)` // Delegates to selectBySqlDefine on db_KK_T_IDO_RSV with SQL key KK_T_IDO_RSV_KK_SELECT_013 |

**Block 5** — EXEC (L1666)

> Fetch the first record from the SQL result set.

| # | Type | Code |
|---|------|------|
| 1 | SET | `iDoRsvMap_013 = db_KK_T_IDO_RSV.selectNext()` // Fetch next record |

**Block 6** — IF/ELSE (null check on iDoRsvMap_013) (L1669)

> Conditional branch: zero records found vs. records exist.

**Block 6.1** — ELSE-NOTHING (branch: `null == iDoRsvMap_013`) (L1671)

> Move reservation search returned zero records — ensure all local fields are empty strings.

| # | Type | Code |
|---|------|------|
| 1 | SET | `svcKeiUcwkNo2 = ""` // Service contract detail number 2 |
| 2 | SET | `geneAddDtm2 = ""` // Registration year/month/day 2 |
| 3 | SET | `idoRsvNo2 = ""` // Move reservation number 2 |
| 4 | SET | `updDtm2 = ""` // Update year/month/day time/second 2 |

**Block 6.2** — ELSE (branch: `null != iDoRsvMap_013`) (L1677)

> Move reservation search returned one or more records — iterate through all records.

**Block 6.2.1** — WHILE (condition: `null != iDoRsvMap_013`) (L1678)

> Loop over all records in the SQL result set. The last iteration calls `selectNext()` which returns `null`, causing the loop to exit.

| # | Type | Code |
|---|------|------|
| 1 | SET | `svcKeiUcwkNo2 = JBSbatStringUtil.Rtrim(iDoRsvMap_013.getString(JBSbatKK_T_SVC_KEI_UCWK.SVC_KEI_UCWK_NO))` // Service contract detail number [-> column: SVC_KEI_UCWK_NO] |
| 2 | SET | `geneAddDtm2 = JBSbatStringUtil.Rtrim(iDoRsvMap_013.getString(JBSbatKK_T_SVC_KEI_UCWK.GENE_ADD_DTM))` // Registration year/month/day [-> column: GENE_ADD_DTM] |
| 3 | SET | `idoRsvNo2 = JBSbatStringUtil.Rtrim(iDoRsvMap_013.getString(JBSbatKK_T_IDO_RSV.IDO_RSV_NO))` // Move reservation number [-> column: IDO_RSV_NO] |
| 4 | SET | `updDtm2 = JBSbatStringUtil.Rtrim(iDoRsvMap_013.getString(JBSbatKK_T_IDO_RSV.UPD_DTM))` // Update year/month/day time/second [-> column: UPD_DTM] |
| 5 | SET | `iDoRsvMap_013 = db_KK_T_IDO_RSV.selectNext()` // Fetch next record for loop iteration |

**Block 7** — EXEC (outmap.setString calls) (L1698)

> Write the extracted field values (from the last iteration of the while loop, or empty strings if no records) into the output interface map.

| # | Type | Code |
|---|------|------|
| 1 | EXEC | `outmap.setString(JBSbatKKIFM151.SVC_KEI_UCWK_NO2, svcKeiUcwkNo2)` // Write service contract detail number 2 [-> key: SVC_KEI_UCWK_NO2] |
| 2 | EXEC | `outmap.setString(JBSbatKKIFM151.GENE_ADD_DTM2, geneAddDtm2)` // Write registration year/month/day 2 [-> key: GENE_ADD_DTM2] |
| 3 | EXEC | `outmap.setString(JBSbatKKIFM151.IDO_RSV_NO2, idoRsvNo2)` // Write move reservation number 2 [-> key: IDO_RSV_NO2] |
| 4 | EXEC | `outmap.setString(JBSbatKKIFM151.UPD_DTM2, updDtm2)` // Write update year/month/day time/second 2 [-> key: UPD_DTM2] |

**Block 8** — IF (debug log check) (L1704)

> Conditional debug logging — only outputs when debug log level is enabled.

**Block 8.1** — IF-BODY (condition: `super.logPrint.chkLogLevel(JBSbatLogUtil.MODE_DEBUG)`) (L1706)

> Print four debug log lines for the move reservation search results.

| # | Type | Code |
|---|------|------|
| 1 | EXEC | `super.logPrint.printDebugLog("idoRsvNo2: " + svcKeiUcwkNo2)` // Debug log: Move reservation search (service contract detail number 2) |
| 2 | EXEC | `super.logPrint.printDebugLog("geneAddDtm2: " + geneAddDtm2)` // Debug log: Move reservation search (registration year/month/day 2) |
| 3 | EXEC | `super.logPrint.printDebugLog("idoRsvNo2: " + idoRsvNo2)` // Debug log: Move reservation search (move reservation number 2) |
| 4 | EXEC | `super.logPrint.printDebugLog("updDtm2: " + updDtm2)` // Debug log: Move reservation search (update year/month/day time/second 2) |

**Block 9** — RETURN (L1713)

> Return the service contract detail number 2 to the caller.

| # | Type | Code |
|---|------|------|
| 1 | RETURN | `return svcKeiUcwkNo2;` // Service contract detail number 2 |

## 7. Glossary

| Term | Type | Business Meaning |
|------|------|------------------|
| `mskmDtlNo` | Field | Order detail number — unique identifier for a line item within a customer order. Used as the primary key to locate associated move reservation records. |
| `svcKeiUcwkNo2` | Field | Service contract detail number 2 — internal tracking ID for service contract line items returned from the move reservation search. This is the method's return value. |
| `geneAddDtm2` | Field | Registration year/month/day 2 — timestamp indicating when the move reservation record was originally created/registered in the system. |
| `idoRsvNo2` | Field | Move reservation number 2 — unique identifier assigned to a service move/change reservation. Represents the reservation reference for the customer's service change request. |
| `updDtm2` | Field | Update year/month/day time/second 2 — timestamp of the last modification to the move reservation record. |
| `outmap` | Field | Output interface map — a key-value container (`JBSbatServiceInterfaceMap`) used to pass extracted data back to the caller (`execute()`). Acts as a structured return mechanism for multiple values. |
| KK_T_IDO_RSV | Table | Move Reservation table — database table storing records of planned service changes/moves (異動予約). Contains reservation numbers, associated service contract details, and timestamps. |
| KK_T_SVC_KEI_UCWK | Entity/Constants | Service contract detail entity — constants class defining column names (`SVC_KEI_UCWK_NO`, `GENE_ADD_DTM`) for the service contract detail line item fields stored within or joined from the move reservation table. |
| JBSbatKKIFM151 | Constants | Interface mapping constants — defines output key names (`SVC_KEI_UCWK_NO2`, `GENE_ADD_DTM2`, `IDO_RSV_NO2`, `UPD_DTM2`) used when writing results to the output interface map. The "151" suffix is a versioned interface mapping identifier. |
| KK_T_IDO_RSV_KK_SELECT_013 | SQL Key | SQL definition key — identifies the pre-defined SELECT query executed against the Move Reservation table. Parameters include the order detail number and next-month first day. |
| `executeKK_T_IDO_RSV_KK_SELECT_013` | Method | Internal SQL execution helper — constructs a parameter list bind array from the input parameters and delegates to `db_KK_T_IDO_RSV.selectBySqlDefine` with the SQL key `KK_T_IDO_RSV_KK_SELECT_013`. |
| `selectNext` | Method | Iterative result set fetcher — retrieves the next row from the SQL query result. Returns `null` when no more rows are available, enabling while-loop iteration. |
| `getOpedateNextMonthFst` | Method | Operating month calculator — returns the first day of the next operating month. Used as a secondary search criterion to scope move reservations to a specific billing/operating cycle. |
| Rtrim | Method | Right-trim utility — strips trailing whitespace/blank characters from string values to normalize database-extracted fields. |
| chkLogLevel / printDebugLog | Methods | Debug logging utilities — `chkLogLevel` checks if debug-level logging is enabled; `printDebugLog` writes timestamped log entries for troubleshooting. |
| MODE_DEBUG | Constant | Debug log level identifier — enables conditional debug output when the application's logging configuration permits verbose logging. |
| KK_T_ | Prefix | "KK Table" naming convention — prefix used for tables in the KK (Kinki/Kanto?) subsystem's batch processing schema. Indicates a batch-managed operational table. |
| IDO | Abbreviation | 異動 (Idou) — "Move" or "Change" — refers to service change/move operations in the telecom billing domain. |
| RS | Abbreviation | 予約 (Yoyaku) — "Reservation" — refers to a scheduled/planned operation in the billing workflow. |

---
