EDI Tools for .NET translates EDI files using EDI Reader and its derived readers for every supported EDI standard. For more information on how to use EDI Reader head on to the Parse EDI files article.
All EDI readers can be configured with additional settings which change the behavior of the EDI reader.
- ReaderSettings Reference
- X12ReaderSettings Reference
- EdifactReaderSettings Reference
- Hl7ReaderSettings Reference
- NcpdpScriptReaderSettings Reference
Common EDI reader settings
- Encoding - this is the System.Encoding of the EDI file. UTF8 by default.
- ContinueOnError - this is to force the parser to continue past an exception. By default, parsing stops when an exception is encountered.
- MaxSegmentLength - this is the maximum number of characters the parser can read before finding a segment terminator. When no segment terminator was found, the parser assumes the EDI stream is corrupt and terminates execution. It is also used in VDA and positional parsers to specify the set length of each segment. 5000 by default for EDIFACT and X12. 128 by default for VDA.
- Separators - this is the set of EDI separators to be used when reading EDI transactions. When used with EDI files that have valid envelopes, this property is overwritten by the delimiters found in the envelopes (ISA, UNA, MSH, etc.).
- NoEnvelope - this flag tells the parser to not expect any envelopes (ISA, UNB, etc.) and that EDI transactions must be parsed using the delimiters specified in the Separators property.
- Split- When a template is marked for splitting it will still be translated as if it had not been marked. To explicitly enable splitting set this to True.
- LeaveOpen - whether to close the underlying stream when the reader is disposed of. False by default.
- DataElementCodesMap - allows you to import external EDI codes at runtime.
Apply reader settings to EDI reader
-
X12ReaderSettings settings = new X12ReaderSettings();
settings.ContinueOnError = true;
settings.Encoding = Encoding.UTF8;
settings.MaxSegmentLength = 5000;
settings.Separators = Separators.X12;
settings.Split = true;
settings.DataElementCodesMap = new public Dictionary<string, List<string>>();
using (var ediReader = new X12Reader(edi, "Templates", settings)) -
EdifactReaderSettings settings = new EdifactReaderSettings ();
settings.ContinueOnError = true;
settings.Encoding = Encoding.UTF8;
settings.MaxSegmentLength = 5000;
settings.Separators = Separators.Edifact;
settings.Split = true;
settings.DataElementCodesMap = new public Dictionary<string, List<string>>();
using (var ediReader = new EdifactReader(edi, "Templates", settings)) -
Hl7ReaderSettings settings = new Hl7ReaderSettings();
settings.ContinueOnError = true;
settings.Encoding = Encoding.UTF8;
settings.MaxSegmentLength = 5000;
settings.Separators = Separators.X12;
settings.Split = true;
settings.DataElementCodesMap = new public Dictionary<string, List<string>>();
using (var ediReader = new Hl7Reader(edi, "Templates", settings)) -
NcpdpScriptReaderSettings settings = new NcpdpScriptReaderSettings();
settings.ContinueOnError = true;
settings.Encoding = Encoding.UTF8;
settings.MaxSegmentLength = 5000;
settings.Separators = Separators.NcpdpScript;
settings.Split = true;
settings.DataElementCodesMap = new public Dictionary<string, List<string>>();
using (var ediReader = new NcpdpScriptReader(edi, "Templates", settings))
Edifact reader settings
The Edifact reader has an extra setting:
- EancomS3IsDefault - By default, all EANCOM transactions for version D01B are parsed according to the EANCOM Syntax 4. When this property is set to True, then EANCOM Syntax 3 is used.
NCPDP Telco and VDA reader settings
NCPDP Telco and VDA standards are flat files and do not require reader settings, like separators, etc. The file encoding can be specified directly as a parameter to the reader constructor.
What is DataElementCodesMap?
Let's illustrate this for Transaction Set Purpose Code, represented by the X12_ID_353 class in the X12 EDI template in version 4010, however, the principle is the same for any EDI code set.
The standard X12_ID_353 code set is defined as allowing the following values: 00, 18, and 19.
///
/// Transaction Set Purpose Code
///
[Serializable()]
[DataContract()]
[EdiCodes(",00,18,19,")]
public class X12_ID_353
Let's assume that a fictional partner A requires a custom set of EDI codes for X12_ID_35, instead of the standard ones, which only allows the following values: 00, PA, and PB.
The templates using this class can be changed to use a new class, for partner A, however, the validation can be configured without any changes to the existing EDI template. The new values can be configured as a DataElementCodesMap in the ValidationSettings. This way IsValid() will match the new values instead of the standard values.
var codeSetMap = new Dictionary<string, List<string>>();
codeSetMap.Add("X12_ID_353", new List<string> { "00", "PA", "PB" });
ediMessage.IsValid(out errorContext,
new ValidationSettings { DataElementCodesMap = codeSetMap });
Use this method to dynamically load external code sets from a file, database, or another configuration source. No redeployment is required and the correct value resolution (by the code set class name) occurs at runtime.
Examples in GitHub:
- Validate X12 transactions with external EDI codes
- Validate EDIFACT transactions with external EDI codes
Comments
0 comments
Please sign in to leave a comment.