# Business Logic — JBSbatKKDelKhChk.canDelUrl() [50 LOC]

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

## 1. Role

### JBSbatKKDelKhChk.canDelUrl()

This method implements a **deletion eligibility check** (消去可否チェック) for **URL-based service contract line items** in the K-Opticom customer base system batch processing. It determines whether a URL-associated option service contract line (オプションサービス契約連) can be safely removed from the database during the batch deletion workflow.

The method uses a **two-stage validation design pattern** — first, it verifies that no other active URL records exist for the same option service contract number, ensuring referential integrity of the URL association. Second (introduced in ANK-2897-00-00, v33.00.00), it cross-checks the `KK_T_ODR_SET` table to ensure that no **cancellation Service Order Data (解除SOD)** has been issued for this service contract line under WEB order type, which would prohibit deletion.

This method serves as a specialized branch handler within the broader `execute()` dispatch logic of `JBSbatKKDelKhChk`, which routes deletion eligibility checks by `del_trgt_sbt` (消去対象種類) — a field that distinguishes between URL, fixed-IP address, PPP authentication ID, email address, and other delete-target categories. It is called exclusively by `JBSbatKKDelKhChk.execute()` when `delTrgtSbt` equals `DEL_TRGT_SBT_URL` (消去対象種類: URL).

## 2. Processing Pattern (Detailed Business Logic)

```mermaid
flowchart TD
    START(["canDelUrl(inMap)"])
    A["Set canDel = false
消去可否"] --> B["Set nextRec = null
次レコード"]
    B --> C["Prepare selectWhereParam
[OPSVKEI_NO, URL, opeDate]
オプションサービス契約番号, URL, 運用日"]
    C --> D["CALL executeKK_T_OP_SVC_KEI_KK_SELECT_042()
KK_T_OP_SVC_KEI table"]
    D --> E["CALL db_KK_T_OP_SVC_KEI.selectNext()
nextRec = 次レコード"]
    E --> F{nextRec == null?
レコードなし?}
    F -->|true| G["Set canDel = true
消去可"]
    F -->|false| H["canDel remains false
消去不可"]
    G --> I{canDel is true?
初回チェック結果}
    H --> I
    I -->|true| J["Prepare kk1041SelectWhereParam
[SVKEI_NO, OPSVKEI_NO, SVC_ORDER_CD_WEB=04]"]
    I -->|false| K["RETURN canDel (false)
処理終了"]
    J --> L["CALL executeKK_T_ODR_SET_KK_SELECT_025()
KK_T_ODR_SET table"]
    L --> M["CALL db_KK_T_ODR_SET.selectNext()
kK1041NextRec"]
    M --> N{kk1041NextRec == null?
解除SOD未発行?}
    N -->|true| O["Set canDel = false
解除SOD未発行のため消去不可
Log error: EKKB1200AI"]
    N -->|false| P["canDel remains true
解除SOD発行済み"]
    O --> Q["RETURN canDel (false)"]
    P --> Q2["RETURN canDel (true)"]
    Q --> END(["Return"])
    Q2 --> END
    K --> END
```

**Constant Resolution:**
- `JBSbatKKConst.SVC_ORDER_CD_WEB = "04"` — Service Order Code: WEB (サービスオーダーコード WEB)
- `JBSbatKKIFM160.OPSVKEI_NO = "OPSVKEI_NO"` — Option Service Contract Number (オプションサービス契約番号)
- `JBSbatKKIFM160.URL = "URL"` — URL field key
- `JBSbatKKIFM160.SVKEI_NO = "SVKEI_NO"` — Service Contract Number (サービス契約番号)
- `DEL_TRGT_SBT_URL` — Delete Target Category: URL (消去対象種類: URL)

## 3. Parameter Analysis

| No | Parameter Name | Type | Business Description |
|----|---------------|------|---------------------|
| 1 | `inMap` | `JBSbatServiceInterfaceMap` | Input message (入力電文) carrying deletion-check parameters. Contains the **Option Service Contract Number** (`OPSVKEI_NO`), **URL** value, and **Service Contract Number** (`SVKEI_NO`) extracted from the originating batch input. |
| — | `opeDate` | `String` (instance field) | Operation date (運用日) — a class-level instance field holding the batch run date, used as a query parameter in the first SQL lookup to ensure date-scoped record resolution. |
| — | `db_KK_T_OP_SVC_KEI` | `JBSbatSQLAccess` (instance field) | SQL accessor for the `KK_T_OP_SVC_KEI` table, instantiated during `initial()` with the common batch item context. |
| — | `db_KK_T_ODR_SET` | `JBSbatSQLAccess` (instance field) | SQL accessor for the `KK_T_ODR_SET` table, used in the second-stage SOD cancellation check. |
| — | `commonItem` | `JBSbatCommonItem` (instance field) | Common batch parameter item, holding the logging service (`getLogPrint()`) and other shared batch configuration. |

## 4. CRUD Operations / Called Services

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

| CRUD | SC / CBS | SC Code | Entity / DB | Operation Description |
|------|----------|---------|-------------|----------------------|
| R | `executeKK_T_OP_SVC_KEI_KK_SELECT_042(Object[])` | KK service | `KK_T_OP_SVC_KEI` (オプションサービス契約連) | Query option service contract line records filtered by `OPSVKEI_NO`, `URL`, and `opeDate` to determine if additional URL records remain |
| R | `executeKK_T_ODR_SET_KK_SELECT_025(Object[])` | KK service | `KK_T_ODR_SET` (オーダーセット連) | Query order-set records filtered by `SVKEI_NO`, `OPSVKEI_NO`, and WEB order code (`"04"`) to detect cancellation SOD issuance |
| - | `JBSbatCommonDBInterface.selectNext()` | DB access | `KK_T_OP_SVC_KEI` cursor | Advance the scrollable result set cursor to the next record |
| - | `JBSbatCommonDBInterface.selectNext()` | DB access | `KK_T_ODR_SET` cursor | Advance the scrollable result set cursor to the next record |
| - | `JBSbatCommonDBInterface.setValue()` | DB access | — | Set bind parameter values for prepared statement execution |
| - | `JBSbatCommonDBInterface.selectBySqlDefine()` | DB access | — | Execute SQL by pre-defined SQL key (`KK_T_OP_SVC_KEI_KK_SELECT_042`, `KK_T_ODR_SET_KK_SELECT_025`) |
| - | `JBSbatCommonDBInterface.setValue()` | DB access | — | Set bind parameter values for second SQL execution |
| - | `JBSbatCommonDBInterface.selectBySqlDefine()` | DB access | — | Execute SQL by pre-defined SQL key for order-set query |
| - | `JKKBatOneTimeLogWriter.printBusinessErrorLog` | Log writer | — | Write business error log with message key `EKKB1200AI` and contextual detail when deletion is rejected due to unissued cancellation SOD |
| - | `JBSbatCommonItem.getLogPrint()` | Logger | — | Retrieve the batch logging service for error output |

### Analysis:

Both queries are **Read (R)** operations against the database:

1. **`executeKK_T_OP_SVC_KEI_KK_SELECT_042`** — Reads the `KK_T_OP_SVC_KEI` (Option Service Contract Line) table. The query filters by three bind parameters: the option service contract number (`OPSVKEI_NO`), the URL string, and the operation date (`opeDate`). The result determines whether any **additional** URL records exist beyond the one being evaluated for deletion.

2. **`executeKK_T_ODR_SET_KK_SELECT_025`** — Reads the `KK_T_ODR_SET` (Order Set Line) table. The query filters by the service contract number (`SVKEI_NO`), the option service contract number (`OPSVKEI_NO`), and the WEB service order code (`SVC_ORDER_CD_WEB = "04"`). This verifies whether a **cancellation order (解除オーダー)** has been generated for this service contract line. If one exists, the URL deletion is considered safe to proceed.

## 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: `printBusinessErrorLog` [-], `selectNext` [R], `selectNext` [R], `selectBySqlDefine` [R], `selectBySqlDefine` [R], `setValue` [-], `setValue` [-], `getLogPrint` [-]

| # | Caller (Screen/Batch) | Call Chain (Full Path to this Method) | Terminal (SC / CRUD / Entity) |
|---|----------------------|--------------------------------------|-------------------------------|
| 1 | Batch: `JBSbatKKDelKhChk.execute()` | `JBSbatKKDelKhChk.execute()` → checks `delTrgtSbt` equals `DEL_TRGT_SBT_URL` → `canDelUrl(inMap)` | `KK_T_OP_SVC_KEI` [R], `KK_T_ODR_SET` [R], `printBusinessErrorLog(EKKB1200AI)` |

The sole caller is the `execute()` method within `JBSbatKKDelKhChk` itself, which acts as a batch processing entry point for the deletion eligibility check unit. It routes to `canDelUrl()` when the delete target category (`del_trgt_sbt`) matches the URL type.

## 6. Per-Branch Detail Blocks

**Block 1** — [SET] Variable initialization (L841-L842)

> Initialize local variables: the return flag (`canDel`) and the cursor holder (`nextRec`) for the first SQL result set.

| # | Type | Code |
|---|------|------|
| 1 | SET | `canDel = false` // 消去可否 (deletion eligibility) — default: not deletable |
| 2 | SET | `nextRec = null` // 次レコード (next record cursor holder) |

**Block 2** — [SET] Prepare first SQL bind parameters (L844-L849)

> Build the `Object[]` array with three bind values for the `KK_T_OP_SVC_KEI` query.

| # | Type | Code |
|---|------|------|
| 1 | SET | `selectWhereParam` = `[OPSVKEI_NO, URL, opeDate]` // Options service contract number, URL value, operation date |
| 1.1 | CALL | `inMap.getString(JBSbatKKIFM160.OPSVKEI_NO)` // オプションサービス契約番号 (option service contract number) |
| 1.2 | CALL | `inMap.getString(JBSbatKKIFM160.URL)` // URL (the URL value to check) |
| 1.3 | SET | `opeDate` // 運用日 (operation date) — instance field |

**Block 3** — [CALL] Execute first SQL query (L851)

> Query `KK_T_OP_SVC_KEI` table to check whether any additional URL-associated option service contract records exist.

| # | Type | Code |
|---|------|------|
| 1 | CALL | `executeKK_T_OP_SVC_KEI_KK_SELECT_042(selectWhereParam)` // SELECT from KK_T_OP_SVC_KEI [R] |

**Block 4** — [CALL] Fetch next record from cursor (L852)

> Advance the scrollable cursor to retrieve the next matching row.

| # | Type | Code |
|---|------|------|
| 1 | CALL | `nextRec = db_KK_T_OP_SVC_KEI.selectNext()` // 次レコードを取得 |

**Block 5** — [IF] Check if no records remain (L853-L856)

> When `nextRec == null`, no other URL records exist for this option service contract line — deletion is permissible.

| # | Type | Code |
|---|------|------|
| 1 | IF | `nextRec == null` // レコードが存在するか (do records exist?) |
| 1.1 | SET | `canDel = true` // 消去可 — no additional records, safe to delete |

**Block 5.1** — [ELSE-IF, implicit] Records exist (L853)

> When `nextRec != null`, additional URL records remain for this contract line — deletion is not allowed at this stage.

| # | Type | Code |
|---|------|------|
| 1 | IF-NOT | `nextRec != null` // レコードが存在する — canDel remains false (消去不可) |

**Block 6** — [IF] ANK-2897-00-00 early return guard (L860-L863)

> If the first check determined deletion is NOT allowed (`canDel == false`), terminate processing early. This is a guard clause introduced in ANK-2897-00-00 to avoid unnecessary second-stage checks when deletion is already rejected.

| # | Type | Code |
|---|------|------|
| 1 | IF | `!canDel` // 初回チェックで消去「否」 → 処理を終了 |
| 1.1 | RETURN | `return canDel;` // Returns false — skip second-stage SOD check |

**Block 7** — [SET] Prepare second SQL bind parameters (L865-L872)

> Initialize local variables and build bind parameters for the cancellation SOD check against `KK_T_ODR_SET`.

| # | Type | Code |
|---|------|------|
| 1 | SET | `kk1041NextRec = null` // 次レコード (next record holder for second query) |
| 2 | SET | `kk1041SelectWhereParam` = `[SVKEI_NO, OPSVKEI_NO, SVC_ORDER_CD_WEB]` |
| 2.1 | CALL | `inMap.getString(JBSbatKKIFM160.SVKEI_NO)` // サービス契約番号 (service contract number) |
| 2.2 | CALL | `inMap.getString(JBSbatKKIFM160.OPSVKEI_NO)` // オプションサービス契約番号 (option service contract number) |
| 2.3 | SET | `JBSbatKKConst.SVC_ORDER_CD_WEB` // [-> SVC_ORDER_CD_WEB="04"] サービスオーダーコード WEB |

**Block 8** — [CALL] Execute second SQL query (L873)

> Query `KK_T_ODR_SET` table to check for cancellation SOD (解除SOD) existence for this service contract line under WEB order type.

| # | Type | Code |
|---|------|------|
| 1 | CALL | `executeKK_T_ODR_SET_KK_SELECT_025(kk1041SelectWhereParam)` // SELECT from KK_T_ODR_SET [R] |

**Block 9** — [CALL] Fetch next record from second cursor (L874)

> Retrieve the next matching row from the order-set query result.

| # | Type | Code |
|---|------|------|
| 1 | CALL | `kk1041NextRec = db_KK_T_ODR_SET.selectNext()` // 解除SODの発行判定用レコード取得 |

**Block 10** — [IF] Cancellation SOD check (L876-L890)

> Japanese comment: 解約SODが発行されているか判定 (determine whether a cancellation SOD has been issued).
>
> If `kk1041NextRec == null`, it means **no cancellation SOD has been issued** (解除オーダーが未発行) — the deletion order cannot proceed and must be skipped.

| # | Type | Code |
|---|------|------|
| 1 | IF | `kk1041NextRec == null` // [解除SOD未発行] 解約オーダーが未発行のため |
| 1.1 | SET | `canDel = false` // 消去不可 — cancellation SOD not yet issued |
| 1.2 | SET | `log` = `"解除オーダーが未発行のため消去オーダーの発行をスキップしました。オプションサービス契約番号[" + inMap.getString(JBSbatKKIFM160.OPSVKEI_NO) + "]"` // Error message: "Skipped issuing deletion order because cancellation order has not been issued. Option service contract number: [XXX]" |
| 1.3 | CALL | `commonItem.getLogPrint().printBusinessErrorLog("EKKB1200AI", new String[] {log})` // Log business error with message key EKKB1200AI |

**Block 10.1** — [ELSE-IF, implicit] Cancellation SOD exists (L876)

> When `kk1041NextRec != null`, a cancellation SOD has been issued for this contract line — the deletion is confirmed safe. `canDel` remains true from the first check.

| # | Type | Code |
|---|------|------|
| 1 | IF-NOT | `kk1041NextRec != null` // 解除SOD発行済み — canDel remains true |

**Block 11** — [RETURN] Return result (L891)

| # | Type | Code |
|---|------|------|
| 1 | RETURN | `return canDel;` // true = URL deletion allowed, false = deletion rejected |

## 7. Glossary

| Term | Type | Business Meaning |
|------|------|------------------|
| `canDel` | Variable | Deletion eligibility flag (消去可否) — `true` means the record may be safely deleted; `false` means deletion is prohibited |
| `OPSVKEI_NO` | Field | Option Service Contract Number (オプションサービス契約番号) — unique identifier for an option service contract line item associated with a base service contract |
| `SVKEI_NO` | Field | Service Contract Number (サービス契約番号) — unique identifier for the top-level service contract |
| `opeDate` | Field | Operation Date (運用日) — the batch processing run date used to scope database queries to the correct operational period |
| `KK_T_OP_SVC_KEI` | Table | Option Service Contract Line (オプションサービス契約連) — stores detail records for option services linked to a base service contract, including URL associations |
| `KK_T_ODR_SET` | Table | Order Set Line (オーダーセット連) — stores order processing records including cancellation orders (解除オーダー) generated when service contracts are terminated |
| `SVC_ORDER_CD_WEB` | Constant | Service Order Code: WEB (サービスオーダーコード WEB) — value `"04"`, identifies orders initiated through the WEB channel |
| `DEL_TRGT_SBT_URL` | Constant | Delete Target Category: URL (消去対象種類: URL) — classifies this method as the URL-specific branch in the deletion eligibility dispatch |
| `解除SOD` | Business term | Cancellation Service Order Data (解約サービスオーダーデータ) — an order record generated when a customer cancels their service; its presence before deletion ensures data consistency |
| `EKKB1200AI` | Log key | Business error message key — when triggered, logs that a deletion order was skipped because the required cancellation order had not yet been issued |
| `JBSbatServiceInterfaceMap` | Type | Input message container (入力電文コンテナ) — a key-value map carrying batch input parameters |
| `JBSbatCommonDBInterface` | Type | Database cursor interface (DBカーソルインターフェース) — handles scrollable SQL result set navigation via `selectNext()` |
| `JBSbatSQLAccess` | Type | SQL execution accessor (SQL実行アクセサ) — database access object parameterized with a table name and batch context |
| `JBSbatCommonItem` | Type | Common batch parameters (バッチ共通パラメータ) — shared batch context carrying logging, configuration, and metadata |
| ANK-2897-00-00 | Change ID | Change request introducing the two-stage deletion check — added the cancellation SOD verification (解除SOD) to prevent premature URL record deletion |
| URL (消去対象) | Business term | URL address associated with an option service contract line — when a customer cancels a service, this URL must be cleaned up only after confirming the cancellation order has been properly generated |
