---

# Business Logic — JKKOrsjgsUseStpRunCC.callSC() [74 LOC]

| Field | Value |
|-------|-------|
| Fully Qualified Name | `com.fujitsu.futurity.bp.custom.common.JKKOrsjgsUseStpRunCC` |
| Layer | CC/Common Component — shared service call utility within the business platform |
| Module | `common` (Package: `com.fujitsu.futurity.bp.custom.common`) |

## 1. Role

### JKKOrsjgsUseStpRunCC.callSC()

This method is the **central service component (SC) invocation gateway** for the order-service grouping step run process. Its sole purpose is to delegate a request to an arbitrary SC (Service Component) through the `ServiceComponentRequestInvoker`, then normalize, validate, and propagate the response back to the caller in a consistent format.

The method implements a **delegation + normalization pattern**: it accepts any SC by reference (`scCall`), forwards a prepared parameter map, and then processes the response through a multi-stage normalization pipeline. This pipeline covers: (1) extracting the result template (`CAANMsg`) containing the SC's business output, (2) interpreting the SC's return code and template status, (3) overriding status to 9000 if the SC itself returned a non-zero return code, (4) validating the status code against a message constant registry, (5) comparing the SC's template status against the caller's business-process (BP) status to decide which message to surface, (6) propagating error information extracted by `TemplateErrorUtil`, and (7) performing a final consistency check — throwing `SCCallException` if the SC's return code and status do not both indicate success.

Its **role in the larger system** is that of a shared utility called during the order-service grouping step (`orsjgsUseStpKanrencheck`) to execute any number of downstream service components (e.g., billing adjustments, service cancellations, configuration lookups) in a uniform manner. Every caller of this method receives a `CAANMsg` on success or an `SCCallException` on failure, and the `param` object is mutated in-place with control map data (return code, return message, error info) that subsequent steps can inspect.

## 2. Processing Pattern (Detailed Business Logic)

```mermaid
flowchart TD
    START(["callSC(params)"])
    A["editInMsg param, mappingData"]
    B["scCall.run paramMap, handle"]
    C["Extract templates from result"]
    D["Get msg = templates[0]"]
    E["Extract returnCode from result"]
    F["Get templateStatus from msg.getStatus()"]
    G{"returnCode != 0?"}
    H["Set templateStatus = 9000"]
    I["Check RETURN_MESSAGE constant"]
    J{"RETURN_MESSAGE exists?"}
    K["Set templateStatus = 0"]
    L["Get BP return code from controlMap"]
    M{"BP return code null?"}
    N["Set bpStatus = -1"]
    O["Parse bpStatus from String"]
    P{"templateStatus > bpStatus?"}
    Q["Set RETURN_CODE in controlMap"]
    R["Set RETURN_MESSAGE in controlMap"]
    S["setErrorInf msg, paramMap"]
    T["Get errList from controlMap"]
    U{"errList null?"}
    V["New errList"]
    W["Set ERROR_INFO in controlMap"]
    X["Check rtnCode and status"]
    Y{"rtnCode != 0 or status != 0?"}
    Z["Throw SCCallException"]
    AA["Return msg"]

    START --> A
    A --> B
    B --> C
    C --> D
    D --> E
    E --> F
    F -- Yes --> H
    F -- No --> I
    H --> I
    I --> J
    J -- No --> K
    J -- Yes --> L
    K --> L
    L --> M
    M -- Yes --> N
    M -- No --> O
    N --> L2["bpStatus ready"]
    O --> L2
    L2 --> P
    P -- Yes --> Q
    Q --> R
    R --> S
    P -- No --> S
    S --> T
    T -- Yes --> V
    T -- No --> W
    V --> W
    W --> X
    X --> Y
    Y -- Yes --> Z
    Y -- No --> AA
```

### Processing Steps

1. **Parameter Preparation** — The method calls `editInMsg(param, mappingData)` (see `editInMsg` [-> "editInMsg method"] (`JKKOrsjgsUseStpRunCC.java:~5620`)) to build a `HashMap<String, Object>` from the request parameters and mapping data. This prepares the payload to be sent to the SC.

2. **SC Invocation** — Calls `scCall.run(paramMap, handle)` which executes the configured Service Component (SC) with the prepared parameter map and session handle. Returns a `Map<?, ?>` containing templates, return code, status, and error info.

3. **Template Extraction** — Extracts the `CAANMsg[]` templates array from `result.get(TEMPLATE_LIST_KEY)` and selects the first element as the response message object.

4. **Return Code Extraction** — Extracts the integer return code from the result map (`RET_CD_INT_KEY`). If the SC returned a non-zero return code, the template status is forced to 9000 (error state) regardless of the SC's reported status.

5. **Status Code Validation** — Checks if the return message constant for the current template status exists in the message registry (`JCMAPLConstMgr.getString("RETURN_MESSAGE_" + formatStatus)`). If the constant does not exist, the template status is reset to 0 (success/neutral), preventing unknown status codes from propagating.

6. **BP Status Comparison** — Reads the business-process (BP) return code from the control map. Compares the SC's template status against the BP's current status. If the SC's status is numerically greater, it overrides the control map with the SC's status and its associated message — implementing a "worst status wins" policy.

7. **Error Information Propagation** — Calls `setErrorInf(msg, paramMap)` to copy error information from the response message into the parameter map. Then retrieves the error list from the control map (or creates a new one), and sets it back using `TemplateErrorUtil.getErrorInfo(result, errList)`.

8. **Final Consistency Check** — Verifies that both the SC's return code is "0" and its status is 0. If either condition fails, throws `SCCallException` with the message "戻値不正" (Invalid return value), carrying the return code and status for diagnostic purposes.

9. **Return** — Returns the `CAANMsg` template on success.

## 3. Parameter Analysis

| No | Parameter Name | Type | Business Description |
|----|---------------|------|---------------------|
| 1 | `handle` | `SessionHandle` | The session context for the SC invocation — contains user session, transaction context, and locale settings needed by the invoked service component to operate within the caller's session scope. |
| 2 | `scCall` | `ServiceComponentRequestInvoker` | The service component invocation bridge — a pre-configured invoker reference pointing to a specific SC (e.g., billing, cancellation, lookup). Determines which downstream service is executed. |
| 3 | `param` | `IRequestParameterReadWrite` | The shared request parameter container that carries input data into the SC and receives mutated control map data (return code, return message, error info) from the SC. This object is modified in-place throughout the method. |
| 4 | `dataMapKey` | `String` | The key used to access the data map within `param` (e.g., a business data area key). Used by `setErrorInf` to inject error information into the correct data area. Corresponds to a business-specific map identifier such as `"seikyYoksiHriwakeList"` or similar context keys. |
| 5 | `mappingData` | `Object[][]` | A 2D array of key-value mapping pairs that describe how request parameters should be transformed or prepared before being sent to the SC. The `editInMsg` method consumes this to build the parameter map. |

**External state / instance fields read:** None directly — the method is stateless with respect to instance fields. All state is carried via parameters and the result map.

## 4. CRUD Operations / Called Services

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

| CRUD | SC / CBS | SC Code | Entity / DB | Operation Description |
|------|----------|---------|-------------|----------------------|
| R | `scCall.run` | (determined by caller — passes any SC) | - | Invokes the designated Service Component through the invoker bridge. The actual SC Code and entity operations are deferred to the caller's configuration. |
| U | `editInMsg` | - | - | Mutates `param` to prepare the parameter map for SC invocation. Updates internal parameter state. |
| U | `setErrorInf` | - | - | Writes error information from the response `CAANMsg` into the parameter data map. Updates param state. |
| - | `TemplateErrorUtil.getErrorInfo` | - | - | Extracts structured error information from the SC result map, producing an `ArrayList<Object>` of error details. |
| U | `param.setControlMapData` | - | - | Updates control map entries: `RETURN_CODE`, `RETURN_MESSAGE`, `ERROR_INFO`. Mutates param's control context. |

**SC Code determination:** The SC Code is not embedded in this method itself — it is determined by the caller's configuration of the `scCall` (`ServiceComponentRequestInvoker`) object. The caller (`orsjgsUseStpKanrencheck`) passes a pre-configured invoker that points to a specific SC at runtime.

**Entity/DB tables:** Similarly, the specific database tables or entities accessed by the SC are determined by the SC's own implementation, not by `callSC`. This method is a SC invocation agnostic — it delegates and normalizes without knowing the underlying data layer.

## 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: `editInMsg` [U], `setErrorInf` [U], `run` [-], `getErrorInfo` [-], `setControlMapData` [U]

| # | Caller (Screen/Batch) | Call Chain (Full Path to this Method) | Terminal (SC / CRUD / Entity) |
|---|----------------------|--------------------------------------|-------------------------------|
| 1 | CBS: `JKKOrsjgsUseStpRunCC` | `orsjgsUseStpKanrencheck` -> `callSC` | `scCall.run [R] (determined by caller config)` |

**Call chain detail:** The method `orsjgsUseStpKanrencheck` (within the same class `JKKOrsjgsUseStpRunCC`) calls `callSC` to invoke the configured SC during the order-service grouping step processing. The `scCall` invoker is pre-configured by `orsjgsUseStpKanrencheck` to point to a specific SC, which determines the actual business operation performed.

**Downstream terminal operations from this method:**
- `editInMsg` [Update] — mutates parameter map
- `setErrorInf` [Update] — writes error info to param
- `scCall.run` [Read/Delegate] — invokes the SC (actual CRUD depends on SC configuration)
- `TemplateErrorUtil.getErrorInfo` [Read] — extracts error info from SC result
- `param.setControlMapData` [Update] — writes return code, message, error info back to param

## 6. Per-Branch Detail Blocks

**Block 1** — SET `(paramMap initialization)` (L5550)

Prepares the parameter map by delegating to `editInMsg`.

| # | Type | Code | Business Description |
|---|------|------|---------------------|
| 1 | SET | `paramMap = editInMsg(param, mappingData)` | Build HashMap from request parameters and mapping data. Transforms raw parameters into a structured map for SC consumption. |

**Block 2** — EXEC (`scCall.run invocation`) (L5552)

Invokes the target Service Component with the prepared parameter map.

| # | Type | Code | Business Description |
|---|------|------|---------------------|
| 1 | EXEC | `result = scCall.run(paramMap, handle)` | Execute the designated SC. Returns a Map containing templates, return code, status, and error info. |

**Block 3** — SET (`template extraction`) (L5554–L5555)

Extracts the response message from the SC result.

| # | Type | Code | Business Description |
|---|------|------|---------------------|
| 1 | SET | `templates = (CAANMsg[])result.get(JCMConstants.TEMPLATE_LIST_KEY)` | Extract the CAANMsg array from the SC result. The TEMPLATE_LIST_KEY constant (`"templateList"`) identifies the response templates. |
| 2 | SET | `msg = templates[0]` | Select the first template as the primary response message. |

**Block 4** — SET (`return code extraction`) (L5558)

Extracts and interprets the SC's return code.

| # | Type | Code | Business Description |
|---|------|------|---------------------|
| 1 | SET | `returnCode = (Integer)result.get(JCMConstants.RET_CD_INT_KEY)` | Extract the numeric return code. `RET_CD_INT_KEY` identifies the return code entry in the result map. |

**Block 5** — SET (`template status extraction`) (L5560)

| # | Type | Code | Business Description |
|---|------|------|---------------------|
| 1 | SET | `templateStatus = msg.getInt(ECK0011A010CBSMsg.STATUS)` | Extract the status code from the response message. `STATUS` constant identifies the status field in the CAANMsg. |

**Block 6** — IF (`returnCode override`) (L5562)

If the SC returned a non-zero return code, force the template status to 9000 (error state). This implements a fail-fast pattern where any non-zero SC return code overrides the SC's own status reporting.

| # | Type | Code | Business Description |
|---|------|------|---------------------|
| 1 | SET | `templateStatus = 9000` | Force status to 9000 when SC return code is non-zero. Indicates a service-level error. |

**Block 7** — IF (`status code validation`) (L5565)

Validates the template status against the message constant registry.

| # | Type | Code | Business Description |
|---|------|------|---------------------|
| 1 | EXEC | `JCMAPLConstMgr.getString("RETURN_MESSAGE_" + formatStatus)` | Check if a return message constant exists for this status code. The status is zero-padded to 4 digits (e.g., `"0000"`). |
| 2 | SET | `templateStatus = 0` | Reset status to 0 if no message constant exists — prevents unknown statuses from propagating. |

**Block 8** — IF/ELSE (`BP status extraction`) (L5567–L5575)

Extracts the business-process return code from the control map.

| # | Type | Code | Business Description |
|---|------|------|---------------------|
| 1 | SET | `obj = param.getControlMapData(SCControlMapKeys.RETURN_CODE)` | Read the BP's current return code from the control map. |
| 2 | SET | `bpStatus = -1` | If BP return code is null, set bpStatus to -1 (lower than any valid status). [-> SCControlMapKeys.RETURN_CODE] |
| 3 | SET | `bpStatus = Integer.parseInt((String)param.getControlMapData(SCControlMapKeys.RETURN_CODE))` | Parse the BP return code as an integer. [-> SCControlMapKeys.RETURN_CODE] |

**Block 9** — IF (`status comparison and override`) (L5577)

If the SC's template status is numerically greater than the BP's status, override the control map with the SC's status and message. This implements a "worst status wins" policy — the more severe status (higher number) takes precedence.

| # | Type | Code | Business Description |
|---|------|------|---------------------|
| 1 | SET | `formatStatus = String.format("%1$04d", templateStatus)` | Format status as zero-padded 4-digit string (e.g., `9000`). |
| 2 | SET | `message = JCMAPLConstMgr.getString("RETURN_MESSAGE_" + formatStatus)` | Retrieve the human-readable message for this status code. |
| 3 | EXEC | `param.setControlMapData(SCControlMapKeys.RETURN_CODE, formatStatus)` | Write the SC's status code back to the control map for BP consumption. [-> SCControlMapKeys.RETURN_CODE] |
| 4 | EXEC | `param.setControlMapData(SCControlMapKeys.RETURN_MESSAGE, message)` | Write the status message back to the control map. [-> SCControlMapKeys.RETURN_MESSAGE] |

**Block 10** — EXEC (`setErrorInf`) (L5582)

| # | Type | Code | Business Description |
|---|------|------|---------------------|
| 1 | CALL | `setErrorInf(msg, paramMap)` | Copy error information from the response message into the parameter data map for the caller to inspect. |

**Block 11** — IF/ELSE (`error list preparation`) (L5585–L5590)

Retrieves the existing error list or creates a new one.

| # | Type | Code | Business Description |
|---|------|------|---------------------|
| 1 | SET | `errList = (ArrayList<Object>)param.getControlMapData(SCControlMapKeys.ERROR_INFO)` | Read existing error list from control map. [-> SCControlMapKeys.ERROR_INFO] |
| 2 | SET | `errList = new ArrayList<Object>()` | Create a new error list if none existed. |

**Block 12** — EXEC (`error info update`) (L5593)

| # | Type | Code | Business Description |
|---|------|------|---------------------|
| 1 | EXEC | `param.setControlMapData(SCControlMapKeys.ERROR_INFO, TemplateErrorUtil.getErrorInfo(result, errList))` | Update the control map's error info with structured error data extracted from the SC result by `TemplateErrorUtil`. [-> SCControlMapKeys.ERROR_INFO] |

**Block 13** — IF (`final consistency check`) (L5597–L5603)

Performs a final validation: if the SC's return code is non-zero OR its status is non-zero, throws `SCCallException`. This is the method's failure propagation mechanism.

| # | Type | Code | Business Description |
|---|------|------|---------------------|
| 1 | SET | `rtnCode = result.get(JCMConstants.RET_CD_INT_KEY).toString()` | Extract return code as string for comparison. [-> JCMConstants.RET_CD_INT_KEY] |
| 2 | SET | `status = msg.getInt(JCMConstants.STATUS_INT_KEY)` | Extract status as Integer from response message. [-> JCMConstants.STATUS_INT_KEY] |
| 3 | THROW | `throw new SCCallException("戻値不正", rtnCode, status)` | Throw exception with "Invalid return value" message (Japanese: "戻値不正"), carrying the return code and status for diagnostics. |

**Block 14** — RETURN (L5605)

| # | Type | Code | Business Description |
|---|------|------|---------------------|
| 1 | RETURN | `return msg` | Return the response CAANMsg template. On reaching this point, the SC completed successfully (returnCode=0, status=0). |

## 7. Glossary

| Term | Type | Business Meaning |
|------|------|------------------|
| SC | Acronym | Service Component — a modular business service in the Fujitsu Futurity platform that performs specific business operations (e.g., billing adjustment, service cancellation, configuration lookup). |
| SC Call | Business term | The act of invoking a Service Component through the `ServiceComponentRequestInvoker` bridge. |
| CAANMsg | Technical | C-AAN Message — the standard message format used by SCs to return business data and status to callers. Contains structured fields including status code, template data, and error information. |
| TEMPLATE_LIST_KEY | Constant | The map key (`"templateList"`) used to extract response templates from SC result maps. Defined in `JCMConstants`. |
| RET_CD_INT_KEY | Constant | The map key for extracting the integer return code from SC result maps. Defined in `JCMConstants`. |
| STATUS_INT_KEY | Constant | The map key for extracting the integer status code from CAANMsg objects. Defined in `JCMConstants`. |
| STATUS | Constant | The field name within `CAANMsg` that holds the template's business status code. Referenced via `ECK0011A010CBSMsg.STATUS`. |
| RETURN_MESSAGE_XXX | Constant | A message registry key format used by `JCMAPLConstMgr` to look up human-readable status messages (e.g., `RETURN_MESSAGE_0000`, `RETURN_MESSAGE_9000`). |
| RETURN_CODE | Constant | Control map key (`SCControlMapKeys.RETURN_CODE`) for storing the BP-level return code. |
| RETURN_MESSAGE | Constant | Control map key (`SCControlMapKeys.RETURN_MESSAGE`) for storing the BP-level return message text. |
| ERROR_INFO | Constant | Control map key (`SCControlMapKeys.ERROR_INFO`) for storing the structured error list (`ArrayList<Object>`). |
| BP | Acronym | Business Process — the calling workflow (often a screen or CBS) that invokes SCs and manages the overall business flow. |
| BP Status | Business term | The current status level tracked by the Business Process. Used for comparison with SC status to determine which message to surface. |
| templateStatus | Field | The status code extracted from the SC's response message. Represents the SC's own assessment of success/failure. |
| bpStatus | Field | The status code currently tracked by the Business Process. Extracted from the control map. |
| 戻値不正 | Japanese term | "Invalid return value" — the error message thrown when the SC's return code or status indicates an abnormal condition that was not handled by the status override logic. |
| editInMsg | Method | Internal method that prepares the parameter map for SC invocation by combining request parameters with mapping data. |
| setErrorInf | Method | Internal method that copies error information from the response message into the parameter data map. |
| TemplateErrorUtil | Class | Utility class that extracts structured error information from SC result maps. |
| SessionHandle | Technical | Session context object containing user session, transaction, and locale information required for SC execution. |
| ServiceComponentRequestInvoker | Technical | The invocation bridge that forwards requests to configured Service Components. Each instance targets a specific SC. |
| SCCallException | Technical | Custom exception thrown when the SC returns abnormal results (non-zero return code or non-zero status). |

---
