# Business Logic — JBSbatKKAdHenkoErrOutput.printFile() [401 LOC]

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

## 1. Role

### JBSbatKKAdHenkoErrOutput.printFile()

This method outputs an **unmodifiable address change list file** (市区町村合併・住所呼称変更不可リスト) containing records from the "Change Target Address List Work Table" (`JBSbatKK_T_CHG_AD_JGRTWK`) that **cannot** be processed due to being excluded from municipal merger or address designation change operations. It acts as the **error/exception extraction step** in a batch address-processing pipeline: after a broader set of address records have been evaluated, this service scans the work table for records whose schema type and item name match predefined *exclusion patterns*, then groups those valid error records by SYSID and SVC_KEI_NO and writes them out.

The method implements a **routing/dispatch pattern**: each qualifying row is inspected against **14 exclusion-type branches** tied to different schema IDs (Customer, Service Contract, Equipment Supply, Billing, BMP Project, etc.) and item name combinations (e.g., `KAISEN_PLACE_AD_CD`, `EMG_AD_CD`, `KEISHA_AD_CD`). For each branch, it copies the relevant old or new address fields from the input work table into the output map using a schema-based dispatcher.

It also serves as a **status updater**: for every qualifying row processed, it sets the `AD_TOHAIGO_TRN_STAT_CD` (Change Target Address Transition Status Code) to `"9"` (Processing Complete — 住所統廃合処理ステータス（処理完了）) on the work table, marking the record as consumed.

The output is split into **two streams** based on `kojinhojinKbn` (Individual vs. Corporate classification): individual records (Kbn=1) go to `addOutMapList`, while corporate records (Kbn=2) go to `addOutMapList_2`.

## 2. Processing Pattern (Detailed Business Logic)

```mermaid
flowchart TD
    START(["printFile outputBean, kojinhojinKbn"])
    INIT["Initialize: insFlag=false, outmap, strSYSID, strSVC_KEI_NO"]
    LOOP_START{"dbAccess.selectNext has data?"}
    READ["Read: CHG_AD_JGRTWK_NO, SYSID, SVC_KEI_NO, schemaId, itemName"]
    TRIM["Trim itemName"]
    CHECK_SKIP{"Skip condition met?"}
    SKIP["Continue to next row"]
    
    CHECK_CHANGE{"SYSID changed OR SVC_KEI_NO changed?"}
    PREV_GROUP["Output previous group:
  setOutFlg(true)
  addOutMapList or addOutMapList_2
  Reset outmap"]
    RESET_FIELDS["Reset all ~80 address fields to SPACE (empty)"]
    
    SET_KEYS["Set AD_TOHAIGO_UPD_FAIL_RSN_CD, SYSID, SVC_KEI_NO"]
    NEW_ADDR{"NEW_AD_CD is not null?"}
    ORIG_ADDR["Use NEW address fields with hyhunPcd for PCD"]
    ORIG_ADDR2["Use ORIGINAL address fields with hyhunPcd for PCD"]
    
    BRANCH_SVKEI["KK0251 + KAISEN_PLACE_AD_CD:
Copy OLD address to KAISEN_PLACE fields"]
    BRANCH_EMG["KK0191 + EMG_AD_CD:
Copy OLD address to EMG fields (3-part address)"]
    BRANCH_KIKI_STC["KK0341 + KIKI_STC_SAKI_AD_CD:
Copy OLD address to KIKI_STC_SAKI fields"]
    BRANCH_KIKI_SOHUS["KK0341 + KIKI_SOHUS_AD_CD:
Copy OLD address to KIKI_SOHUS fields"]
    BRANCH_GUIDE["KK0381 + GUIDEMG_SOHUS_AD_CD:
Copy OLD address to GUIDEMG fields"]
    BRANCH_CUST["CK0011 + KEISHA_AD_CD:
Copy OLD address to KEISHA fields"]
    BRANCH_CSSTI["CK0011 + CSSTI_SHS_AD_CD:
Copy OLD address to CSSTI_SHS fields"]
    BRANCH_SKSHA["Individual(1) + CK0021 + SKSHA_AD_CD:
Copy OLD address to SKSHA fields"]
    BRANCH_NTT["TU0011 + NTT_KEISHA_AD_CD:
Copy OLD address to NTT_KEISHA fields"]
    BRANCH_SETPLACE["TU0011 + SETPLACE_AD_CD:
Copy OLD address to SETPLACE fields"]
    BRANCH_KANYKN["TU0011 + KANYKN_ITENS_AD_CD:
Copy OLD address to KANYKN_ITENS fields"]
    BRANCH_DOBAN["TU0021 + SETPLACE_AD_CD:
Copy OLD address to DOBANITEN fields"]
    BRANCH_KEISAI["TU0091 + KEISAI_AD_CD:
Copy OLD address to KEISAI fields"]
    BRANCH_DNWACHO["TU0091 + SETPLACE_AD_CD:
Copy OLD address to DNWACHO fields"]
    BRANCH_SEIKY["KK0491 + SOHUS_AD_CD:
Copy OLD address + SEIKY_KEI_NO to SOHUS fields"]
    
    UPDATE_ROW["Update CHG_AD_JGRTWK:
Set AD_TOHAIGO_TRN_STAT_CD = 9 (Processing Complete)"]
    TRACK["Update: strSYSID, strSVC_KEI_NO, insFlag=true"]
    
    FINAL_CHECK{"insFlag is true?"}
    FINAL_OUTPUT["Output last group:
  setOutFlg(true)
  addOutMapList or addOutMapList_2"]
    END_NODE(["End"])
    
    START --> INIT --> LOOP_START
    LOOP_START -->|Yes| READ
    READ --> TRIM
    TRIM --> CHECK_SKIP
    CHECK_SKIP -->|Skip| SKIP
    SKIP --> LOOP_START
    CHECK_SKIP -->|Process| CHECK_CHANGE
    CHECK_CHANGE -->|Yes| PREV_GROUP
    PREV_GROUP --> RESET_FIELDS
    CHECK_CHANGE -->|No| RESET_FIELDS
    RESET_FIELDS --> SET_KEYS
    SET_KEYS --> NEW_ADDR
    NEW_ADDR -->|Yes| ORIG_ADDR
    NEW_ADDR -->|No| ORIG_ADDR2
    ORIG_ADDR --> BRANCH_SVKEI
    ORIG_ADDR2 --> BRANCH_SVKEI
    BRANCH_SVKEI --> BRANCH_EMG
    BRANCH_EMG --> BRANCH_KIKI_STC
    BRANCH_KIKI_STC --> BRANCH_KIKI_SOHUS
    BRANCH_KIKI_SOHUS --> BRANCH_GUIDE
    BRANCH_GUIDE --> BRANCH_CUST
    BRANCH_CUST --> BRANCH_CSSTI
    BRANCH_CSSTI --> BRANCH_SKSHA
    BRANCH_SKSHA --> BRANCH_NTT
    BRANCH_NTT --> BRANCH_SETPLACE
    BRANCH_SETPLACE --> BRANCH_KANYKN
    BRANCH_KANYKN --> BRANCH_DOBAN
    BRANCH_DOBAN --> BRANCH_KEISAI
    BRANCH_KEISAI --> BRANCH_DNWACHO
    BRANCH_DNWACHO --> BRANCH_SEIKY
    BRANCH_SEIKY --> UPDATE_ROW
    UPDATE_ROW --> TRACK
    TRACK --> LOOP_START
    LOOP_START -->|No| FINAL_CHECK
    FINAL_CHECK -->|Yes| FINAL_OUTPUT
    FINAL_OUTPUT --> END_NODE
    FINAL_CHECK -->|No| END_NODE
```

## 3. Parameter Analysis

| No | Parameter Name | Type | Business Description |
|----|---------------|------|---------------------|
| 1 | `outputBean` | `JBSbatOutputItem` | The output data carrier that collects all processed error rows. Acts as a buffer that accumulates mapped address change failure records. The method calls `addOutMapList` or `addOutMapList_2` on this bean to append each completed group. |
| 2 | `kojinhojinKbn` | `int` | **Individual/Corporate classification** (個人区分). Determines the output stream: value `1` = Individual (個人) records, routed to `addOutMapList`; value `2` = Corporate (法人) records, routed to `addOutMapList_2`. Also gates the `SKSHA` (Sponsor) address fields, which are only populated for individual customers. |

**Instance fields read by this method:**

| Field | Type | Business Description |
|-------|------|---------------------|
| `dbAccess` | `JBSbatSQLAccess` | DB access object iterating over rows from the Change Target Address List Work Table (`JBSbatKK_T_CHG_AD_JGRTWK`). Provides `selectNext()` for row-by-row cursor traversal. |
| `db_CHG_AD_JGRTWK` | `JBSbatSQLAccess` | DB access object used to UPDATE the `JBSbatKK_T_CHG_AD_JGRTWK` table, setting the transition status to "Processing Complete" (9) for each qualifying row. |

## 4. CRUD Operations / Called Services

| CRUD | SC / CBS | SC Code | Entity / DB | Operation Description |
|------|----------|---------|-------------|----------------------|
| R | `dbAccess.selectNext` | JBSbatKKAdHenkoErrOutput | `JBSbatKK_T_CHG_AD_JGRTWK` (work table) | Reads rows one-by-one from the Change Target Address List Work Table via cursor iteration |
| R | `JBSbatKKAdHenkoErrOutput.getInMapData` | JBSbatKKAdHenkoErrOutput | - | Extracts a string value from the input map by key, returning empty string for null (local helper method) |
| R | `JBSbatKK_T_CHG_AD_JGRTWK.getString` | JBSbatKK_T_CHG_AD_JGRTWK | `JBSbatKK_T_CHG_AD_JGRTWK` work table | Retrieves specific column values (SYSID, SVC_KEI_NO, schemaId, address fields, etc.) from current row |
| C | `JBSbatKKIFE087.setString` | JBSbatKKIFE087 | - | Sets output fields on the interface map (~110+ field assignments per row) |
| R | `JBSbatKKIFE087` constants | JBSbatKKIFE087 | - | References output column constants (AD_TOHAIGO_UPD_FAIL_RSN_CD, SYSID, SVC_KEI_NO, AD_CD, PCD, STATE_NM, CITY_NM, etc.) |
| U | `db_CHG_AD_JGRTWK.updateByPrimaryKeys` | JBSbatKKAdHenkoErrOutput | `JBSbatKK_T_CHG_AD_JGRTWK` table | Updates the transition status code (`AD_TOHAIGO_TRN_STAT_CD`) to `"9"` (Processing Complete) on the work table by primary key |
| - | `JBSbatOutputItem.addOutMapList` | JBSbatOutputItem | - | Appends output map to individual customer stream |
| - | `JBSbatOutputItem.addOutMapList_2` | JBSbatOutputItem | - | Appends output map to corporate customer stream |
| - | `JBSbatServiceInterfaceMap.setOutFlg` | JBSbatServiceInterfaceMap | - | Marks output map with flag indicating group completion |
| - | `JPCUtilCommon.hyhunPcd` | JPCUtilCommon | - | Hyphenates postal codes between 3rd and 4th digit (e.g., `1234567` → `123-4567`) |
| - | `JBSbatCommonDBInterface.setValue` | JBSbatCommonDBInterface | - | Sets key-value pairs in `valueMap` and `whereMap` for the UPDATE operation |

## 5. Dependency Trace

| # | Caller (Screen/Batch) | Call Chain (Full Path to this Method) | Terminal (SC / CRUD / Entity) |
|---|----------------------|--------------------------------------|-------------------------------|
| 1 | Batch: `JBSbatKKAdHenkoErrOutput.execute()` | `JBSbatKKAdHenkoErrOutput.execute()` -> `printFile(outputBean, kojinhojinKbn)` | `selectNext [R] JBSbatKK_T_CHG_AD_JGRTWK`, `updateByPrimaryKeys [U] JBSbatKK_T_CHG_AD_JGRTWK`, `addOutMapList [C] Output Bean`, `addOutMapList_2 [C] Output Bean` |

## 6. Per-Branch Detail Blocks

**Block 1** — SET (Initializations) (L153)

> Initialize local variables and create the first output map buffer before entering the row-processing loop.

| # | Type | Code |
|---|------|------|
| 1 | SET | `inMap = null` |
| 2 | SET | `insFlag = false` |
| 3 | SET | `strSYSID = ""` |
| 4 | SET | `strSVC_KEI_NO = ""` |
| 5 | SET | `outmap = new JBSbatServiceInterfaceMap()` |

**Block 2** — FOR (Row Iteration) (L155)

> Iterate through all rows from the SQL result set using `dbAccess.selectNext()`.

| # | Type | Code |
|---|------|------|
| 1 | SET | `inMap = dbAccess.selectNext()` |
| 2 | CONDITION | `null != inMap` (loop condition) |

**Block 2.1** — SET (Read from Input Row) (L157)

> Extract all relevant fields from the current work table row into local variables.

| # | Type | Code |
|---|------|------|
| 1 | SET | `strChgAdJgrtwkNo = inMap.getString(JBSbatKK_T_CHG_AD_JGRTWK.CHG_AD_JGRTWK_NO)` |
| 2 | SET | `strSysId = inMap.getString(JBSbatKK_T_CHG_AD_JGRTWK.SYSID)` |
| 3 | SET | `strSvcKeiNo = inMap.getString(JBSbatKK_T_CHG_AD_JGRTWK.SVC_KEI_NO)` |
| 4 | SET | `strSkemaId = inMap.getString(JBSbatKK_T_CHG_AD_JGRTWK.CHG_TG_SCHEMA_ID)` |
| 5 | EXEC | `strItemName = inMap.getString(JBSbatKK_T_CHG_AD_JGRTWK.CHG_TG_KMK_NM_EINM).trim()` |

**Block 2.2** — IF (Skip Condition — 14 exclusion branches) (L159)

> A complex negated condition that **skips** rows whose (schemaId, itemName) pair does NOT match any of the 14 defined exclusion patterns. Uses De Morgan's law: all 14 conditions must be false for the row to be skipped (via `continue`).

```
If ANY of these pairs match, the row is processed (NOT skipped):
  KK0251 + "KAISEN_PLACE_AD_CD" (Merged Place Address Code)
  KK0191 + "EMG_AD_CD" (Emergency Address Code)
  KK0341 + "KIKI_STC_SAKI_AD_CD" (Equipment Installation Destination Address Code)
  KK0341 + "KIKI_SOHUS_AD_CD" (Equipment Delivery Destination Address Code)
  KK0381 + "GUIDEMG_SOHUS_AD_CD" (Guide Residence Delivery Address Code)
  CK0011 + "KEISHA_AD_CD" (Customer Address Code)
  CK0011 + "CSSTI_SHS_AD_CD" (Designated Delivery Address Code)
  TU0011 + "NTT_KEISHA_AD_CD" (BMP Project NTT Customer Address Code)
  TU0011 + "SETPLACE_AD_CD" (BMP Project Installation Place Address Code)
  TU0011 + "KANYKN_ITENS_AD_CD" (BMP Project Transfer Destination Address Code)
  TU0021 + "SETPLACE_AD_CD" (Number Portability Installation Place Address Code)
  TU0091 + "KEISAI_AD_CD" (Phone Bill Publication Address Code)
  TU0091 + "SETPLACE_AD_CD" (Phone Bill Installation Place Address Code)
  KK0491 + "SOHUS_AD_CD" (Billing Contract Delivery Address Code)
```

| # | Type | Code |
|---|------|------|
| 1 | EXEC | `continue` (if skip condition is true, skip to next row) |

**Block 2.3** — IF (Group Boundary Check) (L176)

> When the SYSID changes or the SVC_KEI_NO changes (from the previous row), the current accumulated output group is finalized and written out. This implements **batching by (SYSID, SVC_KEI_NO)** — each unique combination forms a logical output group.

| # | Type | Code |
|---|------|------|
| 1 | IF | `insFlag` is true (previous group exists) — (L178) |
| 1.1 | SET | `outmap.setOutFlg(true)` — marks output flag |
| 1.2 | IF | `kojinhojinKbn == 1` (Individual) — (L181) |
| 1.2.1 | CALL | `outputBean.addOutMapList(outmap)` — appends to individual stream |
| 1.3 | ELSE | `kojinhojinKbn != 1` (Corporate) — (L183) |
| 1.3.1 | CALL | `outputBean.addOutMapList_2(outmap)` — appends to corporate stream |
| 2 | SET | `insFlag = false` |
| 3 | SET | `outmap = new JBSbatServiceInterfaceMap()` — resets output buffer |

**Block 2.4** — SET (Set Key Fields) (L188)

> Copy the failure reason code, SYSID, and SVC_KEI_NO from input to output.

| # | Type | Code |
|---|------|------|
| 1 | SET | `outmap.setString(AD_TOHAIGO_UPD_FAIL_RSN_CD, inMap.getString(AD_TOHAIGO_UPD_FAIL_RSN_CD))` |
| 2 | SET | `outmap.setString(SYSID, inMap.getString(SYSID))` |
| 3 | SET | `outmap.setString(SVC_KEI_NO, inMap.getString(SVC_KEI_NO))` |

**Block 2.5** — SET (Reset All Address Fields to Empty) (L190)

> Initializes ~110 address-related output fields to `SPACE` (empty string `""`). Covers 14 address categories (base address, merger place, emergency, equipment, guide, customer, designated delivery, sponsor, NTT, BMP project, number portability, phone bill, billing). Each category has AD_CD, PCD, STATE_NM, CITY_NM, OAZTSU_NM, AZCHO_NM fields.

| # | Type | Code |
|---|------|------|
| 1–15 | SET | Base address: AD_CD, PCD, STATE_NM, CITY_NM, OAZTSU_NM, AZCHO_NM to `SPACE` |
| 16–21 | SET | KAISEN_PLACE: KAISEN_PLACE_AD_CD, KAISEN_PLACE_PCD, KAISEN_PLACE_STATE_NM, KAISEN_PLACE_CITY_NM, KAISEN_PLACE_OAZTSU_NM, KAISEN_PLACE_AZCHO_NM to `SPACE` |
| 22–25 | SET | EMG: EMG_AD_CD, EMG_HOSEI_PCD, EMG_ADD1_NM, EMG_ADD2_NM, EMG_ADD3_NM to `SPACE` |
| 26–31 | SET | KIKI_STC_SAKI: AD_CD, PCD, STATE_NM, CITY_NM, OAZTSU_NM, AZCHO_NM to `SPACE` |
| 32–37 | SET | KIKI_SOHUS: AD_CD, PCD, STATE_NM, CITY_NM, OAZTSU_NM, AZCHO_NM to `SPACE` |
| 38–43 | SET | GUIDEMG_SOHUS: AD_CD, PCD, STATE_NM, CITY_NM, OAZTSU_NM, AZCHO_NM to `SPACE` |
| 44–49 | SET | KEISHA: AD_CD, PCD, STATE_NM, CITY_NM, OAZTSU_NM, AZCHO_NM to `SPACE` |
| 50–55 | SET | CSSTI_SHS: AD_CD, PCD, STATE_NM, CITY_NM, OAZTSU_NM, AZCHO_NM to `SPACE` |
| 56–61 | SET | NTT_KEISHA: AD_CD, PCD, STATE_NM, CITY_NM, OAZTSU_NM, AZCHO_NM to `SPACE` |
| 62–67 | SET | SETPLACE: AD_CD, PCD, STATE_NM, CITY_NM, OAZTSU_NM, AZCHO_NM to `SPACE` |
| 68–73 | SET | KANYKN_ITENS: AD_CD, PCD, STATE_NM, CITY_NM, OAZTSU_NM, AZCHO_NM to `SPACE` |
| 74–79 | SET | DOBANITEN_SETPLACE: AD_CD, PCD, STATE_NM, CITY_NM, OAZTSU_NM, AZCHO_NM to `SPACE` |
| 80–85 | SET | KEISAI: AD_CD, PCD, STATE_NM, CITY_NM, OAZTSU_NM, AZCHO_NM to `SPACE` |
| 86–91 | SET | DNWACHO_SETPLACE: AD_CD, PCD, STATE_NM, CITY_NM, OAZTSU_NM, AZCHO_NM to `SPACE` |
| 92–93 | SET | SOHUS_AD_CD, SOHUS_PCD, SOHUS_STATE_NM, SOHUS_CITY_NM, SOHUS_OAZTSU_NM, SOHUS_AZCHO_NM to `SPACE` |
| 94–95 | SET | SEIKY_KEI_NO to `SPACE` |

**Block 2.5.1** — IF (Individual Customer — Sponsor Fields) (L198)

> For individual customers only, also initialize sponsor (SKSHA) address fields to empty.

| # | Type | Code |
|---|------|------|
| 1 | IF | `kojinhojinKbn == 1` (Individual) |
| 1.1–1.6 | SET | SKSHA_AD_CD, SKSHA_PCD, SKSHA_STATE_NM, SKSHA_CITY_NM, SKSHA_OAZTSU_NM, SKSHA_AZCHO_NM to `SPACE` |

**Block 2.6** — IF (New vs. Original Address Branch) (L205)

> Determines whether to use the NEW address (post-change) or ORIGINAL address (pre-change) fields for the base output address.

| # | Type | Code |
|---|------|------|
| 1 | IF | `null != inMap.getString(NEW_AD_CD)` (NEW_AD_CD is not null — new address exists) |
| 1.1 | SET | `AD_CD = getInMapData(inMap, NEW_AD_CD)` |
| 1.2 | SET | `PCD = hyhunPcd(getInMapData(inMap, NEW_PCD))` — hyphenates postal code (3rd–4th digit) |
| 1.3 | SET | `STATE_NM = getInMapData(inMap, NEW_STATE_NM)` |
| 1.4 | SET | `CITY_NM = getInMapData(inMap, NEW_CITY_NM)` |
| 1.5 | SET | `OAZTSU_NM = getInMapData(inMap, NEW_OAZTSU_NM)` |
| 1.6 | SET | `AZCHO_NM = getInMapData(inMap, NEW_AZCHO_NM)` |
| 2 | ELSE | NEW_AD_CD is null — use original address |
| 2.1 | SET | `AD_CD = getInMapData(inMap, AD_CD)` |
| 2.2 | SET | `PCD = hyhunPcd(getInMapData(inMap, PCD))` — hyphenates postal code |
| 2.3 | SET | `STATE_NM = getInMapData(inMap, STATE_NM)` |
| 2.4 | SET | `CITY_NM = getInMapData(inMap, CITY_NM)` |
| 2.5 | SET | `OAZTSU_NM = getInMapData(inMap, OAZTSU_NM)` |
| 2.6 | SET | `AZCHO_NM = getInMapData(inMap, AZCHO_NM)` |

**Block 2.7** — IF (Branch: KK0251 — Service Contract Line Details / Merged Place) (L230)

> When `schemaId == "KK0251"` AND `itemName == "KAISEN_PLACE_AD_CD"`, copy the OLD address fields to the KAISEN_PLACE (merged place) output fields.

| # | Type | Code |
|---|------|------|
| 1 | SET | `KAISEN_PLACE_AD_CD = getInMapData(inMap, OLD_AD_CD)` |
| 2 | SET | `KAISEN_PLACE_PCD = hyhunPcd(getInMapData(inMap, OLD_PCD))` |
| 3 | SET | `KAISEN_PLACE_STATE_NM = getInMapData(inMap, OLD_STATE_NM)` |
| 4 | SET | `KAISEN_PLACE_CITY_NM = getInMapData(inMap, OLD_CITY_NM)` |
| 5 | SET | `KAISEN_PLACE_OAZTSU_NM = getInMapData(inMap, OLD_OAZTSU_NM)` |
| 6 | SET | `KAISEN_PLACE_AZCHO_NM = getInMapData(inMap, OLD_AZCHO_NM)` |

**Block 2.8** — IF (Branch: KK0191 — eo Hikari Phone / Emergency) (L240)

> When `schemaId == "KK0191"` AND `itemName == "EMG_AD_CD"`, copy the OLD address to the EMG (emergency) output fields. The 3-part address (ADD1, ADD2, ADD3) is constructed by concatenating components.

| # | Type | Code |
|---|------|------|
| 1 | SET | `strADD1 = OLD_STATE_NM + OLD_CITY_NM + OLD_OAZTSU_NM + OLD_AZCHO_NM` |
| 2 | SET | `strADD2 = OLD_BNCHIGO` |
| 3 | SET | `strADD3 = OLD_ADRTTM + OLD_ADRRM` |
| 4 | SET | `EMG_AD_CD = getInMapData(inMap, OLD_AD_CD)` |
| 5 | SET | `EMG_HOSEI_PCD = hyhunPcd(getInMapData(inMap, OLD_PCD))` |
| 6 | SET | `EMG_ADD1_NM = strADD1` |
| 7 | SET | `EMG_ADD2_NM = strADD2` |
| 8 | SET | `EMG_ADD3_NM = strADD3` |

**Block 2.9** — IF (Branch: KK0341 — Equipment Supply / Installation Destination) (L252)

> When `schemaId == "KK0341"` AND `itemName == "KIKI_STC_SAKI_AD_CD"`, copy the OLD address to KIKI_STC_SAKI (equipment installation destination) fields.

| # | Type | Code |
|---|------|------|
| 1 | SET | `KIKI_STC_SAKI_AD_CD = getInMapData(inMap, OLD_AD_CD)` |
| 2 | SET | `KIKI_STC_SAKI_PCD = hyhunPcd(getInMapData(inMap, OLD_PCD))` |
| 3 | SET | `KIKI_STC_SAKI_STATE_NM = getInMapData(inMap, OLD_STATE_NM)` |
| 4 | SET | `KIKI_STC_SAKI_CITY_NM = getInMapData(inMap, OLD_CITY_NM)` |
| 5 | SET | `KIKI_STC_SAKI_OAZTSU_NM = getInMapData(inMap, OLD_OAZTSU_NM)` |
| 6 | SET | `KIKI_STC_SAKI_AZCHO_NM = getInMapData(inMap, OLD_AZCHO_NM)` |

**Block 2.10** — IF (Branch: KK0341 — Equipment Supply / Delivery Destination) (L264)

> When `schemaId == "KK0341"` AND `itemName == "KIKI_SOHUS_AD_CD"`, copy the OLD address to KIKI_SOHUS (equipment delivery destination) fields.

| # | Type | Code |
|---|------|------|
| 1–6 | SET | KIKI_SOHUS_AD_CD, PCD, STATE_NM, CITY_NM, OAZTSU_NM, AZCHO_NM from OLD address fields |

**Block 2.11** — IF (Branch: KK0381 — Option TV / Guide Residence) (L276)

> When `schemaId == "KK0381"` AND `itemName == "GUIDEMG_SOHUS_AD_CD"`, copy the OLD address to GUIDEMG_SOHUS (guide residence delivery) fields.

| # | Type | Code |
|---|------|------|
| 1–6 | SET | GUIDEMG_SOHUS_AD_CD, PCD, STATE_NM, CITY_NM, OAZTSU_NM, AZCHO_NM from OLD address fields |

**Block 2.12** — IF (Branch: CK0011 — Customer / Customer Address) (L288)

> When `schemaId == "CK0011"` AND `itemName == "KEISHA_AD_CD"`, copy the OLD address to KEISHA (customer address) fields.

| # | Type | Code |
|---|------|------|
| 1–6 | SET | KEISHA_AD_CD, PCD, STATE_NM, CITY_NM, OAZTSU_NM, AZCHO_NM from OLD address fields |

**Block 2.13** — IF (Branch: CK0011 — Customer / Designated Delivery) (L300)

> When `schemaId == "CK0011"` AND `itemName == "CSSTI_SHS_AD_CD"`, copy the OLD address to CSSTI_SHS (designated delivery destination) fields.

| # | Type | Code |
|---|------|------|
| 1–6 | SET | CSSTI_SHS_AD_CD, PCD, STATE_NM, CITY_NM, OAZTSU_NM, AZCHO_NM from OLD address fields |

**Block 2.14** — IF (Branch: CK0021 — Individual Customer / Sponsor Address) (L312)

> When `kojinhojinKbn == 1` AND `schemaId == "CK0021"` AND `itemName == "SKSHA_AD_CD"`, copy the OLD address to SKSHA (sponsor address) fields. Only applicable for individual customers.

| # | Type | Code |
|---|------|------|
| 1 | IF | `kojinhojinKbn == 1` (Individual) |
| 1.1 | IF | `CUST_KOJIN_SKEMA_ID` && `"SKSHA_AD_CD"` |
| 1.1.1 | SET | SKSHA_AD_CD, PCD (hyhunPcd), STATE_NM, CITY_NM, OAZTSU_NM, AZCHO_NM from OLD address fields |

**Block 2.15** — IF (Branch: TU0011 — BMP Project / NTT Customer Address) (L326)

> When `schemaId == "TU0011"` AND `itemName == "NTT_KEISHA_AD_CD"`, copy the OLD address to NTT_KEISHA (BMP Project NTT customer address) fields.

| # | Type | Code |
|---|------|------|
| 1–6 | SET | NTT_KEISHA_AD_CD, PCD, STATE_NM, CITY_NM, OAZTSU_NM, AZCHO_NM from OLD address fields |

**Block 2.16** — IF (Branch: TU0011 — BMP Project / Installation Place) (L338)

> When `schemaId == "TU0011"` AND `itemName == "SETPLACE_AD_CD"`, copy the OLD address to SETPLACE (BMP project installation place) fields.

| # | Type | Code |
|---|------|------|
| 1–6 | SET | SETPLACE_AD_CD, PCD, STATE_NM, CITY_NM, OAZTSU_NM, AZCHO_NM from OLD address fields |

**Block 2.17** — IF (Branch: TU0011 — BMP Project / Transfer Destination) (L350)

> When `schemaId == "TU0011"` AND `itemName == "KANYKN_ITENS_AD_CD"`, copy the OLD address to KANYKN_ITENS (BMP project transfer destination) fields.

| # | Type | Code |
|---|------|------|
| 1–6 | SET | KANYKN_ITENS_AD_CD, PCD, STATE_NM, CITY_NM, OAZTSU_NM, AZCHO_NM from OLD address fields |

**Block 2.18** — IF (Branch: TU0021 — Number Portability / Installation Place) (L362)

> When `schemaId == "TU0021"` AND `itemName == "SETPLACE_AD_CD"`, copy the OLD address to DOBANITEN_SETPLACE (number portability installation place) fields.

| # | Type | Code |
|---|------|------|
| 1–6 | SET | DOBANITEN_SETPLACE_AD_CD, PCD, STATE_NM, CITY_NM, OAZTSU_NM, AZCHO_NM from OLD address fields |

**Block 2.19** — IF (Branch: TU0091 — Phone Bill / Publication Address) (L374)

> When `schemaId == "TU0091"` AND `itemName == "KEISAI_AD_CD"`, copy the OLD address to KEISAI (phone bill publication address) fields.

| # | Type | Code |
|---|------|------|
| 1–6 | SET | KEISAI_AD_CD, PCD, STATE_NM, CITY_NM, OAZTSU_NM, AZCHO_NM from OLD address fields |

**Block 2.20** — IF (Branch: TU0091 — Phone Bill / Installation Place) (L386)

> When `schemaId == "TU0091"` AND `itemName == "SETPLACE_AD_CD"`, copy the OLD address to DNWACHO_SETPLACE (phone bill installation place) fields.

| # | Type | Code |
|---|------|------|
| 1–6 | SET | DNWACHO_SETPLACE_AD_CD, PCD, STATE_NM, CITY_NM, OAZTSU_NM, AZCHO_NM from OLD address fields |

**Block 2.21** — IF (Branch: KK0491 — Billing Contract / Delivery Address) (L398)

> When `schemaId == "KK0491"` AND `itemName == "SOHUS_AD_CD"`, copy the OLD address plus SEIKY_KEI_NO to SOHUS (billing contract delivery address) fields.

| # | Type | Code |
|---|------|------|
| 1 | SET | `SEIKY_KEI_NO = getInMapData(inMap, SEIKY_KEI_NO)` |
| 2 | SET | `SOHUS_AD_CD = getInMapData(inMap, OLD_AD_CD)` |
| 3 | SET | `SOHUS_PCD = hyhunPcd(getInMapData(inMap, OLD_PCD))` |
| 4 | SET | `SOHUS_STATE_NM = getInMapData(inMap, OLD_STATE_NM)` |
| 5 | SET | `SOHUS_CITY_NM = getInMapData(inMap, OLD_CITY_NM)` |
| 6 | SET | `SOHUS_OAZTSU_NM = getInMapData(inMap, OLD_OAZTSU_NM)` |
| 7 | SET | `SOHUS_AZCHO_NM = getInMapData(inMap, OLD_AZCHO_NM)` |

**Block 2.22** — SET (Track Group, Update Status) (L408)

> After processing all address branches for the current row, update tracking variables and prepare the DB UPDATE.

| # | Type | Code |
|---|------|------|
| 1 | SET | `strSYSID = strSysId` |
| 2 | SET | `strSVC_KEI_NO = strSvcKeiNo` |
| 3 | SET | `insFlag = true` |
| 4 | SET | `valueMap = new JBSbatCommonDBInterface()` |
| 5 | SET | `valueMap.setValue("AD_TOHAIGO_TRN_STAT_CD", JKKBatConst.HENKO_ADD_CD_ZM)` `[-> HENKO_ADD_CD_ZM = "9" (Processing Complete)]` |
| 6 | SET | `whereMap = new JBSbatCommonDBInterface()` |
| 7 | SET | `whereMap.setValue("CHG_AD_JGRTWK_NO", strChgAdJgrtwkNo)` |
| 8 | CALL | `db_CHG_AD_JGRTWK.updateByPrimaryKeys(whereMap, valueMap)` |

**Block 3** — IF (Final Output — Post-Loop Flush) (L419)

> After the loop ends, if any group was accumulated but not yet output (insFlag is true), flush it to the output bean. This handles the last record group which has no subsequent SYSID/SVC_KEI_NO change to trigger output.

| # | Type | Code |
|---|------|------|
| 1 | IF | `insFlag` is true |
| 1.1 | SET | `outmap.setOutFlg(true)` |
| 1.2 | IF | `kojinhojinKbn == 1` (Individual) |
| 1.2.1 | CALL | `outputBean.addOutMapList(outmap)` |
| 1.3 | ELSE | `kojinhojinKbn != 1` (Corporate) |
| 1.3.1 | CALL | `outputBean.addOutMapList_2(outmap)` |

## 7. Glossary

| Term | Type | Business Meaning |
|------|------|------------------|
| `kojinhojinKbn` | Field | Individual/Corporate Classification — `1` = Individual (個人), `2` = Corporate (法人). Determines which output stream and which address fields are included. |
| `CHG_AD_JGRTWK_NO` | Field | Change Target Address List Work Number — primary key of the work table row. |
| `SYSID` | Field | System ID — internal system identifier used to group records. |
| `SVC_KEI_NO` | Field | Service Detail Number — identifies a specific service contract line item. |
| `CHG_TG_SCHEMA_ID` | Field | Change Target Schema ID — identifies the business entity schema (Customer, Service Contract, Equipment, Billing, etc.). |
| `CHG_TG_KMK_NM_EINM` | Field | Change Target Item Name — identifies the specific address type/item being processed within the schema. |
| `AD_TOHAIGO_UPD_FAIL_RSN_CD` | Field | Address Destination Update Failure Reason Code — indicates why the address update failed. |
| `AD_CD` | Field | Address Code — Japanese address identifier. |
| `PCD` | Field | Postal Code (郵便番号) — 7-digit Japanese postal code, hyphenated between 3rd and 4th digit. |
| `STATE_NM` | Field | Prefecture Name (都道府県名) — e.g., 東京都, 大阪府. |
| `CITY_NM` | Field | City Name (市区名) — e.g., 新宿区, 大阪市. |
| `OAZTSU_NM` | Field | District Name (大字名) — sub-district level in Japanese addresses. |
| `AZCHO_NM` | Field | Block/Chome Name (町丁目名) — block or chome level in Japanese addresses. |
| `OLD_AD_CD` / `OLD_PCD` / `OLD_STATE_NM` / `OLD_CITY_NM` / `OLD_OAZTSU_NM` / `OLD_AZCHO_NM` | Fields | Pre-change (original) address fields. |
| `NEW_AD_CD` / `NEW_PCD` / `NEW_STATE_NM` / `NEW_CITY_NM` / `NEW_OAZTSU_NM` / `NEW_AZCHO_NM` | Fields | Post-change (new) address fields. |
| `AD_TOHAIGO_TRN_STAT_CD` | Field | Address Destination Transition Status Code — tracks processing status on the work table. `"9"` = Processing Complete (処理完了). |
| `hyhunPcd` | Method | Hyphenate Postal Code — formats a 7-digit postal code to `XXX-XXXX` format. |
| `getInMapData` | Method | Helper to extract string value from input map, returning empty string for null. |
| `JBSbatKK_T_CHG_AD_JGRTWK` | Entity | Change Target Address List Work Table — temporary work table holding address change records for processing. |
| KK0251 | Schema ID | Service Contract Line Details (サービス契約内容) — schema for service contract line items. |
| KK0191 | Schema ID | Service Contract Line Details <eo Hikari Phone> (eo光電話) — schema for eo Hikari Phone service contracts. |
| KK0341 | Schema ID | Equipment Supply Service Contract (機器提供サービス契約) — schema for equipment-related service contracts. |
| KK0381 | Schema ID | Option Service Contract <TV> (オプションサービス契約<TV>) — schema for TV option service contracts. |
| CK0011 | Schema ID | Customer (お客様) — schema for customer records. |
| CK0021 | Schema ID | Customer <Individual> (お客様<個人>) — schema for individual customer records. |
| TU0011 | Schema ID | BMP Project (番-post工事) — schema for telephone number portability construction projects. |
| TU0021 | Schema ID | Number Portability Transfer (同番転送) — schema for number portability transfer records. |
| TU0091 | Schema ID | Phone Bill Application Details (電話帳申込内容) — schema for phone directory application records. |
| KK0491 | Schema ID | Billing Contract (請求契約) — schema for billing contract records. |
| `SKSHA_AD_CD` | Field | Sponsor Address Code — address of the individual sponsor (for individual customers only). |
| `EMG_AD_CD` | Field | Emergency Address Code — address for emergency notification purposes. |
| `EMG_ADD1_NM` | Field | Emergency Address Part 1 — concatenation of state + city + district + block. |
| `EMG_ADD2_NM` | Field | Emergency Address Part 2 — branch number (BNCHIGO). |
| `EMG_ADD3_NM` | Field | Emergency Address Part 3 — road name + road name suffix (ADRTTM + ADRRM). |
| `KAISEN_PLACE_*` | Fields | Merged Place Address — address fields for municipal merger change records. |
| `KIKI_STC_SAKI_*` | Fields | Equipment Installation Destination — address where equipment is installed. |
| `KIKI_SOHUS_*` | Fields | Equipment Delivery Destination — address where equipment is delivered. |
| `GUIDEMG_SOHUS_*` | Fields | Guide Residence Delivery — address for guide/material delivery. |
| `KEISHA_*` | Fields | Customer Address — primary customer residence address. |
| `CSSTI_SHS_*` | Fields | Designated Delivery Address — specified delivery destination address. |
| `NTT_KEISHA_*` | Fields | BMP Project NTT Customer Address — NTT customer address for BMP projects. |
| `SETPLACE_*` | Fields | Installation Place Address — physical installation site address. |
| `KANYKN_ITENS_*` | Fields | Transfer Destination Address — destination for number portability transfer. |
| `DOBANITEN_SETPLACE_*` | Fields | Number Portability Installation Place — installation address for number portability projects. |
| `KEISAI_*` | Fields | Publication Address — address for phone directory listing. |
| `DNWACHO_SETPLACE_*` | Fields | Phone Bill Installation Place — installation address for phone bill. |
| `SOHUS_*` | Fields | Delivery Address — billing contract delivery destination address. |
| `SEIKY_KEI_NO` | Field | Billing Contract Number — identifies a billing contract. |
| `BMP` | Acronym | Telephone Number Portability Construction (番ポスト工事) — construction work related to telephone number portability. |
| HENKO_ADD_CD_ZM | Constant | Address Change Processing Status Code `9` = Processing Complete (住所統廃合処理ステータス（処理完了）). |
| `addOutMapList` | Method | Appends output record to the Individual customer output stream. |
| `addOutMapList_2` | Method | Appends output record to the Corporate customer output stream. |
| `setOutFlg` | Method | Sets the output flag indicating the group is complete and ready for output. |
