---
title: "Detailed Design — JBSbatKKKjFinDataInTrn.insertUpdateKktkSvcKeiTV()"
---

# Business Logic — JBSbatKKKjFinDataInTrn.insertUpdateKktkSvcKeiTV() [282 LOC]

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

## 1. Role

### JBSbatKKKjFinDataInTrn.insertUpdateKktkSvcKeiTV()

This method orchestrates the **registration, update, and migration processing of device-provided service contracts** (`KK_T_KKTK_SVC_KEI`) for television (TV) service lines in a telecommunications batch job. It is the central dispatch point for inserting or modifying service contract records based on the current contract status. The method implements a **status-based routing/dispatch pattern**: it queries existing device-provided service contracts and then branches by the contract status code (`KKTK_SVC_KEI_STAT`) to execute the appropriate business path — "Contract Change In Progress" (110) triggers a delete-and-reinsert cycle that migrates old contract data to a new record, while "Inspection Completed" (020) and "Contract Completed" (030) trigger fresh contract registration with agreement creation.

For each contract record iterated, the method first runs two rule-engine validations: **Rule 0075** (Open Date settings for device-provided service) and **Rule 0067** (Charge Start Date settings for service). These rules determine the key date (`kjeYmd`) and planned service/charge start dates (`planStaymd2`, `planChrgStaymd2`). If either rule fails to produce a valid date, processing halts with a `false` return. When processing "Contract Change In Progress" records for STB-to-4K migration (B-CAS unnecessary HDD capacity), the method also extracts legacy B-CAS information from the old set-top box and registers the returned device's B-CAS data internally. Finally, after all conditional branches, the method updates device migration reservations.

## 2. Processing Pattern (Detailed Business Logic)

```mermaid
flowchart TD
    START(["insertUpdateKktkSvcKeiTV method"])

    S1["Set kktkSvcKei_whereParam from kojiakNo and svcKeiNo"]
    S2["executeKK_T_KKTK_SVC_KEI_KK_SELECT_035 query"]
    S3["Fetch kktkSvcKeiMap_035 via selectNext"]

    C1["kktkSvcKeiMap_035 == null?"]

    LOG1["Log debug: service contract number not found"]
    C1B["kktkSvcKeiMap_035 != null?"]

    INIT["Init shorizumiKeyList for dedup tracking"]
    WL["kktkSvcKeiMap_035 != null?"]

    H4["Set haisoWayCd to 2 - Worker Company Delivery"]
    H5["callRule0075001 Rule 75 OpenDate settings"]
    H6["getKjnYmd get key date from Rule 75"]

    C2["kjnYmd is empty?"]
    F1["Log rule75 error - return false"]

    H7["getStaymd2 get planned service start date"]

    C3["planStaymd2 is empty?"]
    F2["Log net end error - return false"]

    H8["callRule0067001 Rule 67 Charge start date"]
    H9["Get svcUseStaKiboYmd from record"]
    H10["getSvcChrgStaymd2 get planned charge start date"]

    C4["planChrgStaymd2 is empty?"]
    F3["Log rule67 error - return false"]

    H11["Get kktkSvcKeiStat from record"]
    H12["chkLogLevel DEBUG log status"]

    C5["kktkSvcKeiStat equals 110?"]

    SUB1["Contract Change Processing"]

    H13["Get kktkSvcKeiNo from record"]
    H14["Get geneAddDtm from record"]

    H15["Build where_map from keys"]
    H16["db selectByPrimaryKeys"]

    C6["keiyakuHenkoMap == null?"]
    F4["Return false"]

    H17["setNewKikiDate update registration with plan dates"]
    H18["executeKK_T_KKTK_SVC_KEI_KK_SELECT_089 full retrieval"]
    H19["Fetch kktkSvcKeiMapCur via selectNext"]

    H20["kktkSvcKeiInsertNetTv insert network contract"]

    H21["logicalDeleteKktkSvcKei delete old record"]

    H22["Get hddCapaCd from record"]

    C7["hddCapaCd in hddCapaBcasNoneList?"]
    H23["searchBcas get B-CAS info"]

    C7B["bcasInfo != null?"]
    H24["insertBcasDsl register B-CAS deregistration"]

    H25["chkHmpinKiki check returned device"]

    C8["chkHmpinKiki true?"]
    H26["insertHmpInKikiBcasInfoIntrnl register device"]

    C9["kktkSvcKeiStat equals 910 or 920?"]

    SUB2["Skip Processing"]

    H27["fetch next record via selectNext"]

    C10["kktkSvcKeiStat equals 020 or 030?"]

    SUB3["Contract Registration"]

    H28["Get kktkSvcKeiNo and geneAddDtm from record"]
    H29["Build kktkSvcKei_param array"]
    H30["executeKK_T_KKTK_SVC_KEI_PKSELECT primary key query"]

    C11["kktkSvcKei_map == null?"]
    F5["Throw JBSbatBusinessException"]

    H31["kktkSvcKeiStat equals 020?"]
    H32["insertKktkSvcKeiTeiketsu register contract agreement"]
    H33["Thread.sleep 1 ms"]

    H34["insertKktkSvcKei register service contract"]

    C12["SVC_KEI_UCWK_NO not in shorizumiKeyList?"]
    H35["insertSvcKeiUcwkNewTv register service internal line"]
    H36["shorizumiKeyList.add SVC_KEI_UCWK_NO"]

    END1["updateIdoRsvTrgGaiWhereKktkSvcKei update migration reservation"]
    END2["fetch next record via selectNext"]

    RET["return true"]
    END_NODE(["End"])

    START --> S1 --> S2 --> S3
    S3 --> C1
    C1 --> LOG1
    LOG1 --> C1B
    C1B --> RET
    C1B --> INIT --> WL
    WL --> H4 --> H5 --> H6
    H6 --> C2
    C2 --> F1
    C2 --> H7
    H7 --> C3
    C3 --> F2
    C3 --> H8 --> H9 --> H10
    H10 --> C4
    C4 --> F3
    C4 --> H11 --> H12 --> C5
    C5 --> SUB1
    C5 --> C9
    SUB1 --> H13 --> H14 --> H15 --> H16
    H16 --> C6
    C6 --> F4
    C6 --> H17 --> H18 --> H19 --> H20 --> H21 --> H22
    H22 --> C7
    C7 --> H23 --> C7B
    C7B --> H24
    C7B --> END1
    H24 --> H25 --> C8
    C8 --> H26 --> END1
    C8 --> END1
    C7 --> END1
    C9 --> SUB2
    C9 --> C10
    SUB2 --> H27 --> WL
    C10 --> SUB3
    C10 --> END1
    SUB3 --> H28 --> H29 --> H30 --> C11
    C11 --> F5
    C11 --> H31
    H31 --> H32 --> H33 --> H34
    H31 --> H34
    H34 --> C12
    C12 --> H35 --> H36 --> END1
    C12 --> END1
    H36 --> END1
    F4 --> RET
    F5 --> RET
    H27 --> WL
    END1 --> END2 --> WL
    RET --> END_NODE

    classDef fail fill:#f96,stroke:#f60,color:#fff
    classDef ret fill:#9f9,stroke:#090,color:#fff
    class F1,F2,F3,F4,F5 fail
    class RET,END_NODE ret
```

## 3. Parameter Analysis

| No | Parameter Name | Type | Business Description |
|----|---------------|------|---------------------|
| 1 | `kojiakNo` | `String` | Work case number (工事案件番号) — The unique identifier for the overall construction/project case that groups service contracts. Used to query device-provided service contracts and passed as a key to Rule 75 for key date resolution. |
| 2 | `svcKeiNo` | `String` | Service contract number (サービス契約番号) — The identifier for the service contract line. Used as the query key to find existing `KK_T_KKTK_SVC_KEI` records via the `KK_SELECT_035` SQL definition. |
| 3 | `svcCd` | `String` | Service code (サービスコード) — The service type code (e.g., FTTH, Cable TV). Passed to `kktkSvcKeiInsertNetTv()` to determine the specific network service being registered. |
| 4 | `svcKeiMap` | `JBSbatCommonDBInterface` | Service contract data map — A structured map containing service contract header information, used as the input to both Rule 75 (open date settings) and Rule 67 (charge start date settings). |
| 5 | `kojiAkSbtCd` | `String` | Work case subtype code (工事案件種別コード) — Classifies the type of work case (e.g., new installation, change, cancellation). Passed to `insertSvcKeiUcwkNewTv()` for service contract internal line registration. |
| 6 | `mskmDtlNo` | `String` | Application details number (申請明細番号) — The specific application detail identifier. Used to link service contract agreements and internal lines to their parent application record. |
| 7 | `idoDiv` | `String` | Migration classification (異動区分) — Indicates the type of migration operation (e.g., device change, address change, new service). Used across multiple insert/update methods to classify the migration action. |
| 8 | `kojiFinYmd` | `String` | Work completion date (工事完了日) — The date when the construction/installation work is completed. Used as a reference date for key date resolution, set-new-start-date, and service contract registration. |
| 9 | `rsvAplyYmd` | `String` | Reservation application date (予約申請日) — The date the device migration reservation was applied. Used in `updateIdoRsvTrgGaiWhereKktkSvcKei()` to update the migration reservation target for processed devices. |

**Instance fields / external state read by this method:**
- `super.opeDate` — The operation date (business processing date), used as the date key in the `KK_SELECT_089` full item retrieval query.
- `super.logPrint` — The logging utility for debug-level status logging of the service contract status.
- `db_KK_T_KKTK_SVC_KEI` — Database access interface for the `KK_T_KKTK_SVC_KEI` (device-provided service contract) table, used for `selectNext()` and `selectByPrimaryKeys()` operations.
- `db_KK_T_KKTK_SVC_KEI_089` — Secondary database access interface for the `KK_SELECT_089` query result cursor.
- `hddCapaBcasNoneList` — A pre-loaded list of HDD capacity codes representing B-CAS unnecessary devices (used for STB-to-4K migration scenarios).

## 4. CRUD Operations / Called Services

| CRUD | SC / CBS | SC Code | Entity / DB | Operation Description |
|------|----------|---------|-------------|----------------------|
| R | `executeKK_T_KKTK_SVC_KEI_KK_SELECT_035` | KK_T_KKTK_SVC_KEI_SELECT_035 | KK_T_KKTK_SVC_KEI | Queries device-provided service contracts by `kojiakNo` and `svcKeiNo` to retrieve existing records for processing. |
| R | `db_KK_T_KKTK_SVC_KEI.selectNext` | - | KK_T_KKTK_SVC_KEI | Fetches the next record from the cursor result of the `KK_SELECT_035` query. |
| R | `getString (KKTK_SVC_KEI_NO)` | - | KK_T_KKTK_SVC_KEI | Reads the service contract number field from the query result map. |
| R | `getString (SVC_USE_STA_KIBO_YMD)` | - | KK_T_KKTK_SVC_KEI | Reads the service usage start requested date field. |
| R | `getString (KKTK_SVC_KEI_STAT)` | - | KK_T_KKTK_SVC_KEI | Reads the service contract status field to determine processing branch (110/020/030/910/920). |
| R | `getString (GENE_ADD_DTM)` | - | KK_T_KKTK_SVC_KEI | Reads the generation registration datetime field, used as a key for PK search and dedup. |
| R | `getString (HDD_CAPA_CD)` | - | KK_T_KKTK_SVC_KEI | Reads the HDD capacity code, used to identify STB-to-4K migration (B-CAS unnecessary) devices. |
| R | `db_KK_T_KKTK_SVC_KEI.selectByPrimaryKeys` | - | KK_T_KKTK_SVC_KEI | Primary key lookup of the contract record using `kktkSvcKeiNo` and `geneAddDtm`. |
| C | `executeKK_T_KKTK_SVC_KEI_KK_SELECT_089` | KK_T_KKTK_SVC_KEI_SELECT_089 | KK_T_KKTK_SVC_KEI | Full item retrieval query with contract number and operation date as keys. |
| R | `db_KK_T_KKTK_SVC_KEI_089.selectNext` | - | KK_T_KKTK_SVC_KEI | Fetches the next record from the `KK_SELECT_089` cursor. |
| C | `executeKK_T_KKTK_SVC_KEI_PKSELECT` | KK_T_KKTK_SVC_KEI_PKSELECT | KK_T_KKTK_SVC_KEI | Primary key search query for the service contract record. |
| C | `insertKktkSvcKeiTeiketsu` | - | KK_T_KKTK_SVC_KEI | Registers the service contract agreement (teiketsu) when inspection is completed (status 020). |
| C | `insertKktkSvcKei` | - | KK_T_KKTK_SVC_KEI | Registers the new device-provided service contract record with planned service/charge start dates. |
| C | `insertSvcKeiUcwkNewTv` | - | KK_T_SVC_KEI_UCWK | Registers the service contract internal line (ucwk) if not already processed (dedup check). |
| C | `kktkSvcKeiInsertNetTv` | - | KK_T_KKTK_SVC_KEI | Inserts the network service contract for contract change-in-progress scenarios. |
| D | `logicalDeleteKktkSvcKei` | - | KK_T_KKTK_SVC_KEI | Performs logical deletion of the old "Contract Change In Progress" record after creating the new one. |
| U | `updateIdoRsvTrgGaiWhereKktkSvcKei` | - | KK_T_IDO_RSV | Updates device migration reservation records for processed devices. |
| R | `searchBcas` | - | (B-CAS related tables) | Retrieves B-CAS information from the old STB for B-CAS deregistration processing. |
| C | `insertBcasDsl` | - | (B-CAS DSL tables) | Registers B-CAS deregistration when old device had B-CAS unnecessary HDD. |
| C | `insertHmpInKikiBcasInfoIntrnl` | - | (Returned device B-CAS tables) | Registers the returned device's B-CAS info when the device is confirmed to exist. |
| - | `callRule0075001` | Rule 0075 | - | Calls Rule 0075 for Open Date settings on device-provided service. |
| - | `callRule0067001` | Rule 0067 | - | Calls Rule 0067 for Charge Start Date settings on service. |
| - | `getKjnYmd` | - | - | Resolves key date (`kjeYmd`) from Rule 75 results. |
| - | `getStaymd2` | - | - | Resolves planned service start date from Rule 75 results. |
| - | `getSvcChrgStaymd2` | - | - | Resolves planned charge start date from Rule 67 results. |
| - | `setNewKikiDate` | - | - | Sets new start dates (`planStaymd2`, `planChrgStaymd2`, `kojiFinYmd`) on the contract record. |
| - | `chkHmpinKiki` | - | - | Checks if a returned device (by model code, serial number, change number) exists. |
| - | `JBSbatStringUtil.Rtrim` | - | - | Trims whitespace from string fields read from database records. |
| - | `JBSbatKKConst.CD01148_HAISO_WAY_CD_2` | - | - | Constant: Delivery method code = "2" (Worker Company Delivery / 工事会社配送). |
| - | `JBSbatKKConst.CD00056_KKTK_SVC_KEI_STAT_110` | - | - | Constant: Contract Change In Progress status = "110". |
| - | `JBSbatKKConst.CD00056_KKTK_SVC_KEI_STAT_020` | - | - | Constant: Inspection Completed status = "020". |
| - | `JBSbatKKConst.CD00056_KKTK_SVC_KEI_STAT_030` | - | - | Constant: Contract Completed status = "030". |
| - | `JBSbatKKConst.CD00056_KKTK_SVC_KEI_STAT_910` | - | - | Constant: Status 910 (data to be skipped). |
| - | `JBSbatKKConst.CD00056_KKTK_SVC_KEI_STAT_920` | - | - | Constant: Status 920 (data to be skipped). |
| - | `JBSbatLogUtil.MODE_DEBUG` | - | - | Log level constant for debug-mode logging. |
| - | `JBSbatBusinessException` | - | - | Throws exception `EKKB0210CE` when PK query for service contract returns null. |
| - | `Thread.sleep(1)` | - | - | Sleeps 1ms after contract agreement registration to prevent timestamp duplication of generation records. |

## 5. Dependency Trace

| # | Caller (Screen/Batch) | Call Chain (Full Path to this Method) | Terminal (SC / CRUD / Entity) |
|---|----------------------|--------------------------------------|-------------------------------|
| 1 | Batch: JBSbatKKKjFinDataInTrn.execute() | `execute()` iterates migration reservations → `insertUpdateKktkSvcKeiTV(kojiakNo_151, svcKeiNo_151, svcCd_151, svcKeiMap_106, kojiAkSbtCd, idoRsvMskmDtlNo, idoRsvIdoDiv, kojiakFinYmd_151, rsvAplyYmd)` | `updateIdoRsvTrgGaiWhereKktkSvcKei [U] KK_T_IDO_RSV`, `insertKktkSvcKei [C] KK_T_KKTK_SVC_KEI`, `insertKktkSvcKeiTeiketsu [C] KK_T_KKTK_SVC_KEI`, `insertSvcKeiUcwkNewTv [C] KK_T_SVC_KEI_UCWK`, `logicalDeleteKktkSvcKei [D] KK_T_KKTK_SVC_KEI`, `kktkSvcKeiInsertNetTv [C] KK_T_KKTK_SVC_KEI`, `searchBcas [R] B-CAS`, `insertBcasDsl [C] B-CAS DSL`, `insertHmpInKikiBcasInfoIntrnl [C] Returned Device B-CAS` |

**Caller details:**
- The method is called from the `execute()` batch entry method within the same class (`JBSbatKKKjFinDataInTrn`), which iterates over device migration reservation records (`KK_T_IDO_RSV`). For each reservation, it invokes `insertUpdateKktkSvcKeiTV` to register or update the corresponding device-provided service contract. The return value determines whether the batch continues (`true`) or aborts with `null` (`false`).

## 6. Per-Branch Detail Blocks

**Block 1** — SET `(Initialize query parameters)` (L11869)

| # | Type | Code |
|---|------|------|
| 1 | SET | `kktkSvcKei_whereParam = {kojiakNo, svcKeiNo}` // Build query key array from input parameters |
| 2 | EXEC | `executeKK_T_KKTK_SVC_KEI_KK_SELECT_035(kktkSvcKei_whereParam)` // Execute SQL definition KK_SELECT_035 to query device-provided service contracts |
| 3 | SET | `kktkSvcKeiMap_035 = db_KK_T_KKTK_SVC_KEI.selectNext()` // Fetch first result from query cursor |

**Block 2** — IF `(null == kktkSvcKeiMap_035 — No contract found)` (L11881)

> When the query returns no records, log a debug message indicating the service contract number does not exist in the table. Note: this branch does NOT return early — processing continues since the outer null-check at Block 3 will handle this.

| # | Type | Code |
|---|------|------|
| 1 | EXEC | `super.logPrint.printDebugLog("機器提供サービス契約テーブルにサービス契約番号：" + svcKeiNo + "が存在しません。")` // Log debug: Service contract number not found in device-provided service contract table |

**Block 3** — IF `(null != kktkSvcKeiMap_035 — Contract records exist)` (L11886)

> This is the main processing block. When contract records are found, iterate through each record and process it based on status.

| # | Type | Code |
|---|------|------|
| 1 | SET | `shorizumiKeyList = new ArrayList<String>()` // Initialize dedup list to track already-processed SVC_KEI_UCWK_NO values |
| 2 | WHILE | `while (null != kktkSvcKeiMap_035)` // Iterate over all records returned by the cursor |

**Block 3.1** — SET `(Delivery method code and Rule 75)` (L11892)

| # | Type | Code |
|---|------|------|
| 1 | SET | `haisoWayCd = JBSbatKKConst.CD01148_HAISO_WAY_CD_2 = "2"` // Delivery method code: "2" = Worker Company Delivery (工事会社配送) — was hardcoded, now constant-resolved |
| 2 | CALL | `checkList75 = callRule0075001(svcKeiMap, haisoWayCd)` // Rule 0075: Open Date settings definition for device-provided service |

**Block 3.2** — IF `(Rule 75 key date resolution — kjnYmd is empty)` (L11899)

> After Rule 75 processing, resolve the key date. If the result is empty, this is a rule error and processing aborts.

| # | Type | Code |
|---|------|------|
| 1 | SET | `kjnYmd = getKjnYmd(checkList75, kktkSvcKeiMap_035, kojiakNo, idoDiv, kojiFinYmd)` // Get key date from Rule 75 results — was previously a boolean flag, now resolves the actual date |
| 2 | IF | `if ("".equals(JBSbatStringUtil.Rtrim(kjnYmd)))` // Key date could not be obtained (Rule error) |
| 3 | EXEC | `super.logPrint.printDebugLog("rule75Flgがfalse:サービス契約番号：" + kktkSvcKeiMap_035.getString(KKTK_SVC_KEI_NO))` // Log debug |
| 4 | RETURN | `return false` // Abort processing — Rule 75 validation failed |

**Block 3.3** — IF `(Rule 75 planned service start date — planStaymd2 is empty)` (L11909)

> After key date resolution, get the planned service start date. If empty, this is a rule error and processing aborts.

| # | Type | Code |
|---|------|------|
| 1 | SET | `planStaymd2 = getStaymd2(checkList75, kktkSvcKeiMap_035, kjnYmd)` // Get planned service start date — v20.00.01 addition, now takes kjnYmd parameter |
| 2 | IF | `if ("".equals(JBSbatStringUtil.Rtrim(planStaymd2)))` // Planned service start date could not be obtained (Rule error) |
| 3 | EXEC | `super.logPrint.printDebugLog("insertUpdatekktkSvcKeiNet_END")` // Log debug |
| 4 | RETURN | `return false` // Abort — Planned service start date invalid |

**Block 3.4** — SET `(Rule 67 charge start date processing)` (L11919)

> Run Rule 0067 to determine the planned charge start date.

| # | Type | Code |
|---|------|------|
| 1 | CALL | `checkList2 = callRule0067001(svcKeiMap, kktkSvcKeiMap_035)` // Rule 0067: Charge start date settings for service |
| 2 | SET | `svcUseStaKiboYmd = JBSbatStringUtil.Rtrim(kktkSvcKeiMap_035.getString(SVC_USE_STA_KIBO_YMD))` // Read service usage start requested date from record |
| 3 | SET | `planChrgStaymd2 = getSvcChrgStaymd2(checkList2, svcUseStaKiboYmd, kjnYmd)` // Get planned charge start date — v20.00.01 change, now takes kjnYmd instead of boolean flag return |
| 4 | IF | `if ("".equals(JBSbatStringUtil.Rtrim(planChrgStaymd2)))` // Planned charge start date could not be obtained (Rule error) |
| 5 | EXEC | `super.logPrint.printDebugLog("rule67Flgがfalse:サービス契約番号：" + kktkSvcKeiMap_035.getString(KKTK_SVC_KEI_NO))` // Log debug |
| 6 | RETURN | `return false` // Abort — Rule 67 validation failed |

**Block 3.5** — SET `(Status-based routing)` (L11931)

> Read the contract status and branch into one of three processing paths based on the status code.

| # | Type | Code |
|---|------|------|
| 1 | SET | `kktkSvcKeiStat = JBSbatStringUtil.Rtrim(kktkSvcKeiMap_035.getString(KKTK_SVC_KEI_STAT))` // Read contract status field |
| 2 | IF | `if (super.logPrint.chkLogLevel(JBSbatLogUtil.MODE_DEBUG))` // Debug logging check |
| 3 | EXEC | `super.logPrint.printDebugLog("機器提供サービス契約ステータス（テレビ）：" + kktkSvcKeiStat)` // Log debug: Device-provided service contract status (TV) |

**Block 3.5.1** — IF-THEN `(Status == "110" — Contract Change In Progress)` (L11941)

> **Condition:** `JBSbatKKConst.CD00056_KKTK_SVC_KEI_STAT_110 = "110"` (Contract Change In Progress / 契約変更中) — OM-2014-0002138/1490 change.

> This branch handles the delete-and-insert pattern for contract change. Instead of updating the existing record, it creates a new record and logically deletes the old one.

| # | Type | Code |
|---|------|------|
| 1 | SET | `kktkSvcKeiNo = JBSbatStringUtil.Rtrim(kktkSvcKeiMap_035.getString(KKTK_SVC_KEI_NO))` // Read contract number |
| 2 | SET | `geneAddDtm = JBSbatStringUtil.Rtrim(kktkSvcKeiMap_035.getString(GENE_ADD_DTM))` // Read generation registration datetime |
| 3 | SET | `keiyakuHenkoMap = new JBSbatCommonDBInterface()` // Allocate new contract change map |
| 4 | SET | `where_map = new JBSbatCommonDBInterface()` // Allocate WHERE clause map |
| 5 | EXEC | `where_map.setValue(KKTK_SVC_KEI_NO, kktkSvcKeiNo)` // Set contract number in WHERE map |
| 6 | EXEC | `where_map.setValue(GENE_ADD_DTM, geneAddDtm)` // Set generation datetime in WHERE map |
| 7 | SET | `keiyakuHenkoMap = db_KK_T_KKTK_SVC_KEI.selectByPrimaryKeys(where_map)` // Primary key lookup of the contract record |
| 8 | IF | `if (null == keiyakuHenkoMap)` // Primary key record not found |
| 9 | RETURN | `return false` // Abort — Contract record not found |
| 10 | SET | `setNewKikiDate(keiyakuHenkoMap, planStaymd2, planChrgStaymd2, kojiFinYmd)` // Set new start dates — v20.00.01 change, now includes planStaymd2 and planChrgStaymd2 |
| 11 | EXEC | `executeKK_T_KKTK_SVC_KEI_KK_SELECT_089(new Object[]{kktkSvcKeiNo, super.opeDate})` // Full item retrieval with contract number and operation date |
| 12 | SET | `kktkSvcKeiMapCur = db_KK_T_KKTK_SVC_KEI_089.selectNext()` // Fetch current record |
| 13 | CALL | `kktkSvcKeiInsertNetTv(keiyakuHenkoMap, kktkSvcKeiMapCur, idoDiv, kojiFinYmd, svcCd, rsvAplyYmd)` // Insert network service contract — v20.00.01 change, now passes svcCd (not svcCd_151) and rsvAplyYmd |
| 14 | CALL | `logicalDeleteKktkSvcKei(kktkSvcKeiMap_035)` // Logically delete the old "Contract Change In Progress" record |
| 15 | SET | `hddCapaCd = JBSbatStringUtil.Rtrim(kktkSvcKeiMap_035.getString(HDD_CAPA_CD))` // Read HDD capacity code |
| 16 | IF | `if (hddCapaBcasNoneList.contains(hddCapaCd))` // HDD capacity matches B-CAS unnecessary list — STB to 4K exchange scenario |
| 17 | SET | `bcasInfo = searchBcas(kktkSvcKeiMap_035)` // Retrieve B-CAS info from old STB |
| 18 | IF | `if (null != bcasInfo)` // B-CAS info found |
| 19 | CALL | `insertBcasDsl(bcasInfo)` // Register B-CAS deregistration |
| 20 | IF | `if (chkHmpinKiki(TAKNKIKI_MODEL_CD, KIKI_SEIZO_NO, KIKI_CHG_NO))` // Check if returned device exists |
| 21 | CALL | `insertHmpInKikiBcasInfoIntrnl(bcasInfo, idoDiv)` // Register returned device B-CAS info |

**Block 3.5.2** — ELSE-IF `(Status == "910" or "920" — Skip)` (L11997)

> **Conditions:**
> - `JBSbatKKConst.CD00056_KKTK_SVC_KEI_STAT_910 = "910"`
> - `JBSbatKKConst.CD00056_KKTK_SVC_KEI_STAT_920 = "920"`

> Status 910/920 records have their status data excluded from the previous SQL, so skip them and continue to the next record.

| # | Type | Code |
|---|------|------|
| 1 | EXEC | `kktkSvcKeiMap_035 = db_KK_T_KKTK_SVC_KEI.selectNext()` // Skip: fetch next record for the while loop |
| 2 | EXEC | `continue` // Skip to next iteration |

**Block 3.5.3** — ELSE-IF `(Status == "020" or "030" — Contract Registration)` (L12009)

> **Conditions:**
> - `JBSbatKKConst.CD00056_KKTK_SVC_KEI_STAT_020 = "020"` (Inspection Completed / 照査済)
> - `JBSbatKKConst.CD00056_KKTK_SVC_KEI_STAT_030 = "030"` (Contract Completed / 締結済) — OM-2013-0005089 change. Only status 020 and 030 are eligible for creating "100" (Service Provision In Progress) records. Other statuses are silently ignored.

| # | Type | Code |
|---|------|------|
| 1 | SET | `kktkSvcKeiNo_035 = JBSbatStringUtil.Rtrim(kktkSvcKeiMap_035.getString(KKTK_SVC_KEI_NO))` // Read contract number |
| 2 | SET | `geneAddDtm_035 = JBSbatStringUtil.Rtrim(kktkSvcKeiMap_035.getString(GENE_ADD_DTM))` // Read generation registration datetime |
| 3 | SET | `kktkSvcKei_map = null` // Allocate contract map |
| 4 | SET | `kktkSvcKei_param = new String[2]` // Allocate parameter array |
| 5 | SET | `kktkSvcKei_param[0] = kktkSvcKeiNo_035` // Set contract number as key |
| 6 | SET | `kktkSvcKei_param[1] = geneAddDtm_035` // Set generation datetime as key |
| 7 | SET | `kktkSvcKei_map = executeKK_T_KKTK_SVC_KEI_PKSELECT(kktkSvcKei_param)` // Primary key search of service contract |
| 8 | IF | `if (null == kktkSvcKei_map)` // PK query result is null |
| 9 | EXEC | `throw new JBSbatBusinessException(EKKB0210CE, {"機器提供サービス契約", "機器提供サービス契約番号（テレビ）：" + kktkSvcKeiNo_035})` // Throw business exception with service contract identifier |
| 10 | ELSE | // PK query result exists |
| 11 | IF | `if (JBSbatKKConst.CD00056_KKTK_SVC_KEI_STAT_020.equals(kktkSvcKeiStat))` // Inspection Completed (020) — create contract agreement |
| 12 | CALL | `insertKktkSvcKeiTeiketsu(kktkSvcKei_map, mskmDtlNo, idoDiv)` // Register service contract agreement |
| 13 | EXEC | `Thread.sleep(1)` // Sleep 0.001 seconds to prevent generation registration datetime duplication |
| 14 | CALL | `insertKktkSvcKei(kktkSvcKei_map, mskmDtlNo, idoDiv, planStaymd2, planChrgStaymd2, kojiFinYmd)` // Register service contract with plan dates — v20.00.01 change, now takes planStaymd2, planChrgStaymd2, kojiFinYmd |
| 15 | IF | `if (!shorizumiKeyList.contains(kktkSvcKei_map.getString(SVC_KEI_UCWK_NO)))` // Service contract internal line not yet processed (dedup check) |
| 16 | CALL | `insertSvcKeiUcwkNewTv(SVC_KEI_NO, SVC_KEI_UCWK_NO, svcKeiMap, kojiAkSbtCd, mskmDtlNo, idoDiv, kojiakNo, kojiFinYmd)` // Register service contract internal line — v20.00.01 change, now takes kojiakNo and kojiFinYmd |
| 17 | SET | `shorizumiKeyList.add(SVC_KEI_UCWK_NO)` // Mark internal line as processed |

**Block 4** — SET `(Update migration reservation after each record)` (L12047)

> After processing each contract record (regardless of branch), update the device migration reservation target. This is executed for every record in the cursor iteration.

| # | Type | Code |
|---|------|------|
| 1 | CALL | `updateIdoRsvTrgGaiWhereKktkSvcKei(kktkSvcKeiMap_035.getString(KKTK_SVC_KEI_NO), rsvAplyYmd, idoDiv, kojiFinYmd)` // Update device migration reservation for processed device |
| 2 | SET | `kktkSvcKeiMap_035 = db_KK_T_KKTK_SVC_KEI.selectNext()` // Fetch next record for while loop |

**Block 5** — RETURN `(All records processed successfully)` (L12054)

| # | Type | Code |
|---|------|------|
| 1 | RETURN | `return true` // Processing completed successfully |

## 7. Glossary

| Term | Type | Business Meaning |
|------|------|------------------|
| `KKTK_SVC_KEI` | Field/Table | Device-provided service contract — The core service contract record managed by the device-provided (leased equipment) service system. Corresponds to table `KK_T_KKTK_SVC_KEI`. |
| `KKTK_SVC_KEI_STAT` | Field | Service contract status — Classification of the contract lifecycle stage. Values: "010" (Registration in progress), "020" (Inspection completed), "030" (Contract completed), "100" (Service provision in progress), "110" (Contract change in progress), "210" (Service suspension), "220" (Service termination), "910"/"920" (Skip/Reserved). |
| `KKTK_SVC_KEI_NO` | Field | Service contract number — Unique identifier for a device-provided service contract record. |
| `SVC_KEI_NO` | Field | Service contract number (header) — The service contract header identifier, used to link multiple contract lines (internal lines). |
| `SVC_KEI_UCWK_NO` | Field | Service detail work number — Internal tracking ID for service contract line items. Used for deduplication to avoid reprocessing the same internal line. |
| `SVC_USE_STA_KIBO_YMD` | Field | Service usage start requested date — The date the customer requested to start using the service. |
| `GENE_ADD_DTM` | Field | Generation registration datetime — Timestamp when a new generation (version) of the contract record was created. Used for version dedup in contract change scenarios. |
| `HDD_CAPA_CD` | Field | HDD capacity code — Identifies the hard disk drive capacity of the set-top box. Used to determine if the device is B-CAS unnecessary (for STB-to-4K migration). |
| `kjeYmd` | Field | Key date — The reference date resolved from Rule 75, used to determine service and charge start dates. |
| `planStaymd2` | Field | Planned service start date — The planned date when the service will start, resolved from Rule 75. |
| `planChrgStaymd2` | Field | Planned charge start date — The planned date when billing will start, resolved from Rule 67. |
| `kojiakNo` | Field | Work case number — The unique identifier for the construction/project case. |
| `kojiAkSbtCd` | Field | Work case subtype code — Classifies the type of work case. |
| `mskmDtlNo` | Field | Application details number — The specific application detail identifier linking to the parent application. |
| `idoDiv` | Field | Migration classification — Indicates the type of migration operation (device change, address change, etc.). |
| `kojiFinYmd` | Field | Work completion date — The date when construction/installation work was completed. |
| `rsvAplyYmd` | Field | Reservation application date — The date the device migration reservation was applied. |
| `haisoWayCd` | Field | Delivery method code — Classification of delivery method. Value "2" = Worker Company Delivery (工事会社配送). |
| CD00056 | Constant | Device-provided service contract status constant group — Contains status codes 010, 020, 030, 100, 110, 210, 220, 910, 920. |
| CD01148 | Constant | Delivery method constant group — Contains delivery method code "2" (Worker Company Delivery). |
| Rule 0075 | Business rule | Open Date settings definition for device-provided service — Determines the key date and planned service start date based on service contract parameters. |
| Rule 0067 | Business rule | Charge start date settings definition for service — Determines the planned charge start date based on service usage start requested date. |
| `kkTIdoRsv015Flg` | Field | Device migration reservation search flag — Flag indicating whether a migration reservation record was found. |
| STB | Acronym | Set-Top Box — The device used to receive digital broadcast signals. Legacy STBs have B-CAS cards. |
| 4K | Business term | 4K Broadcasting — Next-generation high-resolution broadcasting requiring new 4K-compatible devices (B-CAS unnecessary). |
| B-CAS | Acronym | B-CAS (Broadcasting Data Management System) — A conditional access card used in Japanese digital broadcasting for subscription management and content protection. |
| B-CAS unnecessary HDD | Business term | HDDs that do not require B-CAS cards, used in 4K devices. Migration from STB to 4K requires extracting legacy B-CAS information from the old device. |
| `shorizumiKeyList` | Local variable | Deduplication list — Tracks already-processed service contract internal lines to avoid duplicate processing during cursor iteration. |
| Device-provided service | Business term | Leased equipment service — A service model where the operator provides and maintains the set-top box or other equipment to the customer under a service contract. |
| Contract Change In Progress | Business term | Status "110" — A transitional state where a contract change is being processed. The old record is logically deleted and a new one is created. |
| Inspection Completed | Business term | Status "020" — The service contract has passed inspection and is ready for agreement creation. |
| Contract Completed | Business term | Status "030" — The service contract has been finalized and is ready for registration. |
| `kkTIdoRsv015` | Entity | Device migration reservation table (`KK_T_IDO_RSV_015`) — Stores reservations for device migration operations. |
