# Business Logic — JBSbatKKKnytcsTrgtCst.outPutSbOpSvcKei() [285 LOC]

| Field | Value |
|-------|-------|
| Fully Qualified Name | `eo.business.service.JBSbatKKKnytcsTrgtCst` |
| Layer | Batch (Service layer within the batch processing tier) |
| Module | `service` (Package: `eo.business.service`) |

## 1. Role

### JBSbatKKKnytcsTrgtCst.outPutSbOpSvcKei()

This method extracts sub-option service contracts associated with a service contract number and outputs them as part of a Contract Content Notice document (契約内容通知書). The Contract Content Notice is a formal notification letter sent to K-Opticom customers detailing the charges and services covered under their current service agreement, including any additional sub-option charges (such as optional add-ons for internet, television, or phone services).

The method performs two distinct sub-option service queries against the `KK_T_SBOP_SVC_KEI` (Sub-Option Service Contract) database table. The first query (SQL select 028) retrieves general sub-option service contract records, applying a charge count adjustment logic that subtracts the "SVCTK_BUT_MRYO_VALUE" (sub-option non-chargeable count) from the contract count to prevent double-billing visibility. The second query (SQL select 030) is a Mail Wild Service Check that queries sub-option records filtered by family package contract status (`famipaKeiUm`) and network option pack identifier (`netOpPackSkbtCd`), pulling in additional service records that may be subject to virus checking or special billing rules.

The method implements a batch query-and-extract pattern: it dynamically edits SQL by replacing a single bind variable placeholder with a bind-variable-safe IN clause (one `?` placeholder per service contract number), executes each query, collects results into a shared search result list, and then iterates the combined results to determine which records qualify for output on the Contract Content Notice document. Records that do not match the target display position code are logged separately via `createLog`, ensuring traceability.

It serves as a core data preparation method within the batch contract notice generation pipeline. Called by `JBSbatKKKnytcsTrgtCst.execute()`, it feeds the `outputBean` with `JBSbatServiceInterfaceMap` entries that downstream file writers serialize into the customer-facing notice document.

## 2. Processing Pattern (Detailed Business Logic)

```mermaid
flowchart TD
    START(["outPutSbOpSvcKei"])
    
    START --> INIT["Initial Data Acquisition"]
    INIT --> INIT_LIST["Create serchResultList_SbopSvcKei"]
    INIT_LIST --> INIT_SQL["Get sqlBefore from db_KK_T_SBOP_SVC_KEI<br/>(KK_T_SBOP_SVC_KEI_KK_SELECT_028)"]
    INIT_SQL --> GET_SVC_LIST["Extract svcKeiList via getMapForList<br/>(service contract numbers)"]
    GET_SVC_LIST --> GET_MSKM["Get mskmSbtCd from inMap"]
    
    GET_MSKM --> SQL_EDIT1["SQL Edit Phase 1"]
    SQL_EDIT1 --> EDIT1["Build sqlAfter via getEditSQL<br/>(EDIT_BF_SQL_SVC_KEI / EDIT_AF_SQL_SVC_KEI)"]
    EDIT1 --> SET_SQL1["Set edited SQL to db_KK_T_SBOP_SVC_KEI"]
    
    SET_SQL1 --> BIND1["Bind Variables Setup 1"]
    BIND1 --> BIND1_ARR["Create opSvcKei array<br/>(pcrsCd, opeDate, mskmSbtCd, etc.)"]
    
    BIND1_ARR --> EXEC1["Execute Search 1"]
    EXEC1 --> CALL_SELECT_028["executeKK_T_SBOP_SVC_KEI_KK_SELECT_028<br/>(opSvcKei, svcKeiList)"]
    
    CALL_SELECT_028 --> RESTORE1["Restore sqlBefore to db_KK_T_SBOP_SVC_KEI"]
    RESTORE1 --> FETCH1["Fetch dbInfSbopSvcKei via selectNext"]
    
    FETCH1 --> LOOP1{"dbInfSbopSvcKei<br/>!= null?"}
    
    LOOP1 -->|Yes| RESULT1_MAP["Create resultMap HashMap"]
    RESULT1_MAP --> PUT_KNYTCS_NO["resultMap.put(KNYTCS_NO)"]
    PUT_KNYTCS_NO --> PUT_KNYTCS_DSP_MNGN_CD["resultMap.put(KNYTCS_DSP_MNGN_CD)"]
    PUT_KNYTCS_DSP_MNGN_CD --> PUT_DSP_PST_SKCD["resultMap.put(DSP_PST_SKCD)"]
    PUT_DSP_PST_SKCD --> PUT_TELNO_JUN["resultMap.put(TELNO_JUN)"]
    
    PUT_TELNO_JUN --> CHECK_KEI_CNT{"KEI_CNT and SVCTK_BUT_MRYO_VALUE<br/>both non-blank?"}
    
    CHECK_KEI_CNT -->|Yes| CALC_KEI["Calculate wValue =<br/>KEI_CNT - SVCTK_BUT_MRYO_VALUE"]
    CALC_KEI --> CHECK_NEGATIVE{"wValue < 0?"}
    CHECK_NEGATIVE -->|Yes| SET_ZERO["wValue = 0"]
    CHECK_NEGATIVE -->|No| PUT_KEI_RESULT["resultMap.put(KEI_CNT = wValue)"]
    SET_ZERO --> PUT_KEI_RESULT
    CHECK_KEI_CNT -->|No| PUT_KEI_RESULT
    
    PUT_KEI_RESULT --> ADD1["Add resultMap to<br/>serchResultList_SbopSvcKei"]
    ADD1 --> NEXT1["Read next row:<br/>selectNext()"]
    NEXT1 --> LOOP1
    
    LOOP1 -->|No| MAIL_WILDSVC["Mail Wild Service Check Phase"]
    
    MAIL_WILDSVC --> MAIL_SQL["Get sqlBefore<br/>(KK_T_SBOP_SVC_KEI_KK_SELECT_030)"]
    MAIL_SQL --> MAIL_EDIT["Build sqlAfter via getEditSQL"]
    MAIL_EDIT --> MAIL_SET["Set edited SQL to<br/>db_KK_T_SBOP_SVC_KEI"]
    
    MAIL_SET --> MAIL_BIND["Bind Variables Setup 2"]
    MAIL_BIND --> MAIL_BIND_ARR["Create sbopSvcKei_VirusChk array<br/>(famipaKeiUm, netOpPackSkbtCd, etc.)"]
    
    MAIL_BIND_ARR --> EXEC2["Execute Search 2"]
    EXEC2 --> CALL_SELECT_030["executeKK_T_SBOP_SVC_KEI_KK_SELECT_030<br/>(sbopSvcKei_VirusChk, svcKeiList)"]
    
    CALL_SELECT_030 --> RESTORE2["Restore sqlBefore to<br/>db_KK_T_SBOP_SVC_KEI"]
    RESTORE2 --> FETCH2["Fetch dbInfSbopSvcKei_VirusChk<br/>via selectNext"]
    
    FETCH2 --> LOOP2{"dbInfSbopSvcKei_VirusChk<br/>!= null?"}
    
    LOOP2 -->|Yes| RESULT2_MAP["Create resultMap HashMap"]
    RESULT2_MAP --> PUT2_KNYTCS["resultMap.put(KNYTCS_NO,<br/>KNYTCS_DSP_MNGN_CD,<br/>DSP_PST_SKCD,<br/>TELNO_JUN,<br/>KEI_CNT)"]
    PUT2_KNYTCS --> ADD2["Add resultMap to<br/>serchResultList_SbopSvcKei"]
    ADD2 --> NEXT2["Read next row:<br/>selectNext()"]
    NEXT2 --> LOOP2
    
    LOOP2 -->|No| OUTPUT_DECISION["Output Decision Phase"]
    
    OUTPUT_DECISION --> INIT_TMP["Create tmpMap HashMap"]
    INIT_TMP --> FOR_LOOP["Loop: i = 0 to<br/>serchResultList_SbopSvcKei.size()"]
    
    FOR_LOOP -->|i < size| OUTMAP_CREATE["Create outmap<br/>(JBSbatServiceInterfaceMap)"]
    OUTMAP_CREATE --> LOAD_TMP["Load tmpMap from<br/>serchResultList_SbopSvcKei.get(i)"]
    
    LOAD_TMP --> SET_OUTFIELDS["Set outmap fields:<br/>KNYTCS_NO, KNYTCS_DSP_MNGN_CD,<br/>DSP_PST_SKCD, TELNO_JUN, KEI_CNT"]
    
    SET_OUTFIELDS --> CHECK_OUTPUT{"isOutPutTgDspPstSkcd<br/>(DSP_PST_SKCD)?"}
    
    CHECK_OUTPUT -->|Yes| SET_OUTFLG["outmap.setOutFlg(true)"]
    SET_OUTFLG --> LOG_DEBUG["printDebugLog<br/>output record"]
    LOG_DEBUG --> ADD_OUT["outputBean.addOutMapList(outmap)"]
    ADD_OUT --> NEXT_I["i++"]
    
    CHECK_OUTPUT -->|No| LOG_NONTARGET["createLog:<br/>log non-target record info"]
    LOG_NONTARGET --> NEXT_I
    
    NEXT_I --> FOR_LOOP
    
    FOR_LOOP -->|i >= size| END_METHOD["Return (void)"]
```

**CRITICAL — Constant Resolution:**

| Constant | Value | Business Meaning |
|----------|-------|------------------|
| `EDIT_BF_SQL_SVC_KEI` | `"SVC_KEI_NO IN \\(\\?\\)"` | Pre-edit SQL template: single bind variable inside parentheses |
| `EDIT_AF_SQL_SVC_KEI` | `"SVC_KEI_NO IN "` | Post-edit SQL template: bind variables injected after `IN` |
| `KK_T_SBOP_SVC_KEI_KK_SELECT_028` | SQL key | First query: general sub-option service contract extraction |
| `KK_T_SBOP_SVC_KEI_KK_SELECT_030` | SQL key | Second query: Mail Wild Service Check (virus check / filtering) |

## 3. Parameter Analysis

| No | Parameter Name | Type | Business Description |
|----|---------------|------|---------------------|
| 1 | `inMap` | `JBSbatServiceInterfaceMap` | Contract Content Notice information carrier — holds the Contract Content Notice number (`KNYTCS_NO`) and the application subtype code (`MSKM_SBT_CD`) that classifies the type of order/application being processed (e.g., address change, new contract). Used to extract fields for output and log entries. |
| 2 | `outputBean` | `JBSbatOutputItem` | Output wire message holder — accumulates records destined for the Contract Content Notice file. Records that match the target display position code are marked with `setOutFlg(true)` and added via `addOutMapList()`. Non-matching records are skipped from output but logged. |
| 3 | `svcMapList` | `ArrayList<HashMap<String, String>>` | Service contract map list — a collection of service contract records passed from the caller. Each map contains at minimum the `SVC_KEI_NO` (service contract number), which is extracted into `svcKeiList` for building the dynamic SQL IN clause bind variables. |

**Instance fields read by this method:**

| Field | Type | Business Description |
|-------|------|---------------------|
| `db_KK_T_SBOP_SVC_KEI` | `JBSbatSQLAccess` | Database access object for the `KK_T_SBOP_SVC_KEI` (Sub-Option Service Contract) table |
| `pcrsCd` | `String` | Pricing code (料金コード) — identifies the customer's pricing plan/product line |
| `opeDate` | (inherited `super.opeDate`) | Operation/application effective date — used throughout bind variable arrays as the applicability date for contract terms |
| `famipaKeiUm` | `String` | Family package contract existence flag — indicates whether a family package contract is active; used to filter sub-option records for mail wild service checking |
| `netOpPackSkbtCd` | `String` | Network option pack identifier code — identifies which network option package the customer has; used in the second query to filter relevant sub-option records |

## 4. CRUD Operations / Called Services

| CRUD | SC / CBS | SC Code | Entity / DB | Operation Description |
|------|----------|---------|-------------|----------------------|
| R | `JBSbatKKKnytcsTrgtCst.getMapForList` | - | `KK_T_SVC_KEI` (SVC_KEI_NO) | Extracts a list of service contract numbers from `svcMapList` for building the dynamic SQL IN clause |
| R | `inMap.getString` | - | - | Reads `KNYTCS_NO` and `MSKM_SBT_CD` from the input contract content notice map |
| R | `db_KK_T_SBOP_SVC_KEI.getSql` | - | SQL config | Retrieves the pre-configured SELECT SQL template for the specified query key |
| C | `JBSbatKKKnytcsTrgtCst.getEditSQL` | - | - | Edits SQL by replacing bind variable placeholders with one `?` per service contract number |
| - | `db_KK_T_SBOP_SVC_KEI.setSqlMap` | - | - | Stores the edited SQL back into the SQL access object for execution |
| C | `JBSbatKKKnytcsTrgtCst.executeKK_T_SBOP_SVC_KEI_KK_SELECT_028` | - | `KK_T_SBOP_SVC_KEI` | Executes the first sub-option service contract extraction query with bind variables |
| R | `db_KK_T_SBOP_SVC_KEI.selectNext` | - | `KK_T_SBOP_SVC_KEI` | Fetches the next row from the query result set during result iteration |
| R | `dbInfSbopSvcKei.getString` | - | `KK_T_SBOP_SVC_KEI` (mapped fields) | Reads individual column values (KNYTCS_DSP_MNGN_CD, DSP_PST_SKCD, TELNO_JUN, KEI_CNT, SVCTK_BUT_MRYO_VALUE) from each result row |
| - | `JBSbatKKKnytcsTrgtCst.executeKK_T_SBOP_SVC_KEI_KK_SELECT_030` | - | `KK_T_SBOP_SVC_KEI` | Executes the second sub-option service contract query (Mail Wild Service Check) |
| C | `JBSbatKKKnytcsTrgtCst.createLog` | - | - | Logs non-target records (those not matching the output display position code) for audit traceability |
| - | `JACBatCommon.printDebugLog` | JACBatCommon | - | Writes debug log messages confirming output record processing |
| C | `outputBean.addOutMapList` | JBSbatKKGetCTITelno | - | Adds qualifying records (matched display position code) to the output wire message list |
| - | `JBSbatACIcjknTrkmRsltHenshu.setOutFlg` | JBSbatACIcjknTrkmRsltHenshu | - | Sets the output flag to `true` on records that match the target display position code |
| - | `isOutPutTgDspPstSkcd` | JBSbatKKKnytcsTrgtCst | - | Checks whether a record's display position code matches the target code for output inclusion |

## 5. Dependency Trace

| # | Caller (Screen/Batch) | Call Chain (Full Path to this Method) | Terminal (SC / CRUD / Entity) |
|---|----------------------|--------------------------------------|-------------------------------|
| 1 | Batch: `JBSbatKKKnytcsTrgtCst.execute()` | `execute()` → `outPutSbOpSvcKei(inMap, outputBean, svcMapList)` | `executeKK_T_SBOP_SVC_KEI_KK_SELECT_028 [R] KK_T_SBOP_SVC_KEI`, `executeKK_T_SBOP_SVC_KEI_KK_SELECT_030 [R] KK_T_SBOP_SVC_KEI`, `createLog [C] -`, `addOutMapList [C] outputBean`, `getString [R] inMap/resultMap`, `printDebugLog [-]` |

## 6. Per-Branch Detail Blocks

**Block 1** — [SET] Initial Data Acquisition (L5237)

> Initialize local variables and extract base data from inputs.

| # | Type | Code |
|---|------|------|
| 1 | SET | `serchResultList_SbopSvcKei = new ArrayList<HashMap<String, String>>()` // Initialize search result list for accumulated query data |
| 2 | SET | `sqlBefore = db_KK_T_SBOP_SVC_KEI.getSql(KK_T_SBOP_SVC_KEI_KK_SELECT_028)` // Retrieve base SELECT SQL template for general sub-option contract extraction |
| 3 | SET | `sqlAfter = ""` // Initialize post-edit SQL string |
| 4 | SET | `svcKeiList = getMapForList(svcMapList, JBSbatKK_T_SVC_KEI.SVC_KEI_NO)` // Extract all service contract numbers from the input map list for dynamic SQL IN clause |
| 5 | SET | `mskmSbtCd = inMap.getString(JBSbatKK_T_MSKM.MSKM_SBT_CD)` // Read application subtype code from input map |

**Block 2** — [SET] SQL Edit Phase 1 (L5264)

> Dynamically edit the SQL template to support multiple service contract numbers via bind variables.

| # | Type | Code |
|---|------|------|
| 1 | SET | `sqlAfter = getEditSQL(svcKeiList, sqlBefore, EDIT_BF_SQL_SVC_KEI, EDIT_AF_SQL_SVC_KEI)` // Replace single `?` with `(?,?,...,?)` bind count matching svcKeiList size; EDIT_BF_SQL_SVC_KEI="SVC_KEI_NO IN \\(\\?\\)", EDIT_AF_SQL_SVC_KEI="SVC_KEI_NO IN " |
| 2 | SET | `db_KK_T_SBOP_SVC_KEI.setSqlMap(KK_T_SBOP_SVC_KEI_KK_SELECT_028, sqlAfter)` // Store edited SQL for execution |

**Block 3** — [SET] Bind Variables Setup 1 (L5271)

> Prepare the bind variable array for the first query. The array structure matches the columns expected by `KK_T_SBOP_SVC_KEI_KK_SELECT_028`.

| # | Type | Code |
|---|------|------|
| 1 | SET | `opSvcKei = new Object[] { pcrsCd, "", super.opeDate, super.opeDate, super.opeDate, "", super.opeDate, super.opeDate, "", super.opeDate, super.opeDate, mskmSbtCd, super.opeDate, super.opeDate, super.opeDate }` // Bind variables: pricing code, empty (contract number placeholder), application effective date (repeated for various fields), application subtype code, display language applicability start/end dates |

**Block 4** — [CALL] Execute Search 1 (L5300)

> Run the primary sub-option service contract query.

| # | Type | Code |
|---|------|------|
| 1 | CALL | `this.executeKK_T_SBOP_SVC_KEI_KK_SELECT_028(opSvcKei, svcKeiList)` // Execute general sub-option service contract search with bind variables |
| 2 | SET | `db_KK_T_SBOP_SVC_KEI.setSqlMap(KK_T_SBOP_SVC_KEI_KK_SELECT_028, sqlBefore)` // Restore original SQL after execution to clean up |

**Block 5** — [CALL] SQL Execution Result Fetch (L5308)

> Begin iterating over the query result set.

| # | Type | Code |
|---|------|------|
| 1 | SET | `dbInfSbopSvcKei = db_KK_T_SBOP_SVC_KEI.selectNext()` // Fetch the first result row |

**Block 6** — [WHILE] Iterate Search Results 1 (L5315)

> Loop through all rows returned by the first query, building result maps with charge count adjustment logic.

| # | Type | Code |
|---|------|------|
| 1 | SET | `resultMap = new HashMap<String, String>()` // Create a new map for the current row |
| 2 | SET | `resultMap.put(JBSbatKKIFM689.KNYTCS_NO, inMap.getString(JBSbatKK_T_KNYTCS.KNYTCS_NO))` // Copy contract content notice number from inMap |
| 3 | SET | `resultMap.put(JBSbatKKIFM689.KNYTCS_DSP_MNGN_CD, dbInfSbopSvcKei.getString(JBSbatKK_M_KNYTCS_DSP_MNGN.KNYTCS_DSP_MNGN_CD))` // Copy contract content notice display language code |
| 4 | SET | `resultMap.put(JBSbatKKIFM689.DSP_PST_SKCD, dbInfSbopSvcKei.getString(JBSbatKK_M_KNYTCS_DSP_MNGN.DSP_PST_SKCD))` // Copy display position identification code |
| 5 | SET | `resultMap.put(JBSbatKKIFM689.TELNO_JUN, dbInfSbopSvcKei.getString(JBSbatKK_T_SVKEIUW_EOH_TEL.TELNO_JUN))` // Copy phone number sequence number |

**Block 6.1** — [IF] Charge Count Adjustment (L5326)

> If both the contract count (KEI_CNT) and the sub-option non-chargeable count (SVCTK_BUT_MRYO_VALUE) are present, calculate the adjusted contract count by subtracting the non-chargeable count.

| # | Type | Code |
|---|------|------|
| 1 | IF | `!JKKStringUtil.isNullBlank(dbInfSbopSvcKei.getString(JBSbatKKIFM689.KEI_CNT)) && !JKKStringUtil.isNullBlank(dbInfSbopSvcKei.getString(JBSbatKK_M_PCRS_SBOP_SVC.SVCTK_BUT_MRYO_VALUE))` // Both contract count and non-chargeable value must be present |

**Block 6.1.1** — [IF] Non-chargeable Subtraction (L5328)

> Compute the adjusted count, ensuring the result never goes negative.

| # | Type | Code |
|---|------|------|
| 1 | SET | `wValue = Integer.parseInt(dbInfSbopSvcKei.getString(JBSbatKKIFM689.KEI_CNT)) - Integer.parseInt(dbInfSbopSvcKei.getString(JBSbatKK_M_PCRS_SBOP_SVC.SVCTK_BUT_MRYO_VALUE))` // Adjusted contract count = contract count minus non-chargeable count |
| 2 | IF | `wValue < 0` // Ensure adjusted count does not go below zero |

**Block 6.1.1.1** — [IF-THEN] Clamp to Zero (L5330)

| # | Type | Code |
|---|------|------|
| 1 | SET | `wValue = 0` // Set to zero if subtraction yields a negative number (補正) |

**Block 6.1.1.2** — [IF-ELSE] Put Adjusted Value (L5334)

| # | Type | Code |
|---|------|------|
| 1 | SET | `resultMap.put(JBSbatKKIFM689.KEI_CNT, String.valueOf(wValue))` // Store adjusted contract count as string |

**Block 6.2** — [SET] Add to Result List (L5337)

| # | Type | Code |
|---|------|------|
| 1 | SET | `serchResultList_SbopSvcKei.add(resultMap)` // Store the completed result map for both query phases |
| 2 | SET | `dbInfSbopSvcKei = db_KK_T_SBOP_SVC_KEI.selectNext()` // Read next row from the first query's result set |

**Block 7** — [SET] Mail Wild Service Check - Initial Data Acquisition (L5350)

> Reset sqlBefore for the second query (KK_T_SBOP_SVC_KEI_KK_SELECT_030).

| # | Type | Code |
|---|------|------|
| 1 | SET | `sqlBefore = db_KK_T_SBOP_SVC_KEI.getSql(KK_T_SBOP_SVC_KEI_KK_SELECT_030)` // Retrieve base SQL template for Mail Wild Service Check |
| 2 | SET | `sqlAfter = ""` // Reset post-edit SQL |
| 3 | SET | `sqlAfter = getEditSQL(svcKeiList, sqlBefore, EDIT_BF_SQL_SVC_KEI, EDIT_AF_SQL_SVC_KEI)` // Same SQL edit pattern: replace `?` with multiple bind variables |
| 4 | SET | `db_KK_T_SBOP_SVC_KEI.setSqlMap(KK_T_SBOP_SVC_KEI_KK_SELECT_030, sqlAfter)` // Store edited SQL for execution |

**Block 8** — [SET] Bind Variables Setup 2 (L5359)

> Prepare bind variables for the Mail Wild Service Check query. Includes `famipaKeiUm` (family package contract flag) and `netOpPackSkbtCd` (network option pack identifier), which are instance fields set by the caller.

| # | Type | Code |
|---|------|------|
| 1 | SET | `sbopSvcKei_VirusChk = new Object[] { "", super.opeDate, super.opeDate, "", super.opeDate, famipaKeiUm, netOpPackSkbtCd, mskmSbtCd, super.opeDate, super.opeDate, super.opeDate }` // Bind variables: empty contract number placeholder, application effective date (repeated), family package contract existence flag, network option pack identifier, application subtype code, display language applicability dates |

**Block 9** — [CALL] Execute Search 2 (L5384)

> Run the second sub-option service contract query (Mail Wild Service Check).

| # | Type | Code |
|---|------|------|
| 1 | CALL | `this.executeKK_T_SBOP_SVC_KEI_KK_SELECT_030(sbopSvcKei_VirusChk, svcKeiList)` // Execute Mail Wild Service Check sub-option query |
| 2 | SET | `db_KK_T_SBOP_SVC_KEI.setSqlMap(KK_T_SBOP_SVC_KEI_KK_SELECT_030, sqlBefore)` // Restore original SQL |

**Block 10** — [CALL] SQL Execution Result Fetch 2 (L5392)

| # | Type | Code |
|---|------|------|
| 1 | SET | `dbInfSbopSvcKei_VirusChk = db_KK_T_SBOP_SVC_KEI.selectNext()` // Fetch first result row from second query |

**Block 11** — [WHILE] Iterate Search Results 2 (L5400)

> Loop through all rows from the second query, storing them into the shared result list with KEI_CNT as the virus check count.

| # | Type | Code |
|---|------|------|
| 1 | SET | `resultMap = new HashMap<String, String>()` // New map for current row |
| 2 | SET | `resultMap.put(JBSbatKKIFM689.KNYTCS_NO, inMap.getString(JBSbatKK_T_KNYTCS.KNYTCS_NO))` // Copy contract content notice number |
| 3 | SET | `resultMap.put(JBSbatKKIFM689.KNYTCS_DSP_MNGN_CD, dbInfSbopSvcKei_VirusChk.getString(JBSbatKK_M_KNYTCS_DSP_MNGN.KNYTCS_DSP_MNGN_CD))` // Copy display language code |
| 4 | SET | `resultMap.put(JBSbatKKIFM689.DSP_PST_SKCD, dbInfSbopSvcKei_VirusChk.getString(JBSbatKK_M_KNYTCS_DSP_MNGN.DSP_PST_SKCD))` // Copy display position code |
| 5 | SET | `resultMap.put(JBSbatKKIFM689.TELNO_JUN, dbInfSbopSvcKei_VirusChk.getString(JBSbatKK_T_SVKEIUW_EOH_TEL.TELNO_JUN))` // Copy phone number sequence |
| 6 | SET | `resultMap.put(JBSbatKKIFM689.KEI_CNT, dbInfSbopSvcKei_VirusChk.getString(JBSbatKKIFM689.KEI_CNT))` // Copy virus check count |
| 7 | SET | `serchResultList_SbopSvcKei.add(resultMap)` // Add to shared result list (merged with first query results) |
| 8 | SET | `dbInfSbopSvcKei_VirusChk = db_KK_T_SBOP_SVC_KEI.selectNext()` // Read next row |

**Block 12** — [SET] Output Decision Phase (L5414)

> Create the temporary map holder for the output determination loop.

| # | Type | Code |
|---|------|------|
| 1 | SET | `tmpMap = new HashMap<String, String>()` // Temporary map for iteration |

**Block 13** — [FOR] Iterate Combined Results for Output Determination (L5418)

> Loop through all accumulated records (from both queries) and decide whether each should be included in the output document.

| # | Type | Code |
|---|------|------|
| 1 | SET | `outmap = new JBSbatServiceInterfaceMap()` // Create output map for current record |
| 2 | SET | `tmpMap = serchResultList_SbopSvcKei.get(i)` // Load accumulated data for current index |

**Block 13.1** — [SET] Set Output Fields (L5426)

> Copy all fields from the accumulated result into the output map for final determination.

| # | Type | Code |
|---|------|------|
| 1 | SET | `outmap.setString(JBSbatKKIFM689.KNYTCS_NO, tmpMap.get(JBSbatKK_T_KNYTCS.KNYTCS_NO))` // Contract content notice number |
| 2 | SET | `outmap.setString(JBSbatKKIFM689.KNYTCS_DSP_MNGN_CD, tmpMap.get(JBSbatKK_M_KNYTCS_DSP_MNGN.KNYTCS_DSP_MNGN_CD))` // Display language code |
| 3 | SET | `outmap.setString(JBSbatKKIFM689.DSP_PST_SKCD, tmpMap.get(JBSbatKK_M_KNYTCS_DSP_MNGN.DSP_PST_SKCD))` // Display position code |
| 4 | SET | `outmap.setString(JBSbatKKIFM689.TELNO_JUN, tmpMap.get(JBSbatKK_T_SVKEIUW_EOH_TEL.TELNO_JUN))` // Phone number sequence |
| 5 | SET | `outmap.setString(JBSbatKKIFM689.KEI_CNT, tmpMap.get(JBSbatKKIFM689.KEI_CNT))` // Contract count |

**Block 14** — [IF] Output Target Display Position Check (L5433)

> Determine whether this record's display position code qualifies it for inclusion in the Contract Content Notice document.

| # | Type | Code |
|---|------|------|
| 1 | IF | `isOutPutTgDspPstSkcd(tmpMap.get(JBSbatKK_M_KNYTCS_DSP_MNGN.DSP_PST_SKCD))` // Check if display position code matches a target code for output inclusion |

**Block 14.1** — [IF-THEN] Add to Output (L5435)

> The record matches the target display position — mark it for output and add to the output bean.

| # | Type | Code |
|---|------|------|
| 1 | SET | `outmap.setOutFlg(true)` // Flag this record as output-qualified |
| 2 | SET | `super.logPrint.printDebugLog("サブオプションサービス契約：" + tmpMap.get(JBSbatKK_M_KNYTCS_DSP_MNGN.KNYTCS_DSP_MNGN_CD))` // Debug log confirming output record [サブオプションサービス契約 = Sub-option service contract] |
| 3 | CALL | `outputBean.addOutMapList(outmap)` // Add to output bean for file generation |

**Block 14.2** — [IF-ELSE] Log Non-Target Record (L5443)

> The record does NOT match the target display position — log it for audit purposes instead of outputting.

| # | Type | Code |
|---|------|------|
| 1 | CALL | `createLog(inMap.getString(JBSbatKK_T_KNYTCS.KNYTCS_NO), tmpMap.get(JBSbatKK_M_KNYTCS_DSP_MNGN.KNYTCS_DSP_MNGN_CD), tmpMap.get(JBSbatKK_M_KNYTCS_DSP_MNGN.DSP_PST_SKCD), "サブオプションサービス関連情報")` // Log non-target record details [サブオプションサービス関連情報 = Sub-option service related information] |

## 7. Glossary

| Term | Type | Business Meaning |
|------|------|------------------|
| `KNYTCS_NO` | Field | Contract Content Notice number — unique identifier for the customer notification document (契約内容通知書番号) |
| `KNYTCS_DSP_MNGN_CD` | Field | Contract Content Notice display language code — determines which language the notice document is printed in (契約内容通知書表示言語コード) |
| `DSP_PST_SKCD` | Field | Display position identification code — indicates where and how the contract detail should appear on the notice document (表示位置識別コード) |
| `TELNO_JUN` | Field | Phone number sequence — ordinal position of the phone number when multiple numbers are associated with the contract (電話番号順番) |
| `KEI_CNT` | Field | Contract count — the number of chargeable items/services, adjusted to exclude non-chargeable counts (契約数 / 有料のホームページ容量) |
| `SVC_KEI_NO` | Field | Service contract number — unique identifier for a service contract line item (サービス契約番号) |
| `MSKM_SBT_CD` | Field | Application subtype code — classifies the type of application/order being processed (申請種別コード) |
| `SVCTK_BUT_MRYO_VALUE` | Field | Sub-option non-chargeable count — the count of sub-option services that should NOT appear as chargeable items (サブオプション課金非対象値) |
| `pcrsCd` | Field | Pricing code — identifies the customer's pricing plan/product line (料金コード) |
| `famipaKeiUm` | Field | Family package contract existence flag — indicates whether a family package contract is active (ファミリーパック契約有無) |
| `netOpPackSkbtCd` | Field | Network option pack identifier code — identifies which network option package the customer has (ネットオプションパック識別コード) |
| `opeDate` | Field | Operation/application effective date — the date from which contract terms and conditions become applicable (予約適用年月日) |
| `KK_T_SBOP_SVC_KEI` | Table | Sub-Option Service Contract table — stores records of optional add-on services attached to a primary service contract (サブオプションサービス契約) |
| `KK_T_SVC_KEI` | Table | Service Contract table — stores primary service contract records (サービス契約) |
| `KK_T_KNYTCS` | Table | Contract Content Notice table — stores the header data for Contract Content Notice documents (契約内容通知書) |
| `KK_T_SBOP_SVC_KEI_KK_SELECT_028` | SQL Key | SQL query key 028 — general sub-option service contract extraction query |
| `KK_T_SBOP_SVC_KEI_KK_SELECT_030` | SQL Key | SQL query key 030 — Mail Wild Service Check sub-option query (メールワイルドサービスチェック) |
| `EDIT_BF_SQL_SVC_KEI` | Constant | Pre-edit SQL template: `"SVC_KEI_NO IN \\(\\?\\)"` — template before bind variable expansion |
| `EDIT_AF_SQL_SVC_KEI` | Constant | Post-edit SQL template: `"SVC_KEI_NO IN "` — template after bind variable injection |
| `JBSbatKKKnytcsTrgtCst` | Class | Contract Content Notice Target Constant — batch service class responsible for extracting and formatting data for the Contract Content Notice document (契約内容通知書対象定数) |
| `JBSbatKKIFM689` | Class | Output file constant class for Contract Content Notice target contract file (契約内容通知書対象契約ファイル定数クラス) |
| Sub-option Service Contract | Domain term | An optional service add-on attached to a primary service contract, such as additional internet bandwidth, premium TV channels, or bundled device services (サブオプションサービス契約) |
| Contract Content Notice | Domain term | A formal notification letter sent to customers detailing their contract terms, charges, and any changes — a key customer communication document in the contract lifecycle (契約内容通知書) |
| Mail Wild Service Check | Domain term | A secondary query that checks sub-option service records against family package and network option pack criteria, used for virus checking and special billing rule determination (メールワイルドサービスチェック) |
| Charge Count Adjustment | Business process | The logic of subtracting the non-chargeable sub-option count from the total contract count to prevent the customer-facing notice from showing duplicate or unbillable charges (契約数の調整処理) |
| Output Target Display Position | Domain concept | The display position identification code determines which records appear on the physical Contract Content Notice document versus being logged for internal audit purposes (出力対象表示位置) |
