# Business Logic — JBSbatKKMiStcKikiCncl.executeStbDsl() [493 LOC]

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

## 1. Role

### JBSbatKKMiStcKikiCncl.executeStbDsl()

This method performs the **STB (Set-Top Box) cancellation (DSL) process** for equipment-provided service contracts in a telecom provider's batch processing pipeline. It handles the complete lifecycle of canceling an STB equipment-provided service contract, including associated B-CAS and C-CAS registration numbers, and updates all dependent data structures accordingly.

The method implements a **delegation pattern**, routing work to specialized helper methods for each distinct concern: querying the equipment-provided service contract table (`searchKktk`), updating contract status (`executeKK_T_KKTK_SVC_KEI_PKUPDATE`), processing return equipment (`hampinUpdateAndDelete`), inserting cancellation records (`insertKktk`), and creating sub-type entries (`createSubTypeKK0161`).

It serves as the **core cancellation dispatcher** within the batch service layer, orchestrating a multi-step workflow: first handling the main STB contract cancellation, then iteratively processing any linked B-CAS and C-CAS sub-contracts (including special handling for contracts "in change" — status "110"), and finally triggering downstream price code/plan change checks (`executePcrsPplanChgChk`) if all cancellations completed successfully. The method supports three contractual states: **normal cancellation** (standard path), **contract-change-in-progress** (status "110", requiring reservation cancellation and return equipment handling), and **post-status states** (status "010/020/030" — accepted/checked/signed, requiring B-CAS-specific return equipment retrieval).

## 2. Processing Pattern (Detailed Business Logic)

```mermaid
flowchart TD
    START(["executeStbDsl params"])

    START --> CHK_KKTK["Check kktk_svc_no null/empty"]
    CHK_KKTK --> EARLY_EXIT["Early return if empty"]

    CHK_KKTK --> DEBUG_LOG["Debug log: STB cancellation process"]
    DEBUG_LOG --> DSL_FLG["dslFlg = true"]
    DSL_FLG --> SEARCH_KKTK["searchKktk kktk_svc_no dtm"]
    SEARCH_KKTK --> EXTRACT_STAT["Extract stat and mskmDtlNo from db_map"]

    EXTRACT_STAT --> COND_STAT{"stat equals CD00056_KKTK_SVC_KEI_STAT_110
110 Contract change in progress"}

    COND_STAT -->|true| CHG_BRANCH["Contract change cancellation branch"]
    CHG_BRANCH --> SET_SET_PARAM["setParam[0] opeDate setParam[1] RSV_APLY_CD_CL 3"]
    SET_SET_PARAM --> WHERE_PARAM["whereParam[0] kktk_svc_no whereParam[1] dtm"]
    WHERE_PARAM --> EXEC_PKUPDATE["executeKK_T_KKTK_SVC_KEI_PKUPDATE"]
    EXEC_PKUPDATE --> IDO_RSV_WHERE["idoRsv_whereParam kktk_svc_no mskmDtlNo"]
    IDO_RSV_WHERE --> EXEC_SELECT_070["executeKK_T_IDO_RSV_KK_SELECT_070"]
    EXEC_SELECT_070 --> SELECT_NEXT["db_KK_T_IDO_RSV_070.selectNext"]

    SELECT_NEXT --> WHILE_IDO{"idoRsvMap_070 not null"}
    WHILE_IDO -->|true| UPDATE_IDO["updateIdoRsv idoRsvNo_070"]
    UPDATE_IDO --> SELECT_NEXT_AGAIN["db_KK_T_IDO_RSV_070.selectNext"]
    SELECT_NEXT_AGAIN --> WHILE_IDO

    WHILE_IDO -->|false| HAMPIN_UPDATE["hampinUpdateAndDelete"]
    HAMPIN_UPDATE --> DSL_FLG_FALSE_1["dslFlg = false"]
    DSL_FLG_FALSE_1 --> BCAS_CCAS_SEARCH["searchKktkBcasCcasChg ucwk_kei_no"]

    BCAS_CCAS_SEARCH --> COND_LIST_CHG{"listChg size > 0"}

    COND_LIST_CHG -->|true| LOOP_CHG["for each element in listChg"]
    LOOP_CHG --> COND_DB_CHG{"dbInfoChg not null"}
    COND_DB_CHG -->|true| EXTRACT_CHG["Extract kktkSvkKeiNo geneAddDtm mskmdtlNo"]
    EXTRACT_CHG --> PKUPDATE_CHG["executeKK_T_KKTK_SVC_KEI_PKUPDATE"]
    PKUPDATE_CHG --> SELECT_070_CHG["executeKK_T_IDO_RSV_KK_SELECT_070"]
    SELECT_070_CHG --> WHILE_IDO_CHG{"idoRsvMap_070 not null"}
    WHILE_IDO_CHG -->|true| UPDATE_IDO_CHG["updateIdoRsv"]
    UPDATE_IDO_CHG --> HAMPIN_CHG["hampinUpdateAndDelete bcasCcasDb_map"]
    HAMPIN_CHG --> DSL_FLG_FALSE_2["dslFlg = false"]
    DSL_FLG_FALSE_2 --> NEXT_CHG["next loop iteration"]
    NEXT_CHG --> LOOP_CHG_END["end loop"]

    LOOP_CHG -->|no more| BCAS_SELECT_254["executeKK_T_KKTK_SVC_KEI_KK_SELECT_254 bcasParam"]
    BCAS_SELECT_254 --> MAP_BCAS["db_KK_T_KKTK_SVC_KEI_254.selectNext"]

    MAP_BCAS --> COND_BCAS{"mapBcas not null"}
    COND_BCAS -->|true| EXTRACT_BCAS["Extract kktkSvkKeiNo geneAddDtm"]
    EXTRACT_BCAS --> SEARCH_KKTK_BCAS["searchKktk kktkSvkKeiNo geneAddDtm"]
    SEARCH_KKTK_BCAS --> INSERT_KKTK_BCAS["insertKktk CD00562_TAKNKIKI_IDO_CD_06"]
    INSERT_KKTK_BCAS --> HMPIN_PARAM["hmpinParam modelCd seisyoNo"]
    HMPIN_PARAM --> SELECT_013["executeDK_T_HMPIN_KIKI_KK_SELECT_013"]
    SELECT_013 --> SELECT_NEXT_013["db_DK_T_HMPIN_KIKI_013.selectNext"]
    SELECT_NEXT_013 --> COND_HMPIN{"hmpinBcas null"}
    COND_HMPIN -->|true| INSERT_HMPIN_BCAS["insertHmpinKiki bcasDb_map svc_kei_no"]
    COND_HMPIN -->|false| BCAS_END["BCAS branch end"]
    INSERT_HMPIN_BCAS --> BCAS_END

    COND_BCAS -->|false| ELSE_BRANCH["B-CAS/C-CAS search empty branch"]
    ELSE_BRANCH --> SEARCH_BCAS_CCAS["searchKktkBcasCcas ucwk_kei_no"]
    SEARCH_BCAS_CCAS --> LOOP_ALL["for each element in list"]
    LOOP_ALL --> COND_DB_INFO{"dbInfo not null"}
    COND_DB_INFO -->|true| EXTRACT_INFO["Extract kktkSvkKeiNo geneAddDtm"]
    EXTRACT_INFO --> SEARCH_BCAS_CCAS2["searchKktk kktkSvkKeiNo geneAddDtm"]
    SEARCH_BCAS_CCAS2 --> STAT_BCAS2["Extract stat from bcasCcasDb_map"]
    STAT_BCAS2 --> INSERT_KKTK_CCAS["insertKktk CD00562_TAKNKIKI_IDO_CD_06"]
    INSERT_KKTK_CCAS --> INSERT_HMPIN_CCAS["insertHmpinKiki bcasCcasDb_map svc_kei_no"]
    INSERT_HMPIN_CCAS --> OUT_MAP_CCAS["setMiStcKikiCnclTgData outputBean.addOutMapList_2"]
    OUT_MAP_CCAS --> NEXT_CCAS["next loop iteration"]
    NEXT_CCAS --> LOOP_ALL_END["end loop"]
    COND_DB_INFO -->|false| DSL_FLG_FALSE_3["dslFlg = false"]

    LOOP_ALL_END --> DSL_FLG_CHECK["Debug log dslFlg value"]

    DSL_FLG_CHECK --> COND_DSL{"dslFlg true
All STB B-CAS C-CAS cancelled"}
    COND_DSL -->|true| EXEC_PCRS["executePcrsPplanChgChk svc_kei_no"]
    COND_DSL -->|false| END_NODE["Return"]
    EXEC_PCRS --> END_NODE
    EARLY_EXIT --> END_NODE
```

**Constant Resolutions:**

| Constant | Value | Business Meaning |
|----------|-------|------------------|
| `CD00056_KKTK_SVC_KEI_STAT_110` | `"110"` | Contract change in progress — the STB contract is undergoing a change |
| `CD00056_KKTK_SVC_KEI_STAT_100` | `"100"` | Service provision in progress — STB contract is actively being provided |
| `RSV_APLY_CD_CL` | `"3"` | Reservation cancellation code — indicates cancellation of a pending reservation |
| `RSV_APLY_CD_FIX` | `"2"` | Fixed reservation code — confirms a scheduled reservation |
| `CD00562_TAKNKIKI_IDO_CD_06` | `"06"` | Equipment return/delivery code — triggers return equipment processing |
| `SVC_KEI_STAT_DLS_ZM` | `"910"` | Cancellation complete — service contract detail set to canceled status |
| `SVC_DLRE_CD_NORMAL` | Normal code | Service cancellation reason code — standard cancellation |
| `MK_FLG_YK` | `"0"` | Invalid flag — indicates the record is not invalid/deleted |
| `CD01375_PNLTY_HASSEI_CD_0` | `"0"` | Penalty occurrence code — no penalty incurred (0 = none) |

## 3. Parameter Analysis

| No | Parameter Name | Type | Business Description |
|----|---------------|------|---------------------|
| 1 | `kktk_svc_no` | `String` | Equipment-provided service contract number — the primary identifier for the STB service contract to be cancelled. Acts as the main lookup key. |
| 2 | `dtm` | `String` | Generation registration timestamp — the version timestamp used to locate the correct contract record in versioned tables. |
| 3 | `ucwk_no` | `String` | Service contract detail number (ucwk = service contract inner detail) — identifies the specific line-item within the main service contract. |
| 4 | `ucwk_dtm` | `String` | Detail generation registration timestamp — the version timestamp for the service contract detail record. |
| 5 | `bcas_no` | `String` | Equipment-provided service contract number (B-CAS) — the B-CAS card registration number associated with the STB. Used to locate and cancel the B-CAS sub-contract. |
| 6 | `bcas_dtm` | `String` | Generation registration timestamp (B-CAS) — the version timestamp for the B-CAS record. |
| 7 | `ccas_no` | `String` | Equipment-provided service contract number (C-CAS) — the C-CAS registration number. Used to locate and cancel the C-CAS sub-contract. |
| 8 | `ccas_dtm` | `String` | Generation registration timestamp (C-CAS) — the version timestamp for the C-CAS record. |
| 9 | `kojiak_no` | `String` | Construction case number — the work order/case identifier, referenced when generating the un-installed equipment cancellation output file for STB. |
| 10 | `svc_kei_no` | `String` | Service contract number — the parent service contract identifier, used to look up service contract info and trigger price code/plan change checks at the end of the process. |

**Instance fields read by this method:**
- `opeDate` — Operation date (used for setting cancellation dates, reservation cancellation, plan termination dates)
- `batchUserId` — Batch operation user account (set as registration/updated operation account)
- `logPrint` — Debug logging utility (accessed via `super.logPrint`)
- `db_KK_T_IDO_RSV_070` — SQL definition key for IDO reservation select query (used in `selectNext()`)
- `db_KK_T_KKTK_SVC_KEI_254` — SQL definition key for KK_T_KKTK_SVC_KEI select 254 (used for B-CAS search)
- `db_DK_T_HMPIN_KIKI_013` — SQL definition key for DK_T_HMPIN_KIKI select 013 (used for return equipment search)
- `commonItem` — Common item object (passed to `tvMainSubSwitch` and `createSubTypeKK0161`)

## 4. CRUD Operations / Called Services

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

| CRUD | SC / CBS | SC Code | Entity / DB | Operation Description |
|------|----------|---------|-------------|----------------------|
| R | `searchKktk` | EKK0361A010SC | KK_T_KKTK_SVC_KEI | Searches for the equipment-provided service contract by contract number and timestamp. Returns contract status and detail info. |
| U | `executeKK_T_KKTK_SVC_KEI_PKUPDATE` | EKK0361A010CBS | KK_T_KKTK_SVC_KEI | Updates the equipment-provided service contract record with operation date and reservation cancellation code (for "in change" contracts). |
| R | `executeKK_T_IDO_RSV_KK_SELECT_070` | EKK0361B010SC | KK_T_IDO_RSV | Performs IDO (equipment transfer) reservation search. Returns pending transfer records to update. |
| U | `updateIdoRsv` | EKK0361B010CBS | KK_T_IDO_RSV | Updates the IDO reservation record for the equipment-provided service contract number. |
| D | `hampinUpdateAndDelete` | EKK0361A010CBS | DK_T_HMPIN_KIKI | Handles return equipment: registers return equipment data and cancels original equipment. |
| R | `searchKktkBcasCcasChg` | EKK0361A011SC | KK_T_KKTK_SVC_KEI | Searches B-CAS/C-CAS contracts where status is "110" (contract change in progress). |
| C | `executeKK_T_KKTK_SVC_KEI_KK_SELECT_254` | EKK0361A020SC | KK_T_KKTK_SVC_KEI | Searches B-CAS contracts with status "010" (accepted), "020" (checked), or "030" (signed). |
| C | `insertKktk` | EKK0361A010CBS | KK_T_KKTK_SVC_KEI | Inserts the STB/equipment-provided service contract cancellation record with return equipment delivery code. |
| C | `executeKK_T_SVC_KEI_UCWK_PKSELECT` | EKK0361A010SC | KK_T_SVC_KEI_UCWK | Searches the service contract detail (ucwk) record by detail number and timestamp. |
| C | `executeKK_T_SVC_KEI_UCWK_PKINSERT` | EKK0361A010CBS | KK_T_SVC_KEI_UCWK | Inserts the service contract detail cancellation record with 79 parameter fields (cancellation status, dates, codes). |
| C | `insertHmpinKiki` | EKK0361A010CBS | DK_T_HMPIN_KIKI | Registers return equipment information (model code, serial number) for the STB. |
| R | `executeDK_T_HMPIN_KIKI_KK_SELECT_013` | EKK0361A011SC | DK_T_HMPIN_KIKI | Searches for existing return equipment records by model code and serial number. |
| R | `searchKktkBcasCcas` | EKK0361A011SC | KK_T_KKTK_SVC_KEI | Searches B-CAS/C-CAS contracts excluding status "110" (non-change-in-progress records). |
| R | `searchSvcKeiInfo` | EKK0361A030SC | KK_T_SVC_KEI | Looks up the parent service contract info by service contract number. |
| - | `setMiStcKikiCnclTgData` | EKK0361A040CBS | - | Generates output interface object for un-installed equipment cancellation target file (equipment-provided service contract). |
| - | `setMiStcKikiCnclTgDataUcwk` | EKK0361A040CBS | - | Generates output interface object for un-installed equipment cancellation target file (service contract detail). |
| - | `setStbMiStcKikiCnclData` | EKK0361A040CBS | - | Generates output interface object for STB un-installed equipment cancellation file (includes construction case number). |
| - | `tvMainSubSwitch` | EKK0361A050CBS | - | Handles vertical/horizontal sub-switch processing (linked optional equipment). |
| - | `createSubTypeKK0161` | EKK0361A060CBS | - | Creates sub-type registration for service contract detail number. |
| - | `executePcrsPplanChgChk` | EKK0361A070CBS | - | Executes price code/plan change determination for the service contract (only if all cancellations succeeded). |
| - | `JBSbatCommon.printDebugLog` | - | - | Debug logging utility. |
| - | `JCCBatCommon.getSysDateTimeStamp` | - | - | Retrieves the current system date/time stamp. |
| - | `JBSbatDateUtil.adjustDate` | - | - | Date arithmetic utility (e.g., opeDate - 1 day, plan start date - 1 day). |
| - | `JBSbatStringUtil.Rtrim` | - | - | Right-trims string values to remove trailing whitespace. |

## 5. Dependency Trace

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: JBSbatKKMiStcKikiCncl.execute() | `JBSbatKKMiStcKikiCncl.execute` -> `JBSbatKKMiStcKikiCncl.executeStbDsl` | `insertKktk [C] KK_T_KKTK_SVC_KEI`, `searchKktk [R] KK_T_KKTK_SVC_KEI`, `executeKK_T_KKTK_SVC_KEI_PKUPDATE [U] KK_T_KKTK_SVC_KEI`, `updateIdoRsv [U] KK_T_IDO_RSV`, `insertHmpinKiki [C] DK_T_HMPIN_KIKI`, `hampinUpdateAndDelete [D/U] DK_T_HMPIN_KIKI`, `executeKK_T_SVC_KEI_UCWK_PKINSERT [C] KK_T_SVC_KEI_UCWK`, `executePcrsPplanChgChk [C] EKK0361A070CBS`, `createSubTypeKK0161 [C] KK_T_SVC_KEI_UCWK`, `searchKktkBcasCcas [R] KK_T_KKTK_SVC_KEI`, `searchKktkBcasCcasChg [R] KK_T_KKTK_SVC_KEI`, `executeKK_T_KKTK_SVC_KEI_KK_SELECT_254 [R] KK_T_KKTK_SVC_KEI`, `executeDK_T_HMPIN_KIKI_KK_SELECT_013 [R] DK_T_HMPIN_KIKI`, `executeKK_T_IDO_RSV_KK_SELECT_070 [R] KK_T_IDO_RSV` |

## 6. Per-Branch Detail Blocks

**Block 1** — IF `[kktk_svc_no null or empty]` (L3499)
> Null-check for the primary equipment-provided service contract number. This is the entry gate — if no contract number is provided, the method exits immediately.

| # | Type | Code |
|---|------|------|
| 1 | SET | `dslFlg = true` // Cancellation flag initialized to true |
| 2 | IF | `null == kktk_svc_no || 0 == kktk_svc_no.length()` [L3499] |
| 3 | RETURN | `return;` [L3502] — Early exit if empty |

**Block 2** — IF `[debug log level check]` (L3505)
> If debug logging is enabled, prints the STB cancellation process marker.

| # | Type | Code |
|---|------|------|
| 1 | EXEC | `super.logPrint.chkLogLevel(JBSbatLogUtil.MODE_DEBUG)` [L3506] |
| 2 | EXEC | `super.logPrint.printDebugLog("STB cancellation process")` [L3508] |

**Block 3** — IF `[stat equals CD00056_KKTK_SVC_KEI_STAT_110]` (L3520)
> The equipment-provided service contract status is "110" (contract change in progress). This branch performs a **reservation cancellation** instead of a normal cancellation. The contract is being modified, so the pending reservation must be cancelled and return equipment processed.

| # | Type | Code |
|---|------|------|
| 1 | SET | `dslFlg = true` [L3509] |
| 2 | CALL | `searchKktk(kktk_svc_no, dtm)` [L3512] — Search equipment-provided service contract |
| 3 | SET | `stat = Rtrim(db_map.getString(KKTK_SVC_KEI_STAT))` [L3515] |
| 4 | SET | `mskmDtlNo = Rtrim(db_map.getString(MSKM_DTL_NO))` [L3518] |
| 5 | IF | `stat equals CD00056_KKTK_SVC_KEI_STAT_110` [CONST: `"110" (Contract change in progress)`] [L3520] |
| 6 | SET | `setParam[0] = opeDate` [L3523] — Operation date (reservation cancellation date) |
| 7 | SET | `setParam[1] = RSV_APLY_CD_CL` [CONST: `"3" (Reservation cancellation code)`] [L3526] |
| 8 | SET | `whereParam[0] = kktk_svc_no` [L3528] |
| 9 | SET | `whereParam[1] = dtm` [L3529] |
| 10 | CALL | `executeKK_T_KKTK_SVC_KEI_PKUPDATE(setParam, whereParam)` [L3530] — Update contract status |
| 11 | SET | `idoRsv_whereParam[0] = kktk_svc_no` [L3532] |
| 12 | SET | `idoRsv_whereParam[1] = mskmDtlNo` [L3532] |
| 13 | CALL | `executeKK_T_IDO_RSV_KK_SELECT_070(idoRsv_whereParam)` [L3535] — IDO reservation search |
| 14 | SET | `idoRsvMap_070 = db_KK_T_IDO_RSV_070.selectNext()` [L3537] |

**Block 3.1** — WHILE `[idoRsvMap_070 != null]` (L3540)
> Iterates over all IDO (equipment transfer) reservations found for this contract. Each pending reservation is updated to reflect the cancellation.

| # | Type | Code |
|---|------|------|
| 1 | WHILE | `null != idoRsvMap_070` [L3540] |
| 2 | SET | `idoRsvNo_070 = Rtrim(idoRsvMap_070.getString(IDO_RSV_NO))` [L3542] |
| 3 | CALL | `updateIdoRsv(idoRsvNo_070)` [L3545] — Update IDO reservation |
| 4 | SET | `idoRsvMap_070 = db_KK_T_IDO_RSV_070.selectNext()` [L3547] — Fetch next record |

**Block 3.2** — After IDO loop, return equipment processing (L3553)
> After updating all IDO reservations, the return equipment is registered and original equipment is cancelled.

| # | Type | Code |
|---|------|------|
| 1 | CALL | `hampinUpdateAndDelete(db_map, svc_kei_no, kktk_svc_no, null, false, false)` [L3553] — Return equipment processing |
| 2 | SET | `dslFlg = false` [L3555] — Mark main contract as not fully cancelled yet |

**Block 4** — ELSE `[contract status != "110"]` (L3558)
> Normal cancellation path. The contract is NOT in "change in progress" state. This is the standard STB cancellation flow that handles the main contract cancellation, service contract detail cancellation, and output file generation.

| # | Type | Code |
|---|------|------|
| 1 | CALL | `insertKktk(kktk_svc_no, db_map, CD00562_TAKNKIKI_IDO_CD_06)` [L3562] — Contract cancellation with return equipment code [CONST: `"06"`] |
| 2 | CALL | `insertHmpinKiki(db_map, svc_kei_no)` [L3565] — Register return equipment |
| 3 | SET | `param[0] = ucwk_no` [L3567] |
| 4 | SET | `param[1] = ucwk_dtm` [L3568] |
| 5 | CALL | `ucwk_map = executeKK_T_SVC_KEI_UCWK_PKSELECT(param)` [L3571] — Search service contract detail |

**Block 4.1** — IF `[ucwk_map == null]` (L3574)
> The service contract detail was not found. This is a critical error — the cancellation cannot proceed without the detail record.

| # | Type | Code |
|---|------|------|
| 1 | IF | `null == ucwk_map` [L3574] |
| 2 | EXEC | `throw new JBSbatBusinessException(JPCBatchMessageConstant.EKKB0210CE, new String[]{"KK_T_SVC_KEI_UCWK", ucwk_no})` [L3576] |

**Block 4.2** — Date preparation (L3580–3582)
> Retrieves the system timestamp and calculates the previous day's operation date.

| # | Type | Code |
|---|------|------|
| 1 | SET | `sysDate = JCCBatCommon.getSysDateTimeStamp()` [L3581] |
| 2 | SET | `opeDate_bf = JBSbatDateUtil.adjustDate(opeDate, -1)` [L3583] |

**Block 4.3** — ucwk_param array population (L3586–3671)
> Populates a 79-element parameter array with all service contract detail fields needed to create the cancellation record. This is the largest field-mapping block in the method, covering all dates, codes, and status fields.

| # | Type | Code |
|---|------|------|
| 1 | SET | `ucwk_param[0] = ucwk_no` [L3587] — Service contract detail number |
| 2 | SET | `ucwk_param[1] = sysDate` [L3588] — Generation registration timestamp |
| 3 | SET | `ucwk_param[2] = SVC_KEI_STAT_DLS_ZM` [L3591] — Cancellation complete status [CONST: `"910"`] |
| 4 | SET | `ucwk_param[3] = ucwk_map.getString(SVC_KEI_NO)` [L3592] — Service contract number |
| 5 | SET | `ucwk_param[4] = ucwk_map.getString(MSKM_DTL_NO)` [L3593] — Application detail number |
| 6 | SET | `ucwk_param[5] = ucwk_map.getString(PCRS_CD)` [L3594] — Price code |
| 7 | SET | `ucwk_param[6] = ucwk_map.getString(PPLAN_CD)` [L3595] — Price plan code |
| 8 | SET | `ucwk_param[7..59]` [L3596–3664] — Various service contract detail fields (TK_HOSHIKI_KEI_NO, PAYWAY_KEIZOKU_FLG, etc.) |
| 9 | SET | `ucwk_param[24] = super.opeDate` [L3596] — Reservation application date |
| 10 | SET | `ucwk_param[26] = RSV_APLY_CD_FIX` [L3600] — Fixed reservation code [CONST: `"2"`] |
| 11 | SET | `ucwk_param[28] = super.opeDate` [L3600] — Plan termination date |
| 12 | SET | `ucwk_param[30] = opeDate_bf` [L3602] — Plan billing end date |
| 13 | SET | `ucwk_param[47] = super.opeDate` [L3632] — Service termination date |
| 14 | SET | `ucwk_param[50] = super.opeDate` [L3647] — Service cancellation date |
| 15 | SET | `ucwk_param[51] = SVC_DLRE_CD_NORMAL` [L3650] — Cancellation reason code |
| 16 | SET | `ucwk_param[60] = CD01375_PNLTY_HASSEI_CD_0` [L3658] — Penalty occurrence code (no penalty) [CONST: `"0"`] |
| 17 | SET | `ucwk_param[66] = sysDate` [L3665] — Registration timestamp |
| 18 | SET | `ucwk_param[67] = batchUserId` [L3666] — Registration operator account |
| 19 | SET | `ucwk_param[68] = sysDate` [L3667] — Update timestamp |
| 20 | SET | `ucwk_param[69] = batchUserId` [L3668] — Update operator account |
| 21 | SET | `ucwk_param[72] = MK_FLG_YK` [L3671] — Invalid flag [CONST: `"0"` (not invalid)] |

**Block 4.4** — Conditional billing end date (L3599–3637)
> If the service contract detail status is "100" (service provision in progress), the service billing end date is calculated as `plan start date - 1 day`. Otherwise, it defaults to `opeDate - 1`.

| # | Type | Code |
|---|------|------|
| 1 | SET | `ucwkStat = ucwk_map.getString(SVC_KEI_UCWK_STAT)` [L3590] |
| 2 | IF | `CD00056_KKTK_SVC_KEI_STAT_100.equals(ucwkStat)` [CONST: `"100"` (service provision in progress)] [L3599] |
| 3 | SET | `planStaYmd = ucwk_map.getString(PLAN_STAYMD)` [L3602] |
| 4 | SET | `ucwk_param[48] = JBSbatDateUtil.adjustDate(planStaYmd, -1)` [L3605] — Service billing end date (plan start date - 1) |
| 5 | ELSE | [L3608] |
| 6 | SET | `ucwk_param[48] = opeDate_bf` [L3611] — Service billing end date (opeDate - 1) |

**Block 4.5** — Insert service contract detail (L3675)

| # | Type | Code |
|---|------|------|
| 1 | CALL | `executeKK_T_SVC_KEI_UCWK_PKINSERT(ucwk_param)` [L3675] — Insert cancellation detail record |

**Block 4.6** — Post-insert processing (L3678–3715)
> Handles linked equipment sub-switch, sub-type creation, and output file generation for three types of un-installed equipment cancellation data.

| # | Type | Code |
|---|------|------|
| 1 | SET | `kKTVMainSubSwitch = new JBSbatKKTVMainSubSwitch()` [L3680] |
| 2 | CALL | `kKTVMainSubSwitch.tvMainSubSwitch(commonItem, SVC_KEI_NO, adjustDate(opeDate_bf, 1), MSKM_DTL_NO)` [L3681] — Handle vertical/horizontal sub-switch |
| 3 | CALL | `JKKBatCommon.createSubTypeKK0161(commonItem, ucwk_no, GENE_ADD_DTM, sysDate)` [L3686] — Create sub-type registration |
| 4 | SET | `miStcKikiCnclTgOutKikimap = new JBSbatServiceInterfaceMap()` [L3690] |
| 5 | CALL | `miStcKikiCnclTgOutKikimap = setMiStcKikiCnclTgData(miStcKikiCnclTgOutKikimap, db_map)` [L3694]— Generate output file for equipment-provided service contract |
| 6 | EXEC | `miStcKikiCnclTgOutKikimap.setOutFlg(true)` [L3697] |
| 7 | CALL | `outputBean.addOutMapList_2(miStcKikiCnclTgOutKikimap)` [L3699] — Add to output common message |
| 8 | SET | `svcKei_map = new JBSbatCommonDBInterface()` [L3702] |
| 9 | CALL | `svcKei_map = searchSvcKeiInfo(svc_kei_no)` [L3705] — Search service contract |
| 10 | SET | `sysId = Rtrim(svcKei_map.getString(SYSID))` [L3708] |
| 11 | EXEC | `super.logPrint.printDebugLog("Processing target SYSID====> " + sysId)` [L3710] |
| 12 | SET | `miStcKikiCnclTgOutUcwkmap = new JBSbatServiceInterfaceMap()` [L3713] |
| 13 | CALL | `miStcKikiCnclTgOutUcwkmap = setMiStcKikiCnclTgDataUcwk(miStcKikiCnclTgOutUcwkmap, ucwk_map, svcKei_map)` [L3716] — Generate output for service contract detail |
| 14 | EXEC | `miStcKikiCnclTgOutUcwkmap.setOutFlg(true)` [L3719] |
| 15 | CALL | `outputBean.addOutMapList_2(miStcKikiCnclTgOutUcwkmap)` [L3721] |
| 16 | SET | `stbOutmap = new JBSbatServiceInterfaceMap()` [L3725] |
| 17 | CALL | `stbOutmap = setStbMiStcKikiCnclData(stbOutmap, db_map, kojiak_no)` [L3728] — Generate STB output file |
| 18 | EXEC | `stbOutmap.setOutFlg(true)` [L3731] |
| 19 | CALL | `outputBean.addOutMapList(stbOutmap)` [L3733] |

**Block 5** — Extract `ucwk_kei_no` and search B-CAS/C-CAS (L3738–3741)
> After handling the main STB contract, the method extracts the service contract detail number and searches for associated B-CAS/C-CAS records.

| # | Type | Code |
|---|------|------|
| 1 | SET | `ucwk_kei_no = Rtrim(db_map.getString(SVC_KEI_UCWK_NO))` [L3738] |
| 2 | CALL | `listChg = searchKktkBcasCcasChg(ucwk_kei_no)` [L3741] — Search B-CAS/C-CAS with status "110" |

**Block 6** — IF `[listChg.size() > 0]` (L3744)
> B-CAS/C-CAS records found with status "110" (contract change in progress). Each such record undergoes reservation cancellation and return equipment processing.

| # | Type | Code |
|---|------|------|
| 1 | IF | `0 < listChg.size()` [L3744] |
| 2 | FOR | `for (int i = 0; i < listChg.size(); i++)` [L3747] |
| 3 | SET | `dbInfoChg = listChg.get(i)` [L3748] |
| 4 | IF | `dbInfoChg != null` [L3751] |

**Block 6.1** — Within listChg loop (L3755–3844)
> For each B-CAS/C-CAS record in "change in progress" state, perform reservation cancellation and return equipment processing (mirroring the main contract's Block 3 logic).

| # | Type | Code |
|---|------|------|
| 1 | SET | `kktkSvkKeiNo = Rtrim(dbInfoChg.getString(KKTK_SVC_KEI_NO))` [L3756] |
| 2 | SET | `geneAddDtm = Rtrim(dbInfoChg.getString(GENE_ADD_DTM))` [L3759] |
| 3 | SET | `mskmDtlNo = Rtrim(dbInfoChg.getString(MSKM_DTL_NO))` [L3761] |
| 4 | EXEC | `super.logPrint.printDebugLog(...)` [L3763–3764] |
| 5 | SET | `setParam[0] = opeDate` [L3766] |
| 6 | SET | `setParam[1] = RSV_APLY_CD_CL` [CONST: `"3"`] [L3769] |
| 7 | SET | `whereParam[0] = kktkSvkKeiNo` [L3771] |
| 8 | SET | `whereParam[1] = geneAddDtm` [L3772] |
| 9 | CALL | `executeKK_T_KKTK_SVC_KEI_PKUPDATE(setParam, whereParam)` [L3774] |
| 10 | SET | `idoRsv_whereParam[0] = kktkSvkKeiNo` [L3776] |
| 11 | SET | `idoRsv_whereParam[1] = mskmdtlNo` [L3776] |
| 12 | CALL | `executeKK_T_IDO_RSV_KK_SELECT_070(idoRsv_whereParam)` [L3779] |
| 13 | SET | `idoRsvMap_070 = db_KK_T_IDO_RSV_070.selectNext()` [L3781] |

**Block 6.1.1** — WHILE within listChg (L3784)
> Update all IDO reservations for this B-CAS/C-CAS contract.

| # | Type | Code |
|---|------|------|
| 1 | WHILE | `null != idoRsvMap_070` [L3784] |
| 2 | SET | `idoRsvNo_070 = Rtrim(idoRsvMap_070.getString(IDO_RSV_NO))` [L3786] |
| 3 | CALL | `updateIdoRsv(idoRsvNo_070)` [L3789] |
| 4 | SET | `idoRsvMap_070 = db_KK_T_IDO_RSV_070.selectNext()` [L3791] |

**Block 6.1.2** — Return equipment (L3797–3798)
> Search and process return equipment for this B-CAS/C-CAS contract.

| # | Type | Code |
|---|------|------|
| 1 | CALL | `bcasCcasDb_map = searchKktk(kktkSvkKeiNo, geneAddDtm)` [L3798] |
| 2 | CALL | `hampinUpdateAndDelete(bcasCcasDb_map, svc_kei_no, kktkSvkKeiNo, null, false, false)` [L3798] |
| 3 | SET | `dslFlg = false` [L3800] |

**Block 6.2** — B-CAS search for post-status contracts (L3805–3856)
> After processing "110" contracts, search for B-CAS contracts with statuses "010" (accepted), "020" (checked), or "030" (signed). This is an additional search added in ANK-3488.

| # | Type | Code |
|---|------|------|
| 1 | SET | `bcasParam[0] = ucwk_kei_no` [L3812] |
| 2 | SET | `bcasParam[1] = super.opeDate` [L3813] |
| 3 | CALL | `executeKK_T_KKTK_SVC_KEI_KK_SELECT_254(bcasParam)` [L3816] |
| 4 | SET | `mapBcas = db_KK_T_KKTK_SVC_KEI_254.selectNext()` [L3818] |
| 5 | IF | `mapBcas != null` [L3821] |

**Block 6.2.1** — Within B-CAS 254 result (L3824–3855)
> For the B-CAS record found with post-status, perform cancellation and conditional return equipment registration.

| # | Type | Code |
|---|------|------|
| 1 | SET | `kktkSvkKeiNo = Rtrim(mapBcas.getString(KKTK_SVC_KEI_NO))` [L3825] |
| 2 | SET | `geneAddDtm = Rtrim(mapBcas.getString(GENE_ADD_DTM))` [L3828] |
| 3 | CALL | `bcasDb_map = searchKktk(kktkSvkKeiNo, geneAddDtm)` [L3833] |
| 4 | CALL | `insertKktk(kktkSvkKeiNo, bcasDb_map, CD00562_TAKNKIKI_IDO_CD_06)` [L3836] — Cancel B-CAS contract [CONST: `"06"`] |
| 5 | SET | `hmpinParam[0] = bcasDb_map.getString(TAKNKIKI_MODEL_CD)` [L3841] |
| 6 | SET | `hmpinParam[1] = bcasDb_map.getString(KIKI_SEIZO_NO)` [L3842] |
| 7 | CALL | `executeDK_T_HMPIN_KIKI_KK_SELECT_013(hmpinParam)` [L3845] — Search existing return equipment |
| 8 | SET | `hmpinBcas = db_DK_T_HMPIN_KIKI_013.selectNext()` [L3847] |
| 9 | IF | `hmpinBcas == null` [L3850] — Return equipment not found |
| 10 | CALL | `insertHmpinKiki(bcasDb_map, svc_kei_no)` [L3852] — Register return equipment |

**Block 7** — ELSE `[listChg empty]` (L3858)
> No B-CAS/C-CAS records with status "110". Search for B-CAS/C-CAS records in other states and process them normally.

| # | Type | Code |
|---|------|------|
| 1 | ELSE | [L3858] — listChg.size() == 0 |
| 2 | CALL | `list = searchKktkBcasCcas(ucwk_kei_no)` [L3862] — Search B-CAS/C-CAS excluding status "110" |
| 3 | FOR | `for (int i = 0; i < list.size(); i++)` [L3865] |
| 4 | SET | `dbInfo = list.get(i)` [L3866] |

**Block 7.1** — Within list loop (L3869–3942)
> For each B-CAS/C-CAS record in non-"110" status, perform standard cancellation processing.

| # | Type | Code |
|---|------|------|
| 1 | IF | `dbInfo != null` [L3869] |
| 2 | SET | `kktkSvkKeiNo = Rtrim(dbInfo.getString(KKTK_SVC_KEI_NO))` [L3872] |
| 3 | SET | `geneAddDtm = Rtrim(dbInfo.getString(GENE_ADD_DTM))` [L3875] |
| 4 | CALL | `bcasCcasDb_map = searchKktk(kktkSvkKeiNo, geneAddDtm)` [L3879] |
| 5 | SET | `stat = Rtrim(bcasCcasDb_map.getString(KKTK_SVC_KEI_STAT))` [L3882] |
| 6 | CALL | `insertKktk(kktkSvkKeiNo, bcasCcasDb_map, CD00562_TAKNKIKI_IDO_CD_06)` [L3886] — Cancel [CONST: `"06"`] |
| 7 | CALL | `insertHmpinKiki(bcasCcasDb_map, svc_kei_no)` [L3889] |
| 8 | SET | `miStcKikiCnclTgOutBcasmap = new JBSbatServiceInterfaceMap()` [L3891] |
| 9 | CALL | `miStcKikiCnclTgOutBcasmap = setMiStcKikiCnclTgData(miStcKikiCnclTgOutBcasmap, bcasCcasDb_map)` [L3895] |
| 10 | EXEC | `miStcKikiCnclTgOutBcasmap.setOutFlg(true)` [L3898] |
| 11 | CALL | `outputBean.addOutMapList_2(miStcKikiCnclTgOutBcasmap)` [L3900] |

**Block 7.2** — ELSE `[dbInfo null]` (L3905)

| # | Type | Code |
|---|------|------|
| 1 | ELSE | [L3905] |
| 2 | SET | `dslFlg = false` [L3907] |

**Block 8** — Debug log and final check (L3912–3921)
> Logs the cancellation flag value and, if all cancellations succeeded (`dslFlg` remains true), triggers the price code/plan change check.

| # | Type | Code |
|---|------|------|
| 1 | IF | `super.logPrint.chkLogLevel(JBSbatLogUtil.MODE_DEBUG)` [L3912] |
| 2 | EXEC | `super.logPrint.printDebugLog("STB,B-CAS,C-CAS cancellation flag: " + dslFlg)` [L3914] |
| 3 | IF | `dslFlg` [L3917] — All STB, B-CAS, C-CAS fully cancelled |
| 4 | CALL | `executePcrsPplanChgChk(svc_kei_no)` [L3919] — Price code/plan change determination |

## 7. Glossary

| Term | Type | Business Meaning |
|------|------|------------------|
| `kktk_svc_no` | Field | Equipment-provided service contract number — primary key for the STB service contract in the KK_T_KKTK_SVC_KEI table |
| `dtm` | Field | Generation registration timestamp — version identifier for locating the correct row in versioned database tables |
| `ucwk_no` | Field | Service contract detail number (ucwk = service contract inner detail) — identifies line items within the parent service contract |
| `ucwk_dtm` | Field | Detail generation registration timestamp — version identifier for the service contract detail record |
| `bcas_no` | Field | B-CAS contract number — the B-CAS card registration number tied to the STB subscription |
| `ccas_no` | Field | C-CAS contract number — the C-CAS registration number tied to the STB subscription |
| `kojiak_no` | Field | Construction case number — work order/case identifier used in output file generation |
| `svc_kei_no` | Field | Service contract number — the parent service contract that contains the equipment-provided service contract |
| `ucwk_kei_no` | Field | Service contract detail key number — extracted from the equipment-provided service contract for B-CAS/C-CAS searches |
| `stat` / `KKTK_SVC_KEI_STAT` | Field | Equipment-provided service contract status — indicates the current state of the contract |
| `mskmDtlNo` / `MSKM_DTL_NO` | Field | Application detail number — a reference number within the contract record |
| `dslFlg` | Variable | Cancellation flag — tracks whether all STB/B-CAS/C-CAS contracts were successfully cancelled (true = all done, false = some not done) |
| `opeDate` | Field (instance) | Operation date — the business date used for batch processing, set as registration dates and cancellation dates |
| `batchUserId` | Field (instance) | Batch operation user account — set as the operator account for registration and update records |
| CD00056_KKTK_SVC_KEI_STAT_110 | Constant | Status "110" — Contract change in progress; the contract is undergoing a modification |
| CD00056_KKTK_SVC_KEI_STAT_100 | Constant | Status "100" — Service provision in progress; the STB service is actively being delivered |
| RSV_APLY_CD_CL | Constant | Reservation cancellation code "3" — used to cancel a pending reservation |
| RSV_APLY_CD_FIX | Constant | Fixed reservation code "2" — confirms a scheduled reservation |
| CD00562_TAKNKIKI_IDO_CD_06 | Constant | Equipment return/delivery code "06" — triggers return equipment processing when cancelling the contract |
| SVC_KEI_STAT_DLS_ZM | Constant | Status "910" — Cancellation complete; service contract detail is cancelled |
| MK_FLG_YK | Constant | Invalid flag "0" — the record is NOT invalid (i.e., it is valid) |
| CD01375_PNLTY_HASSEI_CD_0 | Constant | Penalty occurrence code "0" — no penalty has been incurred |
| SVC_DLRE_CD_NORMAL | Constant | Normal cancellation reason code — standard customer cancellation |
| KK_T_KKTK_SVC_KEI | Table | Equipment-provided service contract table — stores STB equipment service contract records |
| KK_T_SVC_KEI_UCWK | Table | Service contract detail table — stores line-item details within the service contract |
| KK_T_IDO_RSV | Table | IDO (equipment transfer) reservation table — stores pending equipment transfer records |
| DK_T_HMPIN_KIKI | Table | Return equipment table — stores information about returned STB equipment |
| KK_T_KKTK_SVC_KEI_254 | Table | Equipment-provided service contract search 254 — specialized view for B-CAS contract search |
| DK_T_HMPIN_KIKI_013 | Table | Return equipment search 013 — specialized query for existing return equipment lookup |
| STB | Business term | Set-Top Box — the cable/satellite decoder equipment provided to customers |
| B-CAS | Business term | B-CAS card — conditional access system card used for digital broadcast subscription authentication |
| C-CAS | Business term | C-CAS card — secondary conditional access card variant |
| hampin | Field | Return equipment — Japanese term (返品) referring to equipment returned by the customer |
| 返品取消 | Business term | Return cancellation — cancelling a previously registered return equipment record |
| 返品機器 | Business term | Return equipment — the physical STB device returned by a cancelling customer |
| 設備取消対象ファイル | Business term | Un-installed equipment cancellation target file — output file containing data for cancelled/returned equipment |
| 料金コード | Business term | Price code — billing code associated with the service contract |
| 料金プラン | Business term | Price plan — the pricing plan attached to the service contract |
| 異動予約 | Business term | IDO (equipment transfer) reservation — a pending equipment transfer record awaiting processing |
| 予約取消し | Business term | Reservation cancellation — cancelling a pending scheduled reservation |
| 契約変更中 | Business term | Contract change in progress — the contract status when a modification is pending |
| 解約完了 | Business term | Cancellation complete — the final status after all cancellation processing |
| 照会済み | Business term | Checked/verified — B-CAS contract status "020" indicating the contract has been verified |
| 締結済み | Business term | Signed/executed — B-CAS contract status "030" |
| 受注済み | Business term | Accepted — B-CAS contract status "010" |
| SVC_KEI_NO | Field | Service contract number — the parent contract identifier |
| GENE_ADD_DTM | Field | Generation registration timestamp — version timestamp for the record |
| PCRS_CD | Field | Price code — billing classification code |
| PPLAN_CD | Field | Price plan code — the pricing plan identifier |
| TAKNKIKI_MODEL_CD | Field | Home equipment model code — the model code of the STB equipment |
| KIKI_SEIZO_NO | Field | Equipment serial number — unique serial number of the STB device |
| MSKM_DTL_NO | Field | Application detail number — detailed application reference number |
| PLAN_STAYMD | Field | Plan start date — when the service plan begins |
| PNLTY_HASSEI_CD | Field | Penalty occurrence code — code indicating if a cancellation penalty applies |
| SVC_CANCEL_YMD | Field | Service cancellation date |
| SVC_DLRE_YMD | Field | Service cancellation accounting date |
| SVC_DSL_KISAN_YMD | Field | Service cancellation accounting start date |
| SHOSA_YMD | Field | Verification date |
| FTRIAL_KANYU_YMD | Field | Trial entry date |
| HONKANYU_YMD | Field | Full entry date |