838 Trading Partner Profile (007040)

This is the standard X12 007040 spec, with 13 loops and 70 segment positions, as OpenEDI JSON, an ediFabric C# template and an ediFabric Native model. To change it for a trading partner, customize it in the EDI Spec Builder.

Loading the spec…
The spec as an OpenAPI 3 schema with x-openedi-* extensions, for ediFabric Native, ediFabric Cloud and the EDI Spec Builder. Download OpenEDI (145 KB) Generate classes
The ediFabric .NET template, class TS838. It needs the common segments, composites and codes of X12 007040, one download for every transaction in the version. Download C# (1 KB) Common files (233 KB)
The intermediary model ediFabric Native loads with set_map. Download Native (109 KB)

Use the 838 spec in your code

ediFabric .NET

Add the C# template and its common files to your project, or reference the template NuGet package, and read 838 files into TS838 objects. See ediFabric .NET.

ediFabric Native

Map version 007040 to the Native model with set_map, then parse 838 files to JSON from Python, Java, C or C#. See Convert between EDI and JSON.

OpenEDI

Select Customize in Spec Builder to copy the spec under your own name, change it for your partner, and parse files against it in EdiNation, ediFabric Native or ediFabric Cloud. Read about OpenEDI.

Generate 838 classes in Python, Java, Node.js, Go, Rust or C

ediFabric Native returns each 838 as JSON, with the property names of the OpenEDI schema. To work with that JSON as typed objects, generate classes from the OpenEDI file in your language and deserialize the JSON into TS838. Serialize the objects back to JSON to build EDI with ediFabric Native. The classes keep the loops, segments, lengths and code lists, but not the EDI data formats, so validate files with ediFabric Native. Read more in Generate a class from OpenEDI.

Python: datamodel-code-generator. Node.js: openapi-typescript. Java, Go, Rust and C: OpenAPI Generator.

838 structure

Loops and segments of the standard 838, with their usage and maximum repeats.

IDNameUsageMax use
STTransaction Set HeaderMandatory1
BTPBTPMandatory1
REQREQOptional1
PERPEROptional1
SPISPIOptional99999
DTMDTMOptional99999
Loop LXLXOptional99999
LXLXMandatory1
PLAPLAOptional1
LCDLCDOptional99999
LINLINOptional99999
Loop N1N1Optional99999
N1N1Mandatory1
N2N2Optional2
N3N3Optional2
N4N4Optional1
N9N9Optional99999
PERPEROptional99999
CURCUROptional99999
TAXTAXOptional99999
FOBFOBOptional99999
ITDITDOptional99999
TD5TD5Optional99999
SPISPIOptional99999
FBBFBBOptional99999
DTMDTMOptional10
MEAMEAOptional99999
Loop LCDLCDOptional99999
LCDLCDMandatory1
N2N2Optional1
N4N4Optional1
DMGDMGOptional99999
MEAMEAOptional99999
Loop TPDTPDOptional99999
TPDTPDMandatory1
N9N9Optional99999
PIDPIDOptional99999
DTMDTMOptional99999
Loop LSLSOptional1
LSLSMandatory1
Loop TUDTUDOptional99999
TUDTUDMandatory1
DTMDTMOptional99999
N1N1Optional1
N2N2Optional2
N3N3Optional2
N4N4Optional1
PERPEROptional99999
LELEMandatory1
Loop SPRSPROptional99999
SPRSPRMandatory1
N9N9Optional99999
DTMDTMOptional99999
Loop PAMPAMOptional99999
PAMPAMMandatory1
DTMDTMOptional99999
TAXTAXOptional99999
CURCUROptional99999
Loop TXNTXNOptional99999
TXNTXNMandatory1
N9N9Optional99999
DTMDTMOptional99999
Loop LMLMOptional99999
LMLMMandatory1
LQLQMandatory99999
Loop ENEENEOptional99999
ENEENEMandatory1
Loop N1N1Optional99999
N1N1Mandatory1
N2N2Optional2
N3N3Optional2
N4N4Optional1
TPDTPDOptional99999
PIDPIDOptional99999
N9N9Optional99999
PERPEROptional99999
Loop TXNTXNOptional99999
TXNTXNMandatory1
N9N9Optional99999
DTMDTMOptional99999
ERIERIOptional99999
AMTAMTOptional99999
SETransaction Set TrailerMandatory1