Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trying out EDI.NET, working with different vendors #231

Open
BrentWhiteNC opened this issue Jul 7, 2022 · 1 comment
Open

Trying out EDI.NET, working with different vendors #231

BrentWhiteNC opened this issue Jul 7, 2022 · 1 comment
Labels

Comments

@BrentWhiteNC
Copy link

I downloaded EDI.NET and was trying to parse 2 different EDI x12 documents, both 850's.

One parsed successfully, one didn't.

The one that didn't I noticed had CRLF characters in the file. The one that parsed just fine did not have these, and I saw where the default grammar settings for x12 choked on the CRLF in another issue someone raised.

I saw about the custom grammar but I'm failing to understand how this is going to be able to handle both files. Is it simpler just to take the file, strip out the CRLF characters and parse that resulting file?

@cleftheris
Copy link
Contributor

cleftheris commented Jul 8, 2022

Hi @BrentWhiteNC and thank you for your interest in the library.

This makes total sense. You can check a related disucssion and an open issue #19. There it is mentioned that in X12 transmissions the first 106 characters are part of what is called "INTERCHANGE CONTROL HEADER" and in there, in specific positions there is the information about all "control characters" otherwise known as "delimiters" needed to parse the file. The first 106 characters no more no less are always inside a transmission.

However for X12 the EDI.Net does not auto discover the delimiters (in other formats like EDIFact it does) so one has to do this manualy through using the SetAdvise on the EDIGrammar of your choice. This is usually no biggie as in each integration with a customer the delimiters are aggreged upfront so you know what to expect and you configure you grammar accordingly.

use the following in case your segment terminator is actually a new line char instead of the default ~

var grammar = EdiGrammar.NewX12();
grammar.SetAdvice(
                segmentNameDelimiter: '*', 
                dataElementSeparator: '*', 
                componentDataElementSeparator: ':', 
                segmentTerminator: '\n', 
                releaseCharacter: null, 
                reserved: null, 
                decimalMark: '.');

So for your actual question. How can you know if you got two files which one is using what kind of delimiters so you can set up your grammar conditionally before parsing. You can either

a) store the configuration in a configfile/database of your choice per vendor and load that up to the grammar before parsing using the grammar.SetAdvice(....) . OR
b) discover it dynamically as follows:

  1. You can try and open the file with a StreamReader and check the 106th character (segment terminator) as stated in the ISA 106 spec
  2. After you know your delimiter use the grammar.SetAdvice(....) method to alter the segment terminator as needed.
  3. Lastly you should reset the stream position to zero stream.Position = 0; and pass it to the EDI net for deserialization
  4. Of course you can find in there the other characters as well.

Hope this helped.

PS: Again this should be automatically discovered in the library but have not found time to do so yet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants