# Business Logic — JBSbatKKKnytcsTrgtCst.outSvcKeiUcwk() [299 LOC]

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

## 1. Role

### JBSbatKKKnytcsTrgtCst.outSvcKeiUcwk()

The `outSvcKeiUcwk` method is a batch-processing entry point that retrieves service contract detail records based on a contract notification number and outputs them to a contract content notification file (電文). It performs two sequential database queries — the first retrieves the primary service contract detail lines, and the second retrieves pre-change phone numbers for records involving pending contract modifications. Each fetched record undergoes display-position filtering to determine whether it should be written to the output file. For records that do not pass the filter, an exclusion log is written for audit tracking. The method implements a dual-query builder pattern: it dynamically edits SQL by injecting bind-variable placeholders for the service contract number list, executes the queries, resets the SQL templates, and then iterates over result sets to populate the output bean. It handles two distinct management display restriction codes (`021` and `022`) with complex branching logic that considers sales division (home/mezono), banpo flag (with/without phone number), and service contract detail status (pre-service, completed, suspended) to decide which records qualify for output. The method is called exclusively by the class's own `execute()` method as part of a larger batch notification file generation workflow.

## 2. Processing Pattern (Detailed Business Logic)

```mermaid
flowchart TD
    START(["outSvcKeiUcwk"])
    SQL1_BF["Get SQL(KK_SELECT_125)"]
    SVC_LIST["Extract SVC_KEI_NO list from svcMapList"]
    MSKM_SBT["Get mskmSbtCd from inMap"]
    SQL_EDIT["Edit SQL (bind variable replacement)"]
    SQL_SET1["Set edited SQL for KK_SELECT_125"]
    BIND1["Build bind variables array"]
    EXEC1["Execute KK_SELECT_125 (DB query)"]
    SQL_RESET1["Reset SQL for KK_SELECT_125"]
    SEL1["selectNext() - fetch result"]
    WLOOP1{dbInfSvcKeiUcwk != null?}
    OUTMAP1["Create outmap instance"]
    MAP1_SET["Map output fields (contract no, lang code, tel no, etc.)"]
    CHK_PST1{"isOutPutTgDspPstSkcd() check"}
    EXTRACT1["Extract banpoDiv, svcKeiUcwkStat, ksiteiCd"]
    CHK_KSITEI1{ksiteiCd is 021 or 022?}
    SPECIAL1["isOutputMngnDspJknKsiteiCd_021or022()"]
    SET_OUT1["Set outFlg=true"]
    LOG1_125["Debug log (service contract detail 125)"]
    ADD125["outputBean.addOutMapList(outmap)"]
    LOG1_129["Debug log (service contract detail 129)"]
    ADD129["outputBean.addOutMapList(outmap)"]
    LOG_EXCL1["createLog() exclusion record"]
    NEXT1["selectNext() - next row"]
    SQL2_BF["Get SQL(KK_SELECT_132)"]
    SQL_EDIT2["Edit SQL (bind variable replacement)"]
    SQL_SET2["Set edited SQL for KK_SELECT_132"]
    BIND2["Build bind variables array"]
    EXEC2["Execute KK_SELECT_132 (DB query)"]
    SQL_RESET2["Reset SQL for KK_SELECT_132"]
    SEL2["selectNext() - fetch result"]
    WLOOP2{dbInfSvcKeiUcwk2 != null?}
    OUTMAP2["Create outmap instance"]
    MAP2_SET["Map output fields (contract no, lang code, etc.)"]
    CHK_STAT{"SVC_KEI_UCWK_STAT is pre-service?"}
    SET_AFTEL["Set TELNO = AF_TEL_NO"]
    SET_BFTSEL["Set TELNO = TELNO (before change)"]
    CHK_PST2{"isOutPutTgDspPstSkcd() check"}
    EXTRACT2["Extract banpoDiv, ksiteiCd"]
    CHK_KSITEI2{ksiteiCd is 021 or 022?}
    SPECIAL2["isOutputMngnDspJknKsiteiCd_021or022()"]
    SET_OUT2["Set outFlg=true"]
    LOG2_132["Debug log (service contract detail 132)"]
    ADD2["outputBean.addOutMapList(outmap)"]
    LOG_EXCL2["createLog() exclusion record"]
    NEXT2["selectNext() - next row"]
    END(["Return (void)"])

    START --> SQL1_BF
    SQL1_BF --> SVC_LIST
    SVC_LIST --> MSKM_SBT
    MSKM_SBT --> SQL_EDIT
    SQL_EDIT --> SQL_SET1
    SQL_SET1 --> BIND1
    BIND1 --> EXEC1
    EXEC1 --> SQL_RESET1
    SQL_RESET1 --> SEL1
    SEL1 --> WLOOP1
    WLOOP1 -->|Yes| OUTMAP1
    WLOOP1 -->|No| SQL2_BF
    OUTMAP1 --> MAP1_SET
    MAP1_SET --> CHK_PST1
    CHK_PST1 -->|Yes| EXTRACT1
    CHK_PST1 -->|No| LOG_EXCL1
    LOG_EXCL1 --> NEXT1
    EXTRACT1 --> CHK_KSITEI1
    CHK_KSITEI1 -->|Yes| SPECIAL1
    CHK_KSITEI1 -->|No| SET_OUT1
    SET_OUT1 --> LOG1_125
    LOG1_125 --> ADD125
    SPECIAL1 -->|true| SET_OUT1
    SPECIAL1 -->|false| NEXT1
    ADD125 --> NEXT1
    ADD129 --> NEXT1
    NEXT1 --> WLOOP1
    WLOOP1 -->|No| SQL2_BF
    SQL2_BF --> SQL_EDIT2
    SQL_EDIT2 --> SQL_SET2
    SQL_SET2 --> BIND2
    BIND2 --> EXEC2
    EXEC2 --> SQL_RESET2
    SQL_RESET2 --> SEL2
    SEL2 --> WLOOP2
    WLOOP2 -->|Yes| OUTMAP2
    WLOOP2 -->|No| END
    OUTMAP2 --> MAP2_SET
    MAP2_SET --> CHK_STAT
    CHK_STAT -->|Yes| SET_AFTEL
    CHK_STAT -->|No| SET_BFTSEL
    SET_AFTEL --> CHK_PST2
    SET_BFTSEL --> CHK_PST2
    CHK_PST2 -->|Yes| EXTRACT2
    CHK_PST2 -->|No| LOG_EXCL2
    LOG_EXCL2 --> NEXT2
    EXTRACT2 --> CHK_KSITEI2
    CHK_KSITEI2 -->|Yes| SPECIAL2
    CHK_KSITEI2 -->|No| SET_OUT2
    SET_OUT2 --> LOG2_132
    LOG2_132 --> ADD2
    SPECIAL2 -->|true| SET_OUT2
    SPECIAL2 -->|false| NEXT2
    ADD2 --> NEXT2
    NEXT2 --> WLOOP2
    WLOOP2 -->|No| END
```

**CRITICAL — Constant Resolution:**

| Constant | Resolved Value | Business Meaning |
|----------|---------------|------------------|
| `MNGN_DSP_JKN_KSITEI_CD_021` | `"021"` | Management display restriction code 021 — for records where phone number absence + completed/settled status qualify for output |
| `MNGN_DSP_JKN_KSITEI_CD_022` | `"022"` | Management display restriction code 022 — for records where phone number presence (home/mezono) or other statuses qualify for output |
| `EDIT_BF_SQL_SVC_KEI` | `"SVC_KEI_NO IN \\(\\?\\)"` | Before-edit SQL template with bind variable placeholder for service contract number filter |
| `EDIT_AF_SQL_SVC_KEI` | `"SVC_KEI_NO IN "` | After-edit SQL template — placeholder replaced with actual IN-list values |
| `KK_T_SVC_KEI_UCWK_KK_SELECT_125` | `"KK_SELECT_125"` | SQL definition key for primary service contract detail query |
| `KK_T_SVC_KEI_UCWK_KK_SELECT_132` | `"KK_SELECT_132"` | SQL definition key for pre-change phone number query (v27.00.04 addition) |
| `CD00037_UK_ZM` | `"010"` | Service contract status: not yet providing (pre-service) |
| `CD00037_SHOSA_ZUMI` | `"020"` | Service contract status: inspection complete |
| `CD00037_CNC_ZM` | `"030"` | Service contract status: settlement complete |
| `CD00037_CANCEL_ZM` | `"920"` | Service contract status: cancellation complete |
| `CD00130_02` | `"02"` | Service type code for telephone service (Home/Mezono) |
| `CD00002_UMU_1` | `"1"` | Banpo type: with phone number |
| `CD01616_STAT_SHOSAZUMI` | `"020"` | Contract detail status: inspection complete |
| `CD01616_STAT_TEIKETSUZUMI` | `"030"` | Contract detail status: settlement complete |

## 3. Parameter Analysis

| No | Parameter Name | Type | Business Description |
|----|---------------|------|---------------------|
| 1 | `inMap` | `JBSbatServiceInterfaceMap` | Contract content notification information — carries the contract notification number (`KNYTCS_NO`) and application subtype code (`MSKM_SBT_CD`) used as input criteria for the output process. This is the primary input envelope containing all contract-level identifiers needed to scope the batch output. |
| 2 | `outputBean` | `JBSbatOutputItem` | Output message bean — accumulates records marked for file output. Records with `outFlg=true` are appended to this list via `addOutMapList()` and ultimately written to the contract content notification file. Acts as the output buffer for the batch job. |
| 3 | `svcMapList` | `ArrayList<HashMap<String, String>>` | Service contract map list — contains service contract records (including service code `SVC_CD` and plan code `PPLAN_CD`) for the contracts being processed. Used both to extract the service contract number list for SQL bind variables and to determine plan codes for Home/Mezono telephone service pricing branch logic in the `isOutputMngnDspJknKsiteiCd_021or022()` helper. |
| 4 | `tvDspMap` | `HashMap<String, String>` | Television display position map — a lookup table mapping service contract line item numbers to TV display position numbers. Used to enrich each output record with the appropriate TV screen positioning reference. |

**Instance fields read by this method:**

| Field | Type | Business Description |
|-------|------|---------------------|
| `db_KK_T_SVC_KEI_UCWK` | DB interface | Database access object for the `KK_T_SVC_KEI_UCWK` table — used for SQL retrieval, binding, and execution across both query phases |
| `super.opeDate` | `String`/`Date` | Operation date — used as the reservation application date, contract notification display language application start/end date, and scheduling effective date in bind variable arrays |
| `super.logPrint` | Debug logger | Logging utility used to emit debug messages (service contract detail 125/129/132) for tracking which records pass output filters |

## 4. CRUD Operations / Called Services

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

| CRUD | SC / CBS | SC Code | Entity / DB | Operation Description |
|------|----------|---------|-------------|----------------------|
| R | `db_KK_T_SVC_KEI_UCWK.getSql` | KK_T_SVC_KEI_UCWK | KK_T_SVC_KEI_UCWK | Retrieves SQL definition template for KK_SELECT_125 from the SQL map |
| R | `db_KK_T_SVC_KEI_UCWK.getSql` | KK_T_SVC_KEI_UCWK | KK_T_SVC_KEI_UCWK | Retrieves SQL definition template for KK_SELECT_132 (v27.00.04) |
| R | `getMapForList` | JBSbatKKKnytcsTrgtCst | - | Extracts unique SVC_KEI_NO values from svcMapList as a string list for SQL bind variables |
| R | `inMap.getString` | JBSbatServiceInterfaceMap | - | Reads KNYTCS_NO (contract notification number) and MSKM_SBT_CD (application subtype code) from input map |
| R | `dbInfSvcKeiUcwk.getString` | KK_T_SVC_KEI_UCWK | KK_T_SVC_KEI_UCWK, KK_T_SVKEIUW_EOH_TEL, KK_M_KNYTCS_DSP_MNGN | Reads output columns during first query result iteration: contract notification display language code, display position code, phone number, banpo flag, phone number sequence, TV display position, service contract detail status, management display restriction code |
| R | `dbInfSvcKeiUcwk2.getString` | KK_T_SVC_KEI_UCWK | KK_T_SVC_KEI_UCWK, KK_T_SVKEIUW_EOH_TEL, KK_M_KNYTCS_DSP_MNGN | Reads output columns during second query result iteration: same fields plus AF_TEL_NO (after-change phone number) |
| C | `JBSbatKKKnytcsTrgtCst.createLog` | JBSbatKKKnytcsTrgtCst | - | Creates exclusion log entries for records that fail the display-position filter check |
| C | `outputBean.addOutMapList` | JBSbatOutputItem | - | Adds a completed output map record to the output file list |
| R | `tvDspMap.get` | HashMap | - | Looks up TV display position number for a given service contract line item number |
| R | `isOutputMngnDspJknKsiteiCd_021or022` | JBSbatKKKnytcsTrgtCst | - | Determines whether a record with management display restriction code 021/022 should be output based on banpo flag, plan code, and service contract status |
| R | `isOutPutTgDspPstSkcd` | JBSbatKKKnytcsTrgtCst | - | Determines whether a record's display position code matches the output target filter criteria |
| - | `db_KK_T_SVC_KEI_UCWK.setSqlMap` | KK_T_SVC_KEI_UCWK | KK_T_SVC_KEI_UCWK | Sets/overwrites SQL definition in the SQL map before and after query execution |
| - | `db_KK_T_SVC_KEI_UCWK.selectBySqlDefine` | KK_T_SVC_KEI_UCWK | KK_T_SVC_KEI_UCWK | Executes the SQL query via database abstraction layer (invoked inside executeKK_T_SVC_KEI_UCWK_KK_SELECT_125/132) |
| R | `db_KK_T_SVC_KEI_UCWK.selectNext` | KK_T_SVC_KEI_UCWK | KK_T_SVC_KEI_UCWK | Fetches the next row from the query result set in a cursor-like iteration pattern |
| - | `outmap.setString` | JBSbatServiceInterfaceMap | - | Populates output map with field values for contract notification file output |
| - | `outmap.setOutFlg` | JBSbatServiceInterfaceMap | - | Sets the output flag to true, marking the record for inclusion in the output file |
| - | `super.logPrint.printDebugLog` | Debug Logger | - | Emits debug log entries identifying which records pass the output filter |

## 5. Dependency Trace

| # | Caller (Screen/Batch) | Call Chain (Full Path to this Method) | Terminal (SC / CRUD / Entity) |
|---|----------------------|--------------------------------------|-------------------------------|
| 1 | Batch: JBSbatKKKnytcsTrgtCst | `execute()` → `outSvcKeiUcwk()` | `createLog [C]`, `getString [R]`, `addOutMapList [C]`, `printDebugLog [-]` |

**Call Chain Detail:**
- The method is called directly by `JBSbatKKKnytcsTrgtCst.execute()` — the class's own batch execution entry point. No intermediate layers exist between the batch executor and this method. The `execute()` method orchestrates multiple such output methods (for different contract notification record types) in sequence.

**Terminal operations reachable from this method:**
- `createLog` [C] — writes exclusion logs for records that fail display-position filtering
- `getString` [R] — reads fields from database result rows and input maps (contract numbers, status codes, phone numbers, etc.)
- `addOutMapList` [C] — adds qualifying records to the output file buffer
- `printDebugLog` [-] — logs which records pass output filters (for operational tracing)

## 6. Per-Branch Detail Blocks

### Block 1 — INITIALIZATION (Data Acquisition) (L4280)

> Retrieves the SQL template, extracts the service contract number list, and reads the application subtype code from input parameters.

| # | Type | Code |
|---|------|------|
| 1 | CALL | `db_KK_T_SVC_KEI_UCWK.getSql(KK_T_SVC_KEI_UCWK_KK_SELECT_125)` | -> `KK_T_SVC_KEI_UCWK_KK_SELECT_125="KK_SELECT_125"` |
| 2 | SET | `sqlBefore = result` | // SQL before-edit template |
| 3 | SET | `sqlAfter = ""` | // SQL after-edit placeholder |
| 4 | CALL | `getMapForList(svcMapList, JBSbatKK_T_SVC_KEI_UCWK.SVC_KEI_NO)` | // Extract service contract number list |
| 5 | SET | `svcKeiList = result` | // List of SVC_KEI_NO values |
| 6 | CALL | `inMap.getString(JBSbatKK_T_MSKM.MSKM_SBT_CD)` | // Read application subtype code |
| 7 | SET | `mskmSbtCd = result` | // Application subtype code for bind variables |

### Block 2 — SQL EDITING (Pre-Query SQL Construction) (L4299)

> Edits the SQL template by replacing bind-variable placeholders with actual service contract number values.

| # | Type | Code |
|---|------|------|
| 1 | CALL | `getEditSQL(svcKeiList, sqlBefore, EDIT_BF_SQL_SVC_KEI, EDIT_AF_SQL_SVC_KEI)` | -> `EDIT_BF_SQL_SVC_KEI="SVC_KEI_NO IN \\(\\?\\)"`, -> `EDIT_AF_SQL_SVC_KEI="SVC_KEI_NO IN "` |
| 2 | SET | `sqlAfter = result` | // Edited SQL with IN-list values |
| 3 | CALL | `db_KK_T_SVC_KEI_UCWK.setSqlMap(KK_T_SVC_KEI_UCWK_KK_SELECT_125, sqlAfter)` | // Set edited SQL |

### Block 3 — BIND VARIABLE SETUP (L4306)

> Builds the bind variable array for the first database query (KK_SELECT_125).

| # | Type | Code |
|---|------|------|
| 1 | SET | `svcKeiUcwk = new Object[]{ "", super.opeDate, mskmSbtCd, super.opeDate, super.opeDate, super.opeDate }` | // Bind variables: (svc_kei_no, reservation_app_date, app_sub_type_cd, notify_lang_app_start_date, notify_lang_app_end_date, reservation_app_date) |

Note: Several commented-out version-specific lines (v24.00.00, v27.00.03) for additional `super.opeDate` fields are excluded — they were removed in v27.00.03 and are inactive.

### Block 4 — FIRST SQL EXECUTION (L4328)

> Executes the primary service contract detail query.

| # | Type | Code |
|---|------|------|
| 1 | CALL | `this.executeKK_T_SVC_KEI_UCWK_KK_SELECT_125(svcKeiUcwk, svcKeiList)` | // Runs DB query with bind variables and service contract number list |
| 2 | CALL | `db_KK_T_SVC_KEI_UCWK.setSqlMap(KK_T_SVC_KEI_UCWK_KK_SELECT_125, sqlBefore)` | // Reset SQL to original template |

### Block 5 — FIRST RESULT FETCH (L4338)

> Retrieves the first result row from the query cursor.

| # | Type | Code |
|---|------|------|
| 1 | CALL | `db_KK_T_SVC_KEI_UCWK.selectNext()` |
| 2 | SET | `dbInfSvcKeiUcwk = result` | // Database interface for first query results |

### Block 6 — FIRST RESULT LOOP (L4345)

> Iterates over all rows from the first query. For each row, maps fields to output, applies output filtering, and either adds to output or logs exclusion.

**Block 6.1 — Create output map (L4350)**

| # | Type | Code |
|---|------|------|
| 1 | SET | `outmap = new JBSbatServiceInterfaceMap()` |
| 2 | CALL | `outmap.setString(JBSbatKKIFM689.KNYTCS_NO, inMap.getString(JBSbatKK_T_KNYTCS.KNYTCS_NO))` | // Contract notification number from input |
| 3 | CALL | `outmap.setString(JBSbatKKIFM689.KNYTCS_DSP_MNGN_CD, dbInfSvcKeiUcwk.getString(JBSbatKK_M_KNYTCS_DSP_MNGN.KNYTCS_DSP_MNGN_CD))` | // Contract notification display language code |
| 4 | CALL | `outmap.setString(JBSbatKKIFM689.DSP_PST_SKCD, dbInfSvcKeiUcwk.getString(JBSbatKK_M_KNYTCS_DSP_MNGN.DSP_PST_SKCD))` | // Display position identification code |
| 5 | CALL | `outmap.setString(JBSbatKKIFM689.TELNO, dbInfSvcKeiUcwk.getString(JBSbatKK_T_SVKEIUW_EOH_TEL.TELNO))` | // Phone number |
| 6 | CALL | `outmap.setString(JBSbatKKIFM689.BMP_UM, dbInfSvcKeiUcwk.getString(JBSbatKK_T_SVKEIUW_EOH_TEL.BMP_UM))` | // Banpo (with/without phone) flag |
| 7 | CALL | `outmap.setString(JBSbatKKIFM689.TELNO_JUN, dbInfSvcKeiUcwk.getString(JBSbatKK_T_SVKEIUW_EOH_TEL.TELNO_JUN))` | // Phone number sequence |
| 8 | CALL | `outmap.setString(JBSbatKKIFM689.TV_DSP_NO, tvDspMap.get(dbInfSvcKeiUcwk.getString(JBSbatKK_T_SVC_KEI_UCWK.SVC_KEI_UCWK_NO)))` | // TV display position number — resolved using service contract line item number as key |

**Block 6.2 — Display position filter check (L4375)**

**[IF]** `isOutPutTgDspPstSkcd(dbInfSvcKeiUcwk.getString(JBSbatKK_M_KNYTCS_DSP_MNGN.DSP_PST_SKCD))` returns `true` (L4375)

> The record's display position code matches the output target criteria. Proceed with additional filtering for restricted codes 021/022.

**Block 6.2.1 — Extract fields for 021/022 evaluation (L4381)**

| # | Type | Code |
|---|------|------|
| 1 | SET | `banpoDiv = dbInfSvcKeiUcwk.getString(JBSbatKK_T_SVKEIUW_EOH_TEL.BMP_UM)` | // Banpo (with/without phone) flag |
| 2 | SET | `svcKeiUcwkStat = dbInfSvcKeiUcwk.getString(JBSbatKK_T_SVC_KEI_UCWK.SVC_KEI_UCWK_STAT)` | // Service contract detail status |
| 3 | SET | `ksiteiCd = dbInfSvcKeiUcwk.getString(JBSbatKK_M_KNYTCS_DSP_MNGN.MNGN_DSP_JKN_KSITEI_CD)` | // Management display restriction code |

**Block 6.2.2 — Management display restriction code check [IF]** `MNGN_DSP_JKN_KSITEI_CD_021.equals(ksiteiCd) \|\| MNGN_DSP_JKN_KSITEI_CD_022.equals(ksiteiCd)` (L4385)

> ksiteiCd is either "021" or "022" — these codes have additional output qualification logic based on plan type, banpo flag, and service status.

**Block 6.2.2.1 — Delegate to complex filter method [IF]** `isOutputMngnDspJknKsiteiCd_021or022(svcMapList, banpoDiv, ksiteiCd, svcKeiUcwkStat)` returns `true` (L4396)

> The helper method evaluates the intricate logic:
> - For Home/Mezono telephone service plans: if banpo is "1" (with phone) AND ksiteiCd is "022" → output; if banpo is absent AND status is "020" (inspection complete) or "030" (settlement complete) AND ksiteiCd is "021" → output; otherwise for other statuses with banpo absent AND ksiteiCd is "022" → output.
> - For other services (non-telephone): if ksiteiCd is "022" → output.

| # | Type | Code |
|---|------|------|
| 1 | CALL | `isOutputMngnDspJknKsiteiCd_021or022(svcMapList, banpoDiv, ksiteiCd, svcKeiUcwkStat)` | // Complex filter: evaluates banpo, plan code, status, ksiteiCd |
| 2 | SET | `outmap.setOutFlg(true)` | // Mark record for output |
| 3 | CALL | `super.logPrint.printDebugLog("サービス契約内訳_129: " + ...)` | // Debug log: "Service contract detail 129" |
| 4 | CALL | `outputBean.addOutMapList(outmap)` | // Add to output list |

**Block 6.2.2.2 — ELSE: ksiteiCd is NOT 021 or 022 (L4410)**

> For codes other than 021/022, all records with matching display position pass through.

| # | Type | Code |
|---|------|------|
| 1 | SET | `outmap.setOutFlg(true)` | // Mark record for output |
| 2 | CALL | `super.logPrint.printDebugLog("サービス契約内訳_125: " + ...)` | // Debug log: "Service contract detail 125" |
| 3 | CALL | `outputBean.addOutMapList(outmap)` | // Add to output list |

**Block 6.3 — ELSE: Display position does NOT match filter (L4440)**

> The record's display position code does not match the output target. Write an exclusion log instead.

| # | Type | Code |
|---|------|------|
| 1 | CALL | `createLog(inMap.getString(JBSbatKK_T_KNYTCS.KNYTCS_NO), dbInfSvcKeiUcwk.getString(JBSbatKK_M_KNYTCS_DSP_MNGN.KNYTCS_DSP_MNGN_CD), dbInfSvcKeiUcwk.getString(JBSbatKK_M_KNYTCS_DSP_MNGN.DSP_PST_SKCD), "サービス契約内訳関連情報")` | // Log exclusion: contract no, display language code, display position code, "service contract detail related info" |

**Block 6.4 — Next row (L4451)**

| # | Type | Code |
|---|------|------|
| 1 | CALL | `dbInfSvcKeiUcwk = db_KK_T_SVC_KEI_UCWK.selectNext()` | // Fetch next row, or null if exhausted |

### Block 7 — SECOND QUERY PREPARATION (v27.00.04 Addition) (L4459)

> Retrieves pre-change phone numbers. This block queries a different SQL (KK_SELECT_132) that joins service contract details with pending modification data to obtain the phone number before any change takes effect.

| # | Type | Code |
|---|------|------|
| 1 | CALL | `db_KK_T_SVC_KEI_UCWK.getSql(KK_T_SVC_KEI_UCWK_KK_SELECT_132)` | -> `KK_T_SVC_KEI_UCWK_KK_SELECT_132="KK_SELECT_132"` |
| 2 | SET | `sqlBefore2 = result` | // SQL before-edit template for second query |
| 3 | SET | `sqlAfter2 = ""` | // SQL after-edit placeholder |
| 4 | CALL | `getEditSQL(svcKeiList, sqlBefore2, EDIT_BF_SQL_SVC_KEI, EDIT_AF_SQL_SVC_KEI)` | // Edit SQL with bind variables |
| 5 | CALL | `db_KK_T_SVC_KEI_UCWK.setSqlMap(KK_T_SVC_KEI_UCWK_KK_SELECT_132, sqlAfter2)` | // Set edited SQL |

### Block 8 — SECOND BIND VARIABLE SETUP (L4491)

> Builds the bind variable array for the second query (KK_SELECT_132). The first element is an empty string (placeholder for SVC_KEI_NO) rather than null, and includes 7 fields instead of 6.

| # | Type | Code |
|---|------|------|
| 1 | SET | `svcKeiUcwk2 = new Object[]{ "", super.opeDate, super.opeDate, mskmSbtCd, super.opeDate, super.opeDate, super.opeDate }` | // 7 bind variables for KK_SELECT_132 |

### Block 9 — SECOND SQL EXECUTION (L4500)

> Executes the pre-change phone number query.

| # | Type | Code |
|---|------|------|
| 1 | CALL | `this.executeKK_T_SVC_KEI_UCWK_KK_SELECT_132(svcKeiUcwk2, svcKeiList)` | // Runs DB query KK_SELECT_132 |
| 2 | CALL | `db_KK_T_SVC_KEI_UCWK.setSqlMap(KK_T_SVC_KEI_UCWK_KK_SELECT_132, sqlBefore2)` | // Reset SQL to original |

### Block 10 — SECOND RESULT FETCH (L4508)

| # | Type | Code |
|---|------|------|
| 1 | CALL | `dbInfSvcKeiUcwk2 = db_KK_T_SVC_KEI_UCWK.selectNext()` | // Fetch first row of second query |

### Block 11 — SECOND RESULT LOOP (L4511)

> Iterates over all rows from the second query. Similar output filtering to Block 6, but with different field mapping and status-based phone number selection.

**Block 11.1 — Create output map (L4513)**

| # | Type | Code |
|---|------|------|
| 1 | SET | `outmap = new JBSbatServiceInterfaceMap()` |
| 2 | CALL | `outmap.setString(JBSbatKKIFM689.KNYTCS_NO, inMap.getString(JBSbatKK_T_KNYTCS.KNYTCS_NO))` | // Contract notification number |
| 3 | CALL | `outmap.setString(JBSbatKKIFM689.KNYTCS_DSP_MNGN_CD, dbInfSvcKeiUcwk2.getString(JBSbatKK_M_KNYTCS_DSP_MNGN.KNYTCS_DSP_MNGN_CD))` | // Contract notification display language code |
| 4 | CALL | `outmap.setString(JBSbatKKIFM689.DSP_PST_SKCD, dbInfSvcKeiUcwk2.getString(JBSbatKK_M_KNYTCS_DSP_MNGN.DSP_PST_SKCD))` | // Display position code |
| 5 | CALL | `outmap.setString(JBSbatKKIFM689.BMP_UM, dbInfSvcKeiUcwk2.getString(JBSbatKK_T_SVKEIUW_EOH_TEL.BMP_UM))` | // Banpo flag |
| 6 | CALL | `outmap.setString(JBSbatKKIFM689.TELNO_JUN, dbInfSvcKeiUcwk2.getString(JBSbatKK_T_SVKEIUW_EOH_TEL.TELNO_JUN))` | // Phone number sequence |
| 7 | CALL | `outmap.setString(JBSbatKKIFM689.TV_DSP_NO, tvDspMap.get(dbInfSvcKeiUcwk2.getString(JBSbatKK_T_SVC_KEI_UCWK.SVC_KEI_UCWK_NO)))` | // TV display position number |

**Block 11.2 — Status-based phone number selection [IF]** (L4530)

> Determines which phone number to use based on the service contract detail status. For pre-service records, the after-change phone number (`AF_TEL_NO`) is used; for all other statuses, the before-change phone number is retained.

**Block 11.2.1 — Status check [IF]** `JKKStrConst.CD00037_UK_ZM.equals(ucwkStat) \|\| JKKStrConst.CD00037_SHOSA_ZUMI.equals(ucwkStat) \|\| JKKStrConst.CD00037_CNC_ZM.equals(ucwkStat) \|\| JKKStrConst.CD00037_CANCEL_ZM.equals(ucwkStat)` (L4530)

> Status values: `"010"` (not yet providing), `"020"` (inspection complete), `"030"` (settlement complete), `"920"` (cancellation complete).

| # | Type | Code |
|---|------|------|
| 1 | CALL | `outmap.setString(JBSbatKKIFM689.TELNO, dbInfSvcKeiUcwk2.getString("AF_TEL_NO"))` | // After-change phone number (service not yet active) |

**Block 11.2.2 — ELSE: status is NOT pre-service (L4535)**

| # | Type | Code |
|---|------|------|
| 1 | CALL | `outmap.setString(JBSbatKKIFM689.TELNO, dbInfSvcKeiUcwk2.getString(JBSbatKK_T_SVKEIUW_EOH_TEL.TELNO))` | // Before-change phone number (service active or ongoing) |

**Block 11.3 — Display position filter [IF]** `isOutPutTgDspPstSkcd(dbInfSvcKeiUcwk2.getString(JBSbatKK_M_KNYTCS_DSP_MNGN.DSP_PST_SKCD))` (L4540)

**Block 11.3.1 — Extract fields for 021/022 check [IF]** `MNGN_DSP_JKN_KSITEI_CD_021.equals(ksiteiCd) \|\| MNGN_DSP_JKN_KSITEI_CD_022.equals(ksiteiCd)` (L4543)

| # | Type | Code |
|---|------|------|
| 1 | SET | `banpoDiv = dbInfSvcKeiUcwk2.getString(JBSbatKK_T_SVKEIUW_EOH_TEL.BMP_UM)` | // Banpo flag |
| 2 | SET | `ksiteiCd = dbInfSvcKeiUcwk2.getString(JBSbatKK_M_KNYTCS_DSP_MNGN.MNGN_DSP_JKN_KSITEI_CD)` | // Management display restriction code |
| 3 | CALL | `isOutputMngnDspJknKsiteiCd_021or022(svcMapList, banpoDiv, ksiteiCd, ucwkStat)` | // Delegate to complex filter |
| 4 | SET | `outmap.setOutFlg(true)` | // Mark for output |
| 5 | CALL | `super.logPrint.printDebugLog("サービス契約内訳_132: " + ...)` | // Debug log: "Service contract detail 132" |
| 6 | CALL | `outputBean.addOutMapList(outmap)` | // Add to output list |

**Block 11.4 — ELSE: Display position does NOT match (L4561)**

| # | Type | Code |
|---|------|------|
| 1 | CALL | `createLog(inMap.getString(JBSbatKK_T_KNYTCS.KNYTCS_NO), ...)` | // Log exclusion for second query records |

**Block 11.5 — Next row (L4569)**

| # | Type | Code |
|---|------|------|
| 1 | CALL | `dbInfSvcKeiUcwk2 = db_KK_T_SVC_KEI_UCWK.selectNext()` | // Fetch next row or null |

### Block 12 — RETURN (L4572)

> Returns void. Output records are accumulated in the `outputBean` parameter.

| # | Type | Code |
|---|------|------|
| 1 | RETURN | `return;` | // Method exits; outputBean contains accumulated records |

## 7. Glossary

| Term | Type | Business Meaning |
|------|------|------------------|
| `outSvcKeiUcwk` | Method | Output service contract detail — generates contract content notification file records from service contract detail data |
| `KNYTCS_NO` | Field | Contract notification number — unique identifier for the contract content notification batch job run |
| `KNYTCS_DSP_MNGN_CD` | Field | Contract notification display language code — determines which language version of the notification to display |
| `DSP_PST_SKCD` | Field | Display position identification code — classifies where in the output document the record should appear |
| `SVC_KEI_NO` | Field | Service contract number — internal key linking service contract header to detail records |
| `SVC_KEI_UCWK_NO` | Field | Service contract line item number — unique identifier for each service contract detail line |
| `SVC_KEI_UCWK_STAT` | Field | Service contract detail status — indicates the lifecycle state (pre-service, inspection complete, settlement complete, cancellation complete, providing, suspended, stopped) |
| `MSKM_SBT_CD` | Field | Application subtype code — classifies the type of contract application being processed |
| `BMP_UM` | Field | Banpo (with/without phone number) flag — indicates whether the sales division includes a phone number: "1" = with phone number |
| `TELNO` | Field | Phone number — the telephone number for the service contract |
| `AF_TEL_NO` | Field | After-change phone number — the new phone number that will take effect after a contract modification |
| `TELNO_JUN` | Field | Phone number sequence — ordering index for multiple phone numbers in a single record |
| `TV_DSP_NO` | Field | TV display position number — reference to the television screen position for displaying this record |
| `MNGN_DSP_JKN_KSITEI_CD` | Field | Management display restriction code — restricts which records appear in management displays: "021" and "022" trigger special output qualification logic |
| `PPLAN_CD` | Field | Plan code — identifies the telephone service pricing plan (Home, Mezono, etc.) |
| `SVC_CD` | Field | Service code — classifies the service type (e.g., "02" = telephone service) |
| `KNYTCS_DSP_MNGN_CD` | Field | Contract notification display language code — language variant for the notification output |
| `CD00037_UK_ZM` | Constant | Service contract status: not yet providing ("010") — pre-service state |
| `CD00037_SHOSA_ZUMI` | Constant | Service contract status: inspection complete ("020") |
| `CD00037_CNC_ZM` | Constant | Service contract status: settlement complete ("030") |
| `CD00037_CANCEL_ZM` | Constant | Service contract status: cancellation complete ("920") |
| `CD00130_02` | Constant | Service type: telephone service ("02") |
| `CD00002_UMU_1` | Constant | Banpo type: with phone number ("1") |
| `CD01616_STAT_SHOSAZUMI` | Constant | Contract detail status: inspection complete ("020") |
| `CD01616_STAT_TEIKETSUZUMI` | Constant | Contract detail status: settlement complete ("030") |
| `MNGN_DSP_JKN_KSITEI_CD_021` | Constant | Management display restriction code 021 — output qualification for absence phone + completed/settled status |
| `MNGN_DSP_JKN_KSITEI_CD_022` | Constant | Management display restriction code 022 — output qualification for presence phone or active status |
| `PPLAN_CD_TELHT_AND_TELMZ` | Constant | Array of telephone service plan codes for Home and Mezono service types |
| KK_T_SVC_KEI_UCWK | Table | Service contract detail table — stores line item details for service contracts |
| KK_T_SVKEIUW_EOH_TEL | Table | Service detail end-of-handling telephone table — stores telephone number data including before/after change values |
| KK_M_KNYTCS_DSP_MNGN | Table | Contract notification display management table — stores display language and position management codes |
| KKIFM689 | Interface | Output file message interface (interface map 689) — defines the field structure for the contract content notification file output |
| `execute()` | Method | Batch execution entry point — orchestrates all notification file output methods including `outSvcKeiUcwk` |
| `getEditSQL` | Method | SQL editing utility — replaces bind variable placeholders in SQL templates with actual IN-list values |
| `getMapForList` | Method | Extracts unique values of a specified key from a list of maps |
| `isOutPutTgDspPstSkcd` | Method | Determines whether a display position code matches the output target filter |
| `isOutputMngnDspJknKsiteiCd_021or022` | Method | Complex output qualification method for management display restriction codes 021/022 — evaluates banpo flag, plan type, and service status |
| DB (Database) | Entity | Database access layer for `KK_T_SVC_KEI_UCWK` table — accessed via `db_KK_T_SVC_KEI_UCWK` interface |
