# Business Logic — JKKSmtvlYoSanshoKeiInfCC.editErrorInfo() [59 LOC]

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

## 1. Role

### JKKSmtvlYoSanshoKeiInfCC.editErrorInfo()

This method maps service interface error information onto the request parameter object, acting as the error consolidation step after a service component call chain completes. It receives a `CAANMsg` array containing templates returned by a service interface (SC) call, each carrying a status code that indicates the outcome of that SC invocation. The method applies two layers of priority logic: first, if the overall return code from the caller is non-zero (signaling a higher-level error), it forces every template's status to `9000` (a generic failure override). Second, it validates that the status code maps to a known message key in the resource bundle — unknown statuses are normalized to `0` (success/no error). The method then compares the template's effective status against the BP's current return code stored in the control map, and only overwrites the BP's error state when the template's status is strictly higher (worse). For matched error fields, it iterates through all keys in the template's hash map, finds those ending with `_err`, and copies the corresponding error messages into the BP's service data map if the base field exists. In short, it reconciles SC-level error information with the BP-level error tracking, ensuring the screen sees the most severe error that has occurred across the service chain. JP: サービスインターフェースのエラー情報をマッピングする。

## 2. Processing Pattern (Detailed Business Logic)

```mermaid
flowchart TD
    START(["editErrorInfo(param, templates, returnCode)"])
    LOOP["for i = 0 to templates.length"]
    GET_STATUS["template.getInt STATUS_INT_KEY"]
    CHECK_RETURN_CODE{returnCode != 0}
    SET_STATUS_9000["templateStatus = 9000"]
    CHECK_MSG{message key exists?}
    SET_STATUS_0["templateStatus = 0"]
    GET_BP_STATUS["param.getControlMapData RETURN_CODE"]
    CHECK_BP_NULL{bpStatus object == null}
    SET_BP_NEG1["bpStatus = -1"]
    PARSE_BP_STATUS["bpStatus = Integer.parseInt(statusString)"]
    CHECK_PRIORITY{templateStatus > bpStatus}
    FORMAT_STATUS["formatStatus = format templateStatus"]
    GET_MESSAGE["message = JCMAPLConstMgr.getString RETURN_MESSAGE + formatStatus"]
    SET_CONTROL_CODE["param.setControlMapData RETURN_CODE formatStatus"]
    SET_CONTROL_MSG["param.setControlMapData RETURN_MESSAGE message"]
    GET_SERVICE_DATA["param.getData KKSV065101CC"]
    GET_TEMPLATE_HASH["template.getHashMap"]
    ITERATE_KEYS["Iterator it = mp.keySet.iterator"]
    CHECK_HAS_NEXT{it.hasNext}
    GET_KEY["key = it.next"]
    CHECK_ERR_SUFFIX{key endsWith _err}
    FIND_LAST_ERR["keyIdx = key.lastIndexOf _err"]
    CHECK_INMAP{inMap contains base key}
    PUT_ERR["inMap.put errKey errValue"]
    NEXT_ITER["it.next"]
    RETURN_PARAM["return param"]
    END(["Next"])

    START --> LOOP
    LOOP --> GET_STATUS
    GET_STATUS --> CHECK_RETURN_CODE
    CHECK_RETURN_CODE -->|true| SET_STATUS_9000
    CHECK_RETURN_CODE -->|false| CHECK_MSG
    SET_STATUS_9000 --> CHECK_MSG
    CHECK_MSG -->|true| SET_STATUS_0
    CHECK_MSG -->|false| GET_BP_STATUS
    SET_STATUS_0 --> GET_BP_STATUS
    GET_BP_STATUS --> CHECK_BP_NULL
    CHECK_BP_NULL -->|true| SET_BP_NEG1
    CHECK_BP_NULL -->|false| PARSE_BP_STATUS
    SET_BP_NEG1 --> CHECK_PRIORITY
    PARSE_BP_STATUS --> CHECK_PRIORITY
    CHECK_PRIORITY -->|true| FORMAT_STATUS
    CHECK_PRIORITY -->|false| GET_SERVICE_DATA
    FORMAT_STATUS --> GET_MESSAGE
    GET_MESSAGE --> SET_CONTROL_CODE
    SET_CONTROL_CODE --> SET_CONTROL_MSG
    SET_CONTROL_MSG --> GET_SERVICE_DATA
    GET_SERVICE_DATA --> GET_TEMPLATE_HASH
    GET_TEMPLATE_HASH --> ITERATE_KEYS
    ITERATE_KEYS --> CHECK_HAS_NEXT
    CHECK_HAS_NEXT -->|true| GET_KEY
    CHECK_HAS_NEXT -->|false| RETURN_PARAM
    GET_KEY --> CHECK_ERR_SUFFIX
    CHECK_ERR_SUFFIX -->|true| FIND_LAST_ERR
    CHECK_ERR_SUFFIX -->|false| NEXT_ITER
    FIND_LAST_ERR --> CHECK_INMAP
    CHECK_INMAP -->|true| PUT_ERR
    CHECK_INMAP -->|false| NEXT_ITER
    PUT_ERR --> NEXT_ITER
    NEXT_ITER --> CHECK_HAS_NEXT
    RETURN_PARAM --> END
```

**Processing Summary:**
1. For each template in the `CAANMsg[]` returned by the SC:
   - Extract the SC status code from the template's `STATUS_INT_KEY`.
   - If the caller's `returnCode` is non-zero, override template status to `9000` (service call failure).
   - Validate the status against the resource bundle; if the message key `RETURN_MESSAGE_XXXX` does not exist, normalize status to `0` (no error).
   - Retrieve the BP's current return code from the control map; default to `-1` if not set.
   - If the template's effective status is higher (worse) than the BP's, overwrite the control map with the template's status code and message.
2. Iterate through the template's hash map keys, find error keys (ending in `_err`), and copy error values into the service data map if the base field exists.
3. Return the (now enriched) `param` object.

## 3. Parameter Analysis

| No | Parameter Name | Type | Business Description |
|----|---------------|------|---------------------|
| 1 | `param` | `IRequestParameterReadWrite` | The request parameter object carrying all screen input/output data. It holds a control map (for system-level fields like return code and return message) and a service data map under `KKSV065101CC` (the service ID for this screen's business data). Modified in-place to set error status and error messages. |
| 2 | `templates` | `CAANMsg[]` | Array of message templates returned from a service interface (SC) call via `CallSC`. Each template contains a status code (`STATUS_INT_KEY`) and a hash map of key-value pairs where error fields are suffixed with `_err`. Represents the full error/success state of the invoked service. |
| 3 | `returnCode` | `int` | The return code from the BP caller. When non-zero, it signals a higher-level error that overrides all template statuses to `9000` (generic failure). When zero, template statuses are evaluated normally. |

**Instance fields / external state read:**

| Field | Type | Business Description |
|-------|------|---------------------|
| `SERVICE_ID` | `String` (constant) | `"KKSV065101CC"` — the service ID key used to store and retrieve the screen's business data map within the request parameter. |

## 4. CRUD Operations / Called Services

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

The pre-computed CRUD table from the caller's broader scope is **not applicable** to this method — `editErrorInfo` performs **parameter enrichment only** and does not invoke any SC, CBS, or data-access methods directly. All operations are in-memory map manipulations on the `param` object.

| CRUD | SC / CBS | SC Code | Entity / DB | Operation Description |
|------|----------|---------|-------------|----------------------|
| R | `JCMAPLConstMgr.getString` | — | Resource Bundle | Reads message strings from `RETURN_MESSAGE_XXXX` keys in the application resource bundle |
| R | `IRequestParameterReadWrite.getControlMapData` | — | In-Memory Control Map | Reads the BP's current return code from the control map |
| W | `IRequestParameterReadWrite.setControlMapData` | — | In-Memory Control Map | Sets the return code and return message into the control map |
| R | `IRequestParameterReadWrite.getData` | — | In-Memory Service Data Map | Retrieves the service data map for `KKSV065101CC` |
| R | `CAANMsg.getHashMap` | — | In-Memory Template Hash Map | Retrieves all key-value pairs from the SC response template |
| R/W | `HashMap.put` / `HashMap.containsKey` | — | In-Memory Business Data Map | Copies error messages from the template into the service data map |

Note: While the pre-computed evidence table listed many `getData`, `getString`, and `substring` calls, those belong to the **caller** `callSC()` which invokes `editErrorInfo` as one step in a larger chain. This method itself only performs the operations listed above.

## 5. Dependency Trace

| # | Caller (Screen/Batch) | Call Chain (Full Path to this Method) | Terminal (SC / CRUD / Entity) |
|---|----------------------|--------------------------------------|-------------------------------|
| 1 | — | `JKKSmtvlYoSanshoKeiInfCC.callSC` -> `JKKSmtvlYoSanshoKeiInfCC.editErrorInfo` | `getHashMap [R]`, `getString [R]`, `getControlMapData [R]`, `setControlMapData [W]`, `getData [R]`, `put [W]` |

**Notes:** The only direct caller found is `JKKSmtvlYoSanshoKeiInfCC.callSC()`, which is a private helper method within the same class. The `callSC` method is invoked as part of the screen processing flow for `KKSV0651` (the service detail screen). The terminal operations from `editErrorInfo` are all in-memory — no SC or database interaction occurs at this level.

## 6. Per-Branch Detail Blocks

**Block 1** — [FOR LOOP] `for (int i = 0; i < templates.length; i++)` (L803)

> Iterates over each `CAANMsg` template returned from the service interface call.

| # | Type | Code |
|---|------|------|
| 1 | SET | `template = templates[i]` // current template from array |
| 2 | CALL | `template.getInt(JCMConstants.STATUS_INT_KEY)` → `templateStatus` // Extract SC return status code [-> STATUS_INT_KEY="status" (key name constant)] |

**Block 1.1** — [IF] `returnCode != 0` (L805)

> If the caller's return code is non-zero, the entire service call chain is treated as failed. All template statuses are overridden to `9000`. JP: BP側からエラーが返されている場合、テンプレートステータスを9000（エラー）に上書きする

| # | Type | Code |
|---|------|------|
| 1 | SET | `templateStatus = 9000` // Override to generic failure [-> 9000 = "Service call error"] |

**Block 1.2** — [IF] `JCMAPLConstMgr.getString("RETURN_MESSAGE_" + String.format("%1$04d", templateStatus)) == null` (L808)

> Validates that the template status maps to a known message in the resource bundle. If not, normalize to `0` (success/no error). JP: ステータスコードに対するメッセージキーが存在しない場合、ステータスを0（正常）に正規化する

| # | Type | Code |
|---|------|------|
| 1 | SET | `formatKey = "RETURN_MESSAGE_" + String.format("%1$04d", templateStatus)` // Build resource key e.g. "RETURN_MESSAGE_0000" |
| 2 | CALL | `JCMAPLConstMgr.getString(formatKey)` // Lookup message in resource bundle |
| 3 | SET | `templateStatus = 0` // Normalize unknown status to success [-> 0 = "No error"] |

**Block 1.3** — [IF/ELSE] `param.getControlMapData(SCControlMapKeys.RETURN_CODE)` (L813)

> Retrieves the BP's current return code from the control map. If not set (null), defaults to `-1` (lower than any valid status). JP: BPの現在の戻りコードを取得する。未設定の場合は-1とする

| # | Type | Code |
|---|------|------|
| 1 | SET | `obj = param.getControlMapData(SCControlMapKeys.RETURN_CODE)` // Get BP's current return code |
| 2 | SET | `bpStatus = -1` [ELSE] // Default when obj is null [-> -1 = "Below any valid status"] |
| 3 | SET | `bpStatus = Integer.parseInt((String) obj)` [ELSE] // Parse existing status as integer |

**Block 1.4** — [IF] `templateStatus > bpStatus` (L822)

> Only update the BP's error state if the SC's status is strictly worse (higher) than the BP's current status. This implements a "max-wins" priority strategy. JP: サービスコンポーネントのステータスがBPのステータスより大きい場合のみ、BPのエラー情報を設定する

| # | Type | Code |
|---|------|------|
| 1 | SET | `formatStatus = String.format("%1$04d", templateStatus)` // Format as 4-digit string, e.g. "1000" |
| 2 | CALL | `JCMAPLConstMgr.getString("RETURN_MESSAGE_" + formatStatus)` → `message` // Lookup error message text |
| 3 | EXEC | `param.setControlMapData(SCControlMapKeys.RETURN_CODE, formatStatus)` // Set return code to control map |
| 4 | EXEC | `param.setControlMapData(SCControlMapKeys.RETURN_MESSAGE, message)` // Set return message text |

**Block 1.5** — [ELSE/after 1.4] Service data and error map processing (L830)

> After the control map update, extract the service data map and process error-specific keys from the template. JP: コントロールマップの更新後、テンプレートからエラー項目をサービスマップにコピーする

| # | Type | Code |
|---|------|------|
| 1 | SET | `inMap = (HashMap<String, Object>) param.getData(SERVICE_ID)` // Retrieve service data map [-> SERVICE_ID="KKSV065101CC"] |
| 2 | SET | `mp = template.getHashMap()` // Get all key-value pairs from the template |
| 3 | SET | `it = mp.keySet().iterator()` // Create iterator over template keys |

**Block 1.5.1** — [WHILE] `it.hasNext()` (L836)

> Iterates through all keys in the template's hash map to find error fields. JP: テンプレートの全キーを走査し、エラー項目を探す

| # | Type | Code |
|---|------|------|
| 1 | SET | `key = (String) it.next()` // Next key from template hash map |

**Block 1.5.2** — [IF] `key.endsWith("_err")` (L838)

> Identifies error fields by the `_err` suffix convention. JP: キーが「_err」で終わる場合、エラー項目として処理する

| # | Type | Code |
|---|------|------|
| 1 | SET | `keyIdx = key.lastIndexOf("_err")` // Find position of "_err" suffix |
| 2 | SET | `baseKey = key.substring(0, keyIdx)` // Extract base field name (e.g. "return_Message_err" → "return_Message") |
| 3 | CALL | `inMap.containsKey(baseKey)` // Check if the base field exists in the service data map |

**Block 1.5.2.1** — [IF TRUE] `inMap.containsKey(baseKey)` (L840)

> Only copy the error value if the corresponding base field already exists in the service data map. This prevents orphaned error entries for fields that aren't present. JP: ベースフィールドがサービスマップに存在する場合のみ、エラー値をコピーする

| # | Type | Code |
|---|------|------|
| 1 | EXEC | `inMap.put(key, mp.get(key))` // Copy the error message value (e.g. "return_Message_err" → error text) |

## 7. Glossary

| Term | Type | Business Meaning |
|------|------|------------------|
| `STATUS_INT_KEY` | Constant | Status integer key — the map key used to store and retrieve the SC return status code in a `CAANMsg` template |
| `RETURN_CODE` | Field (Control Map) | Return code — the BP's current error/interrupt status, stored as a 4-digit string (e.g., "0000" = success, "1000" = error, "9000" = service call failure) in the control map |
| `RETURN_MESSAGE` | Field (Control Map) | Return message — the human-readable error message text corresponding to the return code, looked up from the resource bundle |
| `_err` suffix | Naming convention | Error field suffix — fields ending with `_err` in the template hash map contain error messages for their base field (e.g., `return_Message_err` is the error message for `return_Message`) |
| `SCControlMapKeys` | Class | Control map keys constant class — provides constants for control map field names such as `RETURN_CODE`, `ERROR_INFO`, `OPERATOR_ID` |
| `JCMConstants` | Class | JCM constants class — provides standard constants for the JCM framework, including `STATUS_INT_KEY` |
| `JCMAPLConstMgr` | Class | JCM Application Constants Manager — utility class for reading messages from the application resource bundle |
| `CAANMsg` | Class | CAAN message object — a key-value message container used to pass data between BP and SC layers; supports `getInt()`, `getString()`, `getHashMap()` accessors |
| `IRequestParameterReadWrite` | Interface | Request parameter read-write interface — the main data carrier for screen-level input/output, containing both a control map (system fields) and service data maps |
| `SERVICE_ID` | Constant | `"KKSV065101CC"` — the service ID key identifying the business data map for screen `KKSV0651` within the request parameter |
| `KKSV0651` | Screen | Service Detail Screen — the screen entry point for viewing and editing service detail information |
| `templateStatus` | Variable | Effective template status — the final status code after applying the `returnCode` override and resource bundle validation |
| `bpStatus` | Variable | BP current status — the business program's currently recorded error level, used as a baseline for priority comparison |
| `9000` | Status | Service call error — generic failure status code used when the caller's return code is non-zero, forcing all templates to be treated as errors |
| `0` | Status | No error / Normal completion — default status for unknown message keys or successful service execution |
| `-1` | Status | Below any valid status — sentinel value used when the BP's return code is not yet set, ensuring any template status will take precedence |
| `RETURN_MESSAGE_XXXX` | Resource key | Resource bundle message key — key pattern for error messages in the application resource bundle, where XXXX is the 4-digit status code |
