# Business Logic — JKKSvkeiShosaChkCC.callSC() [41 LOC]

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

## 1. Role

### JKKSvkeiShosaChkCC.callSC()

This method serves as a **generic service component (SC) invocation wrapper** that delegates to an arbitrary service component while standardizing the request/response lifecycle. It is the shared bridge between the business validation logic in `JKKSvkeiShosaChkCC` and the underlying service components that perform actual domain operations (such as service contract validation, order processing, or data lookup). The method implements the **delegation pattern** — it accepts a `ServiceComponentRequestInvoker` (`scCall`) as a parameter, allowing any configured SC to be invoked without the method needing to know the specific service it targets. Its role in the larger system is that of a **reusable utility**: it is called from `chkSvkeiShosa()`, which performs service detail inspection checks, and potentially from other validation or processing methods in the same class. The method normalizes the contract: it always prepares parameters via `editInMsg`, always inspects the result for return code and status, always aggregates error info, and always throws `SCCallException` on failure — making error handling consistent across all SC invocations.

## 2. Processing Pattern (Detailed Business Logic)

```mermaid
flowchart TD
    START(["callSC params"])
    BUILD_PARAM["editInMsg param, mappingData"]
    SC_CALL["scCall.run paramMap, handle"]
    EXTRACT_TEMPLATES["result.get TEMPLATE_LIST_KEY"]
    GET_MSG["templates 0"]
    GET_RETURN_CODE["result.get RET_CD_INT_KEY"]
    GET_STATUS["msg.getInt STATUS_INT_KEY"]
    EDIT_ERROR["editErrorInfoCom param, templates, RETURN_CODE, dataMapKey"]
    GET_ERR_LIST["param.getControlMapData ERROR_INFO"]
    NULL_ERR{null == errList}
    INIT_ERR["errList = new ArrayList"]
    UPDATE_ERR["param.setControlMapData ERROR_INFO, TemplateErrorUtil.getErrorInfo"]
    CHECK_STATUS{RETURN_CODE equals 0 and status is 0}
    THROW_ERR["throw new SCCallException returns values invalid, RETURN_CODE, status"]
    RETURN_MSG["return msg"]

    START --> BUILD_PARAM
    BUILD_PARAM --> SC_CALL
    SC_CALL --> EXTRACT_TEMPLATES
    EXTRACT_TEMPLATES --> GET_MSG
    SC_CALL --> GET_RETURN_CODE
    GET_RETURN_CODE --> EDIT_ERROR
    SC_CALL --> GET_STATUS
    GET_STATUS --> GET_ERR_LIST
    GET_ERR_LIST --> NULL_ERR
    NULL_ERR -->|Yes| INIT_ERR
    INIT_ERR --> UPDATE_ERR
    NULL_ERR -->|No| UPDATE_ERR
    UPDATE_ERR --> CHECK_STATUS
    CHECK_STATUS -->|False| THROW_ERR
    CHECK_STATUS -->|True| RETURN_MSG
    THROW_ERR --> END_THROW(["Throw exception"])
    RETURN_MSG --> END_OK(["Return msg"])
```

## 3. Parameter Analysis

| No | Parameter Name | Type | Business Description |
|----|---------------|------|---------------------|
| 1 | `handle` | `SessionHandle` | The current user session context, carrying authentication, tenant, and locale information required by the service component to operate within the correct user context. |
| 2 | `scCall` | `ServiceComponentRequestInvoker` | A reference to the target service component to invoke. This is a polymorphic invoker — any SC (e.g., service validation, order creation, data lookup) can be passed, making this method a generic SC dispatcher. |
| 3 | `param` | `IRequestParameterReadWrite` | The request/response parameter carrier that holds business data, control maps (including error info), and the data map keyed by `dataMapKey`. It flows through the entire lifecycle: parameter building, SC invocation, and error aggregation. |
| 4 | `dataMapKey` | `String` | The key used to locate or store the result map within `param`'s internal data map. This key identifies which result set the caller expects — it is passed through to `editErrorInfoCom` for error result mapping. |
| 5 | `mappingData` | `Object[][]` | A two-dimensional array of mapping pairs used by `editInMsg` to populate the parameter map. Each row represents a key-value mapping from source data to the request parameter, enabling data transformation before the SC call. |

**External State / Instance Fields:** None. This method is fully stateless — it reads only from parameters and the session handle, and writes only to `param`.

## 4. CRUD Operations / Called Services

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

| CRUD | SC / CBS | SC Code | Entity / DB | Operation Description |
|------|----------|---------|-------------|----------------------|
| U | `JKKSvkeiShosaChkCC.editInMsg` | JKKSvkeiShosaChkCC | - | Transforms `mappingData` into a parameter map (Update the param's data map) |
| - | `scCall.run` | (Determined by caller) | - | Invokes the target service component with the prepared parameter map. SC Code is determined by which SC instance is passed as `scCall`. |
| R | `result.get(JCMConstants.TEMPLATE_LIST_KEY)` | - | - | Extracts the `CAANMsg[]` templates from the SC response result. |
| R | `result.get(JCMConstants.RET_CD_INT_KEY)` | - | - | Extracts the return code from the SC response to determine success/failure. |
| R | `msg.getInt(JCMConstants.STATUS_INT_KEY)` | - | - | Reads the status field from the response message to check operational status. |
| U | `JKKSvkeiShosaChkCC.editErrorInfoCom` | JKKSvkeiShosaChkCC | - | Updates error information in `param` using templates, return code, and data map key. |
| R | `param.getControlMapData(SCControlMapKeys.ERROR_INFO)` | - | - | Retrieves existing error list from the control map for error aggregation. |
| U | `param.setControlMapData(SCControlMapKeys.ERROR_INFO, ...)` | - | - | Stores the merged error list back into the control map. |
| R | `TemplateErrorUtil.getErrorInfo(result, errList)` | TemplateErrorUtil | - | Extracts and aggregates error information from the SC result combined with existing error list. |


## 5. Dependency Trace

| # | Caller (Screen/Batch) | Call Chain (Full Path to this Method) | Terminal (SC / CRUD / Entity) |
|---|----------------------|--------------------------------------|-------------------------------|
| 1 | Class: JKKSvkeiShosaChkCC | `chkSvkeiShosa` -> `callSC` | `scCall.run [-] (SC varies by caller)` |

**Terminal operations from this method:**

| # | Method | CRUD | Description |
|---|--------|------|-------------|
| 1 | `scCall.run` | - | Invokes the target SC (CRUD type depends on which SC is passed) |
| 2 | `result.get(TEMPLATE_LIST_KEY)` | R | Reads response templates |
| 3 | `result.get(RET_CD_INT_KEY)` | R | Reads return code |
| 4 | `msg.getInt(STATUS_INT_KEY)` | R | Reads status from response |
| 5 | `editErrorInfoCom` | U | Updates error info in param |
| 6 | `param.getControlMapData(ERROR_INFO)` | R | Reads existing error list |
| 7 | `param.setControlMapData(ERROR_INFO, ...)` | U | Writes aggregated error list |
| 8 | `TemplateErrorUtil.getErrorInfo` | R | Extracts error info from SC result |
| 9 | `new SCCallException` | - | Throws exception on failure |

## 6. Per-Branch Detail Blocks

**Block 1** — [SET] `(Parameter mapping and initial processing) (L1884)`

This block builds the parameter map by calling `editInMsg`, which transforms the raw `mappingData` array into a structured `HashMap` ready for the SC invocation.

| # | Type | Code |
|---|------|------|
| 1 | SET | `paramMap = editInMsg(param, mappingData)` // Converts mappingData into a parameter map [-> editInMsg creates HashMap from mappingData] |

**Block 2** — [CALL] `(Service Component invocation) (L1886)`

This block invokes the target service component, passing the prepared parameter map and session handle. The actual SC code (e.g., `EKK0361A010SC`) is determined by which `ServiceComponentRequestInvoker` instance the caller passed in as `scCall`.

| # | Type | Code |
|---|------|------|
| 1 | CALL | `result = scCall.run(paramMap, handle)` // Executes the target service component |

**Block 3** — [SET] `(Extract response templates) (L1888)`

Extracts the CAANMsg template array from the SC response result map using the template list key constant.

| # | Type | Code |
|---|------|------|
| 1 | SET | `templates = (CAANMsg[])result.get(JCMConstants.TEMPLATE_LIST_KEY)` [-> JCMConstants.TEMPLATE_LIST_KEY] |

**Block 4** — [SET] `(Obtain reference to first response message) (L1890)`

Selects the first message template from the array as the primary response message.

| # | Type | Code |
|---|------|------|
| 1 | SET | `msg = templates[0]` // First CAANMsg template is the response |

**Block 5** — [SET] `(Retrieve return code) (L1893)`

Extracts the return code from the result map to determine whether the SC invocation succeeded.

| # | Type | Code |
|---|------|------|
| 1 | SET | `RETURN_CODE = result.get(JCMConstants.RET_CD_INT_KEY)` // Return code from SC [-> JCMConstants.RET_CD_INT_KEY] |

**Block 6** — [SET] `(Retrieve status from message) (L1895)`

Reads the integer status field from the response message.

| # | Type | Code |
|---|------|------|
| 1 | SET | `status = msg.getInt(JCMConstants.STATUS_INT_KEY)` // Status from response message [-> JCMConstants.STATUS_INT_KEY] |

**Block 7** — [CALL] `(Update error info in param) (L1897)`

Calls `editErrorInfoCom` to process and update error information in the parameter object using the response templates, return code, and data map key.

| # | Type | Code |
|---|------|------|
| 1 | CALL | `editErrorInfoCom(param, templates, (Integer)RETURN_CODE, dataMapKey)` // [-> editErrorInfoCom updates param with error info] |

**Block 8** — [CALL] `(Retrieve existing error list) (L1900)`

Retrieves the existing error info list from the control map of the parameter object.

| # | Type | Code |
|---|------|------|
| 1 | CALL | `errList = (ArrayList<Object>)param.getControlMapData(SCControlMapKeys.ERROR_INFO)` // Gets existing error list [-> SCControlMapKeys.ERROR_INFO] |

**Block 9** — [IF] `(null == errList)` `(L1902)`

Checks if an error list already exists. If the list is null (no prior errors), initializes a new empty list.

| # | Type | Code |
|---|------|------|
| 1 | SET | `errList = new ArrayList<Object>()` // Initialize empty list [if null] |

**Block 10** — [CALL] `(Update error list in control map) (L1905)`

Sets the aggregated error list back into the control map by merging existing errors with those extracted from the SC result.

| # | Type | Code |
|---|------|------|
| 1 | CALL | `param.setControlMapData(SCControlMapKeys.ERROR_INFO, TemplateErrorUtil.getErrorInfo(result, errList))` // [-> SCControlMapKeys.ERROR_INFO] [-> TemplateErrorUtil.getErrorInfo aggregates errors] |

**Block 11** — [IF] `("0".equals(RETURN_CODE) && status == 0)` `(L1908)` [CONSTANT: Return code "0" indicates success] `(L1908)`

Checks if the SC invocation was successful. Success requires both the return code to equal "0" and the status to be 0. If either condition fails, an `SCCallException` is thrown with the return value details.

| # | Type | Code |
|---|------|------|
| 1 | EXEC | `throw new SCCallException("戻値不正", RETURN_CODE.toString(), status)` // Throws if return code is not "0" or status is not 0 [-> "戻値不正" = "Returns values invalid"] |

**Block 12** — [RETURN] `(Return response message) (L1913)`

Returns the response CAANMsg on successful invocation.

| # | Type | Code |
|---|------|------|
| 1 | RETURN | `return msg` // Returns the CAANMsg response from SC |

## 7. Glossary

| Term | Type | Business Meaning |
|------|------|-----------------|
| SC | Acronym | Service Component — a reusable business logic component that performs domain operations. Invoked via `ServiceComponentRequestInvoker`. |
| CAANMsg | Class | Common Application Architecture ANdling Message — the standard response message object used across the application for carrying results, status, and error information. |
| SessionHandle | Class | Carries the user session context including authentication, tenant, and locale for service component invocations. |
| IRequestParameterReadWrite | Interface | The request/response parameter carrier that holds business data, control maps, and result maps for the SC call. |
| editInMsg | Method | Transforms raw mapping data (`Object[][]`) into a structured parameter map (`HashMap`) for SC invocation. |
| editErrorInfoCom | Method | Processes and updates error information in the parameter object based on SC response templates, return code, and data map key. |
| TemplateErrorUtil.getErrorInfo | Method | Extracts and aggregates error information from the SC result, merging with any existing error list. |
| SCCallException | Exception | Custom exception thrown when an SC invocation returns a non-zero return code or non-zero status, indicating failure. |
| JCMConstants.TEMPLATE_LIST_KEY | Constant | Key constant used to retrieve the `CAANMsg[]` templates array from the SC response result map. |
| JCMConstants.RET_CD_INT_KEY | Constant | Key constant used to retrieve the return code from the SC response result map. |
| JCMConstants.STATUS_INT_KEY | Constant | Key constant used to retrieve the integer status field from the response `CAANMsg`. |
| SCControlMapKeys.ERROR_INFO | Constant | Key constant used to store and retrieve the error info list in the parameter's control map. |
| "0" | Constant | Standard success return code — when the SC returns code "0", the invocation is considered successful. |
| status == 0 | Constant | Standard success status — when the message status is 0, the SC processed without operational issues. |
