# Business Logic — JBSbatKKAdChgSmtvlRnki.getSvcKei() [12 LOC]

| Field | Value |
|-------|-------|
| Fully Qualified Name | `eo.business.service.JBSbatKKAdChgSmtvlRnki` |
| Layer | Service (Batch Service — inferred from `koptBatch` module and `eo.business.service` package) |
| Module | `service` (Package: `eo.business.service`) |

## 1. Role

### JBSbatKKAdChgSmtvlRnki.getSvcKei()

This method performs a **read-only lookup of service contract information** from the `KK_T_SVC_KEI` (Service Contract) database table. The Javadoc states "サービス契約からサービス契約情報を取得します" (Acquires service contract information from service contracts). It receives a **service contract number** (`svcKeiNo`) as the primary search key, pairs it with the **operating date** (`opeDate`) as a secondary filter, and executes a SQL define query (`KK_SELECT_023`) against the `db_KK_T_SVC_KEI` SQL access object. The method follows a simple **delegation pattern** — it prepares a structured parameter object (`JBSbatCommonDBInterface`), populates it with the lookup criteria, delegates to `selectBySqlDefine` to execute the SQL query, and then fetches the first matching row via `selectNext()`. This method acts as a **private data-fetching utility** within the batch service class, providing a focused read accessor that encapsulates the database query details from its callers. It is called exclusively by the `execute()` method of the same class, serving as the data retrieval step within the batch processing pipeline.

## 2. Processing Pattern (Detailed Business Logic)

```mermaid
flowchart TD
    START(["getSvcKei(svcKeiNo)"])
    STEP1["Create paramList: new JBSbatCommonDBInterface()"]
    STEP2["paramList.setValue(svcKeiNo)"]
    STEP3["paramList.setValue(opeDate)"]
    STEP4["db_KK_T_SVC_KEI.selectBySqlDefine(paramList, KK_T_SVC_KEI_KK_SELECT_023)"]
    STEP5["db_KK_T_SVC_KEI.selectNext()"]
    END_NODE(["Return JBSbatCommonDBInterface"])

    START --> STEP1 --> STEP2 --> STEP3 --> STEP4 --> STEP5 --> END_NODE
```

**Processing Flow Description:**

1. **Parameter Object Initialization (L739)** — A new `JBSbatCommonDBInterface` instance named `paramList` is created to hold the query parameters.
2. **Set Service Contract Number (L740)** — The `svcKeiNo` parameter is set as the first value in `paramList`. This is the primary search key for the SQL query.
3. **Set Operating Date (L741)** — The `opeDate` instance field is set as the second value in `paramList`. This provides a date context filter for the query, ensuring the retrieved contract record is valid for the current operating date.
4. **Execute SQL Query (L744)** — Delegates to `db_KK_T_SVC_KEI.selectBySqlDefine()`, passing the populated parameter list and the SQL define key `KK_T_SVC_KEI_KK_SELECT_023` (resolved to `"KK_SELECT_023"` from `JKKBatConst`). This key references a pre-defined SQL statement that queries the `KK_T_SVC_KEI` (Service Contract) table.
5. **Fetch Result (L746)** — Delegates to `db_KK_T_SVC_KEI.selectNext()` to retrieve the first matching row from the query result set.
6. **Return (L746)** — Returns the `JBSbatCommonDBInterface` result object containing the service contract record data.

**Constant Resolution:**

| Constant | Resolved Value | Business Meaning |
|----------|---------------|-----------------|
| `JKKBatConst.KK_T_SVC_KEI_KK_SELECT_023` | `"KK_SELECT_023"` | Service Contract — SQL define key for querying the service contract table (`KK_T_SVC_KEI`) |

## 3. Parameter Analysis

| No | Parameter Name | Type | Business Description |
|----|---------------|------|---------------------|
| 1 | `svcKeiNo` | `String` | Service Contract Number — the unique identifier of a service contract record in the `KK_T_SVC_KEI` table. This is the primary key used to locate a specific service contract. In the business domain, each service contract (e.g., FTTH subscription, Mail plan, ISDN line) has a distinct contract number that distinguishes it from all others. |

**Instance Fields Read:**

| Field | Type | Business Description |
|-------|------|---------------------|
| `opeDate` | `String` (inherited from batch parent) | Operating Date — the business date for which the batch is running. Used as a date filter to ensure the retrieved service contract record is valid as of the operating date. |

## 4. CRUD Operations / Called Services

| CRUD | SC / CBS | SC Code | Entity / DB | Operation Description |
|------|----------|---------|-------------|----------------------|
| R | `db_KK_T_SVC_KEI.selectBySqlDefine(paramList, KK_T_SVC_KEI_KK_SELECT_023)` | KK_SELECT_023 | `KK_T_SVC_KEI` (Service Contract Table) | Executes a SQL SELECT query to retrieve service contract records matching the given service contract number and operating date. |
| R | `db_KK_T_SVC_KEI.selectNext()` | - | `KK_T_SVC_KEI` | Fetches the first row from the result set of the previously executed query, returning it as a `JBSbatCommonDBInterface` data structure. |
| - | `JBSbatCommonDBInterface.setValue(Object)` | JDK | - | Sets a value into the parameter object; called twice — once for the service contract number and once for the operating date. |

**CRUD Classification Summary:**
- **Read (R)**: 2 database-read operations — one SQL define execution and one result row fetch.
- **No Create, Update, or Delete** operations are performed in this method.

## 5. Dependency Trace

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

No screen/batch entry points found within 8 hops. Direct callers found: 1 methods.
Terminal operations from this method: `selectBySqlDefine` [-], `selectNext` [-], `setValue` [-], `setValue` [-]

| # | Caller (Screen/Batch) | Call Chain (Full Path to this Method) | Terminal (SC / CRUD / Entity) |
|---|----------------------|--------------------------------------|-------------------------------|
| 1 | Batch: JBSbatKKAdChgSmtvlRnki | `execute()` -> `getSvcKei(svcKeiNo)` | `selectBySqlDefine [R] KK_T_SVC_KEI` |

**Call Chain Details:**
- The `execute()` method of `JBSbatKKAdChgSmtvlRnki` is the direct caller. It invokes `getSvcKei(svcKeiNo)` as a data-fetching step within the batch processing pipeline. The method retrieves service contract information needed for subsequent batch processing steps (e.g., contract change, adjustment, or migration logic).

**Terminal Operations Summary:**
The method's terminal operations are two database reads against the `KK_T_SVC_KEI` table, using the `KK_SELECT_023` SQL define, returning a `JBSbatCommonDBInterface` containing the service contract record.

## 6. Per-Branch Detail Blocks

This method contains **no conditional branches** (no if/else, switch, loops, or try/catch). It follows a linear, straight-line execution path.

---

**Block 1** — [INITIALIZATION] (L739)

> Initializes the parameter object for the database query.

| # | Type | Code |
|---|------|------|
| 1 | SET | `JBSbatCommonDBInterface paramList = new JBSbatCommonDBInterface();` // Create parameter object for query |

---

**Block 2** — [PARAMETER SETTING] (L740–L741)

> Populates the parameter object with the service contract number and operating date.

| # | Type | Code |
|---|------|------|
| 1 | EXEC | `paramList.setValue(svcKeiNo);` // Set primary search key: service contract number |
| 2 | EXEC | `paramList.setValue(opeDate);` // Set date filter: operating date |

---

**Block 3** — [SQL QUERY EXECUTION] (L744)

> Executes the SQL define query against the service contract table.

| # | Type | Code |
|---|------|------|
| 1 | CALL | `db_KK_T_SVC_KEI.selectBySqlDefine(paramList, KK_T_SVC_KEI_KK_SELECT_023);` // Execute SQL query: KK_SELECT_023 on KK_T_SVC_KEI table [-> KK_T_SVC_KEI_KK_SELECT_023 = "KK_SELECT_023" (Service Contract)] |

---

**Block 4** — [RESULT FETCH & RETURN] (L746)

> Retrieves the first matching row and returns it.

| # | Type | Code |
|---|------|------|
| 1 | CALL | `db_KK_T_SVC_KEI.selectNext();` // Fetch first row from query result |
| 2 | RETURN | `return db_KK_T_SVC_KEI.selectNext();` // Return service contract info as JBSbatCommonDBInterface |

---

## 7. Glossary

| Term | Type | Business Meaning |
|------|------|------------------|
| `svcKeiNo` | Field | Service Contract Number — the unique identifier for a service contract record in the system. Each service contract (e.g., FTTH subscription, Mail plan, ISDN line) has its own contract number. |
| `opeDate` | Field | Operating Date — the business date for which the batch process is running. Used as a date-based filter for querying active or valid records. |
| `KK_T_SVC_KEI` | Table | Service Contract Table — the database table storing service contract master data. "KK" prefix indicates it is a key master table; "SVC_KEI" stands for Service Contract (サービス契約). |
| `KK_SELECT_023` | SQL Define | SQL query definition key for selecting service contract records by contract number and date. Defined in `JKKBatConst` as `KK_T_SVC_KEI_KK_SELECT_023`. |
| `JBSbatCommonDBInterface` | Type | Common Database Interface — a generic data container used across the batch framework to pass structured data between methods. Holds key-value pairs representing database row columns. |
| `JBSbatSQLAccess` | Type | SQL Access Object — a database access wrapper that provides `selectBySqlDefine()` and `selectNext()` methods for executing pre-defined SQL queries and fetching results. |
| JBSbat | Acronym | Japan Business Service Batch — the batch processing framework prefix used in this codebase for service-related batch components. |
| KKAdChgSmtvlRnki | Acronym/Domain | Contract Change Migration/Transfer — the business domain of the `JBSbatKKAdChgSmtvlRnki` class, relating to service contract change and migration batch processing. |
| SVC_KEI | Domain | Service Contract (サービス契約) — a business entity representing a customer's subscription contract for telecom services (e.g., FTTH, Mail, TV). |
