# Business Logic — JBSbatKKAdChgTekkyoKjFinChsht.execute() [65 LOC]

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

## 1. Role

### JBSbatKKAdChgTekkyoKjFinChsht.execute()

This method extracts and assembles output data for **Address Change Withdrawal Work Completion** (住所変更中撤去工事完了抽出 — *Jusho Henkou Naka Tekkyo Koushi Kanryou Choushuu*), a batch processing function that retrieves relevant identifiers when a service withdrawal installation work has been completed following an address change. It is a dedicated batch service item within the larger **Work Completion Work** (工事完了ワーク — *Koushi Kanryou Work*) processing flow.

The method implements a **delegation and assembly pattern**: it receives work completion work identifiers from the input map, queries two dependent tables to resolve the hierarchical address change chain (detail → header → application number), validates the lookups succeeded, and assembles a structured output file map for downstream consumption. It does **not** branch by service type — every invocation follows the same linear path.

Its role in the larger system is as a **data extraction intermediary**. When the Work Completion Work batch determines that a service withdrawal has been completed, this method traces the address change linkage to collect the Application Number (申請番号 — *Shinsei Bangou*) that identifies the original address change request. The assembled output (Service Contract Number, Work Project Number, Application Number, and optionally Work Project Execution Date) is written as a file record for reporting or further processing.

The method has two skip branches: if the address change detail number cannot be found, or if the application number cannot be found, the method logs the condition and returns `null`, effectively skipping the record from output.

## 2. Processing Pattern (Detailed Business Logic)

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

    START --> S1["Create outputBean (JBSbatOutputItem)"]
    S1 --> S2["Create outmap (JBSbatServiceInterfaceMap)"]
    S2 --> S3["kjfinwk_kojiakNo = inMap.getString(KOJIAK_NO)"]
    S3 --> S4["kjfinwk_svc_kei_no = inMap.getString(SVC_KEI_NO)"]
    S4 --> S5["kjfinwk_kojiak_jssi_ymd = inMap.getString(KOJIAK_JSSI_YMD)"]
    S5 --> S6["adchgdtl_adchg_no = empty string"]
    S6 --> S7["adchg_mskm_no = empty string"]
    S7 --> S8["Log excute_START"]
    S8 --> S9["Log Work Completion Work info"]
    S9 --> S10["Query: KKSELECT_042
Get adchg_no from KK_T_ADCHG_DTL
where KOJIAK_NO = kjfinwk_kojiakNo"]
    S10 --> S11{"adchgdtl_adchg_no
is null or empty?"}
    S11 -->|"Yes"| S12["Log excute_END"]
    S12 --> END1(["Return null (skip)"])
    S11 -->|"No"| S13["Query: KKSELECT_021
Get mskm_no from KK_T_ADCHG
where ADCHG_NO = adchgdtl_adchg_no"]
    S13 --> S14{"adchg_mskm_no
is null or empty?"}
    S14 -->|"Yes"| S15["Log excute_END"]
    S15 --> END2(["Return null (skip)"])
    S14 -->|"No"| S16["Set outmap
SVC_KEI_NO, KOJI_ANK_NO,
MSKM_NO, KOJIAK_JSSI_YMD"]
    S16 --> S17["Log Address Change Withdrawal
Work Data output"]
    S17 --> S18["outmap.setOutFlg(true)"]
    S18 --> S19["outputBean.addOutMapList(outmap)"]
    S19 --> S20["Log excute_END"]
    S20 --> END3(["Return outputBean"])
```

**Processing flow summary:**

1. **Initialize** — Create the output bean and an intermediate service interface map.
2. **Read input** — Extract the Work Completion Work project number (`KOJIAK_NO`), service contract number (`SVC_KEI_NO`), and work project execution date (`KOJIAK_JSSI_YMD`) from the input map.
3. **Clear local fields** — Reset the address change number fields to empty strings to ensure clean state.
4. **Log start** — Emit debug log for processing start and the Work Completion Work identifiers.
5. **Resolve address change detail number** — Call `executeKK_T_ADCHG_DTL_KK_SELECT_042` with the Work Completion Work project number to query the `KK_T_ADCHG_DTL` table (Address Change Detail) via SQL key `KK_SELECT_042`. This returns the Address Change Number (`adchgdtl_adchg_no`).
6. **Validate first query** — If the address change detail number is null or empty, log end and return `null` (skip this record).
7. **Resolve application number** — Call `executeKK_T_ADCHG_KK_SELECT_021` with the address change number to query the `KK_T_ADCHG` table (Address Change) via SQL key `KK_SELECT_021`. This returns the Application Number (`adchg_mskm_no`).
8. **Validate second query** — If the application number is null or empty, log end and return `null` (skip this record).
9. **Assemble output** — Populate the output map with the service contract number, work project number, application number, and work project execution date (added in OM-2014-0003696 for the cancellation calculation date linkage).
10. **Log output data** — Emit debug log showing the assembled address change withdrawal work completion data.
11. **Mark output flag and return** — Set `outFlg` to `true` on the map, add it to the output bean, and return the populated output bean.

## 3. Parameter Analysis

| No | Parameter Name | Type | Business Description |
|----|---------------|------|---------------------|
| 1 | `inMap` | `JBSbatServiceInterfaceMap` | Input message carrying Work Completion Work (工事完了ワーク) identifiers — specifically the Work Project Number (`KOJIAK_NO`), Service Contract Number (`SVC_KEI_NO`), and Work Project Execution Date (`KOJIAK_JSSI_YMD`). These values uniquely identify a completed withdrawal installation work record in the Work Completion Work table (`KK_T_KJ_FIN_WK`). |

**Instance fields read/set by this method:**

| Field | Type | Business Description |
|-------|------|---------------------|
| `kjfinwk_kojiakNo` | `String` | Work Completion Work — Project Number (工事完了ワーク.工事案件番号) — internal key linking to the Work Completion Work table |
| `kjfinwk_svc_kei_no` | `String` | Work Completion Work — Service Contract Number (工事完了ワーク.サービス契約番号) — the service contract associated with the withdrawal |
| `kjfinwk_kojiak_jssi_ymd` | `String` | Work Completion Work — Project Execution Date (工事完了ワーク.工事案件実施年月日) — the actual execution date of the installation work, added via OM-2014-0003696 for cancellation calculation date linkage |
| `adchgdtl_adchg_no` | `String` | Address Change Detail — Address Change Number (住所変更明細.住所変更番号) — resolved from `KK_T_ADCHG_DTL` table |
| `adchg_mskm_no` | `String` | Address Change — Application Number (住所変更.申請番号) — resolved from `KK_T_ADCHG` table, identifies the original address change request |

## 4. CRUD Operations / Called Services

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

| CRUD | SC / CBS | SC Code | Entity / DB | Operation Description |
|------|----------|---------|-------------|----------------------|
| R | `JBSbatKKAdChgTekkyoKjFinChsht.executeKK_T_ADCHG_DTL_KK_SELECT_042` | KKSELECT_042 | `KK_T_ADCHG_DTL` | Selects Address Change Detail record to resolve the Address Change Number (`ADCHG_NO`) by Work Completion Work Project Number (`KOJIAK_NO`). Returns `null` if no matching record found. |
| R | `JBSbatKKAdChgTekkyoKjFinChsht.executeKK_T_ADCHG_KK_SELECT_021` | KKSELECT_021 | `KK_T_ADCHG` | Selects Address Change header record to resolve the Application Number (`MSKM_NO`) by Address Change Number (`ADCHG_NO`). Returns `null` if no matching record found. |
| R | `JBSbatKK_T_KJ_FIN_WK.getString` | - | `KK_T_KJ_FIN_WK` | Reads Work Completion Work fields (KOJIAK_NO, SVC_KEI_NO, KOJIAK_JSSI_YMD) from the input map. The table constants define column names for the Work Completion Work table. |
| - | `JBSbatKKIFM629.setString` | - | File Output | Populates the output file format map with Service Contract Number, Work Project Number, Application Number, and Work Project Execution Date for the Address Change Withdrawal Work Completion output file (IFM629). |
| C | `JBSbatKKIFM629.addOutMapList` | - | File Output | Adds the populated output map to the output bean, marking the record for file output with `setOutFlg(true)`. |
| - | `JBSbatBusinessService.logPrint.printDebugLog` | JBSbatCommon | - | Delegate debug logging through the base class `logPrint` handler for all log entries. |

**How to classify:**
- **R** (Read): SQL SELECT queries against `KK_T_ADCHG_DTL` and `KK_T_ADCHG` tables, plus reading values from the input `inMap`.
- **C** (Create): Adding the output record to the output bean list for file output.

## 5. Dependency Trace

| # | Caller (Screen/Batch) | Call Chain (Full Path to this Method) | Terminal (SC / CRUD / Entity) |
|---|----------------------|--------------------------------------|-------------------------------|
| 1 | Batch: JBSbatKKAdChgTekkyoKjFinChsht | Batch framework → JBSbatKKAdChgTekkyoKjFinChsht.execute | `KKSELECT_042 [R] KK_T_ADCHG_DTL`, `KKSELECT_021 [R] KK_T_ADCHG` |

**Note:** No direct callers were found in the codebase — this method is invoked through the batch processing framework (`JBSbatBusinessService` base class). It is a batch service entry point that operates within the larger Work Completion Work processing flow, triggered when withdrawal installation work completion records exist.

## 6. Per-Branch Detail Blocks

### Block 1 — INIT (Setup) (L118)

> Initialize output structures and extract input data. Set up local fields from the input map.

| # | Type | Code |
|---|------|------|
| 1 | SET | `outputBean = new JBSbatOutputItem()` // Create output bean — generates the output message [-> CONSTANT: outputBean is JBSbatOutputItem] |
| 2 | SET | `outmap = new JBSbatServiceInterfaceMap()` // Create intermediate service interface map for assembling output |
| 3 | SET | `kjfinwk_kojiakNo = inMap.getString(JBSbatKK_T_KJ_FIN_WK.KOJIAK_NO)` // Read Work Completion Work Project Number from input [-> CONSTANT: KOJIAK_NO = "KOJIAK_NO"] |
| 4 | SET | `kjfinwk_svc_kei_no = inMap.getString(JBSbatKK_T_KJ_FIN_WK.SVC_KEI_NO)` // Read Work Completion Work Service Contract Number from input [-> CONSTANT: SVC_KEI_NO = "SVC_KEI_NO"] |
| 5 | SET | `kjfinwk_kojiak_jssi_ymd = inMap.getString(JBSbatKK_T_KJ_FIN_WK.KOJIAK_JSSI_YMD)` // OM-2014-0003696: Read Work Completion Work Project Execution Date [-> CONSTANT: KOJIAK_JSSI_YMD = "KOJIAK_JSSI_YMD"] |
| 6 | SET | `adchgdtl_adchg_no = ""` // Clear address change number from detail table [-> CONSTANT: empty string] |
| 7 | SET | `adchg_mskm_no = ""` // Clear application number from address change header [-> CONSTANT: empty string] |

### Block 2 — LOG_START (Logging) (L127-130)

> Log the start of processing and the Work Completion Work identifiers for debugging.

| # | Type | Code |
|---|------|------|
| 1 | EXEC | `super.logPrint.printDebugLog("excute_START")` // Log processing start |
| 2 | EXEC | `super.logPrint.printDebugLog("工事完了ワーク.工事案件番号: " + kjfinwk_kojiakNo)` // Log: Work Completion Work — Project Number (工事完了ワーク.工事案件番号) |
| 3 | EXEC | `super.logPrint.printDebugLog("工事完了ワーク.サービス契約番号: " + kjfinwk_svc_kei_no)` // Log: Work Completion Work — Service Contract Number (工事完了ワーク.サービス契約番号) |
| 4 | EXEC | `super.logPrint.printDebugLog("工事完了ワーク.工事案件実施年月日: " + kjfinwk_kojiak_jssi_ymd)` // OM-2014-0003696: Log: Work Completion Work — Project Execution Date (工事完了ワーク.工事案件実施年月日) |

### Block 3 — QUERY_ADDRESS_CHANGE_DETAIL (Address Change Detail Lookup) (L131)

> Resolve the Address Change Number (住所変更番号) from the Address Change Detail table (住所変更明細) using the Work Completion Work Project Number.

| # | Type | Code |
|---|------|------|
| 1 | CALL | `adchgdtl_adchg_no = executeKK_T_ADCHG_DTL_KK_SELECT_042(new String[]{kjfinwk_kojiakNo})` // Query KK_T_ADCHG_DTL via SQLKEY KK_SELECT_042 [-> CONSTANT: KK_T_ADCHG_DTL_KK_SELECT_042 = "KK_SELECT_042"] |

### Block 4 — CHECK_ADDRESS_CHANGE_DETAIL (Validation Check) (L133-138)

> If the address change detail number could not be resolved, skip processing and return null.

**Block 4** — IF `[adchgdtl_adchg_no is null or empty]` (L133)

> Skip processing when the address change detail number is not found. Japanese: 住所変更番号が取れなかった場合スキップ — "Skip if address change number cannot be obtained."

| # | Type | Code |
|---|------|------|
| 1 | EXEC | `super.logPrint.printDebugLog("excute_END")` // Log end |
| 2 | RETURN | `return null` // Skip this record — no address change detail found |

### Block 5 — QUERY_ADDRESS_CHANGE_HEADER (Address Change Header Lookup) (L140-141)

> Resolve the Application Number (申請番号) from the Address Change table (住所変更) using the resolved Address Change Number.

| # | Type | Code |
|---|------|------|
| 1 | CALL | `adchg_mskm_no = executeKK_T_ADCHG_KK_SELECT_021(new String[]{adchgdtl_adchg_no})` // Query KK_T_ADCHG via SQLKEY KK_SELECT_021 [-> CONSTANT: KK_T_ADCHG_KK_SELECT_021 = "KK_SELECT_021"] |

### Block 6 — CHECK_ADDRESS_CHANGE_HEADER (Validation Check) (L141-146)

> If the application number could not be resolved, skip processing and return null.

**Block 6** — IF `[adchg_mskm_no is null or empty]` (L141)

> Skip processing when the address change header application number is not found. Japanese: 住所変更から申請番号が取れなかった場合スキップ — "Skip if application number from address change cannot be obtained."

| # | Type | Code |
|---|------|------|
| 1 | EXEC | `super.logPrint.printDebugLog("excute_END")` // Log end |
| 2 | RETURN | `return null` // Skip this record — no application number found |

### Block 7 — ASSEMBLE_OUTPUT (Output Assembly) (L148-154)

> Populate the output file map with the resolved identifiers. This data is destined for file output (IFM629 format).

| # | Type | Code |
|---|------|------|
| 1 | EXEC | `outmap.setString(JBSbatKKIFM629.SVC_KEI_NO, kjfinwk_svc_kei_no)` // Set Service Contract Number [-> CONSTANT: SVC_KEI_NO = "SVC_KEI_NO"] |
| 2 | EXEC | `outmap.setString(JBSbatKKIFM629.KOJI_ANK_NO, kjfinwk_kojiakNo)` // Set Work Project Number [-> CONSTANT: KOJI_ANK_NO = "KOJI_ANK_NO"] |
| 3 | EXEC | `outmap.setString(JBSbatKKIFM629.MSKM_NO, adchg_mskm_no)` // Set Application Number [-> CONSTANT: MSKM_NO = "MSKM_NO"] |
| 4 | EXEC | `outmap.setString(JBSbatKKIFM629.KOJIAK_JSSI_YMD, kjfinwk_kojiak_jssi_ymd)` // OM-2014-0003696: Set Work Project Execution Date [-> CONSTANT: KOJIAK_JSSI_YMD = "KOJIAK_JSSI_YMD"] |

### Block 8 — LOG_OUTPUT (Output Logging) (L156-163)

> Log the assembled address change withdrawal work completion data for debugging. Japanese: 住所変更中撤去工事完了データ出力 — "Address Change Withdrawal Work Completion Data Output."

| # | Type | Code |
|---|------|------|
| 1 | EXEC | `super.logPrint.printDebugLog("----住所変更中撤去工事完了データ出力----")` // Log output header |
| 2 | EXEC | `super.logPrint.printDebugLog("・サービス契約番号: " + kjfinwk_svc_kei_no)` // Log: Service Contract Number |
| 3 | EXEC | `super.logPrint.printDebugLog("・工事案件番号: " + kjfinwk_kojiakNo)` // Log: Work Project Number |
| 4 | EXEC | `super.logPrint.printDebugLog("・申請番号: " + adchg_mskm_no)` // Log: Application Number |
| 5 | EXEC | `super.logPrint.printDebugLog("・工事案件実施年月日: " + kjfinwk_kojiak_jssi_ymd)` // OM-2014-0003696: Log: Work Project Execution Date |
| 6 | EXEC | `super.logPrint.printDebugLog("----------------------------------------")` // Log separator |

### Block 9 — WRITE_OUTPUT (Finalize and Return) (L166-168)

> Mark the record for output and return the populated output bean.

| # | Type | Code |
|---|------|------|
| 1 | EXEC | `outmap.setOutFlg(true)` // Set output flag to include this record in file output |
| 2 | EXEC | `outputBean.addOutMapList(outmap)` // Add the output map to the output bean |
| 3 | EXEC | `super.logPrint.printDebugLog("excute_END")` // Log processing end |
| 4 | RETURN | `return outputBean` // Return the output bean with one record |

## 7. Glossary

| Term | Type | Business Meaning |
|------|------|------------------|
| `kjfinwk_kojiakNo` | Field | Work Completion Work — Project Number (工事完了ワーク.工事案件番号) — internal key identifying a completed work project record in `KK_T_KJ_FIN_WK` |
| `kjfinwk_svc_kei_no` | Field | Work Completion Work — Service Contract Number (工事完了ワーク.サービス契約番号) — the service contract number associated with the completed work |
| `kjfinwk_kojiak_jssi_ymd` | Field | Work Completion Work — Project Execution Date (工事完了ワーク.工事案件実施年月日) — the actual date the installation work was executed; added via OM-2014-0003696 to link with cancellation calculation date |
| `adchgdtl_adchg_no` | Field | Address Change Detail — Address Change Number (住所変更明細.住所変更番号) — resolved from `KK_T_ADCHG_DTL` table, links the work to a specific address change detail record |
| `adchg_mskm_no` | Field | Address Change — Application Number (住所変更.申請番号) — the original application number for the address change request, resolved from `KK_T_ADCHG` table |
| `KK_T_KJ_FIN_WK` | Table | Work Completion Work (工事完了ワーク) — table storing records of completed installation work, serving as the input source for this method |
| `KK_T_ADCHG_DTL` | Table | Address Change Detail (住所変更明細) — table storing detail records of address changes; queried via SQLKEY `KK_SELECT_042` to resolve the address change number |
| `KK_T_ADCHG` | Table | Address Change (住所変更) — table storing header records of address change applications; queried via SQLKEY `KK_SELECT_021` to resolve the application number |
| KKSELECT_042 | SQL Key | SQL define key for querying `KK_T_ADCHG_DTL` by Work Completion Work Project Number to obtain the Address Change Number |
| KKSELECT_021 | SQL Key | SQL define key for querying `KK_T_ADCHG` by Address Change Number to obtain the Application Number |
| IFM629 | File Format | Output file format for Address Change Withdrawal Work Completion Data (住所変更中撤去工事完了データ) — defines the output message structure with fields SVC_KEI_NO, KOJI_ANK_NO, MSKM_NO, KOJIAK_JSSI_YMD |
| 住所変更 | Business term | Address Change (Shusho Henkou) — the process of changing a customer's registered address, which may involve withdrawal and reinstallation of services |
| 撤去工事 | Business term | Withdrawal Installation / Removal Work (Tekkyo Koushi) — the process of removing services at a former address as part of an address change |
| 工事完了ワーク | Business term | Work Completion Work (Koushi Kanryou Work) — the batch work/processing stage that tracks completed installation work records |
| 中撤去 | Business term | Intermediate Withdrawal (Naka Tekkyou) — services being withdrawn mid-contract during an address change, as opposed to final termination |
| 工事案件実施年月日 | Business term | Work Project Execution Date (Koushi Anjii Jissi Nenngetsuhi) — the date the installation work was actually carried out; used for cancellation calculation date linkage |
| 申請番号 | Business term | Application Number (Shinsei Bangou) — unique identifier for an address change application request |
| 住所変更番号 | Business term | Address Change Number (Shusho Henkou Bangou) — unique identifier linking address change detail records to header records |
| JBSbatBusinessService | Base class | Base class for batch business services, providing common infrastructure including `logPrint` for debug logging and `initial()`/`terminal()` lifecycle hooks |
| JBSbatServiceInterfaceMap | Class | Service interface map — a key-value map used to pass structured data between batch processing steps |
| JBSbatOutputItem | Class | Output item — the container that holds output maps for file output, used by the batch framework to write results |
