# Business Logic — JBSbatKKAdHenkoErrOutput.execute() [32 LOC]

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

## 1. Role

### JBSbatKKAdHenkoErrOutput.execute()

This method is the **main processing entry point** of a batch job that extracts records with update failures from the **Change Target Address List Work** file (変更住所一覧ワーク). The batch class comment states: "It is a class that extracts items with update failures from the change target address list work" (変更住所一覧ワークから変更不可データ抽出クラスです). It processes both **individual** (個人, kojinnin) and **corporate** (法人, houjin) address records in two separate database read phases.

The method implements a **sequential batch processing pattern**: it performs an initial DB read using SQL definition `KK_SELECT_004` for individual data (kojinhojinKbn=1), delegates row-by-row filtering and field mapping to `printFile()`, then re-initializes the DB access cursor and reads again using SQL definition `KK_SELECT_005` for corporate data (kojinhojinKbn=2). Each phase filters records against 13 validated schema/field combinations, extracts only the error-reason address fields, and builds structured output maps.

Its role in the larger system is to produce output files containing **non-updatable address data** — records where an address update could not be performed during the Change Target Address List Work workflow. The output is segmented into two files (individual and corporate) and populated with address fields that are intentionally cleared to SPACE, leaving only the update failure reason code and identifying metadata.

## 2. Processing Pattern (Detailed Business Logic)

```mermaid
flowchart TD
    START(["execute()"])

    START --> LOG["Log: Main processing
(super.logPrint.printDebugLog)"]
    LOG --> OUT1["Create outputBean
JBSbatOutputItem"]
    OUT1 --> PL1["Create paramList
JBSbatCommonDBInterface"]
    PL1 --> SEL1["dbAccess.selectBySqlDefine
paramList, KK_SELECT_004"]
    SEL1 --> PF1["printFile(outputBean, 1)
Set File 1 - Individual"]

    PF1 --> NEW1["Re-init dbAccess
new JBSbatSQLAccess
commonItem, KK_T_CHG_AD_JGRTWK"]
    NEW1 --> PL2["paramList = new
JBSbatCommonDBInterface"]
    PL2 --> SEL2["dbAccess.selectBySqlDefine
paramList, KK_SELECT_005"]
    SEL2 --> PF2["printFile(outputBean, 2)
Set File 2 - Corporate"]
    PF2 --> RET["Return outputBean"]
    RET --> END(["Next / End"])
```

**Branch descriptions:**

| Step | Type | Description |
|------|------|-------------|
| Step 1 | EXEC | Log entry via `super.logPrint.printDebugLog("主処理")` (Main processing) |
| Step 2 | SET | Create `outputBean` as `new JBSbatOutputItem()` — the output envelope |
| Step 3 | SET + CALL | Create `paramList` and execute `dbAccess.selectBySqlDefine(paramList, "KK_SELECT_004")` — reads personal data from `KK_T_CHG_AD_JGRTWK` |
| Step 4 | CALL | `printFile(outputBean, 1)` — processes File 1 for **individual** (個人) data |
| Step 5 | SET | Re-instantiate `dbAccess = new JBSbatSQLAccess(commonItem, "KK_T_CHG_AD_JGRTWK")` to reset the cursor |
| Step 6 | SET + CALL | Re-create `paramList` and execute `dbAccess.selectBySqlDefine(paramList, "KK_SELECT_005")` — reads corporate data |
| Step 7 | CALL | `printFile(outputBean, 2)` — processes File 2 for **corporate** (法人) data |
| Step 8 | RETURN | Return the fully populated `outputBean` |

## 3. Parameter Analysis

| No | Parameter Name | Type | Business Description |
|----|---------------|------|---------------------|
| - | (none — `inMap` from Javadoc is a remnant of a template) | - | This method takes no parameters. All input comes from the instance fields (`dbAccess`, `commonItem`) initialized during `initial()`. |

### Instance Fields / External State Read

| Field | Type | Business Description |
|-------|------|---------------------|
| `dbAccess` | `JBSbatSQLAccess` | Database access cursor. Initialized in `initial()` against table `KK_T_CHG_AD_JGRTWK` (Change Target Address List Work). Re-initialized mid-method to reset the cursor between the two read phases. |
| `commonItem` | `JBSbatCommonItem` | Batch common parameters (passed to `JBSbatSQLAccess` constructor on re-initialization). |

## 4. CRUD Operations / Called Services

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

| CRUD | SC / CBS | SC Code | Entity / DB | Operation Description |
|------|----------|---------|-------------|----------------------|
| R | `super.logPrint.printDebugLog` | DebugLog | - | Logs debug message "Main processing" via the inherited debug logger |
| R | `JBSbatSQLAccess.selectBySqlDefine` | KK_SELECT_004 / KK_SELECT_005 | `KK_T_CHG_AD_JGRTWK` | Executes SQL definitions `KK_SELECT_004` (individual data) and `KK_SELECT_005` (corporate data) to read from the Change Target Address List Work table |
| R | `JBSbatSQLAccess.selectNext` | - | `KK_T_CHG_AD_JGRTWK` | Iterates row-by-row through the result set within `printFile()` |
| - | `JBSbatKKAdHenkoErrOutput.printFile` | - | - | Core processing method — iterates records, validates schema+field combinations, maps address fields to output |

### Detailed call analysis:

| CRUD | SC / CBS | SC Code | Entity / DB | Operation Description |
|------|----------|---------|-------------|----------------------|
| R | `dbAccess.selectBySqlDefine(paramList, KK_SELECT_004)` | KK_SELECT_004 | `KK_T_CHG_AD_JGRTWK` | Reads personal (individual) address change records from the work table using SQL definition KK_SELECT_004 |
| R | `dbAccess.selectBySqlDefine(paramList, KK_SELECT_005)` | KK_SELECT_005 | `KK_T_CHG_AD_JGRTWK` | Reads corporate (法人) address change records from the work table using SQL definition KK_SELECT_005 |
| R | `printFile(outputBean, 1)` | - | - | Processes File 1: iterates DB rows for individual records, filters by 13 schema/field pairs, populates output map with cleared address fields and failure reason code |
| R | `printFile(outputBean, 2)` | - | - | Processes File 2: iterates DB rows for corporate records, applies same filtering and mapping logic, adds to output list 2 |

## 5. Dependency Trace

| # | Caller (Screen/Batch) | Call Chain (Full Path to this Method) | Terminal (SC / CRUD / Entity) |
|---|----------------------|--------------------------------------|-------------------------------|
| 1 | Batch: JBSbatKKAdHenkoErrOutput | `JBSbatBusinessService.invoke` -> `JBSbatKKAdHenkoErrOutput.execute` | `selectBySqlDefine [R] KK_T_CHG_AD_JGRTWK` |

**Notes:** This class extends `JBSbatBusinessService`, which is the base batch service class. The batch framework invokes `execute()` through the standard batch lifecycle (`initial()` -> `execute()` -> `terminal()`). No external caller (screen/CBS) references this class directly — it is a standalone batch job.

## 6. Per-Branch Detail Blocks

### Block 1 — EXEC (L99)

> Log the start of main processing.

| # | Type | Code |
|---|------|------|
| 1 | EXEC | `super.logPrint.printDebugLog("主処理")` // Log: Main processing (主処理) |

### Block 2 — SET (L102)

> Create the output envelope.

| # | Type | Code |
|---|------|------|
| 1 | SET | `JBSbatOutputItem outputBean = new JBSbatOutputItem()` // Output common envelope (出力共通電文) |

### Block 3 — SET (L105)

> Create parameter list for the first DB read.

| # | Type | Code |
|---|------|------|
| 1 | SET | `JBSbatCommonDBInterface paramList = new JBSbatCommonDBInterface()` // Variable list generation (バイト変数のリストを生成します) |

### Block 4 — EXEC (L107)

> Execute first SQL definition to read individual data.

| # | Type | Code |
|---|------|------|
| 1 | CALL | `dbAccess.selectBySqlDefine(paramList, "KK_SELECT_004")` // Execute DB access (DBアクセスを実行します) |

### Block 5 — CALL (L109)

> Process File 1 — individual (個人) data.

| # | Type | Code |
|---|------|------|
| 1 | CALL | `printFile(outputBean, 1)` // Set File 1 information — Individual (ファイル目の情報を設定(個人)) |

### Block 6 — SET (L112)

> Re-initialize the DB access cursor for the second read phase.

| # | Type | Code |
|---|------|------|
| 1 | SET | `dbAccess = new JBSbatSQLAccess(commonItem, "KK_T_CHG_AD_JGRTWK")` // Generate DB access cursor (DBアクセスクローズを生成します) — re-creates cursor on same table |

### Block 7 — SET (L115)

> Re-create parameter list for the second DB read.

| # | Type | Code |
|---|------|------|
| 1 | SET | `paramList = new JBSbatCommonDBInterface()` // Variable list generation (バイト変数のリストを生成します) |

### Block 8 — EXEC (L117)

> Execute second SQL definition to read corporate data.

| # | Type | Code |
|---|------|------|
| 1 | CALL | `dbAccess.selectBySqlDefine(paramList, "KK_SELECT_005")` // Execute DB access (DBアクセスを実行します) |

### Block 9 — CALL (L119)

> Process File 2 — corporate (法人) data.

| # | Type | Code |
|---|------|------|
| 1 | CALL | `printFile(outputBean, 2)` // Set File 2 information — Corporate (ファイル目の情報を設定(法人)) |

### Block 10 — RETURN (L121)

> Return the fully populated output.

| # | Type | Code |
|---|------|------|
| 1 | RETURN | `return outputBean` // Return output info (出力情報) |

## 7. Glossary

| Term | Type | Business Meaning |
|------|------|------------------|
| `KK_T_CHG_AD_JGRTWK` | Table | Change Target Address List Work — temporary work table holding records of addresses targeted for modification during batch processing |
| `KK_SELECT_004` | SQL Def | SQL definition for reading individual (個人) address change records |
| `KK_SELECT_005` | SQL Def | SQL definition for reading corporate (法人) address change records |
| `kojinhojinKbn` | Field | Individual/Corporate classification — 1 = individual (個人), 2 = corporate (法人). Determines which output list the data is appended to. |
| `CHG_AD_JGRTWK_NO` | Field | Change target address work number — internal tracking ID for address work records |
| `SYSID` | Field | System ID — unique identifier for the system that generated the record |
| `SVC_KEI_NO` | Field | Service type number — identifies the service category associated with the address record |
| `CHG_TG_SCHEMA_ID` | Field | Change target schema ID — identifies the data schema/table type for the change target |
| `CHG_TG_KMK_NM_EINM` | Field | Change target company name (English) — the company name field of the change target |
| `AD_TOHAIGO_UPD_FAIL_RSN_CD` | Field | Address post-update failure reason code — indicates why an address update failed after processing |
| `SVKEI_KAISEN_UW_SKEMA_ID` | Constant | Schema ID "KK0251" — Service Contract Line Item (internal) |
| `SVKEIUW_EOH_TEL_SKEMA_ID` | Constant | Schema ID "KK0191" — Service Contract Details (eo Hikari Phone) |
| `KKTK_SVC_KEI_SKEMA_ID` | Constant | Schema ID "KK0341" |
| `OPSVKEI_TV_SKEMA_ID` | Constant | Schema ID "KK0381" — Optional Service Contract (TV) |
| `SEIKY_KEI_SKEMA_ID` | Constant | Schema ID "KK0491" — Billing Contract |
| `KOJIAK_SKEMA_ID` | Constant | Schema ID "KU0011" — Work Project |
| `BMP_KOJI_SKEMA_ID` | Constant | Schema ID "TU0011" — Benchmark Work |
| `DOBANITEN_SKEMA_ID` | Constant | Schema ID "TU0021" — Number Portability |
| `DNWACHOMSK_NYO_SKEMA_ID` | Constant | Schema ID "TU0091" — Telephone Bill Application Details |
| `CUST_SKEMA_ID` | Constant | Schema ID "CK0011" — Customer |
| `JBSbatKKIFE087` | Class | Interface file class for output field definitions (address-related output fields) |
| `JBSbatOutputItem` | Class | Output envelope — container for output data maps |
| `JBSbatServiceInterfaceMap` | Class | Service interface map — holds structured key-value pairs for output data |
| 個人 (Kojin) | Business term | Individual customer — kojinhojinKbn = 1 |
| 法人 (Houjin) | Business term | Corporate customer — kojinhojinKbn = 2 |
| 変更住所一覧ワーク | Business term | Change Target Address List Work — the source work file/table for this batch |
| 変更不可データ | Business term | Non-updateable data — records that could not be updated during address modification processing |
| SPACE | Constant | Empty string "" — used to clear all address fields to blank in the output |
