---
title: CtxSegment
summary: API reference for CtxSegment.
status: draft
owner: SAIF Doc Gen
last_reviewed: 2026-09-15
library: SAIF.Framework.Common.Files
reference_type: package
---

# CtxSegment

`CtxSegment` models the X12 CTX context/adjustment segment, used to carry an additional repeating series of adjustment reason-code/amount triplets analogous to `CasSegment`, but with monetary amounts scaled to cents on the wire: `Build()` truncates `amount * 100` before writing, and `Fill()` divides the parsed value by 100 ([BR-050](../../business-rules.md#br-050-ctx-amounts-scaled-to-cents-cas-amounts-unscaled)).

## Purpose
- Represents the CTX segment identity via `SegmentId` returning the literal `"CTX"` ([BR-020](../../business-rules.md#br-020-first-element-is-the-segment-identifier)).
- Carries `GroupCode` classifying the category of adjustment, plus repeating reason-code/amount triplets in the parallel `Reasoncode`/`Amount` lists starting at element 2, mirroring `CasSegment`'s triplet layout ([BR-061](../../business-rules.md#br-061-cas-and-ctx-adjustment-triplets)).
- Scales each triplet's amount to cents by truncating `amount * 100` on `Build()`, and rescales back to a decimal amount by dividing by 100 on `Fill()` — the inverse of `CasSegment`'s unscaled amounts ([BR-050](../../business-rules.md#br-050-ctx-amounts-scaled-to-cents-cas-amounts-unscaled)).
- Omits a reason-code triplet from `Build()` output entirely when its reason code is empty ([BR-059](../../business-rules.md#br-059-optional-segment-elements-written-only-when-populated)).
- The quantity position of each triplet is not implemented — quantities are neither read nor written ([BR-061](../../business-rules.md#br-061-cas-and-ctx-adjustment-triplets)).

## Context
- Namespace: `SAIF.Common.Files.Edi.Segments`
- Assembly/package: `SAIF.Framework.Common.Files`

## Public members
| Member | Signature | Purpose |
| --- | --- | --- |
| SegmentId | `string SegmentId { get; }` | Returns the literal X12 segment identifier `"CTX"`. |
| GroupCode | `string GroupCode { get; set; }` | The adjustment group/category code (CTX01), element 1. |
| Reasoncode | `List<string> Reasoncode { get; set; }` | The parallel list of adjustment reason codes, one per triplet, at elements 2, 5, 8, 11, 14, 17 (up to six triplets) ([BR-061](../../business-rules.md#br-061-cas-and-ctx-adjustment-triplets)). |
| Amount | `List<decimal> Amount { get; set; }` | The parallel list of adjustment amounts corresponding to each `Reasoncode` entry, scaled to/from cents on `Build()`/`Fill()` ([BR-050](../../business-rules.md#br-050-ctx-amounts-scaled-to-cents-cas-amounts-unscaled)). |
| Build | `IEdiSegment Build()` | Creates a `SegmentBuilder("CTX")`, adds `GroupCode` at element 1, then for each populated `Reasoncode` entry adds the reason code and `Decimal.Truncate(Amount[i] * 100)` at the triplet's two positions, skipping triplets whose reason code is empty ([BR-059](../../business-rules.md#br-059-optional-segment-elements-written-only-when-populated)). |
| Fill | `void Fill(IEdiSegment segment)` | Computes the triplet count as `floor((elementCount + 1) / 3)` and, for each triplet index, assigns `Reasoncode[i]` and `Amount[i]` as the parsed value divided by 100 ([BR-050](../../business-rules.md#br-050-ctx-amounts-scaled-to-cents-cas-amounts-unscaled), [BR-061](../../business-rules.md#br-061-cas-and-ctx-adjustment-triplets)). |
| Parse | `static CtxSegment Parse(IEdiSegment segment)` | Instantiates a new `CtxSegment`, calls `Fill(segment)` on it, and returns it. |

## Behavioral notes
- As with `CasSegment`, `Fill()` assigns into `Reasoncode[i]` and `Amount[i]` by list index without first allocating those lists to the required size, which appears to make `Fill()` unreachable for any segment carrying adjustments as currently written**.
- `Build()` similarly requires the caller to have already populated `Reasoncode` and `Amount` with matching-length entries before calling it**.

## Constraints and usage notes
- Callers must manually pre-populate `Reasoncode` and `Amount` with the correct number of entries before invoking either `Build()` or `Fill()`, an usage requirement not enforced or documented by the class itself**.

> **Note:** Statements marked with `**` could not be confirmed; treat
> as unknown until verified.

## Sources
- Common\SAIF.Common.Files\Edi\Segments\CtxSegment.cs
