# Business Logic — JBSbatKKEoTVChgeFix.insertSvcKeiUcwkKjFin() [489 LOC]

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

## 1. Role

### JBSbatKKEoTVChgeFix.insertSvcKeiUcwkKjFin()

This method performs the **service contract detail work registration** triggered by a work cancellation workflow after STB (Set-Top Box) equipment changes in the K-Opticom cable television service system. It is the central dispatching method for recording the final state of a service contract line-item (KK_T_SVC_KEI_UCWK) when a field engineer completes or cancels an installation task.

The method handles two distinct business operations based on the `flg` parameter: **STB addition** (flg = "0", STB_ADD) where a new STB is being provisioned and the contract enters an active "service providing" state, and **STB partial removal** (flg = "1", STB_DSL) where an STB is being decommissioned and the contract line-item transitions to "contract cancelled" status. This routing/dispatch pattern eliminates the need for duplicate registration logic across the two caller methods.

Its role in the larger system is as the **terminal write operation** for the TV change confirmation batch module (JBSbatKKEoTVChgeFix). It is called exclusively by `createSvcKeiUcwkAddInfoKjFin()` (for new STB additions following equipment exchange) and `createSvcKeiUcwkDslInfoKjFin()` (for STB cancellations). It serves as a **data consolidation builder** — it gathers all current contract state from the database via `dbInfo`, applies business-rule-based date calculations (plan end dates, service cancellation dates, recovery date clearing), populates a 79-field parameter array, and delegates the actual database insert to `executeKK_T_SVC_KEI_UCWK_PKINSERT`. After the main insert, it also fires off sub-type registrations (JKKBatCommon.createSubTypeKK0161) and creates primary/secondary contract switch reservation records via `JBSbatKKTVMainSubSwitch.tvMainSubSwitch`.

## 2. Processing Pattern (Detailed Business Logic)

```mermaid
flowchart TD
    START(["insertSvcKeiUcwkKjFin invoked"])

    START --> GET_SYS_DATE["Get system datetime stamp sysDate"]
    GET_SYS_DATE --> READ_KAIHK["Read KAIHK_YMD from dbInfo"]
    READ_KAIHK --> CHK_FLG{flg equals STB_ADD?}

    CHK_FLG -->|Yes: STB Add| STB_ADD_BLOCK["STB Add Branch"]
    STB_ADD_BLOCK --> SET_STAT_SVCTK["Set svcKeiUcwkStat to SVC_KEI_STAT_SVCTK_CHU 100"]
    SET_STAT_SVCTK --> SET_PLAN_DATES["Set plan dates from params planStaymdSvc planChrgStaymdSvc"]
    SET_PLAN_DATES --> SET_MAX_DATES["Set end dates to MAX_YYYYMMDD 20991231"]
    SET_MAX_DATES --> READ_CURRENT_DB["Read current DB values rsvAplyYmd rsvAplyCd svcDslYmd etc"]
    READ_CURRENT_DB --> SET_SWITCH_RSV["Set switchRsvAplyYmd to planChrgStaymd"]
    SET_SWITCH_RSV --> SET_SWITCH_SVC["Set switchSvcStaYmd to planStaymd"]
    SET_SWITCH_SVC --> JOIN_DATA_BUILD

    CHK_FLG -->|No: STB Remove| STB_DSL_BLOCK["STB Remove Branch"]
    STB_DSL_BLOCK --> SET_STAT_DSL["Set svcKeiUcwkStat to SVC_KEI_STAT_DLS_ZM 910"]
    SET_STAT_DSL --> SET_PLAN_END_DSL["Set planStaymd from DB planEndymd to kojiakJssiYmd"]
    SET_PLAN_END_DSL --> SET_CHRG_DSL["Set planChrgEndymd to end-of-month of kojiakJssiYmd"]
    SET_CHRG_DSL --> SET_SVC_DATES_DSL["Set svcStaymd svcEndymd from DB and kojiakJssiYmd"]
    SET_SVC_DATES_DSL --> SET_RSV_DSL["Set rsvAplyYmd to opeDate rsvAplyCd to RSV_APLY_CD_FIX 2"]
    SET_RSV_DSL --> SET_DSL_DATES["Set svcDslYmd svcDslKisanYmd to kojiakJssiYmd"]
    SET_DSL_DATES --> SET_DSL_PARAMS["Set svcDlreCd to SVC_DLRE_CD_NORMAL 01 planEndSbtCd to PLAN_END_SBT_CD_MSDDSL 2"]
    SET_DSL_PARAMS --> CLEAR_KAIHK["Clear kaihkYmd to empty string"]
    CLEAR_KAIHK --> SET_SWITCH_DSL["Set switchRsvAplyYmd to planChrgEndymd plus 1 day switchSvcStaYmd to planEndymd plus 1 day"]
    SET_SWITCH_DSL --> JOIN_DATA_BUILD

    JOIN_DATA_BUILD --> READ_SVC_KEI_UCWK_NO["Read svcKeiUcwkNo from dbInfo"]
    READ_SVC_KEI_UCWK_NO --> BUILD_SETPARAM["Build setParam array with 79 fields"]

    BUILD_SETPARAM --> INSERT_MAIN["executeKK_T_SVC_KEI_UCWK_PKINSERT setParam"]
    INSERT_MAIN --> INSERT_SUBTYPE["JKKBatCommon.createSubTypeKK0161 commonItem svcKeiUcwkNo geneAddDtms sysDate"]
    INSERT_SUBTYPE --> INSERT_SUBTYPE_2["JEKK0161C040TPMA JEKK0161C050TPMA JEKK0161C051TPMA createSubTypeKK0161"]
    INSERT_SUBTYPE_2 --> SWITCH_MAIN["JBSbatKKTVMainSubSwitch tvMainSubSwitch svcKeiNo switchRsvAplyYmd switchSvcStaYmd mskmDtlNo"]
    SWITCH_MAIN --> END_NODE(["Return"])

    style START fill:#e1f5fe
    style END_NODE fill:#e1f5fe
    style CHK_FLG fill:#fff3e0
    style INSERT_MAIN fill:#c8e6c9
    style INSERT_SUBTYPE fill:#c8e6c9
```

## 3. Parameter Analysis

| No | Parameter Name | Type | Business Description |
|----|---------------|------|---------------------|
| 1 | `dbInfo` | `JBSbatCommonDBInterface` | Service contract detail current state — a database row handle (JDBC cursor) containing the current values of the KK_T_SVC_KEI_UCWK table for the contract being processed. Used for both reading existing values and extracting the service contract detail number. |
| 2 | `kojiakJssiYmd` | `String` | Work case implementation date (YYYYMMDD format) — the date the field engineer completed or cancelled the installation task. Used as the effective date for plan/service cancellation, and as the basis for calculating end-of-month dates. |
| 3 | `planStaymdSvc` | `String` | Plan start date (YYYYMMDD format) — in STB addition mode, this becomes the plan start date (first day of the month following the work case date). In STB removal mode, it is read from the existing DB record. |
| 4 | `planChrgStaymdSvc` | `String` | Plan billing start date (YYYYMMDD format) — in STB addition mode, this becomes the plan billing start date. In STB removal mode, it is read from the related KK_T_KKTK_SVC_KEI table. |
| 5 | `flg` | `String` | Operation flag — "0" (STB_ADD) means STB addition (new service registration); "1" (STB_DSL) means STB partial removal (cancellation). Drives the entire conditional branching of the method. |
| 6 | `strIdoDiv` | `String` | Move division — the classification code for the type of contract change/move. Passed through to the sub-type registration and the DB record in STB removal mode. |
| 7 | `strMskmDtlNo` | `String` | Application detail number — the unique identifier for the order application detail line. Used for the main insert and the primary/secondary contract switch reservation creation. |

**Instance fields read:**

| Field | Source | Usage |
|-------|--------|-------|
| `commonItem` | Inherited from `JBSbatBusinessService` parent class | Passed to `createSubTypeKK0161` and `tvMainSubSwitch` for sub-type and switch reservation processing |
| `batchUserId` | Inherited from `JBSbatBusinessService` parent class | Set as register update user and update user in the 79-field parameter array (setParam[67], setParam[69]) |

## 4. CRUD Operations / Called Services

| CRUD | SC / CBS | SC Code | Entity / DB | Operation Description |
|------|----------|---------|-------------|----------------------|
| R | `JBSbatKKConst.SVC_KEI_STAT_SVCTK_CHU` | - | In-memory constant | Reads constant value "100" for service providing status |
| R | `JBSbatKKConst.SVC_KEI_STAT_DLS_ZM` | - | In-memory constant | Reads constant value "910" for contract cancelled status |
| R | `JBSbatKKConst.RSV_APLY_CD_FIX` | - | In-memory constant | Reads constant value "2" for reservation confirmed code |
| R | `JBSbatKKConst.SVC_DLRE_CD_NORMAL` | - | In-memory constant | Reads constant value "01" for normal cancellation reason |
| R | `JBSbatKKConst.PLAN_END_SBT_CD_MSDDSL` | - | In-memory constant | Reads constant value "2" for plan termination by cancellation code |
| R | `JBSbatKKConst.CD01375_PNLTY_HASSEI_CD_0` | - | In-memory constant | Reads constant value "0" for no penalty code |
| R | `JBSbatKKConst.MK_FLG_YK` | - | In-memory constant | Reads constant value "0" for active flag |
| R | `JBSbatDateUtil.getSystemDateTimeStamp` | - | - | Gets system date-time stamp string |
| R | `dbInfo.getString(JBSbatKK_T_KKTK_SVC_KEI.KAIHK_YMD)` | - | KK_T_KKTK_SVC_KEI | Reads recovery date field (KAIHK_YMD) from database cursor |
| R | `dbInfo.getString(JBSbatKK_T_SVC_KEI_UCWK.RSV_APLY_YMD)` | - | KK_T_SVC_KEI_UCWK | Reads reservation application date |
| R | `dbInfo.getString(JBSbatKK_T_SVC_KEI_UCWK.RSV_APLY_CD)` | - | KK_T_SVC_KEI_UCWK | Reads reservation application code |
| R | `dbInfo.getString(JBSbatKK_T_SVC_KEI_UCWK.SVC_DSL_YMD)` | - | KK_T_SVC_KEI_UCWK | Reads service cancellation date |
| R | `dbInfo.getString(JBSbatKK_T_SVC_KEI_UCWK.SVC_DSL_KISAN_YMD)` | - | KK_T_SVC_KEI_UCWK | Reads service cancellation calculation date |
| R | `dbInfo.getString(JBSbatKK_T_SVC_KEI_UCWK.IDO_DIV)` | - | KK_T_SVC_KEI_UCWK | Reads move division code |
| R | `dbInfo.getString(JBSbatKK_T_SVC_KEI_UCWK.MSKM_DTL_NO)` | - | KK_T_SVC_KEI_UCWK | Reads application detail number |
| R | `dbInfo.getString(JBSbatKK_T_SVC_KEI_UCWK.SVC_DLRE_CD)` | - | KK_T_SVC_KEI_UCWK | Reads service cancellation reason code |
| R | `dbInfo.getString(JBSbatKK_T_SVC_KEI_UCWK.PLAN_END_SBT_CD)` | - | KK_T_SVC_KEI_UCWK | Reads plan termination type code |
| R | `dbInfo.getString(JBSbatKK_T_SVC_KEI_UCWK.PNLTY_HASSEI_CD)` | - | KK_T_SVC_KEI_UCWK | Reads penalty occurrence code |
| R | `dbInfo.getString(JBSbatKK_T_SVC_KEI_UCWK.SVC_KEI_UCWK_NO)` | - | KK_T_SVC_KEI_UCWK | Reads service contract detail number (primary key for insert) |
| R | `dbInfo.getString(JBSbatKK_T_SVC_KEI_UCWK.SVC_KEI_NO)` | - | KK_T_SVC_KEI_UCWK | Reads service contract number |
| R | `dbInfo.getString(JBSbatKK_T_SVC_KEI_UCWK.PCRS_CD)` | - | KK_T_SVC_KEI_UCWK | Reads price plan code |
| R | `dbInfo.getString(JBSbatKK_T_SVC_KEI_UCWK.PPLAN_CD)` | - | KK_T_SVC_KEI_UCWK | Reads price plan code |
| R | `dbInfo.getString(JBSbatKK_T_SVC_KEI_UCWK.TK_HOSHIKI_KEI_NO)` | - | KK_T_SVC_KEI_UCWK | Reads provision method contract number |
| R | `dbInfo.getString(JBSbatKK_T_SVC_KEI_UCWK.PAYWAY_KEIZOKU_FLG)` | - | KK_T_SVC_KEI_UCWK | Reads payment method continuation flag |
| R | `dbInfo.getString(JBSbatKK_T_SVC_KEI_UCWK.WEB_OP_ADD_FAIL_FLG)` | - | KK_T_SVC_KEI_UCWK | Reads web option addition failure flag |
| R | `dbInfo.getString(JBSbatKK_T_SVC_KEI_UCWK.WORK_RRK_BIKO)` | - | KK_T_SVC_KEI_UCWK | Reads business contact remarks |
| R | `dbInfo.getString(JBSbatKK_T_SVC_KEI_UCWK.SVC_USE_STA_KIBO_YMD)` | - | KK_T_SVC_KEI_UCWK | Reads service use start desired date |
| R | `dbInfo.getString(JBSbatKK_T_SVC_KEI_UCWK.SVC_UEST_KBTMZ_CD)` | - | KK_T_SVC_KEI_UCWK | Reads service use start desired time slot minute code |
| R | `dbInfo.getString(JBSbatKK_T_SVC_KEI_UCWK.SVC_UEST_KBTM_CD)` | - | KK_T_SVC_KEI_UCWK | Reads service use start desired time code |
| R | `dbInfo.getString(JBSbatKK_T_SVC_KEI_UCWK.RSV_TSTA_KIBO_YMD)` | - | KK_T_SVC_KEI_UCWK | Reads reservation application start desired date |
| R | `dbInfo.getString(JBSbatKK_T_SVC_KEI_UCWK.SKEKKA_SEND_CD)` | - | KK_T_SVC_KEI_UCWK | Reads review result send code |
| R | `dbInfo.getString(JBSbatKK_T_SVC_KEI_UCWK.SVC_KEI_UCWK_KZKWRK_REQYMD)` | - | KK_T_SVC_KEI_UCWK | Reads service contract detail post-processing request date |
| R | `dbInfo.getString(JBSbatKK_T_SVC_KEI_UCWK.SHOSA_YMD)` | - | KK_T_SVC_KEI_UCWK | Reads inspection date |
| R | `dbInfo.getString(JBSbatKK_T_SVC_KEI_UCWK.SHOSA_CL_YMD)` | - | KK_T_SVC_KEI_UCWK | Reads inspection cancellation date |
| R | `dbInfo.getString(JBSbatKK_T_SVC_KEI_UCWK.FTRIAL_KANYU_YMD)` | - | KK_T_SVC_KEI_UCWK | Reads trial addition date |
| R | `dbInfo.getString(JBSbatKK_T_SVC_KEI_UCWK.FTRIAL_PRD_ENDYMD)` | - | KK_T_SVC_KEI_UCWK | Reads trial period end date |
| R | `dbInfo.getString(JBSbatKK_T_SVC_KEI_UCWK.HONKANYU_YMD)` | - | KK_T_SVC_KEI_UCWK | Reads actual addition date |
| R | `dbInfo.getString(JBSbatKK_T_SVC_KEI_UCWK.HONKANYU_IKO_KIGEN_YMD)` | - | KK_T_SVC_KEI_UCWK | Reads actual addition transfer deadline date |
| R | `dbInfo.getString(JBSbatKK_T_SVC_KEI_UCWK.KEI_CNC_YMD)` | - | KK_T_SVC_KEI_UCWK | Reads contract signing date |
| R | `dbInfo.getString(JBSbatKK_T_SVC_KEI_UCWK.RSV_CL_YMD)` | - | KK_T_SVC_KEI_UCWK | Reads reservation cancellation date |
| R | `dbInfo.getString(JBSbatKK_T_SVC_KEI_UCWK.SVC_CANCEL_YMD)` | - | KK_T_SVC_KEI_UCWK | Reads service cancellation date |
| R | `dbInfo.getString(JBSbatKK_T_SVC_KEI_UCWK.SVC_CANCEL_RSN_CD)` | - | KK_T_SVC_KEI_UCWK | Reads service cancellation reason code |
| R | `dbInfo.getString(JBSbatKK_T_SVC_KEI_UCWK.SVC_STP_YMD)` | - | KK_T_SVC_KEI_UCWK | Reads service suspension date |
| R | `dbInfo.getString(JBSbatKK_T_SVC_KEI_UCWK.SVC_STP_RSN_CD)` | - | KK_T_SVC_KEI_UCWK | Reads service suspension reason code |
| R | `dbInfo.getString(JBSbatKK_T_SVC_KEI_UCWK.SVC_STP_RLS_YMD)` | - | KK_T_SVC_KEI_UCWK | Reads service suspension release date |
| R | `dbInfo.getString(JBSbatKK_T_SVC_KEI_UCWK.SVC_STP_RLS_RSN_CD)` | - | KK_T_SVC_KEI_UCWK | Reads service suspension release reason code |
| R | `dbInfo.getString(JBSbatKK_T_SVC_KEI_UCWK.PAUSE_STP_CD)` | - | KK_T_SVC_KEI_UCWK | Reads suspension interruption code |
| R | `dbInfo.getString(JBSbatKK_T_SVC_KEI_UCWK.SVC_PAUSE_YMD)` | - | KK_T_SVC_KEI_UCWK | Reads service pause date |
| R | `dbInfo.getString(JBSbatKK_T_SVC_KEI_UCWK.SVC_PAUSE_RSN_CD)` | - | KK_T_SVC_KEI_UCWK | Reads service pause reason code |
| R | `dbInfo.getString(JBSbatKK_T_SVC_KEI_UCWK.SVC_PAUSE_RSN_MEMO)` | - | KK_T_SVC_KEI_UCWK | Reads service pause reason memo |
| R | `dbInfo.getString(JBSbatKK_T_SVC_KEI_UCWK.SVC_PAUSE_RLS_YMD)` | - | KK_T_SVC_KEI_UCWK | Reads service pause release date |
| R | `dbInfo.getString(JBSbatKK_T_SVC_KEI_UCWK.SVC_PAUSE_RLS_RSN_CD)` | - | KK_T_SVC_KEI_UCWK | Reads service pause release reason code |
| R | `dbInfo.getString(JBSbatKK_T_SVC_KEI_UCWK.SVC_PAUSE_RLS_RSN_MEMO)` | - | KK_T_SVC_KEI_UCWK | Reads service pause release reason memo |
| R | `dbInfo.getString(JBSbatKK_T_SVC_KEI_UCWK.SVC_DLRE_MEMO)` | - | KK_T_SVC_KEI_UCWK | Reads service cancellation reason memo |
| R | `dbInfo.getString(JBSbatKK_T_SVC_KEI_UCWK.SVC_DSL_TTDKI_FIN_FLG)` | - | KK_T_SVC_KEI_UCWK | Reads service cancellation completion flag |
| R | `dbInfo.getString(JBSbatKK_T_SVC_KEI_UCWK.SVC_CANCEL_CL_YMD)` | - | KK_T_SVC_KEI_UCWK | Reads service cancellation withdrawal date |
| R | `dbInfo.getString(JBSbatKK_T_SVC_KEI_UCWK.SVC_DSL_CL_YMD)` | - | KK_T_SVC_KEI_UCWK | Reads service cancellation cancellation date |
| R | `dbInfo.getString(JBSbatKK_T_SVC_KEI_UCWK.SVKEIUW_HKHASYMD)` | - | KK_T_SVC_KEI_UCWK | Reads service contract detail occurrence date |
| R | `dbInfo.getString(JBSbatKK_T_SVC_KEI_UCWK.CHRG_STA_YMD_HOSEI_UM)` | - | KK_T_SVC_KEI_UCWK | Reads billing start date correction validity |
| R | `dbInfo.getString(JBSbatKK_T_SVC_KEI_UCWK.SVC_PAUSE_CHRG_STA_YMD)` | - | KK_T_SVC_KEI_UCWK | Reads service pause billing start date |
| R | `dbInfo.getString(JBSbatKK_T_SVC_KEI_UCWK.SHOSA_DSL_FIN_CD)` | - | KK_T_SVC_KEI_UCWK | Reads inspection cancellation completion code |
| R | `dbInfo.getString(JBSbatKK_T_SVC_KEI_UCWK.SVCTK_BUT_DEL_TRN_JSSI_DTM)` | - | KK_T_SVC_KEI_UCWK | Reads service provision deletion processing execution date-time |
| R | `dbInfo.getString(JBSbatKK_T_SVC_KEI_UCWK.KEIZK_MT_SVC_KEI_UCWK_NO)` | - | KK_T_SVC_KEI_UCWK | Reads successor service contract detail number |
| R | `dbInfo.getString(JBSbatKK_T_SVC_KEI_UCWK.KEIZK_AF_KEI_CHGECHU_FLG)` | - | KK_T_SVC_KEI_UCWK | Reads successor post-contract change processing in-progress flag |
| R | `dbInfo.getString(JBSbatKK_T_SVC_KEI_UCWK.GENE_ADD_DTM)` | - | KK_T_SVC_KEI_UCWK | Reads generation addition date-time |
| R | `dbInfo.getString(JBSbatKK_T_SVC_KEI_UCWK.PLAN_STAYMD)` | - | KK_T_SVC_KEI_UCWK | Reads plan start date (STB removal branch) |
| R | `dbInfo.getString(JBSbatKK_T_KKTK_SVC_KEI.PLAN_CHRG_STAYMD)` | - | KK_T_KKTK_SVC_KEI | Reads plan billing start date from related equipment-provided service contract table |
| R | `dbInfo.getString(JBSbatKK_T_SVC_KEI_UCWK.SVC_STA_YMD)` | - | KK_T_SVC_KEI_UCWK | Reads service start date (STB removal branch) |
| R | `dbInfo.getString(JBSbatKK_T_SVC_KEI_UCWK.SVC_CHRG_STAYMD)` | - | KK_T_SVC_KEI_UCWK | Reads service billing start date (STB removal branch) |
| - | `JBSbatStringUtil.Rtrim` | - | - | Trims whitespace from database string values |
| - | `JBSbatDateUtil.getEndOfMonth` | - | - | Gets end of month for a given YYYYMMDD year-month string |
| - | `JBSbatDateUtil.adjustDate` | - | - | Adjusts a date by N days |
| C | `JBSbatKKEoTVChgeFix.executeKK_T_SVC_KEI_UCWK_PKINSERT` | - | KK_T_SVC_KEI_UCWK | Inserts a new service contract detail record with all 79 fields |
| C | `JKKBatCommon.createSubTypeKK0161` | - | Sub-type 0161 (JKKBatCommon) | Registers sub-type data for the service contract detail |
| C | `JEKK0161C040TPMA.createSubTypeKK0161` | JEKK0161C040SC | Sub-type 0161 | Registers sub-type data for category C040 |
| C | `JEKK0161C050TPMA.createSubTypeKK0161` | JEKK0161C050SC | Sub-type 0161 | Registers sub-type data for category C050 |
| C | `JEKK0161C051TPMA.createSubTypeKK0161` | JEKK0161C051SC | Sub-type 0161 | Registers sub-type data for category C051 |
| - | `JBSbatKKTVMainSubSwitch.tvMainSubSwitch` | - | KK_T_IDO_RSV | Creates primary/secondary contract switch reservation records (for STB move reservations) |

## 5. Dependency Trace

| # | Caller (Screen/Batch) | Call Chain (Full Path to this Method) | Terminal (SC / CRUD / Entity) |
|---|----------------------|--------------------------------------|-------------------------------|
| 1 | Batch: `JBSbatKKEoTVChgeFix.createSvcKeiUcwkAddInfoKjFin` | `createSvcKeiUcwkAddInfoKjFin` -> `insertSvcKeiUcwkKjFin` | `executeKK_T_SVC_KEI_UCWK_PKINSERT [C] KK_T_SVC_KEI_UCWK` |
| 2 | Batch: `JBSbatKKEoTVChgeFix.createSvcKeiUcwkDslInfoKjFin` | `createSvcKeiUcwkDslInfoKjFin` -> `insertSvcKeiUcwkKjFin` | `executeKK_T_SVC_KEI_UCWK_PKINSERT [C] KK_T_SVC_KEI_UCWK` |

**Terminal operations reached from this method:**

| Terminal | CRUD | Entity/DB |
|----------|------|-----------|
| `executeKK_T_SVC_KEI_UCWK_PKINSERT` | C | KK_T_SVC_KEI_UCWK |
| `createSubTypeKK0161` (JKKBatCommon) | C | Sub-type 0161 |
| `createSubTypeKK0161` (JEKK0161C040TPMA) | C | Sub-type 0161 |
| `createSubTypeKK0161` (JEKK0161C050TPMA) | C | Sub-type 0161 |
| `createSubTypeKK0161` (JEKK0161C051TPMA) | C | Sub-type 0161 |
| `tvMainSubSwitch` | C | KK_T_IDO_RSV |

## 6. Per-Branch Detail Blocks

**Block 1** — [SET] Initialize local variables (L6781)

| # | Type | Code |
|---|------|------|
| 1 | SET | `sysDate = JBSbatDateUtil.getSystemDateTimeStamp()` // Get system date-time |
| 2 | SET | `svcKeiUcwkStat = ""` // Service contract detail status |
| 3 | SET | `planStaymd = ""` // Plan start date |
| 4 | SET | `planEndymd = ""` // Plan end date |
| 5 | SET | `planChrgStaymd = ""` // Plan billing start date |
| 6 | SET | `planChrgEndymd = ""` // Plan billing end date |
| 7 | SET | `svcStaymd = ""` // Service start date |
| 8 | SET | `svcChrgStaymd = ""` // Service billing start date |
| 9 | SET | `svcEndymd = ""` // Service end date |
| 10 | SET | `svcChrgEndymd = ""` // Service billing end date |
| 11 | SET | `rsvAplyYmd = ""` // Reservation application date |
| 12 | SET | `rsvAplyCd = ""` // Reservation application code |
| 13 | SET | `svcDslYmd = ""` // Service cancellation date |
| 14 | SET | `svcDslKisanYmd = ""` // Service cancellation calculation date |
| 15 | SET | `idoDiv = ""` // Move division |
| 16 | SET | `mskmDtlNo = ""` // Application detail number |
| 17 | SET | `svcDlreCd = ""` // Service cancellation reason code |
| 18 | SET | `planEndSbtCd = ""` // Plan termination type code |
| 19 | SET | `pnltyHasseiCd = ""` // Penalty occurrence code |
| 20 | SET | `kaihkYmd = JBSbatStringUtil.Rtrim(dbInfo.getString(JBSbatKK_T_KKTK_SVC_KEI.KAIHK_YMD))` // Read recovery date (OM-2014-0000400: preserve during non-cancellation) |

**Block 2** — [SET] Version additions (L6816)

| # | Type | Code |
|---|------|------|
| 1 | SET | `switchRsvAplyYmd = ""` // TV primary/secondary reservation application date (v20.00.02) |
| 2 | SET | `switchSvcStaYmd = ""` // TV primary service start date (v23.00.00) |

**Block 3** — [IF] Check flg == STB_ADD "0" (L6820) `[STB_ADD = "0"]`

> STB Addition (service registration) branch. The contract enters "service providing" state with indefinite end dates.

| # | Type | Code |
|---|------|------|
| 1 | SET | `svcKeiUcwkStat = JBSbatKKConst.SVC_KEI_STAT_SVCTK_CHU` // "100" — Service Providing status |
| 2 | SET | `planStaymd = planStaymdSvc` // Plan start date from parameter |
| 3 | SET | `planEndymd = MAX_YYYYMMDD` // "20991231" — Indefinite end date |
| 4 | SET | `planChrgStaymd = planChrgStaymdSvc` // Plan billing start date from parameter |
| 5 | SET | `planChrgEndymd = MAX_YYYYMMDD` // "20991231" — Indefinite end date |
| 6 | SET | `svcStaymd = planStaymdSvc` // Service start date = plan start date |
| 7 | SET | `svcChrgStaymd = planChrgStaymdSvc` // Service billing start date = plan billing start |
| 8 | SET | `svcEndymd = MAX_YYYYMMDD` // "20991231" — Indefinite service end date |
| 9 | SET | `svcChrgEndymd = MAX_YYYYMMDD` // "20991231" — Indefinite service billing end date |
| 10 | SET | `rsvAplyYmd = JBSbatStringUtil.Rtrim(dbInfo.getString(JBSbatKK_T_SVC_KEI_UCWK.RSV_APLY_YMD))` // Read from current DB |
| 11 | SET | `rsvAplyCd = JBSbatStringUtil.Rtrim(dbInfo.getString(JBSbatKK_T_SVC_KEI_UCWK.RSV_APLY_CD))` // Read from current DB |
| 12 | SET | `svcDslYmd = JBSbatStringUtil.Rtrim(dbInfo.getString(JBSbatKK_T_SVC_KEI_UCWK.SVC_DSL_YMD))` // Read service cancellation date from DB |
| 13 | SET | `svcDslKisanYmd = JBSbatStringUtil.Rtrim(dbInfo.getString(JBSbatKK_T_SVC_KEI_UCWK.SVC_DSL_KISAN_YMD))` // Read cancellation calc date |
| 14 | SET | `idoDiv = JBSbatStringUtil.Rtrim(dbInfo.getString(JBSbatKK_T_SVC_KEI_UCWK.IDO_DIV))` // Read move division from DB |
| 15 | SET | `mskmDtlNo = JBSbatStringUtil.Rtrim(dbInfo.getString(JBSbatKK_T_SVC_KEI_UCWK.MSKM_DTL_NO))` // Read app detail number |
| 16 | SET | `svcDlreCd = JBSbatStringUtil.Rtrim(dbInfo.getString(JBSbatKK_T_SVC_KEI_UCWK.SVC_DLRE_CD))` // Read cancellation reason |
| 17 | SET | `planEndSbtCd = JBSbatStringUtil.Rtrim(dbInfo.getString(JBSbatKK_T_SVC_KEI_UCWK.PLAN_END_SBT_CD))` // Read plan end type |
| 18 | SET | `pnltyHasseiCd = JBSbatStringUtil.Rtrim(dbInfo.getString(JBSbatKK_T_SVC_KEI_UCWK.PNLTY_HASSEI_CD))` // Read penalty code |
| 19 | SET | `switchRsvAplyYmd = planChrgStaymd` // Reservation application date = plan billing start date |
| 20 | SET | `switchSvcStaYmd = planStaymd` // Service start date = plan start date |

**Block 4** — [ELSE] flg != STB_ADD "1" (L6874) `[STB_DSL = "1"]`

> STB Removal (cancellation) branch. The contract enters "contract cancelled" state with end dates calculated from the work case implementation date.

| # | Type | Code |
|---|------|------|
| 1 | SET | `svcKeiUcwkStat = JBSbatKKConst.SVC_KEI_STAT_DLS_ZM` // "910" — Contract Cancelled status |
| 2 | SET | `planStaymd = JBSbatStringUtil.Rtrim(dbInfo.getString(JBSbatKK_T_SVC_KEI_UCWK.PLAN_STAYMD))` // Read plan start from DB |
| 3 | SET | `planEndymd = kojiakJssiYmd` // Plan end = work case implementation date |
| 4 | SET | `planChrgStaymd = JBSbatStringUtil.Rtrim(dbInfo.getString(JBSbatKK_T_KKTK_SVC_KEI.PLAN_CHRG_STAYMD))` // Read billing start from KK_T_KKTK_SVC_KEI |
| 5 | SET | `planChrgEndymd = kojiakJssiYmd.substring(0, 6) + JBSbatDateUtil.getEndOfMonth(kojiakJssiYmd.substring(0, 6))` // Billing end = end of month of work case date |
| 6 | SET | `svcStaymd = JBSbatStringUtil.Rtrim(dbInfo.getString(JBSbatKK_T_SVC_KEI_UCWK.SVC_STA_YMD))` // Service start from DB |
| 7 | SET | `svcChrgStaymd = JBSbatStringUtil.Rtrim(dbInfo.getString(JBSbatKK_T_SVC_KEI_UCWK.SVC_CHRG_STAYMD))` // Service billing start from DB |
| 8 | SET | `svcEndymd = kojiakJssiYmd` // Service end = work case date |
| 9 | SET | `svcChrgEndymd = kojiakJssiYmd.substring(0, 6) + JBSbatDateUtil.getEndOfMonth(kojiakJssiYmd.substring(0, 6))` // Service billing end = end of month |
| 10 | SET | `rsvAplyYmd = super.opeDate` // Reservation application date = batch operation date |
| 11 | SET | `rsvAplyCd = JBSbatKKConst.RSV_APLY_CD_FIX` // "2" — Reservation Confirmed |
| 12 | SET | `svcDslYmd = kojiakJssiYmd` // Service cancellation date = work case date |
| 13 | SET | `svcDslKisanYmd = kojiakJssiYmd` // Service cancellation calculation date = work case date |
| 14 | SET | `idoDiv = strIdoDiv` // Move division from parameter |
| 15 | SET | `mskmDtlNo = strMskmDtlNo` // Application detail number from parameter |
| 16 | SET | `svcDlreCd = JBSbatKKConst.SVC_DLRE_CD_NORMAL` // "01" — Normal cancellation |
| 17 | SET | `planEndSbtCd = JBSbatKKConst.PLAN_END_SBT_CD_MSDDSL` // "2" — Termination by cancellation |
| 18 | SET | `pnltyHasseiCd = JBSbatKKConst.CD01375_PNLTY_HASSEI_CD_0` // "0" — No penalty |
| 19 | SET | `kaihkYmd = ""` // Clear recovery date (OM-2014-0000400: clear when creating cancellation record) |
| 20 | SET | `switchRsvAplyYmd = JBSbatDateUtil.adjustDate(planChrgEndymd, 1)` // Reservation date = plan billing end + 1 day |
| 21 | SET | `switchSvcStaYmd = JBSbatDateUtil.adjustDate(planEndymd, 1)` // Service start = plan end + 1 day |

**Block 5** — [SET] Read service contract detail number (L6935)

| # | Type | Code |
|---|------|------|
| 1 | SET | `svcKeiUcwkNo = JBSbatStringUtil.Rtrim(dbInfo.getString(JBSbatKK_T_SVC_KEI_UCWK.SVC_KEI_UCWK_NO))` |

**Block 6** — [SET] Build 79-element setParam array (L6938)

> Populates the parameter array with all fields for the KK_T_SVC_KEI_UCWK insert. Field indices 0-78 map directly to table columns.

| # | Type | Code |
|---|------|------|
| 1 | SET | `setParam = new Object[79]` |
| 2 | SET | `setParam[0] = svcKeiUcwkNo` // Service contract detail number |
| 3 | SET | `setParam[1] = sysDate` // Generation registration date-time |
| 4 | SET | `setParam[2] = svcKeiUcwkStat` // Service contract detail status |
| 5 | SET | `setParam[3] = dbInfo.getString(JBSbatKK_T_SVC_KEI_UCWK.SVC_KEI_NO)` // Service contract number |
| 6 | SET | `setParam[4] = mskmDtlNo` // Application detail number |
| 7 | SET | `setParam[5]` through `setParam[71]` | // Read 64 additional fields from dbInfo (price plan, contract, dates, cancellation, pause, recovery, etc.) |
| 8 | SET | `setParam[66] = sysDate` // Registration date-time (overwrite) |
| 9 | SET | `setParam[67] = batchUserId` // Register operation account |
| 10 | SET | `setParam[68] = sysDate` // Update date-time |
| 11 | SET | `setParam[69] = batchUserId` // Update operation account |
| 12 | SET | `setParam[70] = ""` // Delete date-time (empty) |
| 13 | SET | `setParam[71] = ""` // Delete operation account (empty) |
| 14 | SET | `setParam[72] = JBSbatKKConst.MK_FLG_YK` // "0" — Valid (active flag) |
| 15 | SET | `setParam[73]` through `setParam[78] = ""` | // Registration operation date, registration process ID, update operation date, update process ID, delete operation date, delete process ID (all empty) |

**Block 7** — [CALL] Insert main record (L7015)

| # | Type | Code |
|---|------|------|
| 1 | CALL | `executeKK_T_SVC_KEI_UCWK_PKINSERT(setParam)` // Insert new KK_T_SVC_KEI_UCWK record |

**Block 8** — [CALL] Register sub-type (L7018)

| # | Type | Code |
|---|------|------|
| 1 | CALL | `JKKBatCommon.createSubTypeKK0161(commonItem, svcKeiUcwkNo, dbInfo.getString(JBSbatKK_T_SVC_KEI_UCWK.GENE_ADD_DTM), sysDate)` // Register sub-type 0161 data |

**Block 9** — [CALL] Create primary/secondary switch reservation (L7023) `[v20.00.02 - v23.00.00]`

| # | Type | Code |
|---|------|------|
| 1 | SET | `kKTVMainSubSwitch = new JBSbatKKTVMainSubSwitch()` // Create switch instance |
| 2 | CALL | `kKTVMainSubSwitch.tvMainSubSwitch(commonItem, dbInfo.getString(JBSbatKK_T_SVC_KEI_UCWK.SVC_KEI_NO), switchRsvAplyYmd, switchSvcStaYmd, mskmDtlNo)` // Create primary/secondary contract switch reservation for STB move |

## 7. Glossary

| Term | Type | Business Meaning |
|------|------|------------------|
| `svc_kei_ucwk_no` | Field | Service contract detail number — internal tracking ID for service contract line items in KK_T_SVC_KEI_UCWK |
| `svc_kei_ucwk_stat` | Field | Service contract detail status — indicates the current lifecycle state of a service contract line item |
| `svc_kei_no` | Field | Service contract number — links the detail record back to its parent service contract |
| `kojiak_jssi_ymd` | Field | Work case implementation date — the date a field engineer completed or cancelled an installation task |
| `plan_staymd` | Field | Plan start date — when the service plan begins |
| `plan_endymd` | Field | Plan end date — when the service plan terminates; "20991231" indicates indefinite/active |
| `plan_chrg_staymd` | Field | Plan billing start date — when billing for the plan begins |
| `plan_chrg_endymd` | Field | Plan billing end date — when billing for the plan terminates; end-of-month calculation applied in cancellation |
| `svc_staymd` | Field | Service start date — when the actual service provision begins |
| `svc_chrg_staymd` | Field | Service billing start date — when billing for the actual service begins |
| `svc_endymd` | Field | Service end date — when the service provision terminates |
| `svc_chrg_endymd` | Field | Service billing end date — end of billing for the service provision |
| `rsv_aply_ymd` | Field | Reservation application date — when the reservation was applied |
| `rsv_aply_cd` | Field | Reservation application code — "1" for pending, "2" for confirmed/locked, "3" for cancelled |
| `svc_dsl_ymd` | Field | Service cancellation date — when the service was cancelled |
| `svc_dsl_kisan_ymd` | Field | Service cancellation calculation date — the date used for pro-rated cancellation calculations |
| `ido_div` | Field | Move division — classifies the type of contract change (add, remove, transfer) |
| `mskm_dtl_no` | Field | Application detail number — unique identifier for the order application detail line |
| `svc_dlre_cd` | Field | Service cancellation reason code — "01" for normal cancellation, "02" for forced, "03" for cancellation |
| `plan_end_sbt_cd` | Field | Plan termination type code — "1" for plan change, "2" for cancellation, "3" for forced, "4" for cancel |
| `pnlty_hassei_cd` | Field | Penalty occurrence code — "0" means no penalty, "1" means penalty applies |
| `kaihkYmd` | Field | Recovery date — used for disaster recovery; cleared when creating a cancellation record |
| `switchRsvAplyYmd` | Field | TV primary/secondary reservation application date — for STB move reservation creation |
| `switchSvcStaYmd` | Field | TV primary service start date — for STB move reservation creation |
| `mk_flg` | Field | Validity flag — "0" means active/valid, "1" means invalid/deleted |
| STB_ADD | Constant | "0" — STB addition operation flag |
| STB_DSL | Constant | "1" — STB partial removal/cancellation operation flag |
| MAX_YYYYMMDD | Constant | "20991231" — maximum date value used to represent indefinite/active contract state |
| SVC_KEI_STAT_SVCTK_CHU | Constant | "100" — Service contract status "Service Providing" |
| SVC_KEI_STAT_DLS_ZM | Constant | "910" — Service contract status "Contract Cancelled" |
| RSV_APLY_CD_FIX | Constant | "2" — Reservation application code "Reservation Confirmed" |
| SVC_DLRE_CD_NORMAL | Constant | "01" — Service cancellation reason "Normal Cancellation" |
| PLAN_END_SBT_CD_MSDDSL | Constant | "2" — Plan termination type "Termination by Cancellation" |
| MK_FLG_YK | Constant | "0" — Valid (active) flag |
| KK_T_SVC_KEI_UCWK | Table | Service contract detail work table — stores line-item level service contract data |
| KK_T_KKTK_SVC_KEI | Table | Equipment-provided service contract table — stores equipment-level (STB) contract data |
| KK_T_IDO_RSV | Table | Move reservation table — stores primary/secondary contract switch reservations for STB moves |
| createSubTypeKK0161 | Method | Sub-type registration for category 0161 — registers subsidiary contract data linked to a service contract detail |
| tvMainSubSwitch | Method | TV primary/secondary contract switch — creates move reservation records for STB equipment changes |
| executeKK_T_SVC_KEI_UCWK_PKINSERT | Method | Primary key insert for KK_T_SVC_KEI_UCWK — performs the actual database INSERT for the service contract detail record |
| opeDate | Field | Batch operation date — the current batch processing date, inherited from the parent service class |
| batchUserId | Field | Batch operation user ID — identifies the batch job as the operator in audit fields |
| geneAddDtms | Field | Generation addition date-time — the timestamp when the original record was generated |
| FTTH | Business term | Fiber To The Home — fiber-optic internet service offered by K-Opticom |
| STB | Business term | Set-Top Box — cable television decoder equipment provided to customers |
| KK_T_ | Naming convention | Prefix for K-Opticom transaction tables in the batch system |