# Business Logic — JBSbatKKCourseChgeTstaDayChsht.selectKktKjClWk() [68 LOC]

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

## 1. Role

### JBSbatKKCourseChgeTstaDayChsht.selectKktKjClWk()

This method performs a **work cancellation query** (工事取消検索 — *koshi torikeshi kensaku*) during the batch processing for daily course change status synchronization. In the K-Opticom customer core system, when a work item (工事案件 — *koshi anken*) associated with a service contract needs to be cancelled or was already cancelled in the field, this method queries the `KK_T_KJ_CL_WK` table to retrieve all cancellation records for the given service contract number (`svcKeiNo`) and work item number (`kojiakNo`). It iterates through every matching cancellation record, extracting the work cancellation status code (always set to `"4"`, meaning "Work Cancellation"), the presence/absence of cancellation fees (`KOJIAK_STP_CANCEL_PRC_UM`), and the work suspension receipt date (`KOJIAK_STP_UK_YMD`). The extracted values are written into the output map (`outmap`) using field keys defined in `JBSbatKKIFM151`, which later feeds downstream batch processing stages such as the course change applicable date update file. Additionally, it returns a boolean flag (`kojiFinClInfFlag`) indicating whether any work completion/cancellation information exists at all — true if cancellation records were found, false otherwise. The method serves as a data-discovery and enrichment step within the larger daily course change batch workflow (`execute`), feeding cancellation metadata into downstream processing without modifying any database state itself.

## 2. Processing Pattern (Detailed Business Logic)

```mermaid
flowchart TD
    START(["selectKktKjClWk outmap svcKeiNo kojiakNo"])
    INIT_VARS["Initialize local variables<br/>kojiRslt kojiakStpCancelPrcUm<br/>kojiFinClInfFlag kojiClYmd"]
    INIT_MAP["Initialize kktKjClWkMap_001 null"]
    BUILD_WHERE["Build whereKjClWkParam array<br/>svcKeiNo and kojiakNo"]
    EXEC_QUERY["executeKK_T_KJ_CL_WK_KK_SELECT_001<br/>whereKjClWkParam"]
    FETCH_FIRST["kktKjClWkMap_001<br/>db_KK_T_KJ_CL_WK.selectNext"]
    CHECK_RESULT{"null != kktKjClWkMap_001"}
    SET_FLAG["kojiFinClInfFlag true"]
    WHILE_LOOP{"null != kktKjClWkMap_001"}
    SET_RSLT["kojiRslt set to KKIFM151_KOJI_RSLT_4<br/>equals 4 (Work Cancellation)"]
    GET_CANCEL_FEE["kojiakStpCancelPrcUm<br/>getString KOJIAK_STP_CANCEL_PRC_UM"]
    GET_SUSP_DATE["kojiClYmd<br/>getString KOJIAK_STP_UK_YMD"]
    FETCH_NEXT["kktKjClWkMap_001<br/>db_KK_T_KJ_CL_WK.selectNext"]
    SET_OUTMAP_RESULT["outmap.setString<br/>KOJI_RSLT"]
    SET_OUTMAP_FEE["outmap.setString<br/>KOJIAK_STP_CANCEL_PRC_UM"]
    SET_OUTMAP_FIN["outmap.setString<br/>KOJIAK_FIN_YMD"]
    CHK_DEBUG{"logPrint chkLogLevel DEBUG"}
    LOG_RESULT["printDebugLog<br/>work cancellation result"]
    LOG_FEE["printDebugLog<br/>cancellation fee presence"]
    RETURN_FLAG["return kojiFinClInfFlag"]

    START --> INIT_VARS --> INIT_MAP --> BUILD_WHERE --> EXEC_QUERY --> FETCH_FIRST --> CHECK_RESULT
    CHECK_RESULT -- true --> SET_FLAG --> WHILE_LOOP
    CHECK_RESULT -- false --> SET_OUTMAP_RESULT
    WHILE_LOOP -- true --> SET_RSLT --> GET_CANCEL_FEE --> GET_SUSP_DATE --> FETCH_NEXT --> WHILE_LOOP
    WHILE_LOOP -- false --> SET_OUTMAP_RESULT
    SET_OUTMAP_RESULT --> SET_OUTMAP_FEE --> SET_OUTMAP_FIN --> CHK_DEBUG
    CHK_DEBUG -- true --> LOG_RESULT --> LOG_FEE
    CHK_DEBUG -- false --> RETURN_FLAG
    LOG_FEE --> RETURN_FLAG
```

**Processing summary:**
1. **Initialization** — Local variables are declared and initialized: `kojiRslt` (work result code), `kojiakStpCancelPrcUm` (cancellation fee indicator), `kojiFinClInfFlag` (completion/cancellation info flag), and `kojiClYmd` (work suspension date). The query result map `kktKjClWkMap_001` is set to `null`.
2. **Query execution** — A WHERE parameter array is built from the service contract number and work item number, then `executeKK_T_KJ_CL_WK_KK_SELECT_001` is invoked to run a SELECT query against the `KK_T_KJ_CL_WK` table.
3. **First record fetch** — `db_KK_T_KJ_CL_WK.selectNext()` retrieves the first record. If records exist, `kojiFinClInfFlag` is set to `true`.
4. **While loop iteration** — For every record, the method sets the work result code to `"4"` (Work Cancellation), extracts the cancellation fee presence flag and the suspension receipt date, then fetches the next record. The last fetched record's values persist after the loop.
5. **Output population** — The work result code, cancellation fee indicator, and suspension date are written into the output map via `setString` calls keyed by `JBSbatKKIFM151` constants.
6. **Debug logging** — If debug logging is enabled, the work cancellation result and cancellation fee presence are logged.
7. **Return** — The method returns `kojiFinClInfFlag` indicating whether cancellation information was found.

## 3. Parameter Analysis

| No | Parameter Name | Type | Business Description |
|----|---------------|------|---------------------|
| 1 | `outmap` | `JBSbatServiceInterfaceMap` | Output interface map used to pass extracted work cancellation metadata downstream. Acts as the communication channel between this batch processing step and subsequent stages. Fields written include `KOJI_RSLT` (work result code), `KOJIAK_STP_CANCEL_PRC_UM` (cancellation fee indicator), and `KOJIAK_FIN_YMD` (work completion date). |
| 2 | `svcKeiNo` | `String` | Service contract number — the unique identifier for a customer's service contract line. Used as a WHERE clause key to find work cancellation records associated with a specific contract. Maps to `KK_T_KJ_CL_WK.SVC_KEI_NO` in the query. |
| 3 | `kojiakNo` | `String` | Work item number — the unique identifier for a field work item (工事案件) linked to a service contract. Combined with `svcKeiNo` to pinpoint exact cancellation records. Maps to `KK_T_KJ_CL_WK.KOJIAK_NO` in the query. |

**Instance fields read:**

| Field | Type | Business Description |
|-------|------|---------------------|
| `db_KK_T_KJ_CL_WK` | JBSbatCommonDBInterface | Database access object for the `KK_T_KJ_CL_WK` (work cancellation work) table. Used to fetch cancellation records via `selectNext()`. |
| `super.logPrint` | JBSbatLogUtil | Logging utility inherited from the parent class, used to conditionally emit debug log entries when debug mode is enabled. |

## 4. CRUD Operations / Called Services

| CRUD | SC / CBS | SC Code | Entity / DB | Operation Description |
|------|----------|---------|-------------|----------------------|
| R | `executeKK_T_KJ_CL_WK_KK_SELECT_001` | - | `KK_T_KJ_CL_WK` | Executes a SELECT query on the work cancellation table (`KK_T_KJ_CL_WK`) using the service contract number and work item number as WHERE clause keys. |
| R | `db_KK_T_KJ_CL_WK.selectNext` | - | `KK_T_KJ_CL_WK` | Fetches the next record from the result set of the work cancellation query. Called once initially and then iteratively in the while loop. |
| R | `JBSbatCommonDBInterface.getString` | JBSbatCommonDBInterface | `KK_T_KJ_CL_WK` (in-memory) | Reads string values from the current query result record — extracts `KOJIAK_STP_CANCEL_PRC_UM` (cancellation fee presence) and `KOJIAK_STP_UK_YMD` (suspension receipt date). |
| - | `JBSbatStringUtil.Rtrim` | JBSbatStringUtil | - | Trims trailing whitespace from extracted string values to normalize data. |
| - | `JBSbatKKConst.KKIFM151_KOJI_RSLT_4` | JBSbatKKConst | - | Constant reference resolving to `"4"` (Work Cancellation result code). |
| - | `outmap.setString` | - | - | Writes extracted cancellation metadata to the output map with keys `KOJI_RSLT`, `KOJIAK_STP_CANCEL_PRC_UM`, and `KOJIAK_FIN_YMD`. |
| - | `super.logPrint.chkLogLevel` | JBSbatLogUtil | - | Checks whether debug-level logging is enabled for conditional debug output. |
| - | `super.logPrint.printDebugLog` | JBSbatLogUtil | - | Writes debug log entries with work cancellation result and cancellation fee presence information. |

**CRUD Classification:**
- **R (Read)**: The method exclusively reads from the `KK_T_KJ_CL_WK` table — it performs no Create, Update, or Delete operations. It is a pure read/extract 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.

| # | Caller (Screen/Batch) | Call Chain (Full Path to this Method) | Terminal (SC / CRUD / Entity) |
|---|----------------------|--------------------------------------|-------------------------------|
| 1 | Batch: JBSbatKKCourseChgeTstaDayChsht | `execute` -> `selectKktKjClWk` | `executeKK_T_KJ_CL_WK_KK_SELECT_001 [R] KK_T_KJ_CL_WK` |

**Call chain description:**
This method is directly invoked from `JBSbatKKCourseChgeTstaDayChsht.execute()`, which is the main batch processing entry point for the daily course change status synchronization batch job. The batch job orchestrates work cancellation discovery by calling this method to populate the output map with cancellation metadata before proceeding to subsequent processing steps.

**Terminal operations reached from this method:**

| Operation | Type | Description |
|-----------|------|-------------|
| `executeKK_T_KJ_CL_WK_KK_SELECT_001` | Read | Queries `KK_T_KJ_CL_WK` table for work cancellation records |
| `db_KK_T_KJ_CL_WK.selectNext` | Read | Iterates through cancellation query result set |
| `JBSbatCommonDBInterface.getString` | Read | Extracts field values from result records |
| `outmap.setString` | Set | Writes work cancellation metadata to output interface map |
| `super.logPrint.printDebugLog` | Log | Emits debug log entries for work cancellation data |

## 6. Per-Branch Detail Blocks

**Block 1** — [LOCAL VARIABLE DECLARATION] `(L1878)`

> Initializes all local working variables for the work cancellation query processing. Declares `kojiRslt` (work result code), `kojiakStpCancelPrcUm` (cancellation fee indicator), `kojiFinClInfFlag` (completion/cancellation info flag), and `kojiClYmd` (work suspension receipt date). All strings are initialized to empty strings and the boolean flag to `false`.

| # | Type | Code |
|---|------|------|
| 1 | SET | `kojiRslt = ""` // Work result — initialized empty |
| 2 | SET | `kojiakStpCancelPrcUm = ""` // Work item cancellation fee presence — initialized empty |
| 3 | SET | `kojiFinClInfFlag = false` // Work completion/cancellation info existence flag (v20.00.01 change: promoted to local variable from instance field) |
| 4 | SET | `kojiClYmd = ""` // Work item suspension receipt date (OM-2014-0000957 addition) |

**Block 2** — [LOCAL VARIABLE DECLARATION] `(L1887)`

> Prepares the query result map holder and builds the WHERE clause parameters array.

| # | Type | Code |
|---|------|------|
| 1 | SET | `kktKjClWkMap_001 = null` // Work cancellation query result map — initialized null |
| 2 | SET | `whereKjClWkParam = {svcKeiNo, kojiakNo}` // WHERE clause parameters: [service contract number, work item number] |

**Block 3** — [METHOD CALL] `(L1893)`

> Executes the work cancellation SELECT query using the built WHERE parameters.

| # | Type | Code |
|---|------|------|
| 1 | CALL | `executeKK_T_KJ_CL_WK_KK_SELECT_001(whereKjClWkParam)` // Executes SELECT on KK_T_KJ_CL_WK table |

**Block 4** — [METHOD CALL] `(L1896)`

> Fetches the first record from the query result set.

| # | Type | Code |
|---|------|------|
| 1 | CALL | `kktKjClWkMap_001 = db_KK_T_KJ_CL_WK.selectNext()` // Retrieves first record from work cancellation query result |

**Block 5** — [IF] `(null != kktKjClWkMap_001)` `(L1898)`

> **Condition:** Checks whether any cancellation records were found in the query result. If records exist, the work completion/cancellation info flag is set to `true` and the while loop processes all records. If no records exist, the method skips to output population with default empty values.

| # | Type | Code |
|---|------|------|
| 1 | SET | `kojiFinClInfFlag = true` // Set flag to true since cancellation records exist |

**Block 5.1** — [WHILE] `(null != kktKjClWkMap_001)` `(L1903)`

> **Condition:** Iterates through all matching work cancellation records. For each record, the work result code is set to `"4"` (Work Cancellation — resolves constant `KKIFM151_KOJI_RSLT_4 = "4"`), the cancellation fee presence flag and suspension receipt date are extracted from the current record, and the next record is fetched. If multiple records exist, the last record's values are the ones that persist after the loop.

| # | Type | Code |
|---|------|------|
| 1 | SET | `kojiRslt = JBSbatKKConst.KKIFM151_KOJI_RSLT_4` // = "4" (Work Cancellation) [-> KKIFM151_KOJI_RSLT_4="4"] |
| 2 | SET | `kojiakStpCancelPrcUm = JBSbatStringUtil.Rtrim(kktKjClWkMap_001.getString(JBSbatKK_T_KJ_CL_WK.KOJIAK_STP_CANCEL_PRC_UM))` // Work item cancellation fee presence |
| 3 | SET | `kojiClYmd = JBSbatStringUtil.Rtrim(kktKjClWkMap_001.getString(JBSbatKK_T_KJ_CL_WK.KOJIAK_STP_UK_YMD))` // Work item suspension receipt date |
| 4 | SET | `kktKjClWkMap_001 = db_KK_T_KJ_CL_WK.selectNext()` // Fetch next record |

**Block 6** — [METHOD CALLS — OUTPUT POPULATION] `(L1918-L1925)`

> Writes the extracted work cancellation metadata to the output interface map. These three `setString` calls populate the fields that downstream processing consumes.

| # | Type | Code |
|---|------|------|
| 1 | CALL | `outmap.setString(JBSbatKKIFM151.KOJI_RSLT, kojiRslt)` // Work result [-> JBSbatKKIFM151.KOJI_RSLT="KOJI_RSLT"] |
| 2 | CALL | `outmap.setString(JBSbatKKIFM151.KOJIAK_STP_CANCEL_PRC_UM, kojiakStpCancelPrcUm)` // Work item cancellation fee presence [-> JBSbatKKIFM151.KOJIAK_STP_CANCEL_PRC_UM="KOJIAK_STP_CANCEL_PRC_UM"] |
| 3 | CALL | `outmap.setString(JBSbatKKIFM151.KOJIAK_FIN_YMD, kojiClYmd)` // Work completion date (OM-2014-0000957 addition) [-> JBSbatKKIFM151.KOJIAK_FIN_YMD="KOJIAK_FIN_YMD"] |

**Block 7** — [IF] `(super.logPrint.chkLogLevel(JBSbatLogUtil.MODE_DEBUG))` `(L1928)`

> **Condition:** Checks if debug logging mode is enabled. If so, logs the work cancellation result code and the cancellation fee presence indicator for troubleshooting purposes.

| # | Type | Code |
|---|------|------|
| 1 | EXEC | `super.logPrint.printDebugLog("Work cancellation search (work result): " + kojiRslt)` // Debug log entry |
| 2 | EXEC | `super.logPrint.printDebugLog("Work cancellation search (work item cancellation fee presence): " + kojiakStpCancelPrcUm)` // Debug log entry |

**Block 8** — [RETURN] `(L1933)`

> Returns the boolean flag indicating whether any work completion/cancellation information was found in the query.

| # | Type | Code |
|---|------|------|
| 1 | RETURN | `return kojiFinClInfFlag` // true if cancellation records existed, false otherwise |

## 7. Glossary

| Term | Type | Business Meaning |
|------|------|------------------|
| `kojiRslt` | Field | Work result — indicates the outcome of a field work operation. Values include: "0" (No Work), "1" (Work Complete), "2" (Work Amendment), "3" (Work Complete Cancellation), "4" (Work Cancellation), "6" (Mobile). |
| `kojiakStpCancelPrcUm` | Field | Work item cancellation fee presence/absence — a flag indicating whether a cancellation fee applies to the work item suspension. "UM" suffix typically denotes a presence/absence (umetsu) indicator in this system. |
| `kojiFinClInfFlag` | Field | Work completion/cancellation information existence flag — boolean set to `true` when the system finds work cancellation records for the given contract/item combination. |
| `kojiClYmd` | Field | Work item suspension receipt date — the date (year-month-day format) when the work item suspension was formally received/registered. Added in OM-2014-0000957. |
| `svcKeiNo` | Field | Service contract number — unique identifier for a customer's service contract line in the K-Opticom system. |
| `kojiakNo` | Field | Work item number — unique identifier for a field work item (工事案件) that is associated with a service contract. |
| `KK_T_KJ_CL_WK` | DB Table | Work Cancellation Work table — stores records of field work cancellations, including cancellation dates, fee indicators, and suspension information. The "KK" prefix indicates K-Opticom core, "T_KJ_CL_WK" stands for "Tabel koshi torikeshi work" (Work Cancellation Work Table). |
| `KKIFM151_KOJI_RSLT_4` | Constant | Work result code "4" — specifically means "Work Cancellation" (工事取消). Part of the work result code enumeration in `JBSbatKKConst`. |
| `JBSbatKKIFM151` | Constant Class | Course change applicable date update intermediate file constant class — defines the output field keys (`KOJI_RSLT`, `KOJIAK_FIN_YMD`, `KOJIAK_STP_CANCEL_PRC_UM`) used when writing work cancellation metadata to the output interface map. |
| `KOJIAK_STP_CANCEL_PRC_UM` | DB Column | Work item suspension cancellation fee presence/absence — column in `KK_T_KJ_CL_WK` indicating whether a cancellation fee applies. |
| `KOJIAK_STP_UK_YMD` | DB Column | Work item suspension receipt date — column in `KK_T_KJ_CL_WK` storing the date (YYYYMMDD format) when work suspension was formally received. |
| `KKSV\d{4}` | Screen Pattern | K-Opticom Service Screen — four-digit screen ID pattern used throughout the system. No direct screen entry points were found calling this method within 8 hops. |
| 工事取消 (koshi torikeshi) | Japanese Term | Work Cancellation — the process of cancelling a field work operation that was previously scheduled or registered. |
| 工事案件 (koshi anken) | Japanese Term | Work Item — a specific field work assignment linked to a service contract, representing a physical installation, modification, or removal task. |
| 工事完了 (koshi kanryo) | Japanese Term | Work Complete — status indicating field work has been successfully completed. |
| 工事正 (koshi tadasi) | Japanese Term | Work Amendment — status indicating the work details have been modified but the work remains active. |
| 工事保留 (koshi horyu) | Japanese Term | Work Retention/Hold — status indicating work has been temporarily paused or deferred. |
| outmap | Parameter | Output interface map — a service interface data transfer object that passes extracted metadata between batch processing stages. |
| `db_KK_T_KJ_CL_WK` | Instance Field | Database access object for the `KK_T_KJ_CL_WK` table — provides `selectNext()` for iterating through query results. |
| `JBSbatStringUtil.Rtrim` | Utility | String utility method that removes trailing whitespace from string values, used for data normalization. |
