# Business Logic — JBSbatKKAdChgFinAddRun.deleteAdchmTppv() [38 LOC]

| Field | Value |
|-------|-------|
| Fully Qualified Name | `eo.business.service.JBSbatKKAdChgFinAddRun` |
| Layer | Batch (Package: `eo.business.service`, part of K-Opticom Customer Backbone System batch processing) |
| Module | `service` |

## 1. Role

### JBSbatKKAdChgFinAddRun.deleteAdchmTppv()

The `deleteAdchmTppv` method performs the logical deletion of records stored in the **Address Change Application Temporary Save** table (`KK_T_ADCHM_TPPV`). This table holds temporary snapshot data created during the address change application process, and once the address change workflow reaches the "completed" state (confirmed by the batch's commitment processing), these temporary records are no longer needed and are soft-deleted to keep the database clean.

The method implements a **read-then-delete** pattern: it first resolves the service contract routing detail number from the address change header, queries all temporary save records associated with that routing number, and then iterates over the result set to perform a logical delete on each row using its primary key (SYSID and ADCHM_TPPV_NO). It is a **shared utility method** called internally by the `execute()` batch entry point after all address change confirmation processing has successfully completed — specifically after the address change detail registration (`addAdchgDtl`) is done and the address change status has been updated to "complete."

## 2. Processing Pattern (Detailed Business Logic)

```mermaid
flowchart TD
    START(["deleteAdchmTppv(adchgNo)"])
    START --> GET_WC["getSvcKaisenWcwkNo(adchgNo)"]
    GET_WC --> SET_PARAM["Set svcKaisenUcwkNo into paramList"]
    SET_PARAM --> SELECT["db_KK_T_ADCHM_TPPV.selectBySqlDefine
(paramList, KK_SELECT_001)"]
    SELECT --> SUCCESS{"selectBySqlDefine
success?"}
    SUCCESS --> |"yes"| FETCH_LOOP{"resultMap =
selectNext()"}
    SUCCESS --> |"no - JBSbatBusinessException"| THROW["throw EKKBO360KE
(Address change temp save,
svcKaisenUcwkNo)"]
    THROW --> END_NODE(["Return (void)"])
    FETCH_LOOP --> |"not null"| ADD_RESULT["resultList.add(resultMap)"]
    ADD_RESULT --> FETCH_LOOP
    FETCH_LOOP --> |"null (EOF)"| FOR_LOOP{"for each resultMap
in resultList?"}
    FOR_LOOP --> |"more rows"| SET_WHERE["Set whereMap with
SYSID, ADCHM_TPPV_NO"]
    SET_WHERE --> LOGICAL_DEL["db_KK_T_ADCHM_TPPV
.logicalDeleteByPrimaryKeys(whereMap)"]
    LOGICAL_DEL --> FOR_LOOP
    FOR_LOOP --> |"no more rows"| END_NODE
```

**Processing flow description:**

1. **Resolve routing detail number:** The method delegates to `getSvcKaisenWcwkNo(adchgNo)` to fetch the service contract routing detail number (`ITNM_SVKEI_KISUW_NO`) from the `KK_T_ADCHG` (address change) header table, using the provided `adchgNo` as the lookup key.

2. **Set query parameters:** A `JBSbatCommonDBInterface` parameter object is created and populated with the routing detail number obtained in step 1.

3. **Query temporary save records:** The method calls `selectBySqlDefine` on the `db_KK_T_ADCHM_TPPV` database access object, executing the `KK_SELECT_001` SQL definition against the `KK_T_ADCHM_TPPV` table, filtering by the service contract routing detail number.

4. **Exception handling:** If a `JBSbatBusinessException` is thrown during the select (e.g., database error, record not found), the method catches it and re-throws a `JBSbatBusinessException` with error code `EKKBO360KE`, including contextual labels ("Address change application temporary save" and the routing detail number) for diagnostics.

5. **Fetch all rows:** The method iterates via `selectNext()` in a loop, collecting all result records into an `ArrayList`. The loop terminates when `selectNext()` returns `null` (EOF).

6. **Logical delete per record:** For each row in the collected result list, a new WHERE condition map is built using the row's primary key values (`SYSID` and `ADCHM_TPPV_NO`), and `logicalDeleteByPrimaryKeys` is called to perform a soft delete on the `KK_T_ADCHM_TPPV` table.

## 3. Parameter Analysis

| No | Parameter Name | Type | Business Description |
|----|---------------|------|---------------------|
| 1 | `adchgNo` | `String` | **Address Change Number** — the unique identifier for an address change record in the `KK_T_ADCHG` table. This number links the method to the address change header, from which the service contract routing detail number is derived. It is assigned when a customer submits an address change application and serves as the primary business key for tracing the entire address change lifecycle. |
| — | `svcKaisenUcwkNo` (internal) | `String` | **Service Contract Routing Detail Number** — retrieved from `KK_T_ADCHG.ITNM_SVKEI_KISUW_NO`. Used as the filter key to locate all temporary save records in `KK_T_ADCHM_TPPV` that belong to this address change's service contract routing. |
| — | `db_KK_T_ADCHM_TPPV` (instance field) | `JBSbatSQLAccess` | Database access object for the `KK_T_ADCHM_TPPV` table. Initialized during the batch `initial()` method with the common item context. |

## 4. CRUD Operations / Called Services

| CRUD | SC / CBS | SC Code | Entity / DB | Operation Description |
|------|----------|---------|-------------|----------------------|
| R | `JBSbatKKAdChgFinAddRun.getSvcKaisenWcwkNo` | (private method) | `KK_T_ADCHG` (via `selectByPrimaryKeys`) | Reads the service contract routing detail number (`ITNM_SVKEI_KISUW_NO`) from the address change header table, keyed by `adchgNo`. |
| R | `db_KK_T_ADCHM_TPPV.selectBySqlDefine` | (internal SQL) | `KK_T_ADCHM_TPPV` | Executes SQL select `KK_SELECT_001` to retrieve all temporary save records where `SVC_KEI_KAISEN_UCWK_NO` matches the given routing detail number. |
| R | `db_KK_T_ADCHM_TPPV.selectNext` | (internal SQL) | `KK_T_ADCHM_TPPV` | Fetches each row from the open cursor one at a time until EOF. |
| D | `db_KK_T_ADCHM_TPPV.logicalDeleteByPrimaryKeys` | (internal SQL) | `KK_T_ADCHM_TPPV` | Performs a soft/physical delete on each temporary save record, filtered by the primary key (`SYSID`, `ADCHM_TPPV_NO`). |

**CRUD summary:** The method is a **Read-heavy Delete** operation — it queries one parent record (`KK_T_ADCHG`), selects multiple child records (`KK_T_ADCHM_TPPV`), then deletes each child row via logical delete by primary key.

## 5. Dependency Trace

| # | Caller (Screen/Batch) | Call Chain (Full Path to this Method) | Terminal (SC / CRUD / Entity) |
|---|----------------------|--------------------------------------|-------------------------------|
| 1 | Batch: JBSbatKKAdChgFinAddRun | `execute(inMap)` -> `deleteAdchmTppv(inAdchgNo)` | `selectBySqlDefine [R] KK_T_ADCHM_TPPV`, `selectNext [R] KK_T_ADCHM_TPPV`, `logicalDeleteByPrimaryKeys [D] KK_T_ADCHM_TPPV`, `getSvcKaisenWcwkNo [R] KK_T_ADCHG` |

**Caller context:** The method is called unconditionally from within the `execute()` method of the same class (line 379), after `addAdchgDtl(inAdchgNo)` has completed. The call is guarded by the outer condition `!(isBlank(inAdchgNo) || isBlank(inAdchgUpdDtm))`, meaning `deleteAdchmTppv` only runs when a valid address change number and update timestamp are provided — i.e., when the address change processing is actually underway.

## 6. Per-Branch Detail Blocks

**Block 1** — [SET] (L1466)

> Retrieve the service contract routing detail number from the address change header.

| # | Type | Code |
|---|------|------|
| 1 | CALL | `svcKaisenUcwkNo = getSvcKaisenWcwkNo(adchgNo)` // Resolve routing detail number (Service Contract Routing Detail Number Acquisition) |

**Block 2** — [SET] (L1467)

> Prepare query parameter.

| # | Type | Code |
|---|------|------|
| 1 | SET | `paramList = new JBSbatCommonDBInterface()` // Create parameter object for delete target condition setup |
| 2 | CALL | `paramList.setValue(svcKaisenUcwkNo)` // Set the routing detail number as the query key |

**Block 3** — [TRY-CATCH] (L1470–1480)

> Query temporary save records, with error handling.

| # | Type | Code |
|---|------|------|
| 1 | SET | `paramList = new JBSbatCommonDBInterface()` // Delete target condition setup |
| 2 | CALL | `paramList.setValue(svcKaisenUcwkNo)` // Set routing detail number [-> ITNM_SVKEI_KISUW_NO] |
| 3 | EXEC | `db_KK_T_ADCHM_TPPV.selectBySqlDefine(paramList, KK_T_ADCHM_TPPV_KK_SELECT_001)` // Delete target record lookup and acquisition [-> KK_SELECT_001] |

**Block 3.1** — [CATCH: JBSbatBusinessException] (L1474–1479)

> Handle query failure — rethrow with contextual error message.

| # | Type | Code |
|---|------|------|
| 1 | SET | `bie` = caught `JBSbatBusinessException` |
| 2 | THROW | `throw new JBSbatBusinessException(JPCBatchMessageConstant.EKKB0360KE, new String[]{"Address change application temporary save", svcKaisenUcwkNo})` // Error handling [-> EKKBO360KE] |

**Block 4** — [SET + WHILE LOOP] (L1482–1488)

> Fetch all result records from the open cursor into an ArrayList.

| # | Type | Code |
|---|------|------|
| 1 | SET | `resultList = new ArrayList<JBSbatCommonDBInterface>()` // Initialize delete target list acquisition |
| 2 | SET | `resultMap = db_KK_T_ADCHM_TPPV.selectNext()` // Inside while(true) loop |
| 3 | IF | `if (resultMap == null) { break; }` // EOF check — Exit loop when no more rows |
| 4 | CALL | `resultList.add(resultMap)` // Accumulate row into result list |

**Block 5** — [FOR LOOP] (L1491–1498)

> Iterate over all fetched records and perform logical delete on each.

| # | Type | Code |
|---|------|------|
| 1 | SET | `resultMap` = current element from `resultList` (for-each iteration) |
| 2 | SET | `whereMap = new JBSbatCommonDBInterface()` // Delete condition setup |
| 3 | CALL | `whereMap.setValue(JBSbatKK_T_ADCHM_TPPV.SYSID, resultMap.getValue(JBSbatKK_T_ADCHM_TPPV.SYSID))` // Set SYSID as delete condition |
| 4 | CALL | `whereMap.setValue(JBSbatKK_T_ADCHM_TPPV.ADCHM_TPPV_NO, resultMap.getValue(JBSbatKK_T_ADCHM_TPPV.ADCHM_TPPV_NO))` // Set ADCHM_TPPV_NO as delete condition [-> Primary Key] |
| 5 | EXEC | `db_KK_T_ADCHM_TPPV.logicalDeleteByPrimaryKeys(whereMap)` // Logical delete by primary key |

## 7. Glossary

| Term | Type | Business Meaning |
|------|------|------------------|
| `adchgNo` | Field | Address Change Number — unique identifier for an address change record in the `KK_T_ADCHG` table |
| `svcKaisenUcwkNo` | Field | Service Contract Routing Detail Number — internal tracking ID for the service contract routing associated with a specific address change |
| `ITNM_SVKEI_KISUW_NO` | Field | Original Transfer Service Contract Routing Number — the routing detail number carried on the pre-transfer (original transfer side) of an address change; stored in `KK_T_ADCHG` table |
| `ITNM_SVKEI_KAISUW_NO` | Field | (related) Original transfer-side service contract routing — used across multiple tables to trace the "from" side of a service contract transfer |
| `ITENS_SVKEI_KISUW_NO` | Field | Post-transfer Service Contract Routing Number — the routing detail number on the "to" side of an address change |
| `KK_T_ADCHG` | Table | Address Change header table — stores the master record for each address change request, including the change status, routing numbers, and timestamps |
| `KK_T_ADCHM_TPPV` | Table | Address Change Application Temporary Save table — holds temporary snapshot data created during the address change application process; records are logically deleted after the change is confirmed |
| `SYSID` | Field | System ID — unique row identifier within `KK_T_ADCHM_TPPV`, used as part of the primary key for targeted deletions |
| `ADCHM_TPPV_NO` | Field | Address Change Application Temporary Save Number — the primary key identifier for a temporary save record within `KK_T_ADCHM_TPPV` |
| `KK_SELECT_001` | Constant | SQL definition key for the select query on `KK_T_ADCHM_TPPV`, filtering by service contract routing detail number |
| `EKKBO360KE` / `EKKB0360KE` | Constant | Error code in `JPCBatchMessageConstant` — thrown when the select operation on temporary save records fails |
| Logical Delete | Concept | Soft-delete pattern — the record is not physically removed from the database; instead, it is marked as deleted (typically via a flag like `MK_FLG`), preserving audit trail while excluding it from active queries |
| `KK_T_ADCHM_TPPV` | Abbreviation | **KK** = K-Opticom, **T** = Temporary table, **ADCHM** = AdChange (Address Change), **TPPV** = Teisho Hitouzhozon (Application Temporary Save — Japanese: 申請一時保存) |
| K-Opticom | Business term | Japanese telecommunications carrier providing FTTH, DSL, mobile, and TV services; the system documents address change, service contract, and provisioning operations |
| Service Contract Routing | Business term | In the K-Opticom customer system, a "routing" represents the lifecycle path of a service contract through address changes, transfers, and service modifications. Each routing has a detail number for precise tracking. |
