# Business Logic — JKKCancelSvcWribCC.cancelSvcWrib() [99 LOC]

| Field | Value |
|-------|-------|
| Fully Qualified Name | `com.fujitsu.futurity.bp.custom.common.JKKCancelSvcWribCC` |
| Layer | Common Component (CC) — Custom Component in the BPM workflow layer |
| Module | `common` (Package: `com.fujitsu.futurity.bp.custom.common`) |

## 1. Role

### JKKCancelSvcWribCC.cancelSvcWrib()

This method performs **discount service contract cancellation** processing for the K-Opticom customer core system (eo customer core system). It handles two distinct service types: **discount service cancellation** (割引サービス契約キャンセル, `wrib` — discount/rebate) and **proxy service cancellation** (代替サービスキャンセル, `hanyo` — substitute/proxy). The method follows a **routing/dispatch pattern**, iterating over two separate lists of service contracts and, for each unique group (identified by `list_no`), performing up-mapping to a service component message, invoking the SC, and then down-mapping the response.

The business domain is telecom service contract management: customers may have discount or rebate agreements tied to their service contracts, and when those agreements are cancelled, the system must atomically update both the discount service line and the proxy service line. Each contract group is processed exactly once (deduplicated by `list_no`), and any single-item error (return code >= `SINGLEDATA_ERR`) triggers an immediate exception to abort the entire operation.

This CC is a **shared utility** called by multiple BPM screen operations (KKSV0568 and KKSV0082). It acts as an orchestration layer that coordinates input preparation, service component invocation, and output mapping — essentially a business façade for the cancellation workflow. The method does not directly query or modify databases; instead, it delegates all data persistence to the EKK0451C070 and EKK1391C040 service components.

## 2. Processing Pattern (Detailed Business Logic)

```mermaid
flowchart TD
    START(["Start: cancelSvcWrib(handle, param, ccName)"])

    A["Initialize: scCall, paramMap, errFlgCc, result, resUserMap"]
    B["Extract: inMap = param.getData(ccName)"]
    C{"inMap == null?"}
    D["Extract: wribSvcCdList, hanyoCdList, func_code = '1'"]
    E["for i = 0 to wribSvcCdListCnt - 1"]
    F["workBeanListMap1 = wribSvcCdList.get(i)"]
    G["listNo = workBeanListMap1.get('list_no')"]
    H{"listNo != oldListNo?"}
    I["editInEKK0451C070 - up mapping"]
    J["scCall.run - EKK0451C070 SC Invocation"]
    K["editRetEKK0451C070 - down mapping"]
    L{"returnCode >= SINGLEDATA_ERR?"}
    M["throw CCException(SC_ERROR_STRING)"]
    N["oldListNo = listNo"]
    O["for i = 0 to hanyoCdListCnt - 1"]
    P["workBeanListMap2 = hanyoCdList.get(i)"]
    Q{"listNo != oldListNo?"}
    R["workList = new ArrayList (add workBeanListMap2)"]
    S["editInEKK1391C040 - up mapping"]
    T["scCall.run - EKK1391C040 SC Invocation"]
    U["editRetEKK1391C040 - down mapping"]
    V{"returnCode >= SINGLEDATA_ERR?"}
    W["throw CCException(SC_ERROR_STRING)"]
    X["oldListNo = listNo"]
    Y["JKKBpCommon.setResultUserData(param, ccName, resUserMap)"]
    Z{"errFlgCc == '0'?"}
    AA["JKKBpCommon.setResultCtrlData(param, result, ccName, 0, 0)"]
    BB["throw CCException(errMsg)"]
    END(["Return param"])

    START --> A --> B --> C
    C -- "Yes" --> END
    C -- "No" --> D --> E --> F --> G --> H
    H -- "No" --> N --> O
    H -- "Yes" --> I --> J --> K --> L
    L -- "Yes" --> M
    L -- "No" --> N --> O
    O --> P --> Q
    Q -- "No" --> X --> Y
    Q -- "Yes" --> R --> S --> T --> U --> V
    V -- "Yes" --> W
    V -- "No" --> X --> Y
    Y --> Z
    Z -- "Yes" --> AA
    Z -- "No" --> BB
    M --> END
    W --> END
    AA --> END
    BB --> END
```

**Processing description:**

1. **Initialization** — Creates a `ServiceComponentRequestInvoker` for SC calls, initializes common input data via `setSCInputCommonData`, and sets the error flag (`errFlgCc`) to `"0"`.

2. **Input extraction** — Retrieves the work area map from `param.getData(ccName)`. If null, returns immediately (early exit). Extracts the discount service cancellation list (`wribSvcCdList`), proxy service cancellation list (`hanyoCdList`), and function code.

3. **Discount service loop** — Iterates over each entry in `wribSvcCdList`. For entries with a new `list_no` (group-by processing), performs up-mapping via `editInEKK0451C070`, invokes the `EKK0451C070` service component, and down-maps the result via `editRetEKK0451C070`. If the return code indicates an error, throws a `CCException`.

4. **Proxy service loop** — Same pattern as step 3, but processes `hanyoCdList` using the `EKK1391C040` service component.

5. **Result mapping** — Sets user data and control data on the response. If `errFlgCc` is still `"0"` (no errors), calls `setResultCtrlData` with the SC result. Otherwise throws an exception.

6. **Return** — Returns the modified `param` object.

## 3. Parameter Analysis

| No | Parameter Name | Type | Business Description |
|----|---------------|------|---------------------|
| 1 | `handle` | `SessionHandle` | Database session handle — provides the transaction context and connection to the database for service component invocations. Passed through to the SC runner. |
| 2 | `param` | `IRequestParameterReadWrite` | Request parameter object — carries the input work area data (`wribSvcCdList`, `hanyoCdList`, `list_no`, etc.), control map data (operator ID, operation date, host info), and serves as the output container for mapped results (error info, status codes, timestamps). |
| 3 | `ccName` | `String` | User-defined string — identifies the custom component work area name (e.g., `"KKSV056801CC"`, `"KKSV008254CC"`). Used as the key to retrieve and store per-screen input/output data within the `param` object's data map. |

**Instance fields read/modified:**

| Field | Type | Business Description |
|-------|------|---------------------|
| `wribSvcKei` | `HashMap<String, String>` | Stores the latest update timestamp per service contract number for discount services (割引サービス). Populated during up-mapping to track which contracts have been processed, so their last update timestamps can be propagated down-mapping. |
| `hanyoSvcKei` | `HashMap<String, String>` | Same as `wribSvcKei` but for proxy services (代替サービス). Used to track update timestamps for substitute service contracts. |

## 4. CRUD Operations / Called Services

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

| CRUD | SC / CBS | SC Code | Entity / DB | Operation Description |
|------|----------|---------|-------------|----------------------|
| U | `EKK0451C070` SC | EKK0451C070SC | Discount service contract table (contract cancellation) | Invokes discount service contract cancellation. Performs up-mapping of cancellation input fields (wrib_svc_kei_no, mskm_dtl_no, svc_cancel_rsn_cd, ido_div, wrib_dsl_cncl_opty_cd, upd_dtm_bf) and down-maps result fields (gene_add_dtm, wrib_svc_kei_stat, rsv_aply_ymd, rsv_aply_cd, svc_cancel_ymd, svc_cancel_cl_ymd, add_dtm, add_opeacnt, upd_dtm, upd_opeacnt, mk_flg). |
| U | `EKK1391C040` SC | EKK1391C040SC | Proxy service data extraction item setting table (cancellation completion) | Invokes proxy service cancellation for data extraction item setting completion. Performs up-mapping of completion fields (dchskmst_no, dchskmst_fin_sbt_cd, dchskmst_end_ymd, ido_div, dchskmst_fin_opty_cd, upd_dtm_bf) and down-maps result fields (gene_add_dtm, dchskmst_stat, add_dtm, add_opeacnt, upd_dtm, upd_opeacnt, mk_flg). |
| - | `JKKCancelSvcWribCC.editInEKK0451C070` | - | - | Up-mapping: transforms work bean map fields into CAANMsg template fields for EKK0451C070 SC invocation. |
| - | `JKKCancelSvcWribCC.editInEKK1391C040` | - | - | Up-mapping: transforms work bean map fields into CAANMsg template fields for EKK1391C040 SC invocation. |
| U | `JKKCancelSvcWribCC.editRetEKK0451C070` | - | - | Down-mapping: extracts result fields from SC response template and populates param data map and work area. |
| U | `JKKCancelSvcWribCC.editRetEKK1391C040` | - | - | Down-mapping: extracts result fields from SC response template and populates param data map and work area. |
| R | `JKKCancelSvcWribCC.getReturnCode` | - | - | Retrieves the SC execution return code from control map data for error status checking. |
| - | `JKKCancelSvcWribCC.putParamMap` | - | - | Wraps the CAANMsg template array into the parameter map for SC invocation. |
| - | `JKKCancelSvcWribCC.setSCInputCommonData` | - | - | Sets common SC input data: transaction ID, use case ID, operation ID, client hostname, client IP, screen ID, operator ID. |
| - | `JKKBpCommon.setResultUserData` | - | - | Sets user-defined result data on the output parameter map under the `ccName` key. |
| - | `JKKBpCommon.setResultCtrlData` | - | - | Sets control data result (SC return values) on the output parameter map. |
| - | `JKKBpCommon.getLastDtmBySvcKeiNo` | - | - | Retrieves the last update datetime for a service contract number from the work area (called within `getDtmMax`). |
| - | `JKKBpCommon.setLastDtmBySvcKeiNo` | - | - | Sets the last update datetime for a service contract number in the work area (called during down-mapping when UPD_DTM is non-empty). |

## 5. Dependency Trace

| # | Caller (Screen/Batch) | Call Chain (Full Path to this Method) | Terminal (SC / CRUD / Entity) |
|---|----------------------|--------------------------------------|-------------------------------|
| 1 | Screen:KKSV0568 | `KKSV0568OPOperation.invoke()` -> `target3.run()` -> `JKKCancelSvcWribCC.cancelSvcWrib` | `EKK0451C070 [U] DiscountSvcContract (cancel)`, `EKK1391C040 [U] ProxySvcDataExtractItem (cancel completion)` |
| 2 | Screen:KKSV0082 | `KKSV0082OPOperation.invoke()` -> `target66.run()` -> `JKKCancelSvcWribCC.cancelSvcWrib` | `EKK0451C070 [U] DiscountSvcContract (cancel)`, `EKK1391C040 [U] ProxySvcDataExtractItem (cancel completion)` |

**Notes:**
- **KKSV0568** is the "Application Cancellation OP" (申請破棄OP) operation — used when a user cancels an application before registration.
- **KKSV0082** is the "Pre-registration confirmation OP" (登録確認OP) operation — used when a user cancels during the pre-registration confirmation step.
- The CC is configured via `CCRequestBroker` in the generated OPOperation classes, with fixed text identifiers `"KKSV056801CC"` and `"KKSV008254CC"` respectively.
- A commented-out caller exists in `KKSV0080_KKSV0080OPBPCheck` (lines 354–356), indicating this CC was previously used by KKSV0080 but is now disabled.

## 6. Per-Branch Detail Blocks

**Block 1** — [SET] Initialization `(L79)`

> Initializes core processing variables before business logic begins.

| # | Type | Code |
|---|------|------|
| 1 | SET | `scCall = new ServiceComponentRequestInvoker()` |
| 2 | SET | `paramMap = setSCInputCommonData(param, new HashMap<String, Object>())` // Common SC input data [-> transaction ID, use case ID, operator ID, client host, client IP, screen ID] |
| 3 | SET | `template = null` |
| 4 | SET | `errFlgCc = "0"` // Error flag for execution judgment (エラーフラグ(実行判定用)) |
| 5 | SET | `result = null` |
| 6 | SET | `resUserMap = new HashMap()` // Down user data (下りユーザデータ) |

**Block 2** — [GET] Input Parameter Extraction `(L90)`

> Retrieves the work area map from the request parameter using the `ccName` key. If null, returns early without processing.

| # | Type | Code |
|---|------|------|
| 1 | EXEC | `inMap = (HashMap)param.getData(ccName)` // Get work area map |
| 2 | IF | `inMap == null` (L92) |
| 2.1 | RETURN | `return param` // Early exit if no work area data |

**Block 3** — [SET] Extract Lists and Function Code `(L97)`

> Extracts the two service lists and the function code from the input map.

| # | Type | Code |
|---|------|------|
| 1 | SET | `wribSvcCdListCnt = ((ArrayList)inMap.get("wribSvcCdList")).size()` // Discount service cancellation list count |
| 2 | SET | `hanyoCdListCnt = ((ArrayList)inMap.get("hanyoCdList")).size()` // Proxy service cancellation list count |
| 3 | SET | `wribSvcCdList = (ArrayList)inMap.get("wribSvcCdList")` // List of discount service contract entries |
| 4 | SET | `hanyoCdList = (ArrayList)inMap.get("hanyoCdList")` // List of proxy service contract entries |
| 5 | SET | `func_code = "1"` // Default function code |
| 6 | SET | `workBeanListMap1 = null` |
| 7 | SET | `workBeanListMap2 = null` |
| 8 | SET | `oldListNo = ""` // Previous list group identifier |
| 9 | IF | `inMap != null` (L101) |
| 9.1 | SET | `func_code = (String)inMap.get(JCMConstants.FUNC_CODE_KEY)` // Override func_code from input [-> JCMConstants.FUNC_CODE_KEY] |

**Block 4** — [FOR] Discount Service Cancellation Loop `(L107)`

> Iterates over discount service contracts, processing each unique `list_no` group once. Each group triggers a full SC cycle: up-mapping -> invocation -> down-mapping -> error check.

| # | Type | Code |
|---|------|------|
| 1 | FOR | `for (int i = 0; i < wribSvcCdListCnt; i++)` |
| 1.1 | SET | `workBeanListMap1 = (HashMap)wribSvcCdList.get(i)` |
| 1.2 | SET | `listNo = (String)workBeanListMap1.get("list_no")` // Group identifier |
| 1.3 | IF | `listNo != oldListNo` (L111) `[listNo change detected — new group]` |
| 1.3.1 | CALL | `template = editInEKK0451C070(param, workBeanListMap1, func_code, listNo, wribSvcCdList)` // Up-mapping for EKK0451C070 (割引サービス契約上りマッピング) |
| 1.3.2 | CALL | `result = scCall.run(putParamMap(paramMap, template), handle)` // SC invocation (SC呼び出し) |
| 1.3.3 | CALL | `editRetEKK0451C070(result, param, ccName)` // Down-mapping for EKK0451C070 (割引サービス契約下りマッピング) |
| 1.3.4 | IF | `getReturnCode(param) >= JPCModelConstant.SINGLEDATA_ERR` (L117) `[SINGLEDATA_ERR threshold check]` |
| 1.3.4.1 | THROW | `throw new CCException(SC_ERROR_STRING, new Exception())` // Service component error — aborts entire processing (ステータスが単項目エラー以上であれば例外をスロー) |
| 1.4 | SET | `oldListNo = listNo` (L122) // Update previous group for next iteration |

**Block 5** — [FOR] Proxy Service Cancellation Loop `(L125)`

> Same pattern as Block 4 but for proxy service contracts. Prepares a `workList` wrapper around the work bean map before up-mapping.

| # | Type | Code |
|---|------|------|
| 1 | SET | `oldListNo = ""` (L124) // Reset group tracker for second pass |
| 2 | FOR | `for (int i = 0; i < hanyoCdListCnt; i++)` |
| 2.1 | SET | `workBeanListMap2 = (HashMap)hanyoCdList.get(i)` |
| 2.2 | SET | `listNo = (String)workBeanListMap2.get("list_no")` |
| 2.3 | IF | `listNo != oldListNo` (L129) `[listNo change detected — new group]` |
| 2.3.1 | SET | `workList = new ArrayList<HashMap>()` |
| 2.3.2 | EXEC | `workList.add((HashMap)workBeanListMap2)` // Wrap single entry in list |
| 2.3.3 | CALL | `template = editInEKK1391C040(param, workBeanListMap2, func_code, listNo, workList)` // Up-mapping for EKK1391C040 (データ抽出項目設定完了上りマッピング) |
| 2.3.4 | CALL | `result = scCall.run(putParamMap(paramMap, template), handle)` // SC invocation (SC呼び出し) |
| 2.3.5 | CALL | `editRetEKK1391C040(result, param, ccName)` // Down-mapping for EKK1391C040 (データ抽出項目設定完了下りマッピング) |
| 2.3.6 | IF | `getReturnCode(param) >= JPCModelConstant.SINGLEDATA_ERR` (L137) `[SINGLEDATA_ERR threshold check]` |
| 2.3.6.1 | THROW | `throw new CCException(SC_ERROR_STRING, new Exception())` // Service component error — aborts entire processing |
| 2.4 | SET | `oldListNo = listNo` (L142) // Update previous group |

**Block 6** — [SET] Result Mapping `(`"下りユーザデータマッピング処理開始"` (L147)`

> Finalizes the response by setting user data and control data. Error flag check determines whether the SC result is propagated.

| # | Type | Code |
|---|------|------|
| 1 | CALL | `JKKBpCommon.setResultUserData(param, ccName, resUserMap)` // Set down user data mapping (下りユーザデータマッピング処理) |
| 2 | IF | `errFlgCc == "0"` (L148) `[errFlgCc="0" means no errors during processing]` |
| 2.1 | CALL | `JKKBpCommon.setResultCtrlData(param, result, ccName, 0, 0)` // Set control data result (コントロールデータマッピング) |
| 2.2 | ELSE | |
| 2.2.1 | SET | `errMsg = "割引情報キャンセルチェックCCで例外が発生しました"` // Exception occurred in discount cancel check CC |
| 2.2.2 | THROW | `throw new CCException(errMsg, new Exception(errMsg))` |
| 3 | RETURN | `return param` |

## 7. Glossary

| Term | Type | Business Meaning |
|------|------|------------------|
| `wrib` | Abbreviation | Short for "waribiki" (割引) — discount/rebate service. Refers to service contracts with discount or rebate agreements. |
| `hanyo` | Abbreviation | Short for "daitai" (代替) — substitute/proxy service. Refers to substitute service contracts that replace cancelled primary services. |
| `svc_kei_no` | Field | Service contract number — unique identifier for a service contract line item in the system. |
| `wrib_svc_kei_no` | Field | Discount service contract number — the service contract number specifically for discount/rebate agreements. |
| `mskm_dtl_no` | Field | Application details number — detailed application number for the service contract line item. |
| `svc_cancel_rsn_cd` | Field | Service cancellation reason code — codes the reason why a service contract was cancelled. |
| `ido_div` | Field | Migration division — classification indicating whether the service contract involves a migration/portability operation. |
| `wrib_dsl_cncl_opty_cd` | Field | Discount contract cancellation option code — codes the option/reason for cancelling a discount contract. |
| `dchskmst_no` | Field | Data extraction item setting number — identifier for data extraction item settings. |
| `dchskmst_fin_sbt_cd` | Field | Data extraction item setting completion subtype code — classification of the data extraction completion type. |
| `dchskmst_end_ymd` | Field | Data extraction item setting end date — the end date for data extraction item settings. |
| `dchskmst_fin_opty_cd` | Field | Data extraction item setting completion option code — option code for data extraction completion. |
| `upd_dtm_bf` | Field | Update datetime before — the timestamp of the last update before the current operation, used for optimistic concurrency control. |
| `gene_add_dtm` | Field | Generation addition datetime — timestamp when the record was initially created/generated. |
| `wrib_svc_kei_stat` | Field | Discount service contract status — current status of the discount service contract. |
| `rsv_aply_ymd` | Field | Reservation application date — date of reservation application. |
| `rsv_aply_cd` | Field | Reservation application code — code indicating the type of reservation application. |
| `svc_cancel_ymd` | Field | Service cancellation date — the date when the service was cancelled. |
| `svc_cancel_cl_ymd` | Field | Service cancellation withdrawal date — the date when a previously issued cancellation was withdrawn. |
| `add_dtm` | Field | Addition datetime — timestamp when the record was added. |
| `add_opeacnt` | Field | Addition operator account — the operator account that performed the addition. |
| `upd_dtm` | Field | Update datetime — timestamp of the last update to the record. |
| `upd_opeacnt` | Field | Update operator account — the operator account that performed the last update. |
| `mk_flg` | Field | Valid/invalid flag — flag indicating whether the record is active (valid) or inactive (invalid). |
| `list_no` | Field | List number — a grouping identifier used to batch-process service contracts. Contracts with the same `list_no` are processed together as a single group. |
| `func_code` | Field | Function code — identifies the operation type being performed. Default value is `"1"`. |
| `errFlgCc` | Field | Error flag for CC — set to `"0"` when no errors occur; changed to trigger error path if processing fails. |
| `SC_ERROR_STRING` | Constant | "サービスコンポーネントエラー" (Service Component Error) — error message string thrown when SC execution fails. |
| `CC_WORK_AREA_NAME_WRIB` | Constant | "JKKCancelSvcWribCCWork" — work area name key for discount service cancellation processing in the mapping work area. |
| `CC_WORK_AREA_NAME_SVKEI_EXC_CTRL` | Constant | "svkei_exc_ctrl" — work area name key for service contract exclusion control. |
| `SINGLEDATA_ERR` | Constant | From `JPCModelConstant` — threshold return code; if the SC return code meets or exceeds this value, it indicates at least one field-level error. |
| EKK0451C070 | SC Code | Discount service contract cancellation service component — handles up-mapping, SC invocation, and down-mapping for discount service contract cancellation. |
| EKK1391C040 | SC Code | Data extraction item setting completion service component — handles cancellation of data extraction item settings for proxy/substitute services. |
| KKSV0568 | Screen | Application cancellation OP screen — triggered when a user abandels/cancels an application before final registration. Calls this CC with fixed text `"KKSV056801CC"`. |
| KKSV0082 | Screen | Pre-registration confirmation OP screen — triggered when a user cancels during the pre-registration confirmation step. Calls this CC with fixed text `"KKSV008254CC"`. |
| CC | Abbreviation | Common Component — a reusable business component in the BPM workflow architecture that sits between OPOperation (BPM layer) and SC (Service Component layer). |
| SC | Abbreviation | Service Component — the data access and business logic layer that performs actual database operations. |
| BPM | Abbreviation | Business Process Management — the workflow orchestration framework (Fujitsu Futurity) used to define screen operations as chains of OPOperation, CC, and SC steps. |
| CAANMsg | Class | Fujitsu's message envelope class — carries structured input/output data between CCs and SCs. Contains template-based field definitions and null-handling. |
| `getDtmMax` | Method | Helper method that finds the service contract with the maximum update datetime across a list, and stores it in `wribSvcKei` or `hanyoSvcKei` for propagation. |
| `up mapping` | Term | 上りマッピング (Nobori mapping) — the process of transforming flat work bean map data into structured CAANMsg template fields for SC invocation. |
| `down mapping` | Term | 下りマッピング (Kudari mapping) — the process of extracting result fields from the SC response template back into flat work bean map data for the calling screen. |
