---

# Business Logic — JBSbatKKKDDIAnkenIktTrkm.insertKDDITrkmRslt() [60 LOC]

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

## 1. Role

### JBSbatKKKDDIAnkenIktTrkm.insertKDDITrkmRslt()

This method is the **KDDI order case import result list registration** routine that produces a structured result file and registers it in the download file management table (`ZM_T_DL_FILE_KANRI`). It is the final step in the batch process that imports KDDI telecom order data: after the main batch logic has parsed, validated, and populated the `dataMapList` with per-record import outcomes (successes, warnings, errors), this method serializes the accumulated results into a human-readable double-quoted CSV-format report and registers that file for downstream retrieval.

The method follows a **three-phase export pattern**: (1) write a header section containing aggregate record counts (total, normal, warning, error), (2) write a title section providing column labels, and (3) write the data body by iterating over every entry in `dataMapList`, extracting seven structured fields per record, and writing them as double-quoted CSV rows. After all records are written, the file handle is closed.

The method also handles **file retention policy registration**: it queries the work parameter table (`ZM_M_WORK_PARAM_KNRI`) for the configured KDDI import result file retention period (`KK_KDDI_TRKM_HOJIPRD`). If no value is set or the value is `-1` (meaning "no retention period configured"), it defaults to the far-future date `20991231`. Otherwise, it computes the retention expiry date by adding the configured number of days to the current operation date (`opeDate`). Finally, it calls `createFile` to register the output file metadata — including file name, record count, and retention expiry date — into the download file management table.

This method is a **private batch utility** called exclusively by the `execute()` method of `JBSbatKKKDDIAnkenIktTrkm` and does not serve as an entry point for any screen or external caller.

## 2. Processing Pattern (Detailed Business Logic)

```mermaid
flowchart TD
    START(["insertKDDITrkmRslt"])
    STEP1["setKDDITrkmRsltCntList"]
    STEP2["setKDDITrkmRsltTitleList"]
    INIT_LOOP["dataCnt = 0"]
    CHECK_LOOP["dataCnt < dataMapList.size()"]
    NEW_MAP["new JBSbatServiceInterfaceMap"]
    SET_MAP["dataMap.setMap(dataMapList.get(dataCnt))"]
    NEW_LIST["new ArrayList dataList"]
    EXTRACT["Extract 7 fields from dataMap"]
    WRITE_FILE["JKKBatCommon.printDoubleQuoteBusinessFileUtil"]
    INCR_LOOP["dataCnt++"]
    CLOSE_FILE["if kddiTrkmRsltFileObj != null: close"]
    GET_PRD["JKKBatCommon.getWorkParamSetteValue(trkm_prd)"]
    CHECK_PRD["trkm_prd is null OR trkm_prd == -1"]
    SET_DEFAULT["delYmd = \"20991231\""]
    CALC_DEL["JKKBatCommon.addDay(opeDate, trkm_prd)"]
    CREATE_REG["JKKBatCommon.createFile(KDDI_TRN_KANRI_IKT_RSLT, record count, delYmd, ZM_T_DL_FILE_KANRI)"]
    END_NODE(["Return"])

    START --> STEP1 --> STEP2 --> INIT_LOOP --> CHECK_LOOP
    CHECK_LOOP -->|true| NEW_MAP --> SET_MAP --> NEW_LIST --> EXTRACT --> WRITE_FILE --> INCR_LOOP --> CHECK_LOOP
    CHECK_LOOP -->|false| CLOSE_FILE
    CLOSE_FILE --> GET_PRD --> CHECK_PRD
    CHECK_PRD -->|true| SET_DEFAULT --> CREATE_REG
    CHECK_PRD -->|false| CALC_DEL --> CREATE_REG
    CREATE_REG --> END_NODE
```

**Processing flow:**

1. **Export count header** — `setKDDITrkmRsltCntList()` writes the processing result count header section (total record count, normal import count, warning import count, error import count) to the output file.
2. **Export title header** — `setKDDITrkmRsltTitleList()` writes the column title row to the output file.
3. **Export data body** — Iterates over all entries in `dataMapList`. For each entry:
   - Creates a `JBSbatServiceInterfaceMap` wrapper and populates it with the current record's data map.
   - Extracts 7 fields: Row Number, Processing Date, Status, Error Item (Name), Error Item (Value), Error Message, Introduction Table Management Number.
   - Writes the 7 fields as a double-quoted CSV row to the file.
4. **Close file** — Closes the file output stream if it is open.
5. **Retrieves retention period** — Queries the work parameter table for the KDDI import result file retention period.
6. **Computes deletion date** — If no retention period is configured (null or -1), uses the default far-future date `20991231`. Otherwise, adds the configured number of days to the current operation date.
7. **Registers file metadata** — Calls `createFile` to register the output file in the download file management table with its record count, file name, and computed retention expiry date.

**CRITICAL — Constant Resolution:**

| Constant | Resolved Value | Business Meaning |
|----------|---------------|------------------|
| `KDDI_WORK_PARAM_ID_TRKM_PRD` | `"KK_KDDI_TRKM_HOJIPRD"` | Work parameter ID for KDDI import result file retention period |
| `KDDI_HOJIPRD_NON` | `-1` | Retention period not configured (no retention) |
| `END_YMD_DEFAULT` | `"20991231"` | Default far-future date used when no retention period is set |
| `KDDI_TRN_KANRI_IKT_RSLT` | `"000000000092"` | SC Code for KDDI takeaway case result import registration |
| `db_ZM_T_DL_FILE_KANRI` | `ZM_T_DL_FILE_KANRI` | Download file management table |

## 3. Parameter Analysis

| No | Parameter Name | Type | Business Description |
|----|---------------|------|---------------------|
| - | (none) | - | This method takes no parameters. All data is sourced from instance fields populated by earlier batch processing steps. |

**Instance fields read by this method:**

| Field | Type | Business Description |
|-------|------|---------------------|
| `dataMapList` | `ArrayList<HashMap<String, String>>` | Accumulated list of KDDI import result data records. Each map contains parsed fields: row number, processing date, status, error info, and introduction table management number. |
| `kddiTrkmRsltFileObj` | File handle | Output file stream for the KDDI import result list. Opened by the caller prior to invoking this method. |
| `kddiTrkmRsltFileName` | `String` | File name for the KDDI import result list output. |
| `commonItem` | `CommonItem` | Common batch processing context containing free-item data and shared configuration. |
| `fileRecordCnt` | `long` | Total number of records processed in the import. |
| `normalRecordCnt` | `long` | Number of records that imported successfully. |
| `warRecordCnt` | `long` | Number of records with warnings (improper data that could still be imported). |
| `errRecordCnt` | `long` | Number of records that failed import due to errors. |
| `opeDate` | `String` | Current operation date (YYYYMMDD), used to calculate retention expiry date. |
| `db_ZM_M_WORK_PARAM_KNRI` | `JBSbatSQLAccess` | Database access object for the work parameter master table. |

## 4. CRUD Operations / Called Services

| CRUD | SC / CBS | SC Code | Entity / DB | Operation Description |
|------|----------|---------|-------------|----------------------|
| C | `JBSbatKKKDDIAnkenIktTrkm.setKDDITrkmRsltCntList` | KDDI import result list registration | - | Writes the count header section (total, normal, warning, error record counts) to the output file |
| C | `JBSbatKKKDDIAnkenIktTrkm.setKDDITrkmRsltTitleList` | KDDI import result list registration | - | Writes the column title header row to the output file |
| R | `JBSbatServiceInterfaceMap.getString` | KDDI import result list (file I/O) | - | Extracts individual field values from the data map wrapper (called 7 times per record for ROW_NO, TRN_DAY, STAT, ERR_KMK_NM, ERR_KMK_VAL, ERR_MSG, INTR_HYO_KANRI_NO) |
| C | `JKKBatCommon.printDoubleQuoteBusinessFileUtil` | KDDI import result list (file I/O) | - | Writes a double-quoted CSV row to the output file for each data record |
| - | `JBSbatServiceInterfaceMap.close` | KDDI import result list (file I/O) | - | Closes the file output stream after all records are written |
| R | `JKKBatCommon.getWorkParamSetteValue` | Work Param Management | ZM_M_WORK_PARAM_KNRI | Reads the file retention period configuration value from the work parameter master table |
| C | `JKKBatCommon.addDay` | Date Management | - | Adds the retention period (in days) to the operation date to compute the file deletion date |
| C | `JKKBatCommon.createFile` | File Management | ZM_T_DL_FILE_KANRI | Registers the KDDI import result file metadata (file name, record count, deletion date) in the download file management table |

## 5. Dependency Trace

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

No screen/batch entry points found within 8 hops. Direct callers found: 1 methods.
Terminal operations from this method: `createFile` [C], `printDoubleQuoteBusinessFileUtil` [C], `setKDDITrkmRsltCntList` [C], `setKDDITrkmRsltTitleList` [C], `getWorkParamSetteValue` [R], `addDay` [C], `close` [-], `getString` [R]

| # | Caller (Screen/Batch) | Call Chain (Full Path to this Method) | Terminal (SC / CRUD / Entity) |
|---|----------------------|--------------------------------------|-------------------------------|
| 1 | Batch:JBSbatKKKDDIAnkenIktTrkm | `execute()` -> `insertKDDITrkmRslt()` | `createFile` [C] ZM_T_DL_FILE_KANRI |

**Description:** This method is called exclusively by the `execute()` method of the same class `JBSbatKKKDDIAnkenIktTrkm`, which is the main batch processing entry point for importing KDDI order cases. It is not called by any screen or CBS. The terminal database operation writes file registration metadata to `ZM_T_DL_FILE_KANRI`.

## 6. Per-Branch Detail Blocks

**Block 1** — [METHOD] (L507)

> Writes the KDDI order case import result list — this method orchestrates the three-phase file export (count header, title, data body) followed by file closure and database registration.

| # | Type | Code |
|---|------|------|
| 1 | CALL | `setKDDITrkmRsltCntList()` // KDDI order case import result list (processing result count section) output |
| 2 | CALL | `setKDDITrkmRsltTitleList()` // KDDI order case import result list (title section) output |
| 3 | SET | `dataCnt = 0` // Loop index initialization |

**Block 1.1** — [FOR] `(dataCnt < dataMapList.size())` (L516)

> Iterates over each record in the data map list, extracts seven fields, and writes them as a double-quoted CSV row.

| # | Type | Code |
|---|------|------|
| 1 | SET | `dataMap = new JBSbatServiceInterfaceMap()` |
| 2 | EXEC | `dataMap.setMap(dataMapList.get(dataCnt))` // Populate wrapper with current record |
| 3 | SET | `dataList = new ArrayList<String>()` |
| 4 | EXEC | `dataList.add(dataMap.getString(JBSbatKKIFM275.ROW_NO))` // Row Number |
| 5 | EXEC | `dataList.add(dataMap.getString(JBSbatKKIFM275.TRN_DAY))` // Processing Date |
| 6 | EXEC | `dataList.add(dataMap.getString(JBSbatKKIFM275.STAT))` // Status |
| 7 | EXEC | `dataList.add(dataMap.getString(JBSbatKKIFM275.ERR_KMK_NM))` // Error Item (Name) |
| 8 | EXEC | `dataList.add(dataMap.getString(JBSbatKKIFM275.ERR_KMK_VAL))` // Error Item (Value) |
| 9 | EXEC | `dataList.add(dataMap.getString(JBSbatKKIFM275.ERR_MSG))` // Error Message |
| 10 | EXEC | `dataList.add(dataMap.getString(JBSbatKKIFM275.INTR_HYO_KANRI_NO))` // Introduction Table Management Number |
| 11 | EXEC | `JKKBatCommon.printDoubleQuoteBusinessFileUtil(kddiTrkmRsltFileObj, dataList)` // Write CSV row to file |

**Block 2** — [IF] `kddiTrkmRsltFileObj != null` (L532)

> Closes the output file handle if it is still open.

| # | Type | Code |
|---|------|------|
| 1 | EXEC | `kddiTrkmRsltFileObj.close()` // Close file stream |

**Block 3** — [METHOD] (L536)

> Retrieves the file retention period setting from the work parameter table.

| # | Type | Code |
|---|------|------|
| 1 | SET | `kddiTrkmRsltPrd = JKKBatCommon.getWorkParamSetteValue(commonItem, KDDI_WORK_PARAM_ID_TRKM_PRD = "KK_KDDI_TRKM_HOJIPRD", db_ZM_M_WORK_PARAM_KNRI)` // Retention period in days |
| 2 | SET | `delYmd = null` |

**Block 4** — [IF] `(kddiTrkmRsltPrd is null) || (kddiTrkmRsltPrd == -1)` `KDDI_HOJIPRD_NON = "-1"` (L541)

> If the retention period is not configured or explicitly set to "no retention", use the default far-future date `20991231`.

| # | Type | Code |
|---|------|------|
| 1 | SET | `delYmd = JKKStrConst.END_YMD_DEFAULT` // "20991231" — default retention expiry (effectively infinite) |

**Block 5** — [ELSE] (L544)

> Otherwise, compute the retention expiry date by adding the configured number of days to the current operation date.

| # | Type | Code |
|---|------|------|
| 1 | SET | `delYmd = JKKBatCommon.addDay(super.opeDate, Integer.valueOf(kddiTrkmRsltPrd))` // opDate + retention period days |

**Block 6** — [METHOD] (L552)

> Registers the KDDI import result file metadata in the download file management table.

| # | Type | Code |
|---|------|------|
| 1 | EXEC | `JKKBatCommon.createFile(commonItem, KDDI_TRN_KANRI_IKT_RSLT = "000000000092", new Long(dataMapList.size()), null, commonItem.getFreeItem(), kddiTrkmRsltFileName, delYmd, db_ZM_T_DL_FILE_KANRI, false)` // SC Code "000000000092" — Register KDDI import result file metadata (file name, record count, deletion date) in ZM_T_DL_FILE_KANRI |

## 7. Glossary

| Term | Type | Business Meaning |
|------|------|------------------|
| `JBSbatKKKDDIAnkenIktTrkm` | Class | KDDI order case import processing batch service — handles importing and processing KDDI telecom order data |
| `insertKDDITrkmRslt` | Method | KDDI order case import result list registration — exports result file and registers it in DB |
| `dataMapList` | Field | KDDI import result data list — accumulated per-record results from the batch import process, each containing row number, processing date, status, error info, and introduction table management number |
| `commonItem` | Field | Common batch processing context — shared configuration and metadata for the batch job |
| `opeDate` | Field | Operation date — the current processing date (YYYYMMDD format) used for retention date calculations |
| `kddiTrkmRsltFileObj` | Field | KDDI import result list file output handle — the file stream used to write the result report |
| `kddiTrkmRsltFileName` | Field | KDDI import result list file name — the output file name for the result report |
| `fileRecordCnt` | Field | Total record count — total number of records processed in the import |
| `normalRecordCnt` | Field | Normal (successful) import record count |
| `warRecordCnt` | Field | Warning import record count — records with issues that were still imported |
| `errRecordCnt` | Field | Error import record count — records that failed import |
| `trn_day` | Field | Processing date — the date the record was processed during batch import |
| `stat` | Field | Status — import status code for each record (e.g., success, warning, error) |
| `err_kmk_nm` | Field | Error item name — identifies which field or validation caused an error |
| `err_kmk_val` | Field | Error item value — the actual value that caused the error |
| `err_msg` | Field | Error message — human-readable description of the error |
| `intr_hyo_kanri_no` | Field | Introduction table management number — internal reference for cross-referencing data |
| `KDDI_WORK_PARAM_ID_TRKM_PRD` | Constant | Work parameter ID `KK_KDDI_TRKM_HOJIPRD` — KDDI import result file retention period configuration key |
| `KDDI_HOJIPRD_NON` | Constant | `-1` — Flag meaning "retention period not configured" |
| `END_YMD_DEFAULT` | Constant | `"20991231"` — Far-future default date used when no retention period is set |
| `KDDI_TRN_KANRI_IKT_RSLT` | Constant | `"000000000092"` — SC Code for KDDI order case result import registration |
| `ROW_NO` | Field | Row number — sequential line number of the record in the source file |
| `ZM_M_WORK_PARAM_KNRI` | Table | Work parameter master table — stores system configuration parameters including file retention periods |
| `ZM_T_DL_FILE_KANRI` | Table | Download file management table — stores metadata about generated output files including file name, record count, and retention/deletion dates |
| KDDI | Business term | NTT Docomo KDDI — Japanese telecommunications carrier; in this system, refers to KDDI order data imported via file batch processing |
| Trkm | Abbreviation | 取込 (Torikomi) — Import; refers to KDDI order case import processing |
| Anken | Business term | 案件 (Anken) — Case/Order — refers to a telecom service order case |
| HOJI (Retention) | Business term | 保全 (Hozen) — Retention/Preservation — refers to how long files are retained before automatic deletion |
| Double-quoted CSV | Format | File output format using double-quotes around fields, typical for enterprise data exchange |
| SC Code | Abbreviation | Service Component Code — a 10-digit code (e.g., `000000000092`) identifying a specific service component operation |
| `JBSbatServiceInterfaceMap` | Class | Map wrapper utility — provides `getString()` and `setMap()` methods for accessing structured data maps by field name |
| `printDoubleQuoteBusinessFileUtil` | Method | File I/O utility — writes a list of strings as a double-quoted CSV line to a file |
| `createFile` | Method | File management CBS — registers file metadata (name, record count, deletion date) in the download file management table |

---
