# Business Logic — KKW05501SF03DBean.addListDataInstance() [43 LOC]

| Field | Value |
|-------|-------|
| Fully Qualified Name | `eo.web.webview.KKW05501SF.KKW05501SF03DBean` |
| Layer | Data Bean / View Component (X33 Web Framework) |
| Module | `KKW05501SF` (Package: `eo.web.webview.KKW05501SF`) |

## 1. Role

### KKW05501SF03DBean.addListDataInstance()

This method is a list-data factory used within the Fujitsu X33 Web Framework's data binding layer for the KKW05501SF screen, which handles telecom service contract line-item management (service detail work management). Its purpose is to instantiate typed data bean objects for specific repeating (list) form fields and append them to the corresponding `X33VDataTypeList` held on the bean, enabling the UI framework to render dynamic multi-row input sections. Specifically, it supports three repeating fields on the service contract detail screen: **Movement Reason Code** (the reason code associated with moving/changing a service record), **Option Service Contract Number** (the contract number of an optional/add-on service bundled with the primary service), and **Simultaneous Application Service Contract Number** (the contract number of a related service applied for concurrently at the same time as the primary service). The method uses a routing/dispatch design pattern: the incoming `key` string — which corresponds to a Japanese-labeled field name — determines which of the three internal list fields receives the new element. Each branch lazily initializes its target list (creating a new `X33VDataTypeList` if the field is `null`), instantiates a typed `X33VDataTypeStringBean` as the row element, appends it, and returns the zero-based index of the newly added row. If the key is `null` or unrecognized, the method returns `-1`. This is a shared utility called by the screen's data bean hierarchy, where the parent `KKW05501SFBean` and subclass `KKW05501SF01DBean` delegate unrecognized keys via `super.addListDataInstance(key)` to maintain the inheritance chain.

## 2. Processing Pattern (Detailed Business Logic)

```mermaid
flowchart TD
    START(["addListDataInstance(key)"])

    START --> CheckNull{"key == null?"}

    CheckNull -->|"Yes"| R1(["return -1"])
    CheckNull -->|"No"| Check1{"key equals
'Movement Reason Code'?"}

    Check1 -->|"Yes"| B1_Init{"hktgi_ido_rsn_cd_list
== null?"}
    Check1 -->|"No"| Check2{"key equals
'Option Service Contract Number'?"}

    B1_Init -->|"Yes"| B1_Create["hktgi_ido_rsn_cd_list = new X33VDataTypeList()"]
    B1_Init -->|"No"| B1_Bean["new X33VDataTypeStringBean()"]

    B1_Create --> B1_Bean
    B1_Bean --> B1_Add["hktgi_ido_rsn_cd_list.add(tmpBean)"]
    B1_Add --> R2(["return hktgi_ido_rsn_cd_list.size() - 1"])

    Check2 -->|"Yes"| B2_Init{"hktgi_op_svc_kei_no_list
== null?"}
    Check2 -->|"No"| Check3{"key equals
'Simultaneous App. Contract Number'?"}

    B2_Init -->|"Yes"| B2_Create["hktgi_op_svc_kei_no_list = new X33VDataTypeList()"]
    B2_Init -->|"No"| B2_Bean["new X33VDataTypeStringBean()"]

    B2_Create --> B2_Bean
    B2_Bean --> B2_Add["hktgi_op_svc_kei_no_list.add(tmpBean)"]
    B2_Add --> R3(["return hktgi_op_svc_kei_no_list.size() - 1"])

    Check3 -->|"Yes"| B3_Init{"hktgi_mskm_svc_kei_no_list
== null?"}
    Check3 -->|"No"| END1(["return -1"])

    B3_Init -->|"Yes"| B3_Create["hktgi_mskm_svc_kei_no_list = new X33VDataTypeList()"]
    B3_Init -->|"No"| B3_Bean["new X33VDataTypeStringBean()"]

    B3_Create --> B3_Bean
    B3_Bean --> B3_Add["hktgi_mskm_svc_kei_no_list.add(tmpBean)"]
    B3_Add --> R4(["return hktgi_mskm_svc_kei_no_list.size() - 1"])
```

**Processing summary:**
The method follows a cascading if/else chain (three branches, each handling one repeating field). Each branch performs the same three-step pattern: (1) lazily initialize the target `X33VDataTypeList` if it is `null`, (2) create a new `X33VDataTypeStringBean` as the row data element, (3) add the bean to the list and return the zero-based index. The field name keys are Japanese string literals, not external constants — they are hardcoded directly in the `equals()` comparisons.

## 3. Parameter Analysis

| No | Parameter Name | Type | Business Description |
|----|---------------|------|---------------------|
| 1 | `key` | `String` | The Japanese-labeled field name that identifies which repeating list field should receive a new row instance. Valid values are: `"移動理由コード"` (Movement Reason Code), `"オプションサービス契約番号"` (Option Service Contract Number), or `"同時申込サービス契約番号"` (Simultaneous Application Service Contract Number). The method branches on exact string match to determine which internal list is appended. |
| — | `hktgi_ido_rsn_cd_list` | `X33VDataTypeList` | Instance field — List of movement reason codes for the service detail work (initialized to `null` by default, lazily created as new `X33VDataTypeList()` on first add). |
| — | `hktgi_op_svc_kei_no_list` | `X33VDataTypeList` | Instance field — List of option service contract numbers for bundled add-on services (initialized to `null` by default, lazily created on first add). |
| — | `hktgi_mskm_svc_kei_no_list` | `X33VDataTypeList` | Instance field — List of simultaneous application service contract numbers for services applied concurrently with the primary service (initialized to `null` by default, lazily created on first add). |

## 4. CRUD Operations / Called Services

This method performs **in-memory data bean creation only** — it does not invoke any SC (Service Component) or CBS (Common Business Service) methods, nor does it interact with any database tables. All operations are local to the bean's data structures.

| CRUD | SC / CBS | SC Code | Entity / DB | Operation Description |
|------|----------|---------|-------------|----------------------|
| — | `new X33VDataTypeList()` | — | — | In-memory list instantiation (lazy initialization of the target list field). |
| — | `new X33VDataTypeStringBean()` | — | — | In-memory typed string data bean instantiation (each represents one row in the repeating list). |
| — | `X33VDataTypeList.add(X33VDataTypeBeanInterface)` | — | — | In-memory list append operation (adds the newly created bean to the target list). |

## 5. Dependency Trace

This method is defined directly on `KKW05501SF03DBean`. The `KKW05501SFBean` (parent data bean) overrides `addListDataInstance()` to handle additional fields (such as `法人格前後` / Legal Entity Status, `法人格` / Legal Entity, `強制窓` / Forced Window) and delegates to `super.addListDataInstance(key)` for keys it does not recognize. The `KKW05501SF03DBean` version further specializes for its three internal repeating fields. `KKW05501SF01DBean` also has its own `addListDataInstance()` implementation with different fields (e.g., `初期設定コード` / Initial Setting Code).

No external callers directly invoke `KKW05501SF03DBean.addListDataInstance()` with a method-call reference in the codebase. Instead, the method is invoked **indirectly through the X33 Web Framework's data binding mechanism** (the framework dispatches form field keys to the bean's `addListDataInstance()` at runtime). The class `KKW05501SF03DBean` is instantiated as a sub-bean within `KKW05501SFBean` (see `KKW05501SFBean` lines ~633, ~9576) for the `hktgi_cust_kei_hktgi_list` (Customer Contract Inheritance List) repeating section.

| # | Caller (Screen/Batch) | Call Chain (Full Path to this Method) | Terminal (SC / CRUD / Entity) |
|---|----------------------|--------------------------------------|-------------------------------|
| 1 | Data Binding Layer | `X33 Framework (runtime dispatch)` -> `KKW05501SFBean.addListDataInstance()` -> `super.addListDataInstance(key)` -> `KKW05501SF03DBean.addListDataInstance(key)` | In-memory list add only |
| 2 | Data Binding Layer | `X33 Framework (runtime dispatch)` -> `KKW05501SF03DBean.addListDataInstance(key)` | In-memory list add only |

## 6. Per-Branch Detail Blocks

**Block 1** — [IF] `(key == null)` (L1335)

> Guard clause: if the caller passes a `null` key, return early with -1.

| # | Type | Code |
|---|------|------|
| 1 | RETURN | `return -1;` // null case: no matching field, return -1 |

**Block 2** — [ELSE-IF] `(key.equals("移動理由コード"))` [移動理由コード="Movement Reason Code"] (L1340)

> Handles the repeating field for movement/change reason codes on the service detail work screen.

| # | Type | Code |
|---|------|------|
| 1 | CHECK | `hktgi_ido_rsn_cd_list == null` // Check if the list has been initialized |
| 2.1 | [IF: list is null] | `hktgi_ido_rsn_cd_list = new X33VDataTypeList();` // Lazily create a new empty list (L1342) |
| 2.2 | EXEC | `new X33VDataTypeStringBean()` // Create a typed string bean instance (L1344) |
| 2.3 | CALL | `hktgi_ido_rsn_cd_list.add(tmpBean);` // Add the bean to the list (L1346) |
| 2.4 | RETURN | `return hktgi_ido_rsn_cd_list.size() - 1;` // Return zero-based index of the added element |

**Block 3** — [ELSE-IF] `(key.equals("オプションサービス契約番号"))` [オプションサービス契約番号="Option Service Contract Number"] (L1351)

> Handles the repeating field for option/add-on service contract numbers bundled with the primary service.

| # | Type | Code |
|---|------|------|
| 1 | CHECK | `hktgi_op_svc_kei_no_list == null` // Check if the list has been initialized |
| 2.1 | [IF: list is null] | `hktgi_op_svc_kei_no_list = new X33VDataTypeList();` // Lazily create a new empty list (L1353) |
| 2.2 | EXEC | `new X33VDataTypeStringBean()` // Create a typed string bean instance (L1355) |
| 2.3 | CALL | `hktgi_op_svc_kei_no_list.add(tmpBean);` // Add the bean to the list (L1357) |
| 2.4 | RETURN | `return hktgi_op_svc_kei_no_list.size() - 1;` // Return zero-based index of the added element |

**Block 4** — [ELSE-IF] `(key.equals("同時申込サービス契約番号"))` [同時申込サービス契約番号="Simultaneous Application Service Contract Number"] (L1362)

> Handles the repeating field for services applied concurrently with the primary service at the same time.

| # | Type | Code |
|---|------|------|
| 1 | CHECK | `hktgi_mskm_svc_kei_no_list == null` // Check if the list has been initialized |
| 2.1 | [IF: list is null] | `hktgi_mskm_svc_kei_no_list = new X33VDataTypeList();` // Lazily create a new empty list (L1364) |
| 2.2 | EXEC | `new X33VDataTypeStringBean()` // Create a typed string bean instance (L1366) |
| 2.3 | CALL | `hktgi_mskm_svc_kei_no_list.add(tmpBean);` // Add the bean to the list (L1368) |
| 2.4 | RETURN | `return hktgi_mskm_svc_kei_no_list.size() - 1;` // Return zero-based index of the added element |

**Block 5** — [ELSE] `(unrecognized key)` (L1370)

> Fallback: no branch matched — the key does not correspond to any supported field.

| # | Type | Code |
|---|------|------|
| 1 | RETURN | `return -1;` // No matching field found, return -1 |

## 7. Glossary

| Term | Type | Business Meaning |
|------|------|------------------|
| `hktgi_ido_rsn_cd` | Field | Movement reason code — the reason code for why a service record was moved, changed, or transferred within the system |
| `hktgi_ido_rsn_cd_list` | Field | List of movement reason code beans — repeating list data for the movement/change reason field |
| `hktgi_op_svc_kei_no` | Field | Option service contract number — the contract number of an optional/add-on service bundled with the primary service contract |
| `hktgi_op_svc_kei_no_list` | Field | List of option service contract number beans — repeating list data for option service contract numbers |
| `hktgi_mskm_svc_kei_no` | Field | Simultaneous application service contract number — the contract number of a related service applied concurrently (at the same time) as the primary service |
| `hktgi_mskm_svc_kei_no_list` | Field | List of simultaneous application service contract number beans — repeating list data for concurrent service contract numbers |
| `hktgi` | Abbreviation | Hikaritai Gou (ひかりTV合) — relates to NTT Hikari TV bundled service offerings (part of the field naming convention) |
| `X33VDataTypeList` | Class | Fujitsu X33 framework class for typed, indexable lists of data bean elements |
| `X33VDataTypeStringBean` | Class | Fujitsu X33 framework class representing a single string-typed data element within a list |
| `X33VListedBeanInterface` | Interface | X33 framework interface marking a bean as supporting list-type fields |
| `KKW05501SF` | Module | Service detail work management screen module — handles creation and management of service contract line items |
| 移動理由コード | Japanese field | Movement reason code — the reason for moving/transferring a service record |
| オプションサービス契約番号 | Japanese field | Option service contract number — contract number for an optional/add-on bundled service |
| 同時申込サービス契約番号 | Japanese field | Simultaneous application service contract number — contract number for a service applied concurrently with the primary service |
| `KKW05501SFBean` | Class | Parent data bean for the KKW05501SF screen — handles additional repeating fields (legal entity status, legal entity, forced window) and delegates unrecognized keys to subclasses |
| `KKW05501SF01DBean` | Class | Subclass data bean for the KKW05501SF screen — handles additional repeating fields (initial setting code, code type code value list, etc.) |
