# Business Logic — JKKCancelSvcWribCC.editErrInfoEKK0451C070() [95 LOC]

| Field | Value |
|-------|-------|
| Fully Qualified Name | `com.fujitsu.futurity.bp.custom.common.JKKCancelSvcWribCC` |
| Layer | CC/Common Component |
| Module | `common` (Package: `com.fujitsu.futurity.bp.custom.common`) |

## 1. Role

### JKKCancelSvcWribCC.editErrInfoEKK0451C070()

This method performs **error information mapping** for discount service contract cancellation (割引サービス契約キャンセル) within the Fujitsu Futurity business process system. It is a **post-SC (Service Component) callback** that runs after a cancellation SC call (`EKK0451C070SC`) has returned its results. The method implements a **routing/dispatch pattern**: it compares the template's error status against any previously recorded BP-level status, and only promotes (overrides) the status if the template's is more severe. When promotion is warranted, it resolves the human-readable error message from a centralized constant map and writes both the status code and message back into the control map.

The method then acts as a **field-level error mapper**, reading individual error fields from the SC response template (`CAANMsg[]`) and writing them into a data map keyed by the caller-supplied `fixedText` parameter. Each field is only written if the template actually carries an error value for that field (checked via `isNull()`) and the target map does not already contain an entry (idempotent — avoids overwriting earlier data). This pattern supports multi-record cancellation processing where each record gets its own error payload stored under a shared work area.

The method plays the role of a **shared utility component (CC)** called by `editRetEKK0451C070()`, which itself is invoked by the main `JKKCancelSvcWribCC.process()` method in a loop over service contract records. This makes it a reusable post-processing step that ensures error data flows correctly from the SC layer back to the presentation/screen layer.

## 2. Processing Pattern (Detailed Business Logic)

```mermaid
flowchart TD
    START(["editErrInfoEKK0451C070(params)"])
    S1["template = templates[0]"]
    S2["templateStatus = template.getInt(STATUS)"]
    S3{returnCode != 0?}
    S4["templateStatus = 9000"]
    S5{RETURN_MESSAGE_ templateStatus exists?}
    S6["templateStatus = 0"]
    S7["bpStatus = -1 (default)"]
    S8["bpStatus = Integer.parseInt(RETURN_CODE)"]
    S9{templateStatus > bpStatus?}
    S10["formatStatus = 04d(templateStatus)"]
    S11["message = RETURN_MESSAGE_ formatStatus"]
    S12["param.setControlMapData(RETURN_CODE, formatStatus)"]
    S13["param.setControlMapData(RETURN_MESSAGE, message)"]
    S14["workMap = param.getMappingWorkArea()"]
    S15{workMap == null?}
    S16["workMap = new HashMap(); param.setMappingWorkArea()"]
    S17["inMap = param.getData(fixedText)"]
    S18{WRIB_SVC_KEI_NO_ERR exists?}
    S19{wrib_svc_kei_no_err in inMap?}
    S20["inMap.put(wrib_svc_kei_no_err, template.getString())"]
    S21{MSKM_DTL_NO_ERR exists?}
    S22{mskm_dtl_no_err in inMap?}
    S23["inMap.put(mskm_dtl_no_err, template.getString())"]
    S24{SVC_CANCEL_RSN_CD_ERR exists?}
    S25{svc_cancel_rsn_cd_err in inMap?}
    S26["inMap.put(svc_cancel_rsn_cd_err, template.getString())"]
    S27{IDO_DIV_ERR exists?}
    S28{ido_div_err in inMap?}
    S29["inMap.put(ido_div_err, template.getString())"]
    S30{UPD_DTM_BF exists?}
    S31{upd_dtm_bf_err in inMap?}
    S32["inMap.put(upd_dtm_bf_err, template.getString())"]
    S33["return param"]

    START --> S1
    S1 --> S2
    S2 --> S3
    S3 -- "Yes" --> S4
    S3 -- "No" --> S5
    S4 --> S5
    S5 -- "No (not found)" --> S6
    S5 -- "Yes" --> S7
    S6 --> S7
    S7 --> S8
    S8 --> S9
    S9 -- "Yes" --> S10
    S9 -- "No" --> S14
    S10 --> S11
    S11 --> S12
    S12 --> S14
    S14 --> S15
    S15 -- "Yes" --> S16
    S15 -- "No" --> S17
    S16 --> S17
    S17 --> S18
    S18 -- "Yes" --> S19
    S18 -- "No" --> S21
    S19 -- "No" --> S20
    S19 -- "Yes (skip)" --> S21
    S20 --> S21
    S21 -- "Yes" --> S22
    S21 -- "No" --> S24
    S22 -- "No" --> S23
    S22 -- "Yes (skip)" --> S24
    S23 --> S24
    S24 -- "Yes" --> S25
    S24 -- "No" --> S27
    S25 -- "No" --> S26
    S25 -- "Yes (skip)" --> S27
    S26 --> S27
    S27 -- "Yes" --> S28
    S27 -- "No" --> S30
    S28 -- "No" --> S29
    S28 -- "Yes (skip)" --> S30
    S29 --> S30
    S30 -- "Yes" --> S31
    S30 -- "No" --> S33
    S31 -- "No" --> S32
    S31 -- "Yes (skip)" --> S33
    S32 --> S33
    S33 --> END(["Return param"])
```

## 3. Parameter Analysis

| No | Parameter Name | Type | Business Description |
|----|---------------|------|---------------------|
| 1 | `param` | `IRequestParameterReadWrite` | The request parameter object carrying the full request context — control map (return codes, error messages, error info lists), mapping work area (intermediate processing state), and typed data maps keyed by business identifiers. This is the primary data structure that flows through the entire request lifecycle. |
| 2 | `templates` | `CAANMsg[]` | An array of CBS message templates returned from the SC (Service Component) layer. Each element holds the SC response data including error status, error flags, and error field values. `templates[0]` is the primary response template. |
| 3 | `returnCode` | `int` | The return code from the SC call. If non-zero, it overrides the template's status to `9000` (generic error), indicating that the SC call itself encountered a non-success condition. Zero means the SC call returned normally and the template's own status governs the behavior. |
| 4 | `fixedText` | `String` | A string key used to identify the data map within the `IRequestParameterReadWrite` object. It serves as the namespace for error fields, allowing different business records (e.g., individual service contract lines) to maintain separate error data under distinct keys. |

### Instance fields / external state read

| Source | Description |
|--------|-------------|
| `param.getControlMapData(SCControlMapKeys.RETURN_CODE)` | Reads a previously stored return code from the control map (BP-level status). Used for status comparison. |
| `param.getMappingWorkArea()` | Reads the work area map that holds intermediate processing data across multiple CC method calls. |
| `param.getData(fixedText)` | Reads the typed data map identified by `fixedText`. This is the target container for error field values. |
| `JCMAPLConstMgr.getString("RETURN_MESSAGE_" + status)` | Reads from a global constant/message manager. Returns the human-readable error message for a given status code, or `null` if no message exists. |

## 4. CRUD Operations / Called Services

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

| CRUD | SC / CBS | SC Code | Entity / DB | Operation Description |
|------|----------|---------|-------------|----------------------|
| - | `JCMAPLConstMgr.getString` | - | - | Reads error message text from centralized message constants by key (`RETURN_MESSAGE_XXXX`) |
| R | `template.getInt` | EKK0451C070CBS | - | Reads the STATUS field from the CBS response template |
| R | `template.isNull` | EKK0451C070CBS | - | Checks if each error field (WRIB_SVC_KEI_NO_ERR, MSKM_DTL_NO_ERR, SVC_CANCEL_RSN_CD_ERR, IDO_DIV_ERR, UPD_DTM_BF) is null in the template — used as a guard before reading |
| R | `template.getString` | EKK0451C070CBS | - | Reads non-null error field values from the template for mapping to the data map |
| R | `param.getControlMapData` | - | - | Reads the previously stored return code from the control map |
| R | `param.getMappingWorkArea` | - | - | Reads the mapping work area map for null-check and lazy initialization |
| R | `param.getData` | - | - | Reads the data map identified by the `fixedText` key |
| SET | `param.setControlMapData` | - | - | Writes the resolved return code status (formatted as 4-digit string) to the control map |
| SET | `param.setControlMapData` | - | - | Writes the human-readable error message to the control map |
| SET | `param.setMappingWorkArea` | - | - | Writes a newly created work area map back to the parameter object |
| SET | `inMap.put` | - | - | Writes each error field value to the data map under its respective key (e.g., `wrib_svc_kei_no_err`) |

**Note:** This method performs **no database operations** and **no SC calls**. It is a pure in-memory data transformation layer that maps CBS template error fields into the request parameter's internal data structures, enabling presentation-layer error display.

## 5. Dependency Trace

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

No screen/batch entry points found within 8 hops. Direct callers found: 1 method.
Terminal operations from this method: `isNull` [-], `isNull` [-], `isNull` [-], `isNull` [-], `isNull` [-], `getString` [-], `getString` [-], `getString` [-], `getString` [-], `getString` [-], `getInt` [-], `getString` (JCMAPLConstMgr) [-], `getControlMapData` [-], `getMappingWorkArea` [-], `getData` [-], `setControlMapData` [-], `setControlMapData` [-], `setMappingWorkArea` [-], `put` [-]

| # | Caller (Screen/Batch) | Call Chain (Full Path to this Method) | Terminal (SC / CRUD / Entity) |
|---|----------------------|--------------------------------------|-------------------------------|
| 1 | CC:JKKCancelSvcWribCC.editRetEKK0451C070 | `editRetEKK0451C070(msgList, param, fixedText)` -> `editErrInfoEKK0451C070(param, templates, returnCode, fixedText)` | template.getString/isNull [R] (error fields), JCMAPLConstMgr.getString [-] |
| 2 | CC:JKKCancelSvcWribCC.process | `process(param)` -> `editRetEKK0451C070(result, param, ccName)` -> `editErrInfoEKK0451C070(param, templates, returnCode, fixedText)` | Same as caller 1 |

**Call chain detail:**
- `JKKCancelSvcWribCC.process()` loops over service contract cancellation records, calls an SC for each record, then calls `editRetEKK0451C070()` to process the SC result.
- `editRetEKK0451C070()` extracts the template array and return code from the SC result map and delegates to `editErrInfoEKK0451C070()` for error field mapping.
- `editErrInfoEKK0451C070()` is a leaf CC method — it performs no further SC or DB calls, only in-memory mapping and control map updates.

## 6. Per-Branch Detail Blocks

### Block 1 — IF (returnCode != 0) `(status override)` (L1092)

When the SC call returns a non-zero return code, the method overrides the template's status to a generic error value of 9000. This ensures that any SC-level failure is visible as a non-OK status regardless of what the template itself reports.

| # | Type | Code |
|---|------|------|
| 1 | EXEC | `templateStatus = 9000` // Override template status to generic error |

### Block 2 — IF (RETURN_MESSAGE_ templateStatus not found) `(status normalization)` (L1096)

Validates that the template's status maps to a known error message. If no message exists in the constant manager for `RETURN_MESSAGE_` + status, the status is normalized to 0 (OK). This prevents unknown status codes from propagating as error conditions.

| # | Type | Code |
|---|------|------|
| 1 | EXEC | `JCMAPLConstMgr.getString("RETURN_MESSAGE_" + formatStatus)` // Check message existence [-> formatStatus = "9000" or original status] |
| 2 | SET | `templateStatus = 0` // Normalize to OK if no message mapping exists |

### Block 3 — IF/ELSE (bpStatus initialization) `(BP status extraction)` (L1100-L1107)

Reads any previously stored return code from the control map and converts it to an integer for comparison. If no prior return code exists (`null`), defaults to -1 (worse than any valid positive status). This ensures that if a later SC call in the loop has a lower severity status, the higher one is preserved.

| # | Type | Code |
|---|------|------|
| 1 | SET | `bpStatus = -1` // Default: worse than any positive status |
| 2 | SET | `bpStatus = Integer.parseInt((String)param.getControlMapData(SCControlMapKeys.RETURN_CODE))` // Parse stored return code |

### Block 4 — IF (templateStatus > bpStatus) `(status promotion)` (L1109)

Compares the template's error status against the BP-level status. If the template's status is numerically higher (indicating a worse error), it promotes the template's status and message into the control map. This implements a "max-severity wins" strategy across multiple SC calls in a loop — only the worst error for a given request is retained.

| # | Type | Code |
|---|------|------|
| 1 | SET | `formatStatus = String.format("%1$04d", templateStatus)` // Format as 4-digit zero-padded string [-> "0001", "9000", etc.] |
| 2 | SET | `message = JCMAPLConstMgr.getString("RETURN_MESSAGE_" + formatStatus)` // Resolve human-readable message |
| 3 | EXEC | `param.setControlMapData(SCControlMapKeys.RETURN_CODE, formatStatus)` // Store formatted status |
| 4 | EXEC | `param.setControlMapData(SCControlMapKeys.RETURN_MESSAGE, message)` // Store error message text |

### Block 5 — IF (workMap == null) `(work area initialization)` (L1118-L1121)

Ensures the mapping work area map exists in the parameter object. If it is null, creates a new HashMap and stores it. This is a lazy initialization guard that must run even when the method's own error data is not being written.

| # | Type | Code |
|---|------|------|
| 1 | SET | `workMap = new HashMap()` // Create new work area map |
| 2 | EXEC | `param.setMappingWorkArea(workMap)` // Store in parameter |

### Block 6 — SET (inMap retrieval) `(data map access)` (L1124)

Retrieves the data map for the current business record. The map is keyed by `fixedText`, which identifies the specific service contract line item. Error field values from the template will be written into this map.

| # | Type | Code |
|---|------|------|
| 1 | SET | `inMap = (HashMap)param.getData(fixedText)` // Get data map for this record |

### Block 7 — IF/ELSE-IF chain: Error field mapping `(error data extraction)` (L1127-L1171)

Each error field follows the same pattern: check if the template carries a non-null value for the field, and if so, check whether the target map already has an entry (idempotent guard). If both conditions pass, read the field value from the template and write it into the data map.

**Block 7.1** — IF (WRIB_SVC_KEI_NO_ERR exists) `[割引サービス契約番号]` (L1127)

| # | Type | Code |
|---|------|------|
| 1 | EXEC | `template.isNull(EKK0451C070CBSMsg.WRIB_SVC_KEI_NO_ERR)` // Check if discount service contract number error is present |
| 2 | EXEC | `inMap.containsKey("wrib_svc_kei_no_err")` // Check if already mapped |
| 3 | SET | `inMap.put("wrib_svc_kei_no_err", template.getString(EKK0451C070CBSMsg.WRIB_SVC_KEI_NO_ERR))` // Map discount service contract number error |

**Block 7.2** — IF (MSKM_DTL_NO_ERR exists) `[申込詳細番号]` (L1135)

| # | Type | Code |
|---|------|------|
| 1 | EXEC | `template.isNull(EKK0451C070CBSMsg.MSKM_DTL_NO_ERR)` // Check if application detail number error is present |
| 2 | EXEC | `inMap.containsKey("mskm_dtl_no_err")` // Check if already mapped |
| 3 | SET | `inMap.put("mskm_dtl_no_err", template.getString(EKK0451C070CBSMsg.MSKM_DTL_NO_ERR))` // Map application detail number error |

**Block 7.3** — IF (SVC_CANCEL_RSN_CD_ERR exists) `[サービスキャンセル理由コード]` (L1143)

| # | Type | Code |
|---|------|------|
| 1 | EXEC | `template.isNull(EKK0451C070CBSMsg.SVC_CANCEL_RSN_CD_ERR)` // Check if service cancel reason code error is present |
| 2 | EXEC | `inMap.containsKey("svc_cancel_rsn_cd_err")` // Check if already mapped |
| 3 | SET | `inMap.put("svc_cancel_rsn_cd_err", template.getString(EKK0451C070CBSMsg.SVC_CANCEL_RSN_CD_ERR))` // Map service cancel reason code error |

**Block 7.4** — IF (IDO_DIV_ERR exists) `[異動区分]` (L1151)

| # | Type | Code |
|---|------|------|
| 1 | EXEC | `template.isNull(EKK0451C070CBSMsg.IDO_DIV_ERR)` // Check if movement classification error is present |
| 2 | EXEC | `inMap.containsKey("ido_div_err")` // Check if already mapped |
| 3 | SET | `inMap.put("ido_div_err", template.getString(EKK0451C070CBSMsg.IDO_DIV_ERR))` // Map movement classification error |

**Block 7.5** — IF (UPD_DTM_BF exists) `[更新年月日時分秒(更新前)]` (L1159)

| # | Type | Code |
|---|------|------|
| 1 | EXEC | `template.isNull(EKK0451C070CBSMsg.UPD_DTM_BF)` // Check if pre-update timestamp error is present |
| 2 | EXEC | `inMap.containsKey("upd_dtm_bf_err")` // Check if already mapped |
| 3 | SET | `inMap.put("upd_dtm_bf_err", template.getString(EKK0451C070CBSMsg.UPD_DTM_BF))` // Map pre-update timestamp error |

### Block 8 — RETURN `(method exit)` (L1173)

Returns the modified parameter object with all resolved error data stored in both the control map (status + message) and the data map (per-field error values).

| # | Type | Code |
|---|------|------|
| 1 | RETURN | `return param` // Return parameter with error info mapped |

## 7. Glossary

| Term | Type | Business Meaning |
|------|------|------------------|
| `WRIB_SVC_KEI_NO` | Field | Discount service contract number — the primary identifier for a discount service contract line item |
| `WRIB_SVC_KEI_NO_ERR` | Field | Discount service contract number error — error flag/value for the contract number |
| `MSKM_DTL_NO` | Field | Application detail number — a sub-identifier for specific application detail records |
| `MSKM_DTL_NO_ERR` | Field | Application detail number error — error flag/value for the detail number |
| `SVC_CANCEL_RSN_CD` | Field | Service cancel reason code — code indicating why the service contract was cancelled |
| `SVC_CANCEL_RSN_CD_ERR` | Field | Service cancel reason code error — error flag/value for the cancel reason |
| `IDO_DIV` | Field | Movement classification — indicates the type of service change/movement (e.g., new, transfer, termination) |
| `IDO_DIV_ERR` | Field | Movement classification error — error flag/value for the movement type |
| `UPD_DTM_BF` | Field | Pre-update datetime — the timestamp before the last update, used for optimistic concurrency control |
| `UPD_DTM_BF_ERR` | Field | Pre-update datetime error — error flag/value for the pre-update timestamp |
| `STATUS` | Field | CBS response status code — numeric code indicating success/failure from the SC layer |
| `RETURN_CODE` | Control Map Key | Stored return code in the request control map — tracks the worst error status across loop iterations |
| `RETURN_MESSAGE` | Control Map Key | Human-readable error message resolved from constant manager |
| `RETURN_MESSAGE_XXXX` | Constant Key Pattern | Message constant key format — concatenated as `"RETURN_MESSAGE_"` + 4-digit status code to look up the display message |
| `CAANMsg` | Class | CBS message container — holds field-value pairs returned from SC calls; supports `getInt()`, `getString()`, `isNull()` |
| `IRequestParameterReadWrite` | Interface | Request parameter interface — carries the full request context including control map, work area, and typed data maps |
| `JCMAPLConstMgr` | Class | Centralized constant/message manager — provides application-wide access to error message strings keyed by name |
| `EKK0451C070CBS` | CBS Module | Discount service contract cancellation CBS — the CBS module whose response template this method processes |
| `editErrInfoEKK0451C070` | Method | Error info mapping method — post-SC callback that maps CBS error fields into request parameters |
| `editRetEKK0451C070` | Method | Edit return handler — caller method that processes SC results and delegates error mapping to this method |
| 割引サービス契約キャンセル | Japanese term | Discount service contract cancellation — the business domain this CC handles |
| エラー情報 | Japanese term | Error information — the error data being mapped from SC response to presentation layer |
| BP | Abbreviation | Business Process — the orchestration layer (CC method) that orchestrates SC calls in loops |
| SC | Abbreviation | Service Component — the layer that executes database operations and returns CAANMsg templates |
| CC | Abbreviation | Common Component — a shared utility class providing cross-cutting processing (mapping, transformation, validation) |
| CBS | Abbreviation | Common Business Service — the message-oriented service layer that interfaces with the SC/DAO layer |
| templateStatus | Variable | The error status extracted from the CBS response template |
| bpStatus | Variable | The previously recorded BP-level return code, used for max-severity comparison |
| fixedText | Parameter | The key used to identify the data map within the request parameter, separating error data per business record |
