# Business Logic — JBSbatKKAdChgAddDataCst.isZanTgSvcKei() [37 LOC]

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

## 1. Role

### JBSbatKKAdChgAddDataCst.isZanTgSvcKei()

This method determines whether any **line-targeted service contracts** (回線対象サービス契約) remain active for a given address change (住所変更) operation. It is invoked during the address change add-data constant processing batch (`JBSbatKKAdChgAddDataCst`) to decide whether downstream cleanup logic — specifically setting the celled (celled = contract celled/canceled) service contract work table record — should be executed. In business terms: when a customer changes their address, the system must check if the original (celled) service contract still has an active service line association. If a valid service line association exists (i.e., the usage end date is blank or set to the maximum future date `20991231`), and the service is continuing under a different contract number (or no new contract was assigned), then this method returns `true` to signal that a remaining service exists and the celled-contract work data should be populated. If no such active contract is found, it returns `false`, and the batch skips the celled-contract work setup. The method implements a **routing/dispatch pattern** — it queries two database tables in sequence (address change details and line-targeted service contracts) and applies business rules across their joined result set. It is called by the batch's `execute()` method as part of the address change determination workflow (ST1-2013-0000090).

## 2. Processing Pattern (Detailed Business Logic)

```mermaid
flowchart TD
    START(["isZanTgSvcKei inAdchgNo inItnmSvkeiKisuwNo"])
    STEP1["Query KK_T_ADCHG_DTL<br/>ADCHG_DTL_SBT_CD_SVC_KEI_NO equals 01"]
    STEP2["Iterate KK_T_ADCHG_DTL rows<br/>via selectNext"]
    STEP3["Extract dslSvcKeiNo CHBF_SKBT_NO<br/>Extract newSvcKeiNo CHAF_SKBT_NO"]
    COND1{"Has celled<br/>service contract<br/>dslSvcKeiNo not blank"}
    STEP4["Query KK_T_KAISEN_TG_SVKEI<br/>opeDate dslSvcKeiNo inItnmSvkeiKisuwNo"]
    STEP5["Read dslKisnTgSvkeiInfo<br/>via selectNext"]
    COND2{"Row found in<br/>KK_T_KAISEN_TG_SVKEI"}
    STEP6["Get KAISEN_UCWK_USE_ENDYMD"]
    COND3{"Use end date blank<br/>or equals 20991231"}
    COND4{"Service continuation<br/>dslSvcKeiNo blank OR<br/>newSvcKeiNo blank OR<br/>dslSvcKeiNo not equals newSvcKeiNo"}
    RET_TRUE["Return true<br/>Remaining service exists"]
    LOOP_END["Continue to next row"]
    RET_FALSE["Return false<br/>No remaining service"]

    START --> STEP1 --> STEP2 --> STEP3 --> COND1
    COND1 -->|Yes| STEP4 --> STEP5 --> COND2
    COND1 -->|No| LOOP_END
    COND2 -->|Yes| STEP6 --> COND3
    COND2 -->|No| LOOP_END
    COND3 -->|Yes| COND4
    COND3 -->|No| LOOP_END
    COND4 -->|Yes| RET_TRUE
    COND4 -->|No| LOOP_END
    LOOP_END --> STEP3
    RET_TRUE --> RET_FALSE
    RET_FALSE --> END_FALSE(["Return false"])
```

**Constant Resolution:**

| Constant | Resolved Value | Business Meaning |
|----------|---------------|------------------|
| `ADCHG_DTL_SBT_CD_SVC_KEI_NO` | `"01"` | Address change detail type code for service contract number |
| `MAX_DATE` | `"20991231"` | Maximum date — used as sentinel value meaning "no usage end date set" |

## 3. Parameter Analysis

| No | Parameter Name | Type | Business Description |
|----|---------------|------|---------------------|
| 1 | `inAdchgNo` | `String` | Address change number — the unique identifier for an address change operation in the system. Used to look up all address change detail records (KK_T_ADCHG_DTL) associated with this specific address change request. |
| 2 | `inItnmSvkeiKisuwNo` | `String` | Service contract line internal detail number — a sub-identifier within the service contract that identifies a specific line item. Used as a filter when querying KK_T_KAISEN_TG_SVKEI (line-targeted service contracts) to find the exact line contract matching this detail number. |

**Instance fields / external state read:**

| Field | Type | Business Description |
|-------|------|---------------------|
| `db_KK_T_ADCHG_DTL` | `JBSbatSQLAccess` | Database access object for the KK_T_ADCHG_DTL (address change details) table. Initialized in `initial()` with SQL key `KK_T_ADCHG_DTL_KK_SELECT_003`. |
| `db_KK_T_KAISEN_TG_SVKEI` | `JBSbatSQLAccess` | Database access object for the KK_T_KAISEN_TG_SVKEI (line-targeted service contracts) table. Initialized in `initial()` with SQL key `KK_T_KAISEN_TG_SVKEI_KK_SELECT_024`. |
| `opeDate` | `String` | Operational date — inherited from `JBSbatBusinessService`. Represents the processing date (YYYYMMDD format) for the batch job, used to determine the effective date for querying line-targeted service contracts. |

## 4. CRUD Operations / Called Services

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

| CRUD | SC / CBS | SC Code | Entity / DB | Operation Description |
|------|----------|---------|-------------|----------------------|
| R | `JBSbatKKAdChgAddDataCst.executeKK_T_ADCHG_DTL_KK_SELECT_003` | KK_T_ADCHG_DTL_KK_SELECT_003 | KK_T_ADCHG_DTL | Read address change detail records filtered by ADCHG_NO and ADCHG_DTL_SBT_CD_SVC_KEI_NO="01" (service contract type) |
| R | `JBSbatKKAdChgAddDataCst.executeKK_T_KAISEN_TG_SVKEI_KK_SELECT_024` | KK_T_KAISEN_TG_SVKEI_KK_SELECT_024 | KK_T_KAISEN_TG_SVKEI | Read line-targeted service contract record by operational date, celled service contract number, and line internal detail number |
| - | `JBSbatKKAdChgAddDataCst.isBlank` | - | - | Internal utility — checks if a String is null, empty, or blank |
| R | `JBSbatCommonDBInterface.getString` | - | - | Reads a column value from the database row interface (KK_T_ADCHG_DTL.CHBF_SKBT_NO, KK_T_ADCHG_DTL.CHAF_SKBT_NO, KK_T_KAISEN_TG_SVKEI.KAISEN_UCWK_USE_ENDYMD) |

**Detailed CRUD classification:**

| CRUD | SC / CBS | SC Code | Entity / DB | Operation Description |
|------|----------|---------|-------------|----------------------|
| R | `executeKK_T_ADCHG_DTL_KK_SELECT_003` | KK_SELECT_003 | KK_T_ADCHG_DTL | Read address change detail records. Joins on ADCHG_NO (= inAdchgNo) and ADCHG_DTL_SBT_CD (= ADCHG_DTL_SBT_CD_SVC_KEI_NO="01") to retrieve all service-contract-type detail rows for the given address change. |
| R | `db_KK_T_ADCHG_DTL.selectNext()` | (iterative) | KK_T_ADCHG_DTL | Iteratively fetch each row from the address change details result set. Used in a for-loop to process all matching detail records. |
| R | `executeKK_T_KAISEN_TG_SVKEI_KK_SELECT_024` | KK_SELECT_024 | KK_T_KAISEN_TG_SVKEI | Read line-targeted service contract. Takes [opeDate, dslSvcKeiNo, inItnmSvkeiKisuwNo] to find the specific line contract associated with the celled service contract number. |
| R | `db_KK_T_KAISEN_TG_SVKEI.selectNext()` | (iterative) | KK_T_KAISEN_TG_SVKEI | Fetch the single line-targeted service contract row from the query result. |
| R | `getString(CHBF_SKBT_NO)` | - | KK_T_ADCHG_DTL | Extract the pre-change (celled) service contract number from the address change detail row. |
| R | `getString(CHAF_SKBT_NO)` | - | KK_T_ADCHG_DTL | Extract the post-change (new) service contract number from the address change detail row. |
| R | `getString(KAISEN_UCWK_USE_ENDYMD)` | - | KK_T_KAISEN_TG_SVKEI | Extract the usage end date to determine if the service contract is still active (blank or "20991231" means active). |

## 5. Dependency Trace

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

No screen/batch entry points found within 8 hops. Direct callers found: 1 methods.
Terminal operations from this method: `executeKK_T_ADCHG_DTL_KK_SELECT_003` [-], `selectNext` [R], `getString` [R], `getString` [R], `executeKK_T_KAISEN_TG_SVKEI_KK_SELECT_024` [-], `selectNext` [R], `getString` [R], `getString` [R], `getString` [R], `getString` [R]  # NOSONAR

| # | Caller (Screen/Batch) | Call Chain (Full Path to this Method) | Terminal (SC / CRUD / Entity) |
|---|----------------------|--------------------------------------|-------------------------------|
| 1 | Batch: JBSbatKKAdChgAddDataCst | `execute()` -> `isZanTgSvcKei(inAdchgNo, dslKjFinRnkiKisnInfo.getString(SVC_KEI_KAISEN_UCWK_NO))` | `executeKK_T_ADCHG_DTL_KK_SELECT_003 [R] KK_T_ADCHG_DTL`, `executeKK_T_KAISEN_TG_SVKEI_KK_SELECT_024 [R] KK_T_KAISEN_TG_SVKEI` |

**Call chain detail:** The `execute()` method in `JBSbatKKAdChgAddDataCst` (line 856) calls `isZanTgSvcKei()` passing the address change number and the service contract line internal detail number extracted from the `KK_T_SVKEI_KAISEN_UW` work table. This occurs inside the processing flow that determines celled (celled service contract) handling — specifically, if no retention (保有其有) exists for the address change, this method is called to check if a remaining line-targeted service contract exists. If `isZanTgSvcKei()` returns `false` (no remaining service), the batch proceeds to set the celled service contract work table data (`setDslSvkeiKaisenUw()`).

## 6. Per-Branch Detail Blocks

**Block 1** — CALL `(executeKK_T_ADCHG_DTL_KK_SELECT_003)` (L2130)

Initialize the address change details query, filtering for service contract type detail records.

| # | Type | Code |
|---|------|------|
| 1 | CALL | `executeKK_T_ADCHG_DTL_KK_SELECT_003([inAdchgNo, ADCHG_DTL_SBT_CD_SVC_KEI_NO])` // Query address change details by ADCHG_NO and type code. [-> ADCHG_DTL_SBT_CD_SVC_KEI_NO="01"] |

**Block 2** — FOR LOOP `(iterate KK_T_ADCHG_DTL rows)` (L2132-2162)

Loop through each address change detail record returned by the previous query.

| # | Type | Code |
|---|------|------|
| 1 | SET | `adcDtlSvcKeiNoInfo = db_KK_T_ADCHG_DTL.selectNext()` // Get next address change detail row from the result set |
| 2 | SET | `dslSvcKeiNo = null` // Declare variable for celled service contract number |
| 3 | SET | `dslSvcKeiNo = adcDtlSvcKeiNoInfo.getString(CHBF_SKBT_NO)` // Extract pre-change (celled) service contract number from detail row |
| 4 | SET | `newSvcKeiNo = adcDtlSvcKeiNoInfo.getString(CHAF_SKBT_NO)` // Extract post-change (new) service contract number from detail row |

**Block 2.1** — IF `(dslSvcKeiNo is not blank)` (L2138)

Check whether the address change detail record has a celled (celled = contract celled/canceled) service contract number. This filters out detail rows that were created without a prior service contract (e.g., brand-new contract additions).

| # | Type | Code |
|---|------|------|
| 1 | CALL | `isBlank(dslSvcKeiNo)` // Check if celled service contract number is empty or null |
| 2 | IF | `!isBlank(dslSvcKeiNo)` // Branch: celled service contract number EXISTS |

**Block 2.1.1** — CALL `(executeKK_T_KAISEN_TG_SVKEI_KK_SELECT_024)` (L2141)

Query the line-targeted service contracts table for the specific contract associated with the celled service contract number.

| # | Type | Code |
|---|------|------|
| 1 | CALL | `executeKK_T_KAISEN_TG_SVKEI_KK_SELECT_024([opeDate, dslSvcKeiNo, inItnmSvkeiKisuwNo])` // Query line-targeted service contracts by operational date, celled service contract number, and line internal detail number |

**Block 2.1.2** — FOR CONTINUATION `(read single row from KK_T_KAISEN_TG_SVKEI)` (L2144-2145)

| # | Type | Code |
|---|------|------|
| 1 | SET | `dslKisnTgSvkeiInfo = null` // Declare variable for line-targeted service contract info |
| 2 | SET | `dslKisnTgSvkeiInfo = db_KK_T_KAISEN_TG_SVKEI.selectNext()` // Fetch the single matching row |

**Block 2.1.3** — IF `(dslKisnTgSvkeiInfo is not null)` (L2147)

Check whether a line-targeted service contract was found for the celled service contract number. If no row exists, the celled service has no active line contract, and the loop continues to the next address change detail row.

| # | Type | Code |
|---|------|------|
| 1 | IF | `dslKisnTgSvkeiInfo != null` // Branch: line-targeted service contract ROW EXISTS |

**Block 2.1.3.1** — IF `(usage end date not set or is MAX_DATE)` (L2150-2152)

Determine whether the line-targeted service contract is still actively in use. If the usage end date is blank (never set) or equals `MAX_DATE` ("20991231" — the system sentinel for "no end date"), the contract is considered still active.

| # | Type | Code |
|---|------|------|
| 1 | CALL | `dslKisnTgSvkeiInfo.getString(KAISEN_UCWK_USE_ENDYMD)` // Get usage end date |
| 2 | CALL | `isBlank(dslKisnTgSvkeiInfo.getString(KAISEN_UCWK_USE_ENDYMD))` // Check if usage end date is blank |
| 3 | CALL | `dslKisnTgSvkeiInfo.getString(KAISEN_UCWK_USE_ENDYMD)` // Get usage end date (second check) |
| 4 | IF | `isBlank(...) || MAX_DATE.equals(...)` [-> MAX_DATE="20991231"] // Branch: NOT usage ended (blank or future sentinel date) |

**Block 2.1.3.1.1** — IF `(service continuation condition)` (L2154-2158)

Determine whether this represents a service continuation scenario (i.e., the customer is continuing service under a different contract number, or there is no new contract number assigned). If true, a remaining service contract exists.

Business condition: `(dslSvcKeiNo is blank OR newSvcKeiNo is blank OR dslSvcKeiNo != newSvcKeiNo)`

- If dslSvcKeiNo is blank: The celled contract number itself is missing (unusual, but treated as remaining service).
- If newSvcKeiNo is blank: No new contract was created (service celled without replacement).
- If dslSvcKeiNo != newSvcKeiNo: The contract numbers differ, meaning the customer is continuing service under a different contract (e.g., service transfer between contracts).

| # | Type | Code |
|---|------|------|
| 1 | CALL | `isBlank(dslSvcKeiNo)` // Check if celled service contract number is empty |
| 2 | CALL | `isBlank(newSvcKeiNo)` // Check if new service contract number is empty |
| 3 | CALL | `dslSvcKeiNo.equals(newSvcKeiNo)` // Compare celled vs new contract numbers |
| 4 | IF | `isBlank(dslSvcKeiNo) || isBlank(newSvcKeiNo) || !dslSvcKeiNo.equals(newSvcKeiNo)` // Branch: service continuation (not same contract) |
| 5 | RETURN | `return true` // Remaining service exists — signal to caller |

**Block 3** — RETURN `(default: no remaining service)` (L2165)

If the loop completes without finding any active, continuing line-targeted service contract, return `false` to indicate no remaining service exists.

| # | Type | Code |
|---|------|------|
| 1 | RETURN | `return false` // No active line-targeted service contract found across all address change detail rows |

## 7. Glossary

| Term | Type | Business Meaning |
|------|------|------------------|
| `inAdchgNo` | Parameter | Address change number — unique identifier for an address change operation. Links all detail records (contract numbers, service types) for a single address change request. |
| `inItnmSvkeiKisuwNo` | Parameter | Service contract line internal detail number — a sub-identifier within the service contract hierarchy that pinpoints a specific line item for the contract. |
| `dslSvcKeiNo` | Field | Celled service contract number (撤去サービス契約番号) — the original/previous service contract number before the address change. "dsl" is an abbreviation of "celled" (撤去 = removal/cancellation). |
| `newSvcKeiNo` | Field | New service contract number (新設サービス契約番号) — the service contract number after the address change. Used to compare against the celled contract to determine if service continued under a new number. |
| `CHBF_SKBT_NO` | Field | Pre-change identified number (変更前識別番号) — column in KK_T_ADCHG_DTL storing the service contract number before the address change. |
| `CHAF_SKBT_NO` | Field | Post-change identified number (変更後識別番号) — column in KK_T_ADCHG_DTL storing the service contract number after the address change. |
| `KAISEN_UCWK_USE_ENDYMD` | Field | Line usage end date (回線内訳使用終了年月日) — column in KK_T_KAISEN_TG_SVKEI indicating when the service line's usage ended. Blank or "20991231" means the service is still active. |
| `ADCHG_DTL_SBT_CD_SVC_KEI_NO` | Constant | Address change detail type code for service contract number — value "01" identifies detail records related to service contract numbers (as opposed to work item records, type "06"). |
| `MAX_DATE` | Constant | Maximum date sentinel — value "20991231", used system-wide to represent "no end date" or "perpetually active" for date fields. |
| `opeDate` | Field | Operational date — inherited from JBSbatBusinessService. The current processing date (YYYYMMDD format) for the batch job, used as the effective date for database queries. |
| KK_T_ADCHG_DTL | Table | Address change details table — stores per-address-change detail records including contract numbers before/after the change, detail type codes, and change flags. |
| KK_T_KAISEN_TG_SVKEI | Table | Line-targeted service contracts table — stores service contract line items with usage start/end dates, registration timestamps, and operational metadata. |
| KK_T_SVKEI_KAISEN_UW | Table | Service contract line work table — a work/instrument table holding service contract line information during processing. |
| 回線対象サービス契約 | Business term | Line-targeted service contract — a service contract tied to a specific physical line (回線). Determines whether active line-based service remains after an address change. |
| 撤去 | Business term | Celled/Removal — the act of removing or canceling a service contract. "dsl" (celled) in variable names is a phonetic abbreviation. |
| 住所変更 | Business term | Address change — the customer-facing operation of updating a customer's registered address. Triggers a batch process that reassigns service contracts to the new address. |
| 保有其有 | Business term | Retention — whether a service is retained (保有其有 = あり) after address change. If retention exists, certain cleanup steps are skipped. |
| JBSbatKKAdChgAddDataCst | Class | Address change add-data constant service component — a batch service class responsible for extracting and processing address change registration data. |
| ST1-2013-0000090 | Change ticket | Work item ticket — a development/change ticket that added the `isZanTgSvcKei` method on 2013/01/16 (by Hoshino). |
| selectNext() | Method | Database interface method — retrieves the next row from a query result set, returning null when exhausted. Used for iterative row processing. |
| getString() | Method | Database interface method — extracts a column value by field name from a JBSbatCommonDBInterface row object. |
