---

# Business Logic — JBSbatKKKjFinClDataInTrn.insertPrg() [58 LOC]

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

## 1. Role

### JBSbatKKKjFinClDataInTrn.insertPrg()

This method performs **progress record registration** (進捗情報の登録処理) for a service contract line item within the batch processing pipeline. In the business domain of telecom service contract management, progress records (T-PRG = Progress) track the state and timeline of all operational changes applied to a subscription detail line, enabling auditability and status reporting throughout the order-to-activation lifecycle.

The method implements a **parameter assembly and delegate insert** design pattern: it gathers system time, resolves the latest movement datetime from the shared item context, constructs a 33-element parameter array encoding every field of the progress record (including foreign keys, movement classification, timestamps, operator IDs, and lifecycle flags), and delegates the actual database insert to `executeKK_T_PRG_PKINSERT()`, which writes a row into the `KK_T_PRG` table using primary-key-based insertion.

This method serves as a **shared batch utility** called internally by the `execute()` processing method at multiple branching points. It is invoked whenever the batch flow needs to register a new progress step for a given subscription detail (`mskmDtlNo_151`) and service contract (`svcKeiNo_151`), regardless of whether the current branch handles FTTH registration, mail services, or other telecom service types. The `idoDiv_151` parameter further classifies the type of movement (e.g., new contract, modification, cancellation), allowing downstream reports to filter progress records by change category.

## 2. Processing Pattern (Detailed Business Logic)

```mermaid
flowchart TD
    START(["insertPreg(params)"])
    
    START --> GETSYS["Get System Date/Time<br/>JCCBatCommon.getSysDateTimeStamp()"]
    
    GETSYS --> GETIDO["Get Max Movement Datetime<br/>JKKBatCommon.getIdoDtmMax()"]
    
    GETIDO --> BUILD["Build 33-Element Parameter Array<br/>setParam[]"]
    
    BUILD --> SEQ["Generate Progress Number<br/>JBSbatOracleSeqUtil.getNextSeq()"]
    
    SEQ --> STRSUB["Extract Time String<br/>sysDate.substring(8)"]
    
    STRSUB --> CONCAT["Concat batchUserId + sysDate<br/>for PRG_DTM"]
    
    CONCAT --> EXEC["Execute DB Insert<br/>executeKK_T_PRG_PKINSERT()"]
    
    EXEC --> DB["db_KK_T_PRG.insertByPrimaryKeys()"]
    
    DB --> END_NODE(["Return"])
```

**CRITICAL — Constant Resolution:**

| Constant | Resolved Value | Business Meaning |
|----------|---------------|-----------------|
| `JBSbatKKConst.CD00647_PRG_STAT_9680` | `"9680"` | Progress state code 9680 — standard initial progress state (changed from hardcoded literal in v20.00.00) |
| `JBSbatKKConst.MK_FLG_YK` | `"0"` | Valid flag: `0` = valid/active (有効) (changed from hardcoded literal in v20.00.00) |
| `JCCBatCommon.SYS_DT_FMT` | Used implicitly | System datetime stamp format used by `getSysDateTimeStamp()` |
| `JKBatConst.SEQ_PRG_NO` | `"SEQ_PRG_NO"` | Oracle sequence name for generating progress numbers |

## 3. Parameter Analysis

| No | Parameter Name | Type | Business Description |
|----|---------------|------|---------------------|
| 1 | `mskmDtlNo_151` | `String` | Application detail number — the unique identifier of a subscription detail line (申込明細番号). This key links the progress record to a specific customer's service line item. Used in intermediate file processing during batch modification updates. |
| 2 | `svcKeiNo_151` | `String` | Service contract number — the unique identifier of a service contract line (サービス契約番号). Identifies the top-level service contract to which this progress step belongs. Also read from the shared `commonItem` context. |
| 3 | `idoDiv_151` | `String` | Movement classification — the type of change operation being performed (異動区分), such as new registration, modification, or cancellation. This determines the semantic meaning of the progress record and is used to categorize batch change operations. |

**Instance fields / external state read by this method:**

| Field | Type | Accessed | Business Description |
|-------|------|----------|---------------------|
| `commonItem` | Shared context object | `getIdoDtmMax(commonItem, ...)` | Shared item context providing connection and configuration for database operations |
| `stmt` | SQLAccess statement object | `getIdoDtmMax(..., stmt)` | Statement object used for datetime resolution queries |
| `batchUserId` | String (inherited) | Used in `setParam[21]`, `setParam[23]` | Batch operator user ID — identifies the batch job executor for audit trail (ADD_OPEACNT, UPD_OPEACNT) |
| `db_KK_T_PRG` | JBSbatSQLAccess | `executeKK_T_PRG_PKINSERT()` → `db_KK_T_PRG.insertByPrimaryKeys()` | Database access object for the `KK_T_PRG` progress table |
| `D_TBL_NAME_KK_T_PRG` | `String = "KK_T_PRG"` | Table name constant | Database table name for progress records |

## 4. CRUD Operations / Called Services

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

| CRUD | SC / CBS | SC Code | Entity / DB | Operation Description |
|------|----------|---------|-------------|----------------------|
| R | `JCCBatCommon.getSysDateTimeStamp` | - | - | Retrieves the current system date/time stamp — provides the base timestamp for progress record creation and audit fields |
| R | `JKKBatCommon.getIdoDtmMax` | - | - | Retrieves the maximum (latest) movement datetime from the `KK_T_PRG` or related movement tables for the given service contract, ensuring chronological ordering of progress records |
| R | `JBSbatOracleSeqUtil.getNextSeq` | - | `SEQ_PRG_NO` | Retrieves the next value from the Oracle sequence `SEQ_PRG_NO` to auto-generate a unique progress number (PRG_NO) — 12-digit zero-padded |
| C | `JBSbatKKKjFinClDataInTrn.executeKK_T_PRG_PKINSERT` | JBSbatKKKjFinClDataInTrn | `KK_T_PRG` | Delegates DB insert of 33 fields into the progress record table using primary-key-based insertion |
| C | `db_KK_T_PRG.insertByPrimaryKeys` | - | `KK_T_PRG` | The actual database-level insert operation on the `KK_T_PRG` table (Progress Record table) |
| - | `JBSbatOracleSeqUtil.padNumFormString` | - | - | Zero-pads the numeric progress sequence to a fixed 12-digit width for consistent key formatting |
| - | `String.substring(8)` | - | - | Extracts the time portion (hhmmssSSS) from the full datetime stamp for the progress datetime field |

**CRUD Summary:**
- **Create (C):** One primary write — registers a new progress record (`KK_T_PRG`) with 33 fields including foreign keys, timestamps, operator IDs, and lifecycle flags.
- **Read (R):** Three reads — system datetime, max movement datetime (for chronological tracking), and sequence number (for auto-generated primary key).

## 5. Dependency Trace

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

No screen/batch entry points found within 8 hops. Direct callers found: 1 methods.

| # | Caller (Screen/Batch) | Call Chain (Full Path to this Method) | Terminal (SC / CRUD / Entity) |
|---|----------------------|--------------------------------------|-------------------------------|
| 1 | Batch: `JBSbatKKKjFinClDataInTrn.execute()` | `execute()` → `insertPrg()` | `executeKK_T_PRG_PKINSERT [C] KK_T_PRG` |

The `execute()` method (public entry point of the same class) calls `insertPrg()` at multiple branching points within its service processing logic (lines 568 and 797). The `execute()` method handles the overall flow of subscription detail processing, calling `insertPrg()` whenever a progress record needs to be registered for a given subscription detail and service contract.

## 6. Per-Branch Detail Blocks

**Block 1** — [SET] (L2496)

> Acquire the system date/time. This timestamp is the source of truth for all timestamp fields in the progress record (progress datetime, add datetime, update datetime).

| # | Type | Code |
|---|------|------|
| 1 | SET | `sysDate = JCCBatCommon.getSysDateTimeStamp();` // Get system date/time [-> DateTimeStamp] |

**Block 2** — [SET] (L2499)

> Retrieve the maximum (latest) movement datetime from the shared item context for this service contract. This ensures the new progress record is chronologically ordered relative to existing movement records.

| # | Type | Code |
|---|------|------|
| 1 | SET | `idoDtm = JKKBatCommon.getIdoDtmMax(commonItem, svcKeiNo_151, idoDiv_151, stmt);` // Get max movement datetime |

**Block 3** — [SET: Build 33-element parameter array] (L2501–L2548)

> Construct the parameter array for the progress record insert. Each element maps to a column in the `KK_T_PRG` table. The array follows a strict positional mapping:

| # | Type | Code | Business Description |
|---|------|------|---------------------|
| 1 | SET | `setParam[0] = JBSbatOracleSeqUtil.getNextSeq(commonItem.getConnection(), SEQ_PRG_NO).padNumFormString(12)` | Progress Number (PRG_NO) — auto-generated sequence number, zero-padded to 12 digits |
| 2 | SET | `setParam[1] = mskmDtlNo_151` | Application Detail Number (MSKM_DTL_NO) — passed from caller |
| 3 | SET | `setParam[2] = ""` | Billing Contract Number (SEIKY_KEI_NO) — NULL (not set) |
| 4 | SET | `setParam[3] = ""` | Billing Method Number - Account (SEIKY_WAY_NO_KOZA) — NULL (not set) |
| 5 | SET | `setParam[4] = ""` | Billing Method Number - Credit Card (SEIKY_WAY_NO_CRECARD) — NULL (not set) |
| 6 | SET | `setParam[5] = svcKeiNo_151` | Service Contract Number (SVC_KEI_NO) — passed from caller |
| 7 | SET | `setParam[6] = ""` | Service Contract Sub-item Number (SVC_KEI_UCWK_NO) — NULL (not set) |
| 8 | SET | `setParam[7] = ""` | Service Contract Prior Sub-item Number (SVC_KEI_KAISEN_UCWK_NO) — NULL (not set) |
| 9 | SET | `setParam[8] = ""` | Equipment Provider Service Contract Number (KKTK_SVC_KEI_NO) — NULL (not set) |
| 10 | SET | `setParam[9] = ""` | Optional Service Contract Number (OP_SVC_KEI_NO) — NULL (not set) |
| 11 | SET | `setParam[10] = ""` | Selected Optional Service Contract Number (SEIOPSVC_KEI_NO) — NULL (not set) |
| 12 | SET | `setParam[11] = ""` | Sub-Optional Service Contract Number (SBOP_SVC_KEI_NO) — NULL (not set) |
| 13 | SET | `setParam[12] = ""` | Reduced-Price Service Contract Number (WRIB_SVC_KEI_NO) — NULL (not set) |
| 14 | SET | `setParam[13] = idoDiv_151` | Movement Classification (IDO_DIV) — passed from caller |
| 15 | SET | `setParam[14] = idoDtm` | Movement Datetime — resolved from `getIdoDtmMax()` |
| 16 | SET | `setParam[15] = JBSbatKKConst.CD00647_PRG_STAT_9680` | Progress State (PRG_STAT) = `"9680"` [-> CD00647_PRG_STAT_9680="9680"] — initial progress state, changed from hardcoded `"9680"` in v20.00.00 |
| 17 | SET | `setParam[16] = super.opeDate + sysDate.substring(8)` | Progress Datetime (PRG_DTM) — batch operation date + time portion (hhmmssSSS), changed in v1.01.00 from just `sysDate` to concatenate the batch operation date for audit traceability |
| 18 | SET | `setParam[17] = ""` | Progress Memo (PRG_MEMO) — NULL (not set) |
| 19 | SET | `setParam[18] = ""` | Progress Special Item 1 (PRG_TKJK_1) — NULL (not set) |
| 20 | SET | `setParam[19] = ""` | Progress Special Item 2 (PRG_TKJK_2) — NULL (not set) |
| 21 | SET | `setParam[20] = sysDate` | Add Datetime (ADD_DTM) — system date/time |
| 22 | SET | `setParam[21] = batchUserId` | Add Operator Account (ADD_OPEACNT) — batch operator ID |
| 23 | SET | `setParam[22] = sysDate` | Update Datetime (UPD_DTM) — system date/time |
| 24 | SET | `setParam[23] = batchUserId` | Update Operator Account (UPD_OPEACNT) — batch operator ID |
| 25 | SET | `setParam[24] = ""` | Delete Datetime (DEL_DTM) — NULL (not set) |
| 26 | SET | `setParam[25] = ""` | Delete Operator Account (DEL_OPEACNT) — NULL (not set) |
| 27 | SET | `setParam[26] = JBSbatKKConst.MK_FLG_YK` | Valid Flag (MK_FLG) = `"0"` [-> MK_FLG_YK="0"] — valid/active, changed from hardcoded `"0"` in v20.00.00 |
| 28 | SET | `setParam[27] = ""` | Add Operation Date (ADD_UNYO_YMD) — NULL (not set) |
| 29 | SET | `setParam[28] = ""` | Add Processing ID (ADD_TRN_ID) — NULL (not set) |
| 30 | SET | `setParam[29] = ""` | Update Operation Date (UPD_UNYO_YMD) — NULL (not set) |
| 31 | SET | `setParam[30] = ""` | Update Processing ID (UPD_TRN_ID) — NULL (not set) |
| 32 | SET | `setParam[31] = ""` | Delete Operation Date (DEL_UNYO_YMD) — NULL (not set) |
| 33 | SET | `setParam[32] = ""` | Delete Processing ID (DEL_TRN_ID) — NULL (not set) |

**Block 4** — [CALL] (L2550)

> Execute the database insert by delegating to the primary-key-based insert method. This maps all 33 parameters into a `JBSbatCommonDBInterface` and calls `db_KK_T_PRG.insertByPrimaryKeys()` to write the row into the `KK_T_PRG` table.

| # | Type | Code | Business Description |
|---|------|------|---------------------|
| 1 | CALL | `executeKK_T_PRG_PKINSERT(setParam);` | Insert progress record into `KK_T_PRG` with primary-key-based insert, writing all 33 fields (PRG_NO, MSKM_DTL_NO, SVC_KEI_NO, IDO_DIV, PRG_STAT, PRG_DTM, ADD/UPD/DEL timestamps and operator accounts, MK_FLG) |

## 7. Glossary

| Term | Type | Business Meaning |
|------|------|-----------------|
| `mskmDtlNo_151` | Field | Application detail number — unique identifier for a subscription detail line (申込明細番号). The "151" suffix is a naming convention derived from intermediate file processing. |
| `svcKeiNo_151` | Field | Service contract number — unique identifier for a service contract line (サービス契約番号). Links the progress record to its parent service contract. |
| `idoDiv_151` | Field | Movement classification — type of change operation (異動区分). Values distinguish between new registration, modification, cancellation, and other service lifecycle changes. |
| `sysDate` | Field | System date/time stamp — current timestamp retrieved from the database server for consistency across all audit fields. |
| `idoDtm` | Field | Movement datetime — the maximum (latest) movement timestamp for the given service contract, ensuring chronological ordering. |
| `PRG_NO` | Field | Progress number — auto-generated 12-digit zero-padded unique key from `SEQ_PRG_NO` Oracle sequence. |
| `PRG_STAT` | Field | Progress state — status code for the progress record. `CD00647_PRG_STAT_9680 = "9680"` is the initial/standard progress state. |
| `PRG_DTM` | Field | Progress datetime — concatenation of batch operation date and the time portion of system date/time (hhmmssSSS). |
| `MK_FLG` | Field | Valid flag — lifecycle indicator where `0` (YK = 有効/valid) means the record is active and `1` would mean invalid/deleted. |
| `ADD_DTM` / `ADD_OPEACNT` | Fields | Add datetime / Add operator account — audit fields recording when the progress record was created and by which operator (batch job ID). |
| `UPD_DTM` / `UPD_OPEACNT` | Fields | Update datetime / Update operator account — audit fields for last-modified timestamp and operator. |
| `DEL_DTM` / `DEL_OPEACNT` | Fields | Delete datetime / Delete operator account — audit fields for logical deletion timestamp and operator. |
| KK_T_PRG | Table | Progress record table — stores all progress/step records for service contract line items. Supports auditability of the order-to-activation pipeline. |
| SEQ_PRG_NO | Sequence | Oracle database sequence name for generating unique progress numbers. |
| CD00647_PRG_STAT_9680 | Constant | Progress state constant = "9680". Represents the initial/standard progress state in the system. Introduced in v20.00.00 to replace hardcoded literal. |
| MK_FLG_YK | Constant | Valid flag constant = "0". YK = 有効 (valid). Introduced in v20.00.00 to replace hardcoded literal. |
| JCCBatCommon | Class | Common batch utility class providing system datetime acquisition (`getSysDateTimeStamp`). |
| JKKBatCommon | Class | Common batch utility class providing movement datetime resolution (`getIdoDtmMax`). |
| db_KK_T_PRG | Field | Database SQL access object for the `KK_T_PRG` table. Handles insert/select/delete operations. |
| batchUserId | Field | Inherited operator ID — identifies the batch job executor for all audit trail fields (ADD_OPEACNT, UPD_OPEACNT). |
| commonItem | Field | Shared item context object — provides database connection and configuration shared across all batch processing methods. |
| `executeKK_T_PRG_PKINSERT` | Method | Primary-key-based insert delegate method that maps `Object[]` parameters to `JBSbatCommonDBInterface` fields and calls `db_KK_T_PRG.insertByPrimaryKeys()`. |
| `execute()` | Method | Public entry point of `JBSbatKKKjFinClDataInTrn` — orchestrates the full service contract processing flow and calls `insertPrg()` at multiple branching points. |
| v20.00.00 | Version | Release version that replaced hardcoded constant literals (`"9680"`, `"0"`) with named constants (`CD00647_PRG_STAT_9680`, `MK_FLG_YK`) for maintainability. |
| v1.01.00 | Version | Release version that changed `PRG_DTM` from using raw `sysDate` to `super.opeDate + sysDate.substring(8)` for batch operation date traceability. |

---
