# Business Logic — JBSbatKKintrjhAdd.outMapEdit() [112 LOC]

| Field | Value |
|-------|-------|
| Fully Qualified Name | `eo.business.service.JBSbatKKintrjhAdd` |
| Layer | Service (Batch processing service) |
| Module | `service` (Package: `eo.business.service`) |

## 1. Role

### JBSbatKKintrjhAdd.outMapEdit()

This method performs **output map editing** for the referrer (shokaisha) information registration process. It is a data preparation routine that transforms incoming request parameters into a structured `JBSbatServiceInterfaceMap` output, which is then written to a file for downstream transmission via HTTP/REST to an external referral information registration system (IFE: Interface Export, module IFE219).

The method serves as a **data mapping and enrichment** step: it takes raw referral and subscription data, enriches it by looking up additional details from the subscription detail table (`KK_T_MSKM_DTL`) and price plan master table (`KK_M_PPLAN`), applies date formatting and string truncation rules, and finally sets a success flag (`setOutFlg(true)`) to signal that the output map has been prepared correctly.

It implements the **builder/accumulator pattern** -- incrementally populating the `outMap` object with key-value pairs. The method branches on two conditional checks: (1) whether a subscription detail number is provided (triggers a DB lookup to resolve the application date and detail number), and (2) whether both a price course code and price plan code are provided (triggers a master price plan lookup with a date-range validation to determine the applicable price plan name). The method is called internally by `createSvcStaTgInf()`, which orchestrates the broader service start tag information creation workflow for referral data.

## 2. Processing Pattern (Detailed Business Logic)

```mermaid
flowchart TD
    START(["outMapEdit start"])
    STEP1["Set debug log START"]
    STEP2["Initialize local vars<br/>mskmYmd, mskmshoDtlNo, pplanDivNm"]
    STEP3["outMap.set SHOKAISHA_SYSID"]
    STEP4["outMap.set SHOKAISHA_SVC_KEI_NO"]
    STEP5["outMap.set ERR_RSN"]
    STEP6["outMap.set INTR_CD"]
    COND1{"Is searchJkn_mskmDtlNo<br/>not empty?"}
    STEP7["Execute executeKK_T_MSKM_DTL_KK_SELECT_022"]
    STEP8["Query db_KK_T_MSKM_DTL.selectNext()"]
    COND2{"Is result not null?"}
    STEP9["Set mskmshoDtlNo from MSKMSHO_DTL_NO"]
    STEP10["Set mskmYmd from MSKM_YMD"]
    STEP11["Edit mskmYmd to YYYY/MM/DD format"]
    STEP12["outMap.set MSKM_YMD (formatted)"]
    STEP13["outMap.set MSKMSHO_DTL_NO"]
    STEP14["outMap.set SVC_KEI_NO"]
    COND3{"Are searchJkn_pcrsCd and<br/>searchJkn_pplanCd both non-empty?"}
    STEP15["Execute executeKK_M_PPLAN_PKSELECT"]
    STEP16["Get pplanTstaYmd, pplanTendYmd, PPLAN_NM"]
    COND4{"Is opeDate between<br/>start and end date?"}
    STEP17["Set pplanDivNm from PPLAN_NM"]
    COND5{"Is pplanDivNm longer than 15 chars?"}
    STEP18["Truncate pplanDivNm to 15 chars"]
    STEP19["outMap.set SHOKAISHA_PPLAN_DIVNM"]
    STEP20["outMap.set CAMPAIGN_CD"]
    STEP21["outMap.setOutFlg(true)"]
    STEP22["Set debug log END"]
    END(["outMapEdit return"])

    START --> STEP1
    STEP1 --> STEP2
    STEP2 --> STEP3
    STEP3 --> STEP4
    STEP4 --> STEP5
    STEP5 --> STEP6
    STEP6 --> COND1
    COND1 -- "true" --> STEP7
    COND1 -- "false" --> STEP11
    STEP7 --> STEP8
    STEP8 --> COND2
    COND2 -- "true" --> STEP9
    STEP9 --> STEP10
    STEP10 --> STEP11
    COND2 -- "false" --> STEP11
    STEP11 --> STEP12
    STEP12 --> STEP13
    STEP13 --> STEP14
    STEP14 --> COND3
    COND3 -- "true" --> STEP15
    STEP15 --> STEP16
    STEP16 --> COND4
    COND4 -- "true" --> STEP17
    STEP17 --> COND5
    COND5 -- "true" --> STEP18
    COND5 -- "false" --> STEP19
    STEP18 --> STEP19
    COND4 -- "false" --> STEP19
    COND3 -- "false" --> STEP19
    STEP19 --> STEP20
    STEP20 --> STEP21
    STEP21 --> STEP22
    STEP22 --> END
```

**Processing flow:**

1. Log the start of processing.
2. Initialize three local variables: `mskmYmd` (application date), `mskmshoDtlNo` (application detail number), and `pplanDivNm` (price plan name).
3. Set basic referrer information onto the output map: SHOKAISHA_SYSID (referrer system ID), SHOKAISHA_SVC_KEI_NO (referrer service contract number), ERR_RSN (error reason), and INTR_CD (referral code).
4. **Branch 1 -- Subscription detail lookup:** If `searchJkn_mskmDtlNo` is not empty, execute a DB select on `KK_T_MSKM_DTL` to retrieve the application date (`MSKM_YMD`) and detail number (`MSKMSHO_DTL_NO`). Format the date into `YYYY/MM/DD` and write both values to the output map.
5. Set the customer service contract line number (`SVC_KEI_NO`) onto the output map.
6. **Branch 2 -- Price plan lookup:** If both `searchJkn_pcrsCd` (price course code) and `searchJkn_pplanCd` (price plan code) are non-empty, query the `KK_M_PPLAN` master table to find the applicable price plan. Validate that the current operation date (`opeDate`) falls within the plan's effective date range (`PPLAN_TSTAYMD` to `PPLAN_TENDYMD`). If valid, extract the price plan name (`PPLAN_NM`), truncate to 15 characters if longer, and store it.
7. Write the resolved price plan name (`SHOKAISHA_PPLAN_DIVNM`) and campaign code (`CAMPAIGN_CD`) onto the output map.
8. Set the output flag to `true` and log the end of processing.

## 3. Parameter Analysis

| No | Parameter Name | Type | Business Description |
|----|---------------|------|---------------------|
| 1 | `outMap` | `JBSbatServiceInterfaceMap` | Output data container -- the structured map that accumulates all key-value pairs to be written to the IFE219 file for the external referral information registration system. |
| 2 | `shokaisha_sysid` | `String` | Referrer (shokaisha) system ID -- the unique identifier of the referral partner in the K-Opticom system. Set directly onto the output map. |
| 3 | `searchJkn_intrCd` | `String` | Referral code (JKN = K-Opticom internal abbreviation for referral/referral registration) -- the unique code identifying a referral relationship. Set directly onto the output map. |
| 4 | `searchJkn_mskmDtlNo` | `String` | Application detail number -- the primary key of the subscription detail record. If non-empty, triggers a DB lookup on `KK_T_MSKM_DTL` to resolve the application date and detail number for enrichment. |
| 5 | `svcKeiNo` | `String` | Customer service contract line number (SVC_KEI_NO) -- identifies the specific service contract line item for the customer. Set directly onto the output map. |
| 6 | `searchJkn_pcrsCd` | `String` | Price course code -- the pricing tier/course classification used to look up price plan details. Part of the composite key for the price plan master query. |
| 7 | `searchJkn_pplanCd` | `String` | Price plan code -- the specific pricing plan identifier. Combined with `searchJkn_pcrsCd` as the composite key for the price plan master query. |
| 8 | `shokaisha_svcKeiNo` | `String` | Referrer service contract number -- the service contract line item associated with the referrer partner. Set directly onto the output map. |
| 9 | `errRsn` | `String` | Error reason -- a descriptive string explaining any error condition. Set directly onto the output map for downstream error tracking. |
| 10 | `campaignCd` | `String` | Campaign code -- the marketing campaign identifier associated with the referral. Set directly onto the output map. |

**Instance fields read:**

| Field | Type | Business Description |
|-------|------|---------------------|
| `super.opeDate` | `String` | Operation date (current processing date) -- used in the price plan effective date validation to determine whether the plan is active on the current operation date. |
| `super.logPrint` | `JBSbatCommonDBInterface` | Logging utility -- used to emit debug logs at method start and end. |
| `db_KK_T_MSKM_DTL` | `JBSbatCommonDBInterface` | Database access handle for the subscription detail table -- used by `selectNext()` after `executeKK_T_MSKM_DTL_KK_SELECT_022` populates it. |

## 4. CRUD Operations / Called Services

| CRUD | SC / CBS | SC Code | Entity / DB | Operation Description |
|------|----------|---------|-------------|----------------------|
| R | `executeKK_T_MSKM_DTL_KK_SELECT_022` | (internal select) | `KK_T_MSKM_DTL` (subscription detail table) | Reads subscription detail record by detail number to obtain application date and detail number. |
| R | `executeKK_M_PPLAN_PKSELECT` | (internal select) | `KK_M_PPLAN` (price plan master table) | Reads price plan master record by price course code and plan code to obtain effective dates and plan name. |
| - | `JPCUtilCommon.formatDate` | JPCUtilCommon | - | Formats a date string into `YYYY/MM/DD` format. |
| - | `JBSbatStringUtil.Rtrim` | JBSbatStringUtil | - | Right-trims whitespace from string values retrieved from DB records. |
| - | `JBSbatServiceInterfaceMap.setString` | JBSbatServiceInterfaceMap | - | Writes a key-value pair to the output interface map. |
| - | `JBSbatServiceInterfaceMap.setOutFlg` | JBSbatServiceInterfaceMap | - | Sets the output flag to indicate successful preparation of the map. |
| - | `super.logPrint.printDebugLog` | JACBatCommon | - | Emits debug log messages for start, end, and intermediate values. |

## 5. Dependency Trace

| # | Caller (Screen/Batch) | Call Chain (Full Path to this Method) | Terminal (SC / CRUD / Entity) |
|---|----------------------|--------------------------------------|-------------------------------|
| 1 | Class: JBSbatKKintrjhAdd | `createSvcStaTgInf` -> `outMapEdit` | `setOutFlg` [SET], `setString` [SET] x10 |

**No screen/batch entry points found.** This method is a private utility called exclusively by `createSvcStaTgInf()` within the same class, which orchestrates service start tag information creation for the referral data export workflow.

**Terminal operations:** `setOutFlg(true)`, `setString(...)` (10 calls), `printDebugLog` (3 calls).

## 6. Per-Branch Detail Blocks

**Block 1** — [INIT] `(local variable initialization)` (L1340)

> Initialize local variables used for data enrichment (application date, detail number, price plan name).

| # | Type | Code |
|---|------|------|
| 1 | SET | `mskmYmd = ""` // Application date -- initialized empty |
| 2 | SET | `mskmshoDtlNo = ""` // Application detail number -- initialized empty |
| 3 | SET | `pplanDivNm = ""` // Price plan name -- initialized empty |

**Block 2** — [SET] `(direct output map population)` (L1348)

> Set basic referrer information fields directly from method parameters onto the output map without any transformation.

| # | Type | Code |
|---|------|------|
| 1 | CALL | `outMap.setString(JBSbatKKIFE219.SHOKAISHA_SYSID, shokaisha_sysid)` // Set referrer system ID [-> "SHOKAISHA_SYSID"] |
| 2 | CALL | `outMap.setString(JBSbatKKIFE219.SHOKAISHA_SVC_KEI_NO, shokaisha_svcKeiNo)` // Set referrer service contract number [-> "SHOKAISHA_SVC_KEI_NO"] |
| 3 | CALL | `outMap.setString(JBSbatKKIFE219.ERR_RSN, errRsn)` // Set error reason [-> "ERR_RSN"] |
| 4 | CALL | `outMap.setString(JBSbatKKIFE219.INTR_CD, searchJkn_intrCd)` // Set referral code [-> "INTR_CD"] |

**Block 3** — [IF] `(searchJkn_mskmDtlNo is not empty)` (L1369)

> If a subscription detail number is provided, look up the subscription detail record from the database to resolve the application date and detail number.

| # | Type | Code |
|---|------|------|
| 1 | COND | `!"".equals(searchJkn_mskmDtlNo)` // Check if detail number is provided |
| 2 | SET | `whereParam_mskm_dtl = {searchJkn_mskmDtlNo}` // Build WHERE clause parameter array |
| 3 | CALL | `executeKK_T_MSKM_DTL_KK_SELECT_022(whereParam_mskm_dtl)` // Execute DB select on KK_T_MSKM_DTL [-> R KK_T_MSKM_DTL] |
| 4 | CALL | `outDbMap_mskm_dtl = db_KK_T_MSKM_DTL.selectNext()` // Fetch the next result row |
| 5 | IF | See Block 3.1 -- inner null check |

**Block 3.1** — [IF] `(outDbMap_mskm_dtl is not null)` (L1375)

> If the DB query returned a result, extract the subscription detail number and application date.

| # | Type | Code |
|---|------|------|
| 1 | SET | `mskmshoDtlNo = JBSbatStringUtil.Rtrim(outDbMap_mskm_dtl.getString(JBSbatKK_T_MSKM_DTL.MSKMSHO_DTL_NO))` // Resolve subscription detail number [-> "MSKMSHO_DTL_NO"] [-> R KK_T_MSKM_DTL] |
| 2 | SET | `mskmYmd = JBSbatStringUtil.Rtrim(outDbMap_mskm_dtl.getString(JBSbatKK_T_MSKM_DTL.MSKM_YMD))` // Resolve application date [-> "MSKM_YMD"] [-> R KK_T_MSKM_DTL] |

**Block 4** — [SET] `(date formatting and output)` (L1384)

> Format the application date into `YYYY/MM/DD` format and write both the formatted date and detail number to the output map. Also set the customer service contract line number.

| # | Type | Code |
|---|------|------|
| 1 | SET | `mskmYmdEdit = JPCUtilCommon.formatDate(mskmYmd)` // Format date to YYYY/MM/DD |
| 2 | EXEC | `super.logPrint.printDebugLog("mskmYmd : " + mskmYmd)` // Debug log original date |
| 3 | EXEC | `super.logPrint.printDebugLog("mskmYmdEdit: " + mskmYmdEdit)` // Debug log formatted date |
| 4 | CALL | `outMap.setString(JBSbatKKIFE219.MSKM_YMD, mskmYmdEdit)` // Write formatted application date [-> "MSKM_YMD"] |
| 5 | CALL | `outMap.setString(JBSbatKKIFE219.MSKMSHO_DTL_NO, mskmshoDtlNo)` // Write application detail number [-> "MSKMSHO_DTL_NO"] |
| 6 | CALL | `outMap.setString(JBSbatKKIFE219.SVC_KEI_NO, svcKeiNo)` // Write customer service contract line number [-> "SVC_KEI_NO"] |

**Block 5** — [IF] `(both price course code and price plan code are non-empty)` (L1391)

> If both a price course code and a price plan code are provided, look up the price plan master table to resolve the applicable price plan name. Validate that the operation date falls within the plan's effective date range.

| # | Type | Code |
|---|------|------|
| 1 | COND | `!" ".equals(searchJkn_pcrsCd) && !"".equals(searchJkn_pplanCd)` // Check both price codes are provided |
| 2 | SET | `whereParam_pplan = {searchJkn_pcrsCd, searchJkn_pplanCd}` // Build composite WHERE clause parameter |
| 3 | SET | `outDbMap_pplan = null` // Initialize DB result holder |
| 4 | CALL | `outDbMap_pplan = executeKK_M_PPLAN_PKSELECT(whereParam_pplan)` // Execute price plan master lookup [-> R KK_M_PPLAN] |
| 5 | IF | See Block 5.1 -- inner null check |

**Block 5.1** — [IF] `(outDbMap_pplan is not null)` (L1397)

> If the price plan master query returned a result, extract the effective dates and plan name, then validate the date range.

| # | Type | Code |
|---|------|------|
| 1 | SET | `pplanTstaYmd = JBSbatStringUtil.Rtrim(outDbMap_pplan.getString(JBSbatKK_M_PPLAN.PPLAN_TSTAYMD))` // Resolve price plan effective start date [-> "PPLAN_TSTAYMD"] [-> R KK_M_PPLAN] |
| 2 | SET | `pplanTendYmd = JBSbatStringUtil.Rtrim(outDbMap_pplan.getString(JBSbatKK_M_PPLAN.PPLAN_TENDYMD))` // Resolve price plan effective end date [-> "PPLAN_TENDYMD"] [-> R KK_M_PPLAN] |
| 3 | IF | See Block 5.2 -- date range validation |

**Block 5.2** — [IF] `(opeDate falls within effective date range)` (L1404)

> Validate that the current operation date (`opeDate`) is on or after the price plan's effective start date AND on or before the effective end date. If within range, resolve the plan name.

| # | Type | Code |
|---|------|------|
| 1 | COND | `(super.opeDate.compareTo(pplanTstaYmd) >= 0) && (super.opeDate.compareTo(pplanTendYmd) <= 0)` // Date within range check |
| 2 | SET | `pplanDivNm = JBSbatStringUtil.Rtrim(outDbMap_pplan.getString(JBSbatKK_M_PPLAN.PPLAN_NM))` // Resolve price plan name [-> "PPLAN_NM"] [-> R KK_M_PPLAN] |
| 3 | IF | See Block 5.3 -- string truncation |

**Block 5.3** — [IF] `(pplanDivNm length exceeds 15 characters)` (L1410)

> Truncate the price plan name to 15 characters if it exceeds this limit, per the output file format specification.

| # | Type | Code |
|---|------|------|
| 1 | COND | `pplanDivNm.length() > 15` // Check length exceeds 15 chars |
| 2 | SET | `pplanDivNm = pplanDivNm.substring(0, 15)` // Truncate to first 15 characters |

**Block 6** — [SET] `(price plan name and campaign code output)` (L1415)

> Write the resolved price plan name and campaign code to the output map, then set the output success flag.

| # | Type | Code |
|---|------|------|
| 1 | CALL | `outMap.setString(JBSbatKKIFE219.SHOKAISHA_PPLAN_DIVNM, pplanDivNm)` // Write referrer price plan name [-> "SHOKAISHA_PPLAN_DIVNM"] |
| 2 | CALL | `outMap.setString(JBSbatKKIFE219.CAMPAIGN_CD, campaignCd)` // Write campaign code [-> "CAMPAIGN_CD"] |
| 3 | CALL | `outMap.setOutFlg(true)` // Set output success flag |
| 4 | EXEC | `super.logPrint.printDebugLog("outMapEdit_END")` // Log processing completion |

## 7. Glossary

| Term | Type | Business Meaning |
|------|------|------------------|
| `shokaisha` | Field (Japanese) | Referrer -- the partner or entity that refers customers to K-Opticom services. |
| `svcKeiNo` | Field | Service contract line number (`SVC_KEI_NO`) -- the unique identifier for a specific service contract line item. |
| `intrCd` | Field | Referral code (`INTR_CD`) -- identifies a referral relationship between a referrer and K-Opticom. |
| `mskmDtlNo` | Field | Application detail number (`MSKMSHO_DTL_NO`) -- the primary key of a subscription detail record. `mskm` = 申込 (application/subscription). |
| `mskmYmd` | Field | Application date (`MSKM_YMD`) -- the date a subscription was applied for. `Ymd` = YYYY/MM/DD format. |
| `pplanCd` | Field | Price plan code -- the identifier for a specific pricing plan. |
| `pcrsCd` | Field | Price course code -- the pricing tier/course classification. |
| `pplanDivNm` | Field | Price plan name (`PPLAN_NM`) -- the human-readable name of the applicable price plan. |
| `errRsn` | Field | Error reason (`ERR_RSN`) -- describes the reason for an error condition. |
| `campaignCd` | Field | Campaign code -- the marketing campaign identifier. |
| `outMap` | Field | Output service interface map -- the data container passed between methods, ultimately written to the IFE219 file. |
| `outMapEdit` | Method | Output map editing -- the process of populating and formatting the output data map. |
| IFE219 | File format | Interface Export file #219 -- the output file format for referral information registration external system communication. |
| `JBSbatKKIFE219` | Constant class | File format constants for IFE219 -- defines all field keys (e.g., `SHOKAISHA_SYSID`, `INTR_CD`, `MSKM_YMD`). |
| `KK_T_MSKM_DTL` | DB table | Subscription detail table -- stores detailed subscription/application records. |
| `KK_M_PPLAN` | DB table | Price plan master table -- stores pricing plan definitions including effective dates and plan names. |
| `mskmsyoDtlNo` | Field | Application detail number -- the detail number of a subscription application record. |
| `opeDate` | Field | Operation date -- the current processing date, used for date range validation. |
| `SHOKAISHA_SYSID` | Constant | Referrer system ID -- the unique system identifier for a referrer. |
| `SHOKAISHA_SVC_KEI_NO` | Constant | Referrer service contract number -- the service contract line item of the referrer. |
| `SHOKAISHA_PPLAN_DIVNM` | Constant | Referrer price plan name -- the resolved price plan name for the referrer output. |
| `PPLAN_TSTAYMD` | Field | Price plan effective start date (`PPLAN_TSTAYMD`) -- the date from which the price plan becomes effective. |
| `PPLAN_TENDYMD` | Field | Price plan effective end date (`PPLAN_TENDYMD`) -- the date until which the price plan remains effective. |
| `PPLAN_NM` | Field | Price plan name (`PPLAN_NM`) -- the human-readable name of the price plan. |
| `MSKM_YMD` | Field | Application date (`MSKM_YMD`) -- the date the subscription was applied. |
| `MSKMSHO_DTL_NO` | Field | Subscription detail number (`MSKMSHO_DTL_NO`) -- the unique detail number of a subscription record. |
| `ERR_RSN` | Constant | Error reason -- the reason code or description for an error. |
| `CAMPAIGN_CD` | Constant | Campaign code -- the marketing campaign identifier. |
| `INTR_CD` | Constant | Referral code -- the code identifying a referral relationship. |
| `SVC_KEI_NO` | Constant | Service contract line number -- the identifier for a specific service contract line item. |
| `setOutFlg(true)` | Operation | Output flag -- when set to `true`, signals that the output map has been successfully prepared. |
| JKN | Acronym | K-Opticom internal code abbreviation (JKN) -- used as a prefix for referral-related parameters and constants. |
| IFE | Acronym | Interface Export -- the export interface for transmitting data to external systems. |
