# Business Logic — KKW05601SFLogic.setTokiInfoFromDB() [194 LOC]

| Field | Value |
|-------|-------|
| Fully Qualified Name | `eo.web.webview.KKW05601SF.KKW05601SFLogic` |
| Layer | Controller / Web Logic (Controller logic layer) |
| Module | `KKW05601SF` (Package: `eo.web.webview.KKW05601SF`) |

## 1. Role

### KKW05601SFLogic.setTokiInfoFromDB()

This method retrieves porting (number portability / 番号ポート) registration information from the service work phone data bean (`svcUtwkEoTelBean`) and populates the service form bean (`bean`) with all displayed fields for the porting registration confirmation screen (KKW05603). It serves as the data-loading bridge between the pre-fetched service work data and the web form, supporting both port-forward (移転先登録 / destination-side porting) and port-out (移転元解約 / source-side cancellation) scenarios. The method implements a conditional routing pattern: when no porting is registered (`TOKI_NASHI = "0"`), it initializes the port content field to an empty string and returns early to avoid JSP display errors. When porting data exists, it resolves whether the data comes from the port-forward side (`TOKI_ADD_OPAF = "2"`) or the port-out side using different key suffixes, then fetches the appropriate set of porting detail fields (request flag, type code, registration code, start/end dates, target phone, target service contract number). Finally, it computes the original phone number via `getItenMTelNo`, derives the contact phone number via `getRRSKTelNo`, translates the porting type code into a human-readable description via `getTokiNaiyo`, and delegates to `actionTokiAddCfmInit` to perform confirmation-screen display initialization — including code-to-label resolution for all pull-down fields and date formatting. The method also sets the porting start and end date display fields that `actionTokiAddCfmInit` cannot handle on its own.

## 2. Processing Pattern (Detailed Business Logic)

```mermaid
flowchart TD
    START(["setTokiInfoFromDB bean custKeiHktgiBean svcUtwkEoTelBean mode"])
    GET_TEL["Get target phone from svcUtwkEoTelBean TELNO_05"]
    SET_TEL["Set target phone to bean TOKI_TG_TELNO"]
    GET_COND["CALL getTokiAddCondtion bean"]
    COND_NASHI{tokiAddCond = TOKI_NASHI 0}
    INIT_NAIYO["Set TOKI_NAIYO to empty string"]
    EARLY_RETURN["Return early no porting registered"]
    DECL_VARS["Declare local variables"]
    COND_OPAF{tokiAddCond = TOKI_ADD_OPAF 2}
    BRANCH_OPAF["OPAF branch get from svcUtwkEoTelBean OPAF keys"]
    BRANCH_DEFAULT["Default branch get from svcUtwkEoTelBean"]
    SET_KIBO["Get itenKibo tokiSbtCd tokiAddCd dates tokiTensoSkSvkuwno"]
    SET_KIBO2["Get itenKibo tokiSbtCd tokiAddCd dates tokiTensoSk fields"]
    GET_ALL["Get porting detail fields from svcUtwkEoTelBean"]
    SET_ITENM_TEL["CALL getItenMTelNo set to bean ITENM_TELNO"]
    SET_RRSK_TEL["CALL getRRSKTelNo set to bean RRKS_TELNO"]
    SET_TOKI_NAIYO["CALL getTokiNaiyo add to bean TOKI_NAIYO"]
    CALL_ACTION["CALL actionTokiAddCfmInit"]
    SET_STA_DISP["setBeanRsvYmd TOKI_STA_RSV_DSP"]
    SET_END_DISP["setBeanRsvYmd TOKI_END_RSV_DSP"]
    END_NODE(["Return to caller"])
    START --> GET_TEL --> SET_TEL --> GET_COND --> COND_NASHI
    COND_NASHI -- "true" --> INIT_NAIYO --> EARLY_RETURN
    COND_NASHI -- "false" --> DECL_VARS --> COND_OPAF
    COND_OPAF -- "true" --> BRANCH_OPAF --> SET_KIBO
    COND_OPAF -- "false" --> BRANCH_DEFAULT --> SET_KIBO2
    SET_KIBO --> GET_ALL
    SET_KIBO2 --> GET_ALL
    GET_ALL --> SET_ITENM_TEL
    SET_ITENM_TEL --> SET_RRSK_TEL
    SET_RRSK_TEL --> SET_TOKI_NAIYO
    SET_TOKI_NAIYO --> CALL_ACTION
    CALL_ACTION --> SET_STA_DISP --> SET_END_DISP --> END_NODE
```

**Constant Resolution in Branches:**

| Condition | Constant Name | Resolved Value | Business Meaning |
|-----------|--------------|----------------|------------------|
| `TOKI_NASHI` | `TOKI_NASHI` | `"0"` | No porting registered — early exit |
| `TOKI_ADD_OPAF` | `TOKI_ADD_OPAF` | `"2"` | Port-forward registration (destination-side) — triggers OPAF key suffix data fetch |

## 3. Parameter Analysis

| No | Parameter Name | Type | Business Description |
|----|---------------|------|---------------------|
| 1 | `bean` | `X31SDataBeanAccess` | Service form bean — the primary data carrier for the porting registration confirmation screen. Used to set target phone, original phone, contact phone, porting content, start date, and end date display values. Also serves as input to helper methods (`getTokiAddCondtion`, `getRRSKTelNo`, `getTokiNaiyo`). |
| 2 | `custKeiHktgiBean` | `X31SDataBeanAccess` | Customer contract line-item bean — carries reservation phone number (`RSV_TELNO_S_11`) and other customer-level contract data. Currently unused in the active code path (commented out), retained for future use. |
| 3 | `svcUtwkEoTelBean` | `X31SDataBeanAccess` | Service work phone data bean — source of all porting registration data fetched from the database. Contains fields with suffix `_05` (e.g., `ITENS_OPAF_TOKI_KIBO_UM_05`, `ITNTOKI_SBT_CD_05`) for the target line's porting details. Different key sets are used based on whether port-forward or port-out data is active. |
| 4 | `mode` | `int` | Processing mode flag. Currently unused in the active code path (all mode == 2 code is commented out from the OT-2013-0000311 phone number change feature). Reserved for future onchange porting registration switch scenarios. |

**External State Read:**
- Instance fields: `TOKI_NASHI`, `TOKI_ADD_OPAF`, `ITENSAKI_ADD_TOKI` (private static final String constants defined in `KKW05601SFLogic`)
- Base class: `JCCWebBusinessLogic` — provides `DEBUG_LOG`, `invokeServiceKKSV0171`, `setNextScreen`

## 4. CRUD Operations / Called Services

| CRUD | SC / CBS | SC Code | Entity / DB | Operation Description |
|------|----------|---------|-------------|----------------------|
| R | `KKW05601SFLogic.getTokiAddCondtion` | KKW05601SFLogic | - | Reads porting registration status (DSL, port-forward, or both) from EKK0191A010DETAILLIST data bean array |
| R | `KKW05601SFLogic.getItenMTelNo` | KKW05601SFLogic | - | Computes the port-out original phone number by resolving against target and port-forward target phones based on porting registration code |
| R | `KKW05601SFLogic.getRRSKTelNo` | KKW05601SFLogic | - | Derives the contact phone number — for port-forward registration, looks up the phone number matching the target service contract internal number from EKK0191B003DETAILLIST |
| R | `KKW05601SFLogic.getTokiNaiyo` | KKW05601SFLogic | - | Translates the porting type code (`tokiSbtCd`) into a human-readable description of the porting content |
| - | `KKW05601SFLogic.actionTokiAddCfmInit` | KKW05601SFLogic | - | Initializes the confirmation screen display — resolves pull-down display values, formats start/end dates, sets update message |
| - | `KKW05601SFLogic.setBeanRsvYmd` | KKW05601SFLogic | - | Sets a single date display field by splitting a YMD string into year, month, day components |
| - | `KKW05601SFLogic.getTokiAddCondtion` (internal) | KKW05601SFLogic | EKK0191A010 | Queries service contract info (eo optical phone) for porting registration status |

## 5. Dependency Trace

| # | Caller (Screen/Batch) | Call Chain (Full Path to this Method) | Terminal (SC / CRUD / Entity) |
|---|----------------------|--------------------------------------|-------------------------------|
| 1 | `KKW05601SFLogic.actionTokiCfmInit` | `actionTokiCfmInit` -> `setTokiInfoFromDB(bean, custKeiHktgiBean, svcUtwkEoTelBean, mode)` | `actionTokiAddCfmInit [-]`, `setBeanRsvYmd [-]` (x2), `getItenMTelNo [R]`, `getRRSKTelNo [R]`, `getTokiNaiyo [R]` |

**Notes:** The method is called by `actionTokiCfmInit`, which is itself invoked from the screen initialization flow of `KKW05601SF` (KKSV0170/KKSV0171 service calls for porting registration). The terminal operations are all internal to `KKW05601SFLogic` — this method does not directly call any external SC/CBS components or database layers.

## 6. Per-Branch Detail Blocks

**Block 1** — SET (L2729)

Retrieve the target phone number (ported number / 移転先電話番号) from the service work phone bean.

| # | Type | Code |
|---|------|------|
| 1 | GET | `telNo = svcUtwkEoTelBean.sendMessageString(KKW05601SFConst.TELNO_05, X31CWebConst.DATABEAN_GET_VALUE)` |
| 2 | SET | `bean.sendMessageString(KKW05601SFConst.TOKI_TG_TELNO, X31CWebConst.DATABEAN_SET_VALUE, telNo)` // Set target phone to confirmation screen |

**Block 2** — CALL (L2739)

Fetch the porting registration status to determine if any porting is registered.

| # | Type | Code |
|---|------|------|
| 1 | CALL | `tokiAddCond = getTokiAddCondtion(bean)` // Returns "0" (none), "1" (DSL only), "2" (OPAF only), or "3" (both) |

**Block 3** — IF [`TOKI_NASHI = "0"`] (L2744)

Early exit when no porting is registered. The JSP page would throw an error if `TOKI_NAIYO` (port content) is not initialized, so set it to empty string.

| # | Type | Code |
|---|------|------|
| 1 | SET | `tokiNaiyoInit = ""` // Initialize port content to avoid JSP error |
| 2 | SET | `bean.sendMessageString(KKW05601SFConst.TOKI_NAIYO, X31CWebConst.DATABEAN_ADD_VALUE, tokiNaiyoInit)` |
| 3 | EXEC | `DEBUG_LOG.debug("###setTokiInfoFromDB: when port end date is set, it is already cancelled so do not display.")` |
| 4 | RETURN | `return` // Early exit — no porting data to display |

**Block 4** — SET (L2752–L2760)

Declare local variables that will hold the porting detail fields. Two categories exist: general porting data (`itenKibo`, `tokiSbtCd`, `tokiAddCd`, `itenTokiStaRsvYmd`, `itenTokiEndRsvYmd`, `tokiTensoSkTelno`, `tokiTensoSkSvkuwno`) and port-forward discriminator fields (`tokiAddCdMt`, `tokiAddCdSk`).

| # | Type | Code |
|---|------|------|
| 1 | SET | `itenKibo = ""` // Porting request flag |
| 2 | SET | `tokiSbtCd = ""` // Porting type code |
| 3 | SET | `tokiAddCd = ""` // Porting registration code |
| 4 | SET | `itenTokiStaRsvYmd = ""` // Porting manual start reserved date |
| 5 | SET | `itenTokiEndRsvYmd = ""` // Porting end reserved date |
| 6 | SET | `tokiTensoSkTelno = ""` // Port-forward target phone number |
| 7 | SET | `tokiTensoSkSvkuwno = ""` // Port-forward target service contract internal number |
| 8 | SET | `tokiAddCdMt = ""` // Porting registration code (port-out source side) |
| 9 | SET | `tokiAddCdSk = ""` // Porting registration code (port-forward destination side) |

**Block 5** — IF [`TOKI_ADD_OPAF = "2"`] (L2762)

Branch on porting registration status. When `tokiAddCond` equals `"2"` (port-forward / 移転先登録), fetch data using `_OPAF_` suffix keys. Otherwise (port-out, port-out + port-forward, or suspension), use non-OPAF keys. When both are set, prefer port-out source side per `setTokiHdn()` logic.

| # | Type | Code |
|---|------|------|
| 1 | IF | `[TOKI_ADD_OPAF = "2"]` // Port-forward registration |
| 2 | SET | `itenKibo = svcUtwkEoTelBean.sendMessageString(KKW05601SFConst.ITENS_OPAF_TOKI_KIBO_UM_05, X31CWebConst.DATABEAN_GET_VALUE)` // Port-forward porting request flag |
| 3 | SET | `tokiSbtCd = svcUtwkEoTelBean.sendMessageString(KKW05601SFConst.ITENS_OPAF_TOKI_SBT_CD_05, X31CWebConst.DATABEAN_GET_VALUE)` // Port-forward porting type code |
| 4 | SET | `tokiAddCd = svcUtwkEoTelBean.sendMessageString(KKW05601SFConst.ITENS_OPAF_TOKI_ADD_CD_05, X31CWebConst.DATABEAN_GET_VALUE)` // Port-forward registration code |
| 5 | SET | `itenTokiStaRsvYmd = svcUtwkEoTelBean.sendMessageString(KKW05601SFConst.ITENS_OPAF_TOKI_STA_RSYMD_05, X31CWebConst.DATABEAN_GET_VALUE)` // Port-forward manual start date |
| 6 | SET | `itenTokiEndRsvYmd = svcUtwkEoTelBean.sendMessageString(KKW05601SFConst.ITENS_OPAF_TOKI_END_RSYMD_05, X31CWebConst.DATABEAN_GET_VALUE)` // Port-forward end date |
| 7 | SET | `tokiTensoSkTelno = ""` // Clear port-forward target phone (not applicable for OPAF branch) |
| 8 | SET | `tokiTensoSkSvkuwno = svcUtwkEoTelBean.sendMessageString(KKW05601SFConst.ITNS_OPAF_TOKI_TSS_SVKUWNO_05, X31CWebConst.DATABEAN_GET_VALUE)` // Port-forward target service contract number |
| 9 | SET | `tokiAddCdSk = svcUtwkEoTelBean.sendMessageString(KKW05601SFConst.ITENS_OPAF_TOKI_ADD_CD_05, X31CWebConst.DATABEAN_GET_VALUE)` // Port-forward registration code (destination discriminator) |

**Block 5.1** — ELSE [Non-OPAF: port-out or both] (L2772)

| # | Type | Code |
|---|------|------|
| 1 | SET | `itenKibo = svcUtwkEoTelBean.sendMessageString(KKW05601SFConst.ITNTOKI_KIBO_UM_05, X31CWebConst.DATABEAN_GET_VALUE)` |
| 2 | SET | `tokiSbtCd = svcUtwkEoTelBean.sendMessageString(KKW05601SFConst.ITNTOKI_SBT_CD_05, X31CWebConst.DATABEAN_GET_VALUE)` |
| 3 | SET | `tokiAddCd = svcUtwkEoTelBean.sendMessageString(KKW05601SFConst.ITNTOKI_ADD_CD_05, X31CWebConst.DATABEAN_GET_VALUE)` |
| 4 | SET | `itenTokiStaRsvYmd = svcUtwkEoTelBean.sendMessageString(KKW05601SFConst.ITNTOKI_MAN_STA_RSV_YMD_05, X31CWebConst.DATABEAN_GET_VALUE)` |
| 5 | SET | `itenTokiEndRsvYmd = svcUtwkEoTelBean.sendMessageString(KKW05601SFConst.ITNTOKI_END_RSV_YMD_05, X31CWebConst.DATABEAN_GET_VALUE)` |
| 6 | SET | `tokiTensoSkTelno = svcUtwkEoTelBean.sendMessageString(KKW05601SFConst.TOKI_TENSO_SK_TELNO_05, X31CWebConst.DATABEAN_GET_VALUE)` |
| 7 | SET | `tokiTensoSkSvkuwno = svcUtwkEoTelBean.sendMessageString(KKW05601SFConst.TOKI_TENSO_SK_SVKUWNO_05, X31CWebConst.DATABEAN_GET_VALUE)` |
| 8 | SET | `tokiAddCdMt = svcUtwkEoTelBean.sendMessageString(KKW05601SFConst.ITNTOKI_ADD_CD_05, X31CWebConst.DATABEAN_GET_VALUE)` // Port-out source discriminator |

**Block 6** — SET (L2878)

Compute the port-out original phone number. Uses `getItenMTelNo` which resolves the original number based on the porting registration code and available phone numbers.

| # | Type | Code |
|---|------|------|
| 1 | CALL | `getItenMTelNo(tokiAddCd, telNo, tokiTensoSkTelno)` // Resolves original phone number |
| 2 | SET | `bean.sendMessageString(KKW05601SFConst.ITENM_TELNO, X31CWebConst.DATABEAN_SET_VALUE, result)` // Set port-out original phone |

**Block 7** — SET (L2883)

Derive the contact phone number. For port-forward registration, looks up the phone number matching the target service contract internal number from the phone list data bean.

| # | Type | Code |
|---|------|------|
| 1 | CALL | `rrksTelNo = getRRSKTelNo(bean, tokiAddCd, tokiTensoSkTelno, tokiTensoSkSvkuwno)` // Looks up contact phone |
| 2 | SET | `bean.sendMessageString(KKW05601SFConst.RRKS_TELNO, X31CWebConst.DATABEAN_SET_VALUE, rrksTelNo)` // Set contact phone |

**Block 8** — SET (L2896)

Add the porting content description. Translates the porting type code into a human-readable label.

| # | Type | Code |
|---|------|------|
| 1 | CALL | `getTokiNaiyo(bean, tokiSbtCd)` // Translates type code to description |
| 2 | SET | `bean.sendMessageString(KKW05601SFConst.TOKI_NAIYO, X31CWebConst.DATABEAN_ADD_VALUE, result)` // Add porting content |

**Block 9** — CALL (L2899)

Initialize the confirmation screen with all porting fields. Sets pull-down display values, formats start/end dates, and sets the update change message.

| # | Type | Code |
|---|------|------|
| 1 | CALL | `actionTokiAddCfmInit(telNo, tokiAddCd, tokiSbtCd, itenKibo, itenTokiStaRsvYmd, itenTokiEndRsvYmd, telNo, rrksTelNo, "0")` |

**Block 10** — SET (L2902)

Set the porting manual start date display field — handled separately because `actionTokiAddCfmInit` does not cover this display format.

| # | Type | Code |
|---|------|------|
| 1 | CALL | `setBeanRsvYmd(bean, KKW05601SFConst.TOKI_STA_RSV_DSP, itenTokiStaRsvYmd)` // Display porting start date |

**Block 11** — SET (L2905)

Set the porting end date display field — handled separately for the same reason as Block 10.

| # | Type | Code |
|---|------|------|
| 1 | CALL | `setBeanRsvYmd(bean, KKW05601SFConst.TOKI_END_RSV_DSP, itenTokiEndRsvYmd)` // Display porting end date |

## 7. Glossary

| Term | Type | Business Meaning |
|------|------|------------------|
| `tokiAddCond` | Field | Porting registration status — indicates whether port-out cancellation, port-forward destination registration, or both are registered. Values: "0" (none), "1" (DSL only), "2" (OPAF only), "3" (both) |
| `TOKI_NASHI` | Constant | No porting registered — value `"0"`. Triggers early exit to prevent JSP errors |
| `TOKI_ADD_OPAF` | Constant | Port-forward registration — value `"2"`. Indicates porting via destination-side registration |
| `itenKibo` | Field | Porting request flag — whether the customer requests number porting (`"4"` = input required, per `KIBO_UMU_INPUT_TOKI`) |
| `tokiSbtCd` | Field | Porting type code — classifies the type of porting action (e.g., port-forward number guidance `"231"`, cancellation `"216"`, suspension `"216"`, suspension + contact `"236"`) |
| `tokiAddCd` | Field | Porting registration code — classifies the registration type: `"1"` = port-forward destination registration, `"2"` = port-out source cancellation, `"3"` = suspension |
| `itenTokiStaRsvYmd` | Field | Porting manual start reserved date (YYYYMMDD) — the date the porting operation is scheduled to begin |
| `itenTokiEndRsvYmd` | Field | Porting end reserved date (YYYYMMDD) — the date the porting process is scheduled to complete |
| `tokiTensoSkTelno` | Field | Port-forward target phone number — the destination phone number after number porting |
| `tokiTensoSkSvkuwno` | Field | Port-forward target service contract internal number — internal identifier for the destination service contract line |
| `telNo` | Field | Target phone number — the phone number subject to porting (移転対象電話番号) |
| `tokiNaiyo` | Field | Porting content description — human-readable label describing the porting type |
| `RRKS_TELNO` | Field | Contact phone number — the phone number to contact the customer regarding porting |
| `ITENM_TELNO` | Field | Port-out original phone number — the original phone number before porting (移転元電話番号) |
| `svcUtwkEoTelBean` | Field | Service work phone data bean — carries porting data fetched from the database, used as the data source for this method |
| `bean` | Field | Service form bean — the data carrier for the confirmation screen (KKW05603), populated by this method |
| `getTokiAddCondtion` | Method | Returns porting registration status by examining service contract info bean data. Returns `"0"` through `"3"` based on presence of port-out and port-forward registration codes |
| `getItenMTelNo` | Method | Computes the port-out original phone number by resolving against available phone numbers and the porting registration code |
| `getRRSKTelNo` | Method | Derives the contact phone number from the target service contract internal number by searching the phone list data bean |
| `getTokiNaiyo` | Method | Translates the porting type code into a human-readable description string |
| `actionTokiAddCfmInit` | Method | Initializes the porting registration confirmation screen display — sets pull-down values with code-to-label resolution, formats date fields, sets update change message |
| `setBeanRsvYmd` | Method | Sets a single date display field in the bean by splitting a YMD date string |
| 番号ポート | Business term | Number Portability / Port-in — the service allowing customers to keep their phone number when switching providers. In this system, also refers to internal porting registration for number changes |
| トーク登録 | Business term | Porting registration (口キ登録) — the process of registering porting settings for a phone number |
| 移転先登録 | Business term | Port-forward destination registration — registering porting after the destination service has been opened (`"1"` code) |
| 移転元解約 | Business term | Port-out source cancellation — registering porting due to cancellation at the original provider (`"2"` code) |
| 休止 | Business term | Suspension — porting registration due to service suspension (`"3"` code) |
| EKK0191A010DETAILLIST | Field | Service contract info (eo optical phone) detail list data bean array — queried by `getTokiAddCondtion` to determine porting registration status |
| EKK0191B003DETAILLIST | Field | Phone number one-line agreement detail list — queried by `findTensoSkSvkuwno` and `findTensoSkSvkuwStat` to look up service contract numbers matching a phone number |
| EKK2101B002DETAILLIST | Field | Address change detail list (pre-change identifier) — used in `actionTokiAddCfmInit` for address change validation |
| EKK2091A010DETAILLIST | Field | Address change agreement detail list — used to check address change status |
| EKU0011A010DETAILLIST | Field | Work project agreement detail list — used to check work project status |
| KKW05603 | Screen ID | Porting registration confirmation screen — the screen whose data is initialized by this method |
| KIW05601SF | Module | Porting registration module — the web screen module this logic belongs to |
