# Business Logic — JBSbatKKCourseChgFileBnkt.setKjClStr() [74 LOC]

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

## 1. Role

### JBSbatKKCourseChgFileBnkt.setKjClStr()

This method performs **construction of a work cancellation string** (工事取消文字列設定処理) used during the course-change batch processing for customer telecom service records. It is a **builder-pattern utility** that formats 23 fields from an incoming data array into a comma-separated string record, which is then written to a "work cancellation file" (工事取消ファイル). The method serves as a **data-to-file serialization step** within the batch job `JBSbatKKCourseChgFileBnkt` — specifically triggered when a work result indicates cancellation (work result code 4, i.e., `KKIFM151_KOJI_RSLT_4`), causing the batch to write cancellation detail records. It operates purely as a **data transformer** with no database or service component calls, making it a pure formatting routine. The method is **private** and called only internally by the `execute()` method of the same class, within the cancellation-file-writing branch of the batch's main processing loop. The output is a flat CSV-style line containing service contract metadata, timestamps, error/reservation details, work case information, financial codes, and pricing data.

## 2. Processing Pattern (Detailed Business Logic)

```mermaid
flowchart TD
    START(["setKjClStr params"])

    subgrp1["Fields 0-9: Contract & Timestamp Data"]
    S0["Append data[0]: Service Contract Number"]
    S0a["Append comma"]
    S1["Append data[1]: Update Timestamp"]
    S1a["Append comma"]
    S2["Append data[2]: Error Reservation Number"]
    S2a["Append comma"]
    S3["Append data[3]: Update Timestamp 1"]
    S3a["Append comma"]
    S4["Append data[4]: Service Code"]
    S4a["Append comma"]
    S5["Append data[5]: Service Contract Detail No. 1"]
    S5a["Append comma"]
    S6["Append data[6]: Registration Date 1"]
    S6a["Append comma"]
    S7["Append data[7]: Service Contract Detail No. 2"]
    S7a["Append comma"]
    S8["Append data[8]: Registration Date 2"]
    S8a["Append comma"]
    S9["Append data[9]: Error Reservation Number 2"]
    S9a["Append comma"]

    subgrp2["Fields 10-15: Work Status & Case Data"]
    S10["Append data[10]: Update Timestamp 2 (Disconnection)"]
    S10a["Append comma"]
    S11["Append data[11]: Work Result"]
    S11a["Append comma"]
    S12["Append data[12]: Work Completion Date"]
    S12a["Append comma"]
    S13["Append data[13]: Work Case Key Charge Flag"]
    S13a["Append comma"]
    S14["Append data[14]: Application Detail Number"]
    S14a["Append comma"]
    S15["Append data[15]: Error Distinction"]
    S15a["Append comma"]

    subgrp3["Fields 16-22: Financial & Pricing Data"]
    S16["Append data[16]: Work Case Number"]
    S16a["Append comma"]
    S17["Append data[17]: Group Code"]
    S17a["Append comma"]
    S18["Append data[18]: Service Contract Status"]
    S18a["Append comma"]
    S19["Append data[19]: Error Reservation Detail Code"]
    S19a["Append comma"]
    S20["Append data[20]: Old Price Plan Code [ANK-2765]"]
    S20a["Append comma"]
    S21["Append data[21]: New Price Course Code [ANK-3949]"]
    S21a["Append comma"]
    S22["Append data[22]: Old Price Course Code [ANK-3949]"]

    RET["Return kjClstrBuilder"]
    END(["End"])

    START --> subgrp1
    subgrp1 --> S0 --> S0a --> S1 --> S1a --> S2 --> S2a --> S3 --> S3a --> S4 --> S4a --> S5 --> S5a --> S6 --> S6a --> S7 --> S7a --> S8 --> S8a --> S9 --> S9a
    S9a --> subgrp2
    subgrp2 --> S10 --> S10a --> S11 --> S11a --> S12 --> S12a --> S13 --> S13a --> S14 --> S14a --> S15 --> S15a
    S15a --> subgrp3
    subgrp3 --> S16 --> S16a --> S17 --> S17a --> S18 --> S18a --> S19 --> S19a --> S20 --> S20a --> S21 --> S21a --> S22 --> RET --> END
```

**Constant Resolution:**
- `CONMA` = `","` (comma) — a static final field defined in `JBSbatKKCourseChgFileBnkt` as the CSV delimiter character used to separate fields in the output cancellation record string.

## 3. Parameter Analysis

| No | Parameter Name | Type | Business Description |
|----|---------------|------|---------------------|
| 1 | `kjClstrBuilder` | `StringBuilder` | The mutable string buffer being built up with the work cancellation record. It is initialized as `new StringBuilder()` in the caller (`execute()`) before being passed in. After this method returns, it holds a fully formed CSV-style line (23 comma-separated fields) ready to be written to the work cancellation output file. |
| 2 | `data` | `String[]` | A 23-element string array containing the raw data fields extracted from the processed course-change input file. Each index maps to a specific business field (see Blocks section for the full mapping). The array is populated by the caller's file-parsing logic and carries service contract metadata, timestamps, reservation/error data, work case information, and pricing details. |

**Instance fields read by this method:** None — this method accesses only its parameters and the static `CONMA` constant.

## 4. CRUD Operations / Called Services

This method performs **pure data transformation** with no external calls to service components, CBS routines, or database operations. It only mutates the passed-in `StringBuilder` via `append()` calls.

| CRUD | SC / CBS | SC Code | Entity / DB | Operation Description |
|------|----------|---------|-------------|----------------------|
| (N/A) | `StringBuilder.append()` | — | — | In-memory string concatenation only — no database or service layer interaction |

## 5. Dependency Trace

| # | Caller (Screen/Batch) | Call Chain (Full Path to this Method) | Terminal (SC / CRUD / Entity) |
|---|----------------------|--------------------------------------|-------------------------------|
| 1 | Batch: `JBSbatKKCourseChgFileBnkt.execute()` | `execute()` → `setKjClStr(kjClstrBuilder, data)` | (none — pure in-memory formatting, output written to cancellation file) |

**Caller Details:**
- `JBSbatKKCourseChgFileBnkt.execute()` is a private batch method in the same class. It is called when the work result (`kojiRslt`) matches `KKIFM151_KOJI_RSLT_4` (work result code "4", indicating work cancellation). The method builds a `StringBuilder`, passes it to `setKjClStr()`, then writes the resulting string to the work cancellation file via a `BufferedWriter` (`kjClWr`).

## 6. Per-Branch Detail Blocks

**Block 1** — [SEQUENTIAL APPEND] `Fields 0-9: Contract & Timestamp Data` (L515)

> Appends the first 10 data fields (service contract number, timestamps, error reservation numbers, service code, contract detail numbers, registration dates) to the builder, separated by commas.

| # | Type | Code |
|---|------|------|
| 1 | EXEC | `kjClstrBuilder.append(data[0])` // Service Contract Number — the unique identifier for the customer's service contract |
| 2 | EXEC | `kjClstrBuilder.append(CONMA)` // Comma delimiter [-> CONMA=","] |
| 3 | EXEC | `kjClstrBuilder.append(data[1])` // Update Timestamp — the date/time of the latest update to the contract record |
| 4 | EXEC | `kjClstrBuilder.append(CONMA)` // Comma delimiter [-> CONMA=","] |
| 5 | EXEC | `kjClstrBuilder.append(data[2])` // Error Reservation Number — a reservation/tracking number associated with an error condition |
| 6 | EXEC | `kjClstrBuilder.append(CONMA)` // Comma delimiter [-> CONMA=","] |
| 7 | EXEC | `kjClstrBuilder.append(data[3])` // Update Timestamp 1 — first update timestamp field (possibly from a related record) |
| 8 | EXEC | `kjClstrBuilder.append(CONMA)` // Comma delimiter [-> CONMA=","] |
| 9 | EXEC | `kjClstrBuilder.append(data[4])` // Service Code — the telecom service type code (e.g., FTTH, Mail, etc.) |
| 10 | EXEC | `kjClstrBuilder.append(CONMA)` // Comma delimiter [-> CONMA=","] |
| 11 | EXEC | `kjClstrBuilder.append(data[5])` // Service Contract Detail No. 1 — first line item identifier for service contract details |
| 12 | EXEC | `kjClstrBuilder.append(CONMA)` // Comma delimiter [-> CONMA=","] |
| 13 | EXEC | `kjClstrBuilder.append(data[6])` // Registration Date 1 — the date when the first contract detail was registered |
| 14 | EXEC | `kjClstrBuilder.append(CONMA)` // Comma delimiter [-> CONMA=","] |
| 15 | EXEC | `kjClstrBuilder.append(data[7])` // Service Contract Detail No. 2 — second line item identifier for service contract details |
| 16 | EXEC | `kjClstrBuilder.append(CONMA)` // Comma delimiter [-> CONMA=","] |
| 17 | EXEC | `kjClstrBuilder.append(data[8])` // Registration Date 2 — the date when the second contract detail was registered |
| 18 | EXEC | `kjClstrBuilder.append(CONMA)` // Comma delimiter [-> CONMA=","] |
| 19 | EXEC | `kjClstrBuilder.append(data[9])` // Error Reservation Number 2 — a secondary reservation/tracking number for error conditions |
| 20 | EXEC | `kjClstrBuilder.append(CONMA)` // Comma delimiter [-> CONMA=","] |

**Block 2** — [SEQUENTIAL APPEND] `Fields 10-15: Work Status & Case Data` (L544)

> Appends work cancellation metadata: update timestamp for disconnection, work result, work completion date, work case charge flag, application detail number, and error distinction.

| # | Type | Code |
|---|------|------|
| 1 | EXEC | `kjClstrBuilder.append(data[10])` // Update Timestamp 2 (Disconnection Details) — the timestamp of the disconnection operation |
| 2 | EXEC | `kjClstrBuilder.append(CONMA)` // Comma delimiter [-> CONMA=","] |
| 3 | EXEC | `kjClstrBuilder.append(data[11])` // Work Result — the result code of the work operation (e.g., success, failure, cancellation) |
| 4 | EXEC | `kjClstrBuilder.append(CONMA)` // Comma delimiter [-> CONMA=","] |
| 5 | EXEC | `kjClstrBuilder.append(data[12])` // Work Completion Date — the calendar date when the work was completed |
| 6 | EXEC | `kjClstrBuilder.append(CONMA)` // Comma delimiter [-> CONMA=","] |
| 7 | EXEC | `kjClstrBuilder.append(data[13])` // Work Case Key Charge Flag — indicates whether the work case involves a chargeable key item |
| 8 | EXEC | `kjClstrBuilder.append(CONMA)` // Comma delimiter [-> CONMA=","] |
| 9 | EXEC | `kjClstrBuilder.append(data[14])` // Application Detail Number — the detail number associated with the service application |
| 10 | EXEC | `kjClstrBuilder.append(CONMA)` // Comma delimiter [-> CONMA=","] |
| 11 | EXEC | `kjClstrBuilder.append(data[15])` // Error Distinction — a classification distinguishing types of errors or anomalies |
| 12 | EXEC | `kjClstrBuilder.append(CONMA)` // Comma delimiter [-> CONMA=","] |

**Block 3** — [SEQUENTIAL APPEND] `Fields 16-22: Financial & Pricing Data` (L558)

> Appends the remaining fields covering work case identification, group classification, service status, error details, and pricing/plan codes. Fields 20–22 are added via version-specific changes (ANK-2765 for Old Price Plan Code, ANK-3949 for New Price Course Code and Old Price Course Code).

| # | Type | Code |
|---|------|------|
| 1 | EXEC | `kjClstrBuilder.append(data[16])` // Work Case Number — the unique identifier for the work case |
| 2 | EXEC | `kjClstrBuilder.append(CONMA)` // Comma delimiter [-> CONMA=","] |
| 3 | EXEC | `kjClstrBuilder.append(data[17])` // Group Code — the customer billing or service group classification code |
| 4 | EXEC | `kjClstrBuilder.append(CONMA)` // Comma delimiter [-> CONMA=","] |
| 5 | EXEC | `kjClstrBuilder.append(data[18])` // Service Contract Status — the current status of the service contract (e.g., active, suspended, terminated) |
| 6 | EXEC | `kjClstrBuilder.append(CONMA)` // Comma delimiter [-> CONMA=","] |
| 7 | EXEC | `kjClstrBuilder.append(data[19])` // Error Reservation Detail Code — detailed code for the error reservation condition |
| 8 | EXEC | `kjClstrBuilder.append(CONMA)` // Comma delimiter [-> CONMA=","] |
| 9 | EXEC | `kjClstrBuilder.append(data[20])` // Old Price Plan Code [ANK-2765: Authentication ID Unification] — the former pricing plan code before a rate change |
| 10 | EXEC | `kjClstrBuilder.append(CONMA)` // Comma delimiter [-> CONMA=","] |
| 11 | EXEC | `kjClstrBuilder.append(data[21])` // New Price Course Code [ANK-3949: Netflix Introduction Support] — the new pricing course code introduced for Netflix-related service changes |
| 12 | EXEC | `kjClstrBuilder.append(CONMA)` // Comma delimiter [-> CONMA=","] |
| 13 | EXEC | `kjClstrBuilder.append(data[22])` // Old Price Course Code [ANK-3949: Netflix Introduction Support] — the previous pricing course code before the Netflix-related price change |

**Block 4** — [RETURN] (L584)

| # | Type | Code |
|---|------|------|
| 1 | RETURN | `return kjClstrBuilder;` // Returns the fully constructed cancellation record string |

## 7. Glossary

| Term | Type | Business Meaning |
|------|------|------------------|
| `kjClstrBuilder` | Field | Work Cancellation String Builder — the StringBuilder used to assemble the cancellation detail record |
| `data` | Field | Retrieved data array — 23-element string array carrying fields parsed from the course-change input file |
| `CONMA` | Constant | Comma character (",") — CSV delimiter used to separate fields in the output record |
| Work Cancellation (工事取消) | Business term | A work result indicating that a previously scheduled installation/maintenance work order has been cancelled |
| Service Contract Number (契約番号) | Field | Unique identifier for a customer's service contract |
| Update Timestamp (更新年月日时分秒) | Field | Date and time of the most recent update to a service contract record |
| Error Reservation Number (異動予約番号) | Field | A tracking/reservation number assigned when a service contract change results in an error condition |
| Service Code (サービスコード) | Field | Classification code identifying the type of telecom service (e.g., FTTH broadband, mail service) |
| Service Contract Detail Number (契約内容番号) | Field | Line-item identifier within a service contract for specific service components or features |
| Registration Date (世代登録年月日) | Field | The date when a particular version/revision of a service record was registered in the system |
| Work Result (工事結果) | Field | The outcome code of a field work operation (e.g., completion, failure, cancellation). Code "4" specifically indicates work cancellation |
| Work Completion Date (工事完了日) | Field | The calendar date on which the field work was actually completed |
| Work Case Key Charge Flag (工事案件キンスル料有無) | Field | Boolean flag indicating whether a work case involves a billable/chargeable key component |
| Application Detail Number (申込明細番号) | Field | Detail number for a service application or order line item |
| Error Distinction (異動区分) | Field | Classification distinguishing the type of service contract change or anomaly (e.g., addition, modification, cancellation) |
| Work Case Number (工事案件番号) | Field | Unique identifier for a field work case/order |
| Group Code (料金グループコード) | Field | Billing or customer group classification code used for rate/pricing determination |
| Service Contract Status (サービス契約ステータス) | Field | The current lifecycle status of a service contract (e.g., active, provisionally confirmed, suspended, terminated) |
| Error Reservation Detail Code (異動予約詳細コード) | Field | Granular classification code for the error condition associated with a reservation |
| Old Price Plan Code (旧料金プランコード) | Field | The previous pricing plan code, preserved for audit/transition purposes when a price plan is changed (added in ANK-2765: Authentication ID Unification) |
| New Price Course Code (新料金コースコード) | Field | The new pricing course code introduced during price changes, particularly for Netflix-related service changes (added in ANK-3949: Netflix Introduction Support) |
| Old Price Course Code (旧料金コースコード) | Field | The previous pricing course code before a rate/course change, retained for audit trail purposes (added in ANK-3949) |
| ANK-2765 | Change request | Authentication ID unification initiative — added the old price plan code field to support customer data migration |
| ANK-3949 | Change request | Netflix introduction support (Step 1) — added new and old price course codes to track pricing changes associated with Netflix service offerings |
| Course Change (コース変更) | Business term | The process of modifying a customer's service course/package, which may involve addition, modification, or cancellation of service components. This batch handles the file output for course-change operations |
| `JBSbatKKCourseChgFileBnkt` | Class | Course Change File Partitioning Batch — the batch class responsible for processing course-change input files and generating output files (work completion file, work cancellation file, etc.) |
