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).
Purpose¶
- Represents the CTX segment identity via
SegmentIdreturning the literal"CTX"(BR-020). - Carries
GroupCodeclassifying the category of adjustment, plus repeating reason-code/amount triplets in the parallelReasoncode/Amountlists starting at element 2, mirroringCasSegment's triplet layout (BR-061). - Scales each triplet's amount to cents by truncating
amount * 100onBuild(), and rescales back to a decimal amount by dividing by 100 onFill()— the inverse ofCasSegment's unscaled amounts (BR-050). - Omits a reason-code triplet from
Build()output entirely when its reason code is empty (BR-059). - The quantity position of each triplet is not implemented — quantities are neither read nor written (BR-061).
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). |
| 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). |
| 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). |
| 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, BR-061). |
| 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 intoReasoncode[i]andAmount[i]by list index without first allocating those lists to the required size, which appears to makeFill()unreachable for any segment carrying adjustments as currently written**. Build()similarly requires the caller to have already populatedReasoncodeandAmountwith matching-length entries before calling it**.
Constraints and usage notes¶
- Callers must manually pre-populate
ReasoncodeandAmountwith the correct number of entries before invoking eitherBuild()orFill(), 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