# Business Logic — JBSbatKKKjClDataInTrn.insertHmpInKikiNewKiki() [219 LOC]

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

## 1. Role

### JBSbatKKKjClDataInTrn.insertHmpInKikiNewKiki()

This method performs **return equipment registration** (返品機器情報の登録処理) for equipment return processing common to both Net and TV services. It is a dedicated batch-oriented service method responsible for registering returned equipment records into the `T_HMPIN_KIKI` (return equipment) table, while also handling ancillary delivery status management.

The method implements a **two-branch dispatch pattern** based on the delivery status of the equipment return candidate records. First, it searches the `KK_T_KKTK_SVC_KEI` table for delivery records matching the given service contract number and generation date. For each found record, if the delivery status is "001" (Accepted), the method transitions the delivery record to "005" (Canceled) with a cancellation code of "2" (Cancel) — effectively rolling back the delivery workflow for equipment being returned. For records that are not in "001" status, the method evaluates whether the equipment provision type is "02" (Rental); only rental-type equipment triggers the creation of a new return equipment record.

The return equipment record is populated with a system-generated sequence number, operational date, cancellation-related metadata, and a return reason code of "96" (Pre-work cancellation — common). This method serves as a **shared service component** called by `execute()` and `insertUpdateKktkSvcKeiTV()`, making it a critical integration point in the equipment return workflow for both Net service and TV service batch processes.

## 2. Processing Pattern (Detailed Business Logic)

```mermaid
flowchart TD
    START(["insertHmpInKikiNewKiki"])
    INIT["Initialize: henpinKikiNoList = new ArrayList"]
    GET_KKTK["Get kktkSvcKeiNo and geneAddDtm from kktkSvcKeiMap"]
    EXEC_SELECT["executeKK_T_KKTK_SVC_KEI_KK_SELECT_148 with hmpinKiki_param"]
    GET_RESULT["kktkSvcKeiMap_148 = db.selectNext"]
    CHECK_NULL{kktkSvcKeiMap_148 == null}
    LOG_NO_DATA["Log: No return equipment info found"]
    RETURN_EARLY["Return and exit method"]
    WHILE_LOOP{Has records}
    GET_HAISO_STAT["Get haisoStat from map"]
    CHECK_HAISO{haisoStat equals 001}
    EXEC_PKUPDATE_START["Execute HAISO update flow"]
    GET_HAISO_NO["Get haisoNo"]
    SET_WHERE["Set where_map with haisoNo"]
    SELECT_LOCK["selectByPrimaryKeysForUpdateWait"]
    CHECK_MAP{map not null}
    SET_HAISO_CANCEL["Set haisoStat=005, haisoStpCd=2, haisoStpDtm=opeDate"]
    EXEC_UPDATE["executeDK_T_HAISO_PKUPDATE"]
    THROW_ERROR["Throw JBSbatBusinessException EKB0210CE"]
    GET_PARAMS["Get: kktkSvcKeiNo, modelCd, seqNo, chgNo, sbtCd"]
    CHECK_RENTAL{kktkSbtCd equals 02}
    GEN_SEQ["Generate seqHenpinKikiNo from SEQ_HMPIN_KIKI_NO"]
    GET_SYS_DATE["Get sysDate from getSysDateTimeStamp"]
    SET_PARAM["Build setParam array with 63 fields"]
    INSERT_HMPIN["executeDK_T_HMPIN_KIKI_PKINSERT"]
    ADD_TO_LIST["henpinKikiNoList.add seqHenpinKikiNo"]
    GET_NEXT["kktkSvcKeiMap_148 = db.selectNext"]
    END_NODE(["Return to caller"])
    SKIP_INSERT["Skip: not rental type"]

    START --> INIT --> GET_KKTK --> EXEC_SELECT --> GET_RESULT --> CHECK_NULL
    CHECK_NULL -- Yes --> LOG_NO_DATA --> RETURN_EARLY
    CHECK_NULL -- No --> WHILE_LOOP
    WHILE_LOOP -- Yes --> GET_HAISO_STAT
    GET_HAISO_STAT --> CHECK_HAISO
    CHECK_HAISO -- Yes Accepted --> EXEC_PKUPDATE_START
    EXEC_PKUPDATE_START --> GET_HAISO_NO --> SET_WHERE --> SELECT_LOCK --> CHECK_MAP
    CHECK_MAP -- Yes found --> SET_HAISO_CANCEL --> EXEC_UPDATE
    CHECK_MAP -- No conflict --> THROW_ERROR
    CHECK_HAISO -- No --> GET_PARAMS --> CHECK_RENTAL
    CHECK_RENTAL -- Yes Rental --> GEN_SEQ --> GET_SYS_DATE --> SET_PARAM --> INSERT_HMPIN --> ADD_TO_LIST --> GET_NEXT
    CHECK_RENTAL -- No --> SKIP_INSERT --> GET_NEXT
    WHILE_LOOP -- No more --> END_NODE
    GET_NEXT --> WHILE_LOOP
```

**Processing Summary:**
The method follows a 4-phase flow:
1. **Lookup phase**: Search `KK_T_KKTK_SVC_KEI` for return equipment candidate records using the service contract number and generation date.
2. **Null check**: If no records exist, log and exit gracefully (no error thrown).
3. **Iterative processing**: For each record, branch based on delivery status:
   - If delivery status is "001" (Accepted), update the delivery record to "005" (Canceled) via pessimistic lock.
   - If delivery status is not "001", fetch equipment details and evaluate provision type.
4. **Rental evaluation**: If provision type is "02" (Rental), generate a return equipment number, build a 63-field parameter array, and insert the return equipment record into `T_HMPIN_KIKI`.

**Constant Resolution:**
- `CD00009_HAISO_STAT_001` = "001" (Delivery status: Accepted / 受注済)
- `CD00009_HAISO_STAT_005` = "005" (Delivery status: Canceled / 中止)
- `CD00022_HAISO_STP_CD_2` = "2" (Delivery cancellation code: Cancel / キャンセル)
- `CD00212_KKTK_SBT_CD_02` = "02" (Equipment provision type: Rental / レンタル)
- `CD00296_HMPIN_KIKI_STAT_001` = "001" (Return equipment status: Accepted / 受注済)
- `CD00291_HMPIN_DIV_1` = "1" (Return classification: Cancelled item / キャンセル品)
- `CD00293_HMPIN_RSN_CD_96` = "96" (Return reason: Pre-work cancellation (common) / 工事前キャンセル（共通）)
- `MK_FLG_YK` = "0" (Invalid flag: Valid / 有効)

## 3. Parameter Analysis

| No | Parameter Name | Type | Business Description |
|----|---------------|------|---------------------|
| 1 | `kktkSvcKeiMap` | `JBSbatCommonDBInterface` | Input message map containing equipment provision service contract data (機器提供サービス契約). This is the primary data carrier that holds the service contract number, generation registration date, model code, serial number, change number, and provision type code for the equipment being processed. |
| 2 | `svcKeiNo` | `String` | Service contract number (サービス契約番号). Used as the "upstream parent service contract number" (読込親サービス契約番号) when registering the return equipment record, linking it to the original service contract. |
| 3 | `idoDtm` | `String` | Transfer/operation registration date/time (異動登録年月日時分秒). The common item transfer/operation registration timestamp, propagated to the return equipment record as the "registration contract transfer date/time" (登録契約異動年月日時分秒). |
| 4 | `idoDiv` | `String` | Transfer classification (異動区分). The intermediate file's transfer classification, indicating the type of contract change being performed (e.g., new registration, modification). |

**Instance fields read:**
| Field | Type | Business Description |
|-------|------|---------------------|
| `henpinKikiNoList` | `ArrayList<String>` | Return equipment number list — accumulates registered return equipment numbers for use by subsequent processing (e.g., notification document updates). Initialized as new ArrayList at method entry. |
| `commonItem` | `JDKStructuredMap` | Common item configuration map — used as the source for sequence generation parameters (e.g., sequence name, date prefix, length). |
| `db_KK_T_KKTK_SVC_KEI_RUTER` | Database router | DB router for the `KK_T_KKTK_SVC_KEI` table — used to fetch return equipment search results via `selectNext()`. |
| `db_DK_T_HAISO` | Database accessor | DB accessor for the `DK_T_HAISO` (delivery) table — used for pessimistic lock reads via `selectByPrimaryKeysForUpdateWait()`. |
| `opeDate` | `String` | Operation date (運用年月日) — the operational date used as the delivery cancellation date and return reception date. |
| `batchUserId` | `String` | Batch user ID (バッチ更新者ID) — the batch processor user ID recorded as the registrant and updater of return equipment records. |
| `logPrint` | `JBSbatLogUtil` | Log printing utility — used for conditional debug logging (e.g., when no return equipment info is found). |

## 4. CRUD Operations / Called Services

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

| CRUD | SC / CBS | SC Code | Entity / DB | Operation Description |
|------|----------|---------|-------------|----------------------|
| R | `JBSbatKKKjClDataInTrn.executeKK_T_KKTK_SVC_KEI_KK_SELECT_148` | EKK0361A010SC (inferred) | `KK_T_KKTK_SVC_KEI` | Executes SQL definition key KK_SELECT_148 to search for return equipment candidate records matching the service contract number and generation date. Returns a `JBSbatCommonDBInterface` map. |
| R | `JBSbatDK_T_HAISO.selectByPrimaryKeysForUpdateWait` | EKK0361A010SC (inferred) | `DK_T_HAISO` | Performs a pessimistic lock read on the delivery record by primary key (haisoNo) to prepare for status update. Blocks if the record is locked by another process. |
| U | `JBSbatKKKjClDataInTrn.executeDK_T_HAISO_PKUPDATE` | EKK0361A010SC (inferred) | `DK_T_HAISO` | Updates the delivery record status from "001" (Accepted) to "005" (Canceled), sets cancellation code to "2" (Cancel), and records the cancellation date (opeDate). |
| C | `JBSbatKKKjClDataInTrn.executeDK_T_HMPIN_KIKI_PKINSERT` | EKK0361A020SC (inferred) | `T_HMPIN_KIKI` (Return Equipment Table) | Inserts a complete return equipment record with 63 fields including the generated return equipment number, model code, serial number, provision type, return reason code "96" (pre-work cancellation), system timestamps, and batch user ID. |
| R | `JCCBatCommon.getFormatedNextSeq` | JCCBatCommon | Sequence: `SEQ_HMPIN_KIKI_NO` | Generates a formatted return equipment number (Henpin Kiki Number) using the sequence table, with date-based prefix "R" + YY and 7-digit length. |
| R | `JCCBatCommon.getSysDateTimeStamp` / `JCCBPCommon.getSysDateTimeStamp` | JCCBatCommon | - | Retrieves the current system date-time stamp used as the system registration date and update date for the return equipment record. |
| - | `JBSbatStringUtil.Rtrim` | JBSbatStringUtil | - | Trims whitespace from string values extracted from database maps. Used extensively for data extraction. |
| - | `JDKStructuredMap.setValue` | JDKStructuredMap | - | Sets key-value pairs in structured maps used for passing parameters to database operations. |
| - | `JBSbatCommonDBInterface.setValue` | JBSbatCommonDBInterface | - | Sets values in the interface map for WHERE clause construction (e.g., `where_map.setValue(HAISO_NO, haisoNo)`). |
| - | `JACBatCommon.printDebugLog` | JACBatCommon | - | Conditional debug log output when debug mode is enabled. |
| - | `JBSbatLogUtil.chkLogLevel` | JBSbatLogUtil | - | Checks whether debug log level is active before emitting debug messages. |

## 5. Dependency Trace

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

No screen/batch entry points found within 8 hops. Direct callers found: 2 methods.
Terminal operations from this method: `executeDK_T_HAISO_PKUPDATE` [U], `executeDK_T_HMPIN_KIKI_PKINSERT` [C], `executeKK_T_KKTK_SVC_KEI_KK_SELECT_148` [R], `getFormatedNextSeq` [R], `getSysDateTimeStamp` [R], `selectByPrimaryKeysForUpdateWait` [R], `Rtrim` [-], `setValue` [-]

| # | Caller (Screen/Batch) | Call Chain (Full Path to this Method) | Terminal (SC / CRUD / Entity) |
|---|----------------------|--------------------------------------|-------------------------------|
| 1 | Batch: JBSbatKKKjClDataInTrn.execute() | `execute()` -> `insertHmpInKikiNewKiki(kktkSvcKeiMap, svcKeiNo, idoDtm, idoDiv)` | `executeDK_T_HMPIN_KIKI_PKINSERT [C] T_HMPIN_KIKI`, `executeDK_T_HAISO_PKUPDATE [U] DK_T_HAISO`, `executeKK_T_KKTK_SVC_KEI_KK_SELECT_148 [R] KK_T_KKTK_SVC_KEI` |
| 2 | Batch: JBSbatKKKjClDataInTrn.insertUpdateKktkSvcKeiTV() | `insertUpdateKktkSvcKeiTV()` -> `insertHmpInKikiNewKiki(kktkSvcKeiMap, svcKeiNo, idoDtm, idoDiv)` | `executeDK_T_HMPIN_KIKI_PKINSERT [C] T_HMPIN_KIKI`, `executeDK_T_HAISO_PKUPDATE [U] DK_T_HAISO`, `executeKK_T_KKTK_SVC_KEI_KK_SELECT_148 [R] KK_T_KKTK_SVC_KEI` |

## 6. Per-Branch Detail Blocks

**Block 1** — [SET] (L6322) Initialize the return equipment number list.

| # | Type | Code |
|---|------|------|
| 1 | SET | `henpinKikiNoList = new ArrayList<String>()` // V9.00.01 added — clears the list for each call |

**Block 2** — [PROCESS] Retrieve equipment provision service contract data (L6328-L6335)
Obtain key fields from the input map and execute the search query for return equipment candidates.

| # | Type | Code | Business Description |
|---|------|------|---------------------|
| 1 | SET | `kktkSvcKeiNo = Rtrim(kktkSvcKeiMap.getString(KKTK_SVC_KEI_NO))` | Get equipment provision service contract number |
| 2 | SET | `geneAddDtm = Rtrim(kktkSvcKeiMap.getString(GENE_ADD_DTM))` | Get equipment provision service contract generation registration date/time |
| 3 | SET | `hmpinKiki_param = {kktkSvcKeiNo, geneAddDtm}` | Build search parameter array |
| 4 | CALL | `executeKK_T_KKTK_SVC_KEI_KK_SELECT_148(hmpinKiki_param)` | Execute SQL KK_SELECT_148 to search `KK_T_KKTK_SVC_KEI` for return equipment candidates |
| 5 | SET | `kktkSvcKeiMap_148 = db_KK_T_KKTK_SVC_KEI_RUTER.selectNext()` | Fetch the first result from the search |

**Block 3** — [IF] Null check for search results (L6340-L6351)
If no delivery records are found for the given service contract number and generation date, log and exit.

| # | Type | Code | Business Description |
|---|------|------|---------------------|
| 1 | SET | `condition: kktkSvcKeiMap_148 == null` | No return equipment info found |
| 2 | EXEC | `logPrint.printDebugLog("配送に機器提供サービス契約番号:" + svcKeiNo + "、世代登録年月日時分秒:" + geneAddDtm + "に該当する返品機器情報が存在しません。")` | Log: No return equipment info found for the given service contract number and generation date |
| 3 | RETURN | `return;` | Exit method — no further processing |

**Block 4** — [WHILE] Iterative processing of return equipment candidates (L6352-L6537)
Process each found delivery record. Two mutually exclusive branches based on delivery status and provision type.

**Block 4.1** — [IF] Delivery status is "001" (Accepted) — HAISO update flow (L6359-L6360)
When the delivery status is "001" (Accepted / 受注済), transition the delivery record to canceled state via pessimistic locking.

| # | Type | Code | Business Description |
|---|------|------|---------------------|
| 1 | SET | `haisoStat_148 = Rtrim(kktkSvcKeiMap_148.getString(HAISO_STAT))` | Get delivery status |
| 2 | SET | `condition: haisoStat_148.equals(CD00009_HAISO_STAT_001)` [CD00009_HAISO_STAT_001 = "001"] | Delivery status is "001" (Accepted / 受注済) |

**Block 4.1.1** — [PROCESS] HAISO pessimistic lock and cancel update (L6363-L6399)

| # | Type | Code | Business Description |
|---|------|------|---------------------|
| 1 | SET | `where_map = new JBSbatCommonDBInterface()` | Create WHERE clause map for PK lookup |
| 2 | SET | `haisoNo = Rtrim(kktkSvcKeiMap_148.getString(HAISO_NO))` | Get delivery number |
| 3 | SET | `where_map.setValue(HAISO_NO, haisoNo)` | Set WHERE clause: HAISO_NO = haisoNo |
| 4 | CALL | `map = db_DK_T_HAISO.selectByPrimaryKeysForUpdateWait(where_map)` | Pessimistic lock read on delivery record |

**Block 4.1.2** — [IF] Lock succeeded — update delivery to canceled (L6370-L6392)

| # | Type | Code | Business Description |
|---|------|------|---------------------|
| 1 | SET | `condition: null != map` | Record was found and locked |
| 2 | SET | `value[0] = CD00009_HAISO_STAT_005` [CD00009_HAISO_STAT_005 = "005"] | Delivery status -> "005" (Canceled / 中止) |
| 3 | SET | `value[1] = CD00022_HAISO_STP_CD_2` [CD00022_HAISO_STP_CD_2 = "2"] | Delivery cancellation code -> "2" (Cancel / キャンセル) |
| 4 | SET | `value[2] = super.opeDate` | Delivery cancellation date = operational date |
| 5 | SET | `param[0] = haisoNo` | Delivery number for the update |
| 6 | IF | `logPrint.chkLogLevel(MODE_DEBUG)` | Conditional debug logging |
| 7 | EXEC | `logPrint.printDebugLog("配送更新対象 配送番号:" + param[0])` | Log: Delivery update target delivery number |
| 8 | CALL | `executeDK_T_HAISO_PKUPDATE(value, param)` | Update delivery record: status=005, stpCd=2, stpDtm=opeDate |

**Block 4.1.3** — [ELSE] Lock conflict — throw business exception (L6395-L6399)

| # | Type | Code | Business Description |
|---|------|------|---------------------|
| 1 | THROW | `throw new JBSbatBusinessException(EKKB0210CE, new String[]{"配送", "配送番号" + haisoNo})` | Record not found during lock — delivery record absence error |

**Block 4.2** — [ELSE-IF] Delivery status is not "001" — fetch equipment details and evaluate provision type (L6402-L6535)

| # | Type | Code | Business Description |
|---|------|------|---------------------|
| 1 | SET | `kktkSvcKeiNo = Rtrim(kktkSvcKeiMap.getString(KKTK_SVC_KEI_NO))` | Re-fetch equipment provision service contract number |
| 2 | SET | `taknkikiModelCd = Rtrim(kktkSvcKeiMap.getString(TAKNKIKI_MODEL_CD))` | Get indoor equipment model code |
| 3 | SET | `kikiSeizoNo = Rtrim(kktkSvcKeiMap.getString(KIKI_SEIZO_NO))` | Get equipment serial number |
| 4 | SET | `kktkChgNo = Rtrim(kktkSvcKeiMap.getString(KIKI_CHG_NO))` | Get equipment change number |
| 5 | SET | `kktkSbtCd = Rtrim(kktkSvcKeiMap.getString(KKTK_SBT_CD))` | Get equipment provision type code |

**Block 4.2.1** — [IF] Provision type is "02" (Rental) — insert return equipment record (L6410-L6411)
Only rental-type equipment generates a return equipment record.

| # | Type | Code | Business Description |
|---|------|------|---------------------|
| 1 | SET | `condition: kktkSbtCd.equals(CD00212_KKTK_SBT_CD_02)` [CD00212_KKTK_SBT_CD_02 = "02"] | Equipment provision type is "02" (Rental / レンタル) |

**Block 4.2.1.1** — [PROCESS] Generate return equipment number and timestamp (L6414-L6417)

| # | Type | Code | Business Description |
|---|------|------|---------------------|
| 1 | SET | `seqHenpinKikiNo = getFormatedNextSeq(commonItem, "SEQ_HMPIN_KIKI_NO", "R" + opeDate.substring(2,4), 7)` | Generate return equipment number: "R" + YY prefix + 7-digit sequence |
| 2 | SET | `sysDate = getSysDateTimeStamp()` | Get current system date-time stamp |

**Block 4.2.1.2** — [PROCESS] Build 63-field parameter array and insert return equipment record (L6420-L6535)

| # | Type | Code | Business Description |
|---|------|------|---------------------|
| 1 | SET | `setParam[0] = seqHenpinKikiNo` | Return equipment number -> generated sequence |
| 2 | SET | `setParam[1] = CD00296_HMPIN_KIKI_STAT_001` [CD00296_HMPIN_KIKI_STAT_001 = "001"] | Return equipment status -> "001" (Accepted / 受注済) |
| 3 | SET | `setParam[2] = opeDate` | Return reception date -> operational date |
| 4 | SET | `setParam[3] = ""` | Return warehouse entry date -> NULL (not set) |
| 5 | SET | `setParam[4] = CD00291_HMPIN_DIV_1` [CD00291_HMPIN_DIV_1 = "1"] | Return classification -> "1" (Cancelled item / キャンセル品) |
| 6 | SET | `setParam[5] = ""` | Work company code -> NULL |
| 7 | SET | `setParam[6] = ""` | Advance office office code -> NULL |
| 8 | SET | `setParam[7] = ""` | Location number -> NULL |
| 9 | SET | `setParam[8] = ""` | Warehouse code -> NULL |
| 10 | SET | `setParam[9] = ""` | Bed code -> NULL |
| 11 | SET | `setParam[10] = kktkSvcKeiNo` | Equipment provision service contract number |
| 12 | SET | `setParam[11] = kktkChgNo` | Equipment change number |
| 13 | SET | `setParam[12] = taknkikiModelCd` | Indoor equipment model code |
| 14 | SET | `setParam[13] = kikiSeizoNo` | Equipment serial number |
| 15 | SET | `setParam[14] = ""` | Accessory model code -> NULL |
| 16 | SET | `setParam[15] = ""` | Logistics security number -> NULL |
| 17 | SET | `setParam[16] = ""` | Return original individual flag -> NULL |
| 18 | SET | `setParam[17] = ""` | Returner name -> NULL |
| 19 | SET | `setParam[18] = ""` | Returner address code -> NULL |
| 20 | SET | `setParam[19] = ""` | Returner postal code -> NULL |
| 21 | SET | `setParam[20] = ""` | Returner prefecture name -> NULL |
| 22 | SET | `setParam[21] = ""` | Returner city/town/village name -> NULL |
| 23 | SET | `setParam[22] = ""` | Returner oaza-chozoname -> NULL |
| 24 | SET | `setParam[23] = ""` | Returner chomei-name -> NULL |
| 25 | SET | `setParam[24] = ""` | Returner lot number -> NULL |
| 26 | SET | `setParam[25] = ""` | Returner address supplement · building name -> NULL |
| 27 | SET | `setParam[26] = ""` | Returner address supplement · room number -> NULL |
| 28 | SET | `setParam[27] = ""` | Returner phone number -> NULL |
| 29 | SET | `setParam[28] = CD00293_HMPIN_RSN_CD_96` [CD00293_HMPIN_RSN_CD_96 = "96"] | Return reason code -> "96" (Pre-work cancellation (common) / 工事前キャンセル（共通）) |
| 30 | SET | `setParam[29] = ""` | Return reason memo -> NULL |
| 31 | SET | `setParam[30] = ""` | Return equipment acceptance date -> NULL |
| 32 | SET | `setParam[31] = ""` | Return equipment cancellation date -> NULL |
| 33 | SET | `setParam[32] = ""` | Return equipment cancellation reason code -> NULL |
| 34 | SET | `setParam[33] = ""` | Return equipment cancellation reason memo -> NULL |
| 35 | SET | `setParam[34] = ""` | Failure content -> NULL |
| 36 | SET | `setParam[35] = ""` | Recurrence yes/no -> NULL |
| 37 | SET | `setParam[36] = ""` | Operation confirmation code -> NULL |
| 38 | SET | `setParam[37] = ""` | Return type code -> NULL |
| 39 | SET | `setParam[38] = ""` | Return reception code -> NULL |
| 40 | SET | `setParam[39] = idoDiv` | Registration contract transfer classification |
| 41 | SET | `setParam[40] = idoDtm` | Registration contract transfer date/time |
| 42 | SET | `setParam[41] = "BATSERVICE"` | Return responsible user ID -> BATSERVICE |
| 43 | SET | `setParam[42] = svcKeiNo` | Upstream parent service contract number |
| 44 | SET | `setParam[43] = ""` | Product status code -> NULL |
| 45 | SET | `setParam[44] = ""` | Rental cancellation application yes/no -> NULL |
| 46 | SET | `setParam[45] = ""` | Pickup lot number -> NULL |
| 47 | SET | `setParam[46] = ""` | Customer equipment return date -> NULL |
| 48 | SET | `setParam[47] = ""` | HSTD return data status code -> NULL |
| 49 | SET | `setParam[48] = ""` | Return equipment remarks -> NULL |
| 50 | SET | `setParam[49] = ""` | Return warehouse responsible user ID -> NULL |
| 51 | SET | `setParam[50] = ""` | Return equipment acceptance responsible user ID -> NULL |
| 52 | SET | `setParam[51] = ""` | Return equipment cancellation responsible user ID -> NULL |
| 53 | SET | `setParam[52] = ""` | WMS return number -> NULL |
| 54 | SET | `setParam[53] = ""` | WMS return record number -> NULL |
| 55 | SET | `setParam[54] = kktkSbtCd` | Provision type code -> equipment provision type code |
| 56 | SET | `setParam[55] = ""` | Return original contract name -> NULL |
| 57 | SET | `setParam[56] = ""` | Return target equipment error yes/no -> NULL |
| 58 | SET | `setParam[57] = ""` | Work case number -> NULL |
| 59 | SET | `setParam[58] = sysDate` | Registration date/time -> system date-time |
| 60 | SET | `setParam[59] = batchUserId` | Registering operator account -> batch updater user ID |
| 61 | SET | `setParam[60] = sysDate` | Update date/time -> system date-time |
| 62 | SET | `setParam[61] = batchUserId` | Updating operator account -> batch updater user ID |
| 63 | SET | `setParam[62] = ""` | Deletion date/time -> NULL |
| 64 | SET | `setParam[63] = ""` | Deleting operator account -> NULL |
| 65 | SET | `setParam[64] = ""` | Deletion date/time -> NULL |
| 66 | SET | `setParam[65] = ""` | Deleting operator account -> NULL |
| 67 | SET | `setParam[66] = CD00293_HMPIN_RSN_CD_96` [CD00293_HMPIN_RSN_CD_96 = "96"] | Return reason code -> "96" (Pre-work cancellation (common) / 工事前キャンセル（共通）) |
| 68 | SET | `setParam[67] = ""` | Return reason memo -> NULL |
| 69 | SET | `setParam[68] = ""` | Return equipment acceptance date -> NULL |
| 70 | SET | `setParam[69] = ""` | Return equipment cancellation date -> NULL |
| 71 | SET | `setParam[70] = ""` | Return equipment cancellation reason code -> NULL |
| 72 | SET | `setParam[71] = ""` | Return equipment cancellation reason memo -> NULL |
| 73 | SET | `setParam[72] = ""` | Failure content -> NULL |
| 74 | SET | `setParam[73] = ""` | Recurrence yes/no -> NULL |
| 75 | SET | `setParam[74] = ""` | Operation confirmation code -> NULL |
| 76 | SET | `setParam[75] = ""` | Return type code -> NULL |
| 77 | SET | `setParam[76] = ""` | Return reception code -> NULL |
| 78 | SET | `setParam[77] = idoDiv` | Registration contract transfer classification |
| 79 | SET | `setParam[78] = idoDtm` | Registration contract transfer date/time |
| 80 | SET | `setParam[79] = "BATSERVICE"` | Return responsible user ID -> BATSERVICE |
| 81 | SET | `setParam[80] = svcKeiNo` | Upstream parent service contract number |
| 82 | SET | `setParam[81] = ""` | Product status code -> NULL |
| 83 | SET | `setParam[82] = ""` | Rental cancellation application yes/no -> NULL |
| 84 | SET | `setParam[83] = ""` | Pickup lot number -> NULL |
| 85 | SET | `setParam[84] = ""` | Customer equipment return date -> NULL |
| 86 | SET | `setParam[85] = ""` | HSTD return data status code -> NULL |
| 87 | SET | `setParam[86] = ""` | Return equipment remarks -> NULL |
| 88 | SET | `setParam[87] = ""` | Return warehouse responsible user ID -> NULL |
| 89 | SET | `setParam[88] = ""` | Return equipment acceptance responsible user ID -> NULL |
| 90 | SET | `setParam[89] = ""` | Return equipment cancellation responsible user ID -> NULL |
| 91 | SET | `setParam[90] = ""` | WMS return number -> NULL |
| 92 | SET | `setParam[91] = ""` | WMS return record number -> NULL |
| 93 | SET | `setParam[92] = kktkSbtCd` | Provision type code |
| 94 | SET | `setParam[93] = ""` | Return original contract name -> NULL |
| 95 | SET | `setParam[94] = ""` | Return target equipment error yes/no -> NULL |
| 96 | SET | `setParam[95] = ""` | Work case number -> NULL |
| 97 | SET | `setParam[96] = sysDate` | Registration date/time -> system date-time |
| 98 | SET | `setParam[97] = batchUserId` | Registering operator account -> batch updater user ID |
| 99 | SET | `setParam[98] = sysDate` | Update date/time -> system date-time |
| 100 | SET | `setParam[99] = batchUserId` | Updating operator account -> batch updater user ID |
| 101 | SET | `setParam[100] = ""` | Deletion date/time -> NULL |
| 102 | SET | `setParam[101] = ""` | Deleting operator account -> NULL |
| 103 | SET | `setParam[102] = MK_FLG_YK` [MK_FLG_YK = "0"] | Invalid flag -> "0" (Valid / 有効) |
| 104 | SET | `setParam[103] = ""` | Registration operation date -> NULL |
| 105 | SET | `setParam[104] = ""` | Registration processing DTM -> NULL |
| 106 | SET | `setParam[105] = ""` | Update operation date -> NULL |
| 107 | SET | `setParam[106] = ""` | Update processing DTM -> NULL |
| 108 | SET | `setParam[107] = ""` | Deletion operation date -> NULL |
| 109 | SET | `setParam[108] = ""` | Deletion processing DTM -> NULL |
| 110 | CALL | `executeDK_T_HMPIN_KIKI_PKINSERT(setParam)` | Insert complete return equipment record into `T_HMPIN_KIKI` table |
| 111 | EXEC | `henpinKikiNoList.add(seqHenpinKikiNo)` // V9.00.01 added | Accumulate the generated return equipment number for downstream use |

**Block 5** — [END OF WHILE] Fetch next record and loop (L6537)

| # | Type | Code | Business Description |
|---|------|------|---------------------|
| 1 | SET | `kktkSvcKeiMap_148 = db_KK_T_KKTK_SVC_KEI_RUTER.selectNext()` | Fetch next record; null means loop ends |

## 7. Glossary

| Term | Type | Business Meaning |
|------|------|------------------|
| `henpinKikiNo` | Field | Return equipment number — a unique identifier generated via `SEQ_HMPIN_KIKI_NO` sequence for each returned piece of equipment. Format: "R" + YY (year suffix) + 7-digit sequence number. |
| `henpinKikiNoList` | Field | Return equipment number list — an instance-level `ArrayList<String>` that accumulates all return equipment numbers registered during the current batch execution, used by downstream processing (e.g., notification document updates). |
| `kktkSvcKeiNo` | Field | Equipment provision service contract number — the unique contract number for the equipment provision service line item in `KK_T_KKTK_SVC_KEI`. |
| `geneAddDtm` | Field | Equipment provision service contract generation registration date/time — the timestamp when the service contract record was originally registered, used as a key for searching return equipment candidates. |
| `haisoStat` | Field | Delivery status — a code indicating the current state of the delivery workflow. "001" = Accepted (受注済), "005" = Canceled (中止). |
| `haisoNo` | Field | Delivery number — the unique identifier for a delivery record in `DK_T_HAISO`. |
| `haisoStpCd` | Field | Delivery cancellation code — the reason code for canceling a delivery. "2" = Cancel (キャンセル). |
| `haisoStpDtm` | Field | Delivery cancellation date/time — the timestamp when the delivery was canceled. |
| `taknkikiModelCd` | Field | Indoor equipment model code — the model code of the indoor equipment associated with the service contract. |
| `kikiSeizoNo` | Field | Equipment serial number — the manufacturing serial number of the piece of equipment being returned. |
| `kktkChgNo` | Field | Equipment change number — the change/change-order number associated with equipment modifications. |
| `kktkSbtCd` | Field | Equipment provision type code — classifies the type of equipment provision. "02" = Rental (レンタル). |
| `svcKeiNo` | Field | Service contract number — the service contract line item number, passed as the "upstream parent service contract number" when registering return equipment. |
| `idoDtm` | Field | Transfer/operation registration date/time — the common item transfer/operation registration timestamp, recorded in the return equipment record. |
| `idoDiv` | Field | Transfer classification — the type of contract change (new registration, modification, etc.) from the intermediate file. |
| `opeDate` | Field | Operation date — the operational date used as both the delivery cancellation date and the return reception date. |
| `batchUserId` | Field | Batch user ID — the user ID of the batch processor, recorded as the registrant and updater for return equipment records. |
| CD00009_HAISO_STAT_001 | Constant | Delivery status "001" (Accepted / 受注済) — indicates the delivery order has been accepted and is pending fulfillment. |
| CD00009_HAISO_STAT_005 | Constant | Delivery status "005" (Canceled / 中止) — indicates the delivery order has been canceled. |
| CD00022_HAISO_STP_CD_2 | Constant | Delivery cancellation code "2" (Cancel / キャンセル) — the cancellation reason code indicating a general cancellation. |
| CD00212_KKTK_SBT_CD_02 | Constant | Equipment provision type "02" (Rental / レンタル) — indicates the equipment was provided under a rental agreement, which triggers return equipment registration. |
| CD00291_HMPIN_DIV_1 | Constant | Return classification "1" (Cancelled item / キャンセル品) — classifies the returned equipment as a cancelled-item return. |
| CD00293_HMPIN_RSN_CD_96 | Constant | Return reason code "96" (Pre-work cancellation (common) / 工事前キャンセル（共通）) — indicates the equipment is being returned before the installation work has commenced, a common return reason across service types. |
| CD00296_HMPIN_KIKI_STAT_001 | Constant | Return equipment status "001" (Accepted / 受注済) — the initial status assigned to newly registered return equipment. |
| MK_FLG_YK | Constant | Invalid flag "0" (Valid / 有効) — indicates the return equipment record is active/valid (not soft-deleted). |
| `SEQ_HMPIN_KIKI_NO` | Sequence | Return equipment number sequence — the database sequence used to generate unique return equipment numbers with a date-based prefix. |
| KK_T_KKTK_SVC_KEI | Table | Equipment provision service contract table — stores equipment provision service contract line items, including model codes, serial numbers, change numbers, and provision types. |
| KK_T_KKTK_SVC_KEI_KK_SELECT_148 | SQL Key | SQL definition key #148 — searches `KK_T_KKTK_SVC_KEI` for return equipment candidate records by service contract number and generation registration date. |
| T_HMPIN_KIKI | Table | Return equipment table — stores records of returned equipment, including the return equipment number, model code, serial number, provision type, return reason, and timestamps. |
| DK_T_HAISO | Table | Delivery table — stores delivery workflow records, including delivery status, cancellation codes, and cancellation dates. |
| HMPIN | Acronym | 返品 (Henpin) — Japanese for "return" or "return goods", referring to equipment returned by the customer. |
| KIKI | Acronym | 機器 (Kiki) — Japanese for "equipment" or "device", referring to telecom equipment (e.g., ONTs, routers, set-top boxes). |
| KKTK | Acronym | 機器提供 (Kiki Teiyou) — Japanese for "equipment provision", referring to the business process of providing equipment to customers. |
| SVC_KEI | Acronym | Service Contract Line (SVC Keiyaku) — refers to a service contract line item within the telecom service ordering system. |
| HAISO | Acronym | 配送 (Haiso) — Japanese for "delivery" or "dispatch", referring to the physical delivery of equipment to customers. |
| BATSERVICE | Value | Batch service user ID — a system user ID used to identify batch-processed records as originating from the batch system rather than manual operation. |
| pessimistic lock | Technical | A database concurrency control mechanism (`selectByPrimaryKeysForUpdateWait`) that acquires an exclusive lock on a row to prevent concurrent modifications during update operations. |
