# Business Logic — JBSbatKKIntrCdIkaAdd.initial() [31 LOC]

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

## 1. Role

### JBSbatKKIntrCdIkaAdd.initial()

This method performs the **initialization** for the "Introduction Code Bulk Registration" batch process (`JBSbatKKIntrCdIkaAdd`). Its business purpose is to prepare the runtime environment before the batch iterates over and registers introduction codes en masse — a function used to manage pre-assigned reference/registration codes for customer service contracts. Specifically, it calls the inherited `setCommonInfo` from `JBSbatBusinessService` to attach the batch common parameters to the service context, then instantiates eight `JBSbatSQLAccess` objects (one per database table) so that subsequent processing stages can read and write to the relevant data layers. It then queries the `ZM_M_WORK_PARAM_KNRI` (business parameter management) table to retrieve the "validity period addition days" (`KK_INTR_CD_YK_PRD`) parameter, which determines how many days are added to the effective expiration of newly registered introduction codes. The method is an **entry point** invoked by the batch framework after construction, serving as the shared initialization step that all introduction code registration batches rely upon before delegating to deeper processing (file I/O, SQL DML, error/result reporting).

## 2. Processing Pattern (Detailed Business Logic)

```mermaid
flowchart TD
    START(["initial(commonItem)"])

    START --> SET_COMMON["setCommonInfo(commonItem)"]

    SET_COMMON --> CREATE_DB["Create JBSbatSQLAccess instances for DB tables"]

    CREATE_DB --> STEP2["Create 8 JBSbatSQLAccess:
  - KK_T_INTR
  - CK_T_CUST
  - KK_T_SVC_KEI
  - KK_T_KAISEN_TG_SVKEI
  - KK_T_SVKEI_KAISEN_UW
  - ZM_M_WORK_PARAM_KNRI
  - ZM_T_DL_FILE_KANRI
  - ZM_T_DATAIKTTRK_KNRI"]

    STEP2 --> SELECT_WORK["executeZM_M_WORK_PARAM_KNRI_KK_SELECT_002
  param: INTR_CD_YK_KIGEN, opeDate, opeDate"]

    SELECT_WORK --> FETCH["db_ZM_M_WORK_PARAM_KNRI.selectNext()"]

    FETCH --> CHECK_NULL{workParamMap1 is null?}

    CHECK_NULL -->|No| TRY_PARSE["Try parse ykKigenNDate
(workParamMap1.getString(WORK_PARAM_SETTE_VALUE))"]

    TRY_PARSE --> PARSE_SUCCESS{NumberFormat
successful?}

    PARSE_SUCCESS -->|Yes| SET_VALUE["ykKigenNDate = parsed int"]

    PARSE_SUCCESS -->|No| CATCH_CATCH["catch NumberFormatException"]

    CATCH_CATCH --> SET_ZERO["ykKigenNDate = 0"]

    SET_VALUE --> END_NODE(["Return / Next"])

    SET_ZERO --> END_NODE

    CHECK_NULL -->|Yes| END_NODE
```

**CRITICAL — Constant Resolution:**

| Constant Name | Resolved Value | Business Meaning |
|--------------|----------------|------------------|
| `D_TBL_NAME_KK_T_INTR` | `"KK_T_INTR"` | Introduction table |
| `D_TBL_NAME_CK_T_CUST` | `"CK_T_CUST"` | Customer table |
| `D_TBL_NAME_KK_T_SVC_KEI` | `"KK_T_SVC_KEI"` | Service contract table |
| `D_TBL_NAME_KK_T_KAISEN_TG_SVKEI` | `"KK_T_KAISEN_TG_SVKEI"` | Line target service contract table |
| `D_TBL_NAME_KK_T_SVKEI_KAISEN_UW` | `"KK_T_SVKEI_KAISEN_UW"` | Service contract line details |
| `D_TBL_NAME_ZM_M_WORK_PARAM_KNRI` | `"ZM_M_WORK_PARAM_KNRI"` | Business parameter management table |
| `D_TBL_NAME_ZM_T_DL_FILE_KANRI` | `"ZM_T_DL_FILE_KANRI"` | Downloaded file management table |
| `D_TBL_NAME_ZM_T_DATAIKTTRK_KNRI` | `"ZM_T_DATAIKTTRK_KNRI"` | Data bulk registration management table |
| `INTR_CD_YK_KIGEN` | `"KK_INTR_CD_YK_PRD"` | External definition key for introduction code validity period |

## 3. Parameter Analysis

| No | Parameter Name | Type | Business Description |
|----|---------------|------|---------------------|
| 1 | `commonItem` | `JBSbatCommonItem` | Batch common parameters — carries shared batch execution context including the operation date (`opeDate` via `super.opeDate`), which is used to parameterize SQL queries for retrieving work parameters. Represents the unified data envelope passed throughout the batch processing pipeline. |

**Instance fields / external state read by this method:**

| Field | Type | Business Meaning |
|-------|------|------------------|
| `super.opeDate` | (from `JBSbatBusinessService`) | Operation date — the business date for this batch run, passed as a SQL query parameter |
| `db_*` (8 SQLAccess fields) | `JBSbatSQLAccess` | Created and assigned during this method; used by subsequent processing methods for table-specific SQL execution |
| `ykKigenNDate` | `int` | Validity period addition days — set here from the work parameter table, used later to compute expiration dates for introduction codes |

## 4. CRUD Operations / Called Services

| CRUD | SC / CBS | SC Code | Entity / DB | Operation Description |
|------|----------|---------|-------------|----------------------|
| - | `JBSbatBusinessService.setCommonInfo` | - | - | Calls `setCommonInfo` in `JBSbatBusinessService` to set common batch parameters into service context |
| - | `new JBSbatSQLAccess(commonItem, tableName)` | - | KK_T_INTR | Creates SQL access handler for the Introduction table |
| - | `new JBSbatSQLAccess(commonItem, tableName)` | - | CK_T_CUST | Creates SQL access handler for the Customer table |
| - | `new JBSbatSQLAccess(commonItem, tableName)` | - | KK_T_SVC_KEI | Creates SQL access handler for the Service Contract table |
| - | `new JBSbatSQLAccess(commonItem, tableName)` | - | KK_T_KAISEN_TG_SVKEI | Creates SQL access handler for the Line Target Service Contract table |
| - | `new JBSbatSQLAccess(commonItem, tableName)` | - | KK_T_SVKEI_KAISEN_UW | Creates SQL access handler for the Service Contract Line Details table |
| - | `new JBSbatSQLAccess(commonItem, tableName)` | - | ZM_M_WORK_PARAM_KNRI | Creates SQL access handler for the Business Parameter Management table |
| - | `new JBSbatSQLAccess(commonItem, tableName)` | - | ZM_T_DL_FILE_KANRI | Creates SQL access handler for the Downloaded File Management table |
| - | `new JBSbatSQLAccess(commonItem, tableName)` | - | ZM_T_DATAIKTTRK_KNRI | Creates SQL access handler for the Data Bulk Registration Management table |
| - | `executeZM_M_WORK_PARAM_KNRI_KK_SELECT_002` | - | ZM_M_WORK_PARAM_KNRI | Calls `executeZM_M_WORK_PARAM_KNRI_KK_SELECT_002` in `JBSbatKKIntrCdIkaAdd` — executes a SQL query with defined key `ZM_M_WORK_PARAM_KNRI_KK_SELECT_002` (`KK_SELECT_002`) to retrieve the work parameter by parameter name and date range |
| R | `db_ZM_M_WORK_PARAM_KNRI.selectNext` | - | ZM_M_WORK_PARAM_KNRI | Fetches the next row from the SQL query result of the business parameter management table |
| R | `workParamMap1.getString(JBSbatZM_M_WORK_PARAM_KNRI.WORK_PARAM_SETTE_VALUE)` | JBSbatZM_M_WORK_PARAM_KNRI | - | Retrieves the parameter value string from the result set |

## 5. Dependency Trace

| # | Caller (Screen/Batch) | Call Chain (Full Path to this Method) | Terminal (SC / CRUD / Entity) |
|---|----------------------|--------------------------------------|-------------------------------|
| 1 | Batch: JBSbatKKIntrCdIkaAdd | (batch framework entry) -> `JBSbatKKIntrCdIkaAdd.initial` | `setCommonInfo`, `executeZM_M_WORK_PARAM_KNRI_KK_SELECT_002 [R] ZM_M_WORK_PARAM_KNRI`, `selectNext [R] ZM_M_WORK_PARAM_KNRI` |

**Notes:**
- `JBSbatKKIntrCdIkaAdd` is a standalone batch service class extending `JBSbatBusinessService`. No external class directly calls `initial` — it is invoked by the batch execution framework as the entry point for the Introduction Code Bulk Registration batch process. The search across 54,100+ Java files confirmed no other file references `JBSbatKKIntrCdIkaAdd`.
- The method's own called methods (`executeZM_M_WORK_PARAM_KNRI_KK_SELECT_002`, `selectNext`) terminate at the `ZM_M_WORK_PARAM_KNRI` table (business parameter management).

## 6. Per-Branch Detail Blocks

**Block 1** — [SET / EXEC] `(common parameters setup)` (L232-L233)

> Sets common batch parameters via the inherited service method. This is a standard initialization pattern in the batch framework.

| # | Type | Code |
|---|------|------|
| 1 | CALL | `super.setCommonInfo(commonItem);` // Sets common batch parameters from the incoming envelope |

---

**Block 2** — [SET / EXEC] `(DB access object instantiation)` (L236-L244)

> Creates 8 `JBSbatSQLAccess` instances, one per database table used throughout the batch. Each instance holds a reference to `commonItem` and the table name, enabling subsequent SQL execution against that specific table.

| # | Type | Code |
|---|------|------|
| 1 | SET | `db_KK_T_INTR = new JBSbatSQLAccess(commonItem, D_TBL_NAME_KK_T_INTR);` // DB access class (Introduction) [-> `D_TBL_NAME_KK_T_INTR = "KK_T_INTR"`] |
| 2 | SET | `db_CK_T_CUST = new JBSbatSQLAccess(commonItem, D_TBL_NAME_CK_T_CUST);` // DB access class (Customer) [-> `D_TBL_NAME_CK_T_CUST = "CK_T_CUST"`] |
| 3 | SET | `db_KK_T_SVC_KEI = new JBSbatSQLAccess(commonItem, D_TBL_NAME_KK_T_SVC_KEI);` // DB access class (Service Contract) [-> `D_TBL_NAME_KK_T_SVC_KEI = "KK_T_SVC_KEI"`] |
| 4 | SET | `db_KK_T_KAISEN_TG_SVKEI = new JBSbatSQLAccess(commonItem, D_TBL_NAME_KK_T_KAISEN_TG_SVKEI);` // DB access class (Line Target Service Contract) [-> `D_TBL_NAME_KK_T_KAISEN_TG_SVKEI = "KK_T_KAISEN_TG_SVKEI"`] |
| 5 | SET | `db_KK_T_SVKEI_KAISEN_UW = new JBSbatSQLAccess(commonItem, D_TBL_NAME_KK_T_SVKEI_KAISEN_UW);` // DB access class (Service Contract Line Details) [-> `D_TBL_NAME_KK_T_SVKEI_KAISEN_UW = "KK_T_SVKEI_KAISEN_UW"`] |
| 6 | SET | `db_ZM_M_WORK_PARAM_KNRI = new JBSbatSQLAccess(commonItem, D_TBL_NAME_ZM_M_WORK_PARAM_KNRI);` // DB access class (Business Parameter Management) [-> `D_TBL_NAME_ZM_M_WORK_PARAM_KNRI = "ZM_M_WORK_PARAM_KNRI"`] |
| 7 | SET | `db_ZM_T_DL_FILE_KANRI = new JBSbatSQLAccess(commonItem, D_TBL_NAME_ZM_T_DL_FILE_KANRI);` // DB access class (Downloaded File Management) [-> `D_TBL_NAME_ZM_T_DL_FILE_KANRI = "ZM_T_DL_FILE_KANRI"`] |
| 8 | SET | `db_ZM_T_DATAIKTTRK_KNRI = new JBSbatSQLAccess(commonItem, D_TBL_NAME_ZM_T_DATAIKTTRK_KNRI);` // DB access class (Data Bulk Registration Management) [-> `D_TBL_NAME_ZM_T_DATAIKTTRK_KNRI = "ZM_T_DATAIKTTRK_KNRI"`] |

---

**Block 3** — [CALL] `(Retrieve work parameter - validity period addition days)` (L246)

> Executes a SQL select query against the business parameter management table to look up the introduction code validity period parameter. Passes three parameters: the parameter name key, and two date values (both `opeDate` — operation date).

| # | Type | Code |
|---|------|------|
| 1 | CALL | `executeZM_M_WORK_PARAM_KNRI_KK_SELECT_002(new String[] {INTR_CD_YK_KIGEN, super.opeDate, super.opeDate});` // Executes SQL query to fetch work parameter [-> `INTR_CD_YK_KIGEN = "KK_INTR_CD_YK_PRD"`] |

**Block 3.1** — [nested call: `executeZM_M_WORK_PARAM_KNRI_KK_SELECT_002`] (L685-L703)

> Builds a `JBSbatCommonDBInterface` parameter list from the 3-element string array and executes a select by SQL definition key `ZM_M_WORK_PARAM_KNRI_KK_SELECT_002` (`KK_SELECT_002`). This is a framework-level select that populates the `db_ZM_M_WORK_PARAM_KNRI` result set for iteration via `selectNext()`.

| # | Type | Code |
|---|------|------|
| 1 | SET | `paramList = new JBSbatCommonDBInterface();` // Generates parameter value list |
| 2 | EXEC | `paramList.setValue(param[0].toString());` // Sets parameter name [-> `param[0] = "KK_INTR_CD_YK_PRD"`] |
| 3 | EXEC | `paramList.setValue(param[1].toString());` // Sets start date [-> `param[1] = super.opeDate`] |
| 4 | EXEC | `paramList.setValue(param[2].toString());` // Sets end date [-> `param[2] = super.opeDate`] |
| 5 | CALL | `db_ZM_M_WORK_PARAM_KNRI.selectBySqlDefine(paramList, ZM_M_WORK_PARAM_KNRI_KK_SELECT_002);` // Executes SQL select [-> `ZM_M_WORK_PARAM_KNRI_KK_SELECT_002 = "KK_SELECT_002"`] |

---

**Block 4** — [SET / IF] `(Fetch work parameter result and parse validity period)` (L247-L257)

> Reads the next row from the SQL query result. If a row exists, attempts to parse its value field as an integer representing the number of days to add to the introduction code's expiration. On parse failure, defaults to 0.

| # | Type | Code |
|---|------|------|
| 1 | SET | `workParamMap1 = db_ZM_M_WORK_PARAM_KNRI.selectNext();` // Gets next row from query result |
| 2 | IF | `if(workParamMap1 != null)` |

**Block 4.1** — [nested: if block] `(Parse validity period value)` (L249-L256)

> Attempts to parse the parameter value as an integer. Uses a try-catch to handle `NumberFormatException` — if the value stored in the parameter table is not a valid integer, it defaults to 0.

| # | Type | Code |
|---|------|------|
| 1 | TRY | `try { ... }` |
| 2 | SET | `ykKigenNDate = Integer.parseInt(workParamMap1.getString(JBSbatZM_M_WORK_PARAM_KNRI.WORK_PARAM_SETTE_VALUE));` // Parses the parameter value as int |
| 3 | CATCH | `catch (NumberFormatException e)` // If value conversion fails |

**Block 4.1.1** — [nested: catch] `(Fallback to default 0)` (L255-L256)

> When the stored parameter value cannot be parsed as an integer (e.g., empty string, null text), the addition days default to zero — meaning no extra days are added to the introduction code's validity period.

| # | Type | Code |
|---|------|------|
| 1 | SET | `ykKigenNDate = 0;` // If value conversion fails, set addition days to 0 (Value conversion failure — set addition days to 0) |

---

**Block 5** — [RETURN] `(Method completes)` (L259)

> No explicit return statement — method returns `void`. All instance fields (`db_*` accessors, `ykKigenNDate`) are now initialized and ready for the batch's main processing logic.

| # | Type | Code |
|---|------|------|
| 1 | RETURN | `(implicit return void)` // Initialization complete |

## 7. Glossary

| Term | Type | Business Meaning |
|------|------|------------------|
| `INTR_CD` | Field | Introduction Code — a unique reference/registration code assigned to a customer or service line item for tracking and onboarding purposes |
| `ykKigen` | Field | Validity Period — the expiration timeframe for introduction codes |
| `ykKigenNDate` | Field | Validity Period Addition Days — number of extra days added to the introduction code's expiration date, retrieved from the parameter table |
| `INTR_CD_YK_KIGEN` | Constant | External Definition Key (`"KK_INTR_CD_YK_PRD"`) — the parameter name used to look up the validity period addition days in the work parameter management table |
| `opeDate` | Field | Operation Date — the business date of the current batch run, used to query time-scoped parameters |
| `KK_T_INTR` | Table | Introduction Table — stores introduction code records and their lifecycle status |
| `CK_T_CUST` | Table | Customer Table — stores customer master data referenced during introduction code registration |
| `KK_T_SVC_KEI` | Table | Service Contract Table — stores service contract header records |
| `KK_T_KAISEN_TG_SVKEI` | Table | Line Target Service Contract Table — identifies which service contracts are targets of line-level operations (回線対象サービス契約) |
| `KK_T_SVKEI_KAISEN_UW` | Table | Service Contract Line Details Table — stores detailed line-level information within a service contract (サービス契約回線内訳) |
| `ZM_M_WORK_PARAM_KNRI` | Table | Business Parameter Management Table — stores configurable system parameters including the introduction code validity period |
| `ZM_T_DL_FILE_KANRI` | Table | Downloaded File Management Table — tracks downloaded/processed files for audit and re-processing |
| `ZM_T_DATAIKTTRK_KNRI` | Table | Data Bulk Registration Management Table — manages batch data ingestion and registration tracking (データ一括登録管理) |
| `JBSbatCommonItem` | Class | Batch Common Parameters Envelope — carries shared batch context (operation date, process ID, etc.) throughout the batch pipeline |
| `JBSbatSQLAccess` | Class | Database SQL Access Handler — framework class that encapsulates prepared statement execution against a specific table with a defined SQL key |
| `KKIFM875` | Component | Input File Definition — defines the format and structure of the introduction code batch input file |
| `KKIFM876` | Component | Result List File — output file containing registration results (with timestamp in filename) |
| `KKIFM877` | Component | Error List File — output file containing registration errors (with timestamp in filename) |
| `setCommonInfo` | Method | Inherited service method that configures common batch parameters in the service context |
| `selectBySqlDefine` | Method | Framework method that executes a pre-defined SQL select statement with parameter binding |
| `selectNext` | Method | Framework method that fetches the next row from the result set of a prior `selectBySqlDefine` call |
| `WORK_PARAM_SETTE_VALUE` | Field | Parameter value field — the column/field name holding the actual parameter value in `ZM_M_WORK_PARAM_KNRI` |
| `SEQ_INTR_CD` | Constant | Sequence Name (`"SEQ_INTR_CD"`) — database sequence used to generate sequential introduction codes |
| `INTR_CD_PREFIX` | Constant | Introduction Code Prefix (`"Z"`) — the leading character used in generated introduction codes |
| `ENCODE_SHIFT_JIS` | Constant | File Encoding (`"Shift-JIS"`) — character encoding for input/output files |
| SOD | Acronym | Service Order Data — telecom order fulfillment entity (referenced in error codes) |
| YK | Acronym | 有効期限 (Valid Expiration) — refers to validity period configuration |
| ZM | Prefix | 管理 (Management) — prefix for management/administration tables (e.g., ZM_M_..., ZM_T_...) |
| KK | Prefix | 株 (Kabushiki/K-Opticom) — prefix for K-Opticom core business tables |
| Ika | Term | 一括 (Bulk) — indicates bulk/mass operation |
| Cd | Abbreviation | Code — short for "code" in class/table naming |
