We are a modern company using modern technology like XML interfaces, but many of our customers want for example electronic invoices from us in an EDIFACT format like D96A.
No we cannot use already existing libraries, as they are not written in the C/AL programming language our Navision software uses.
So in order to parse it in C/AL I need to understand its specification. But it looks extremely difficult and complicated.
So can someone give me an overview how to interpret say D96A and how to parse it?
I know that this question is older, but I had to do a little research for a customer's project. There are several good add-ons for Dynamics NAV. Have for example a look at Anveo EDI Connect they implemented the import and export of EDIFACT (and many more formats) directly in NAV. Other solutions are available from BMI, Yaveon, Lanham and several other companies. There are also several service providers that process the data and you agree with them on a simple XML or file based structure.
Parsing EDIFACT is actually not that complicated. Just split at the sytax chars: first at '
to get the segments, than at +
to get data elements of that segments and at :
to get the individual components. You need to take care of escaped seperator chars, of course. The chars used here are only the default, they can be changed at the beginning of the message by the optional UNA-segment. Actually the wikipedia article on EDIFACT gives a pretty good (but brief) introduction to that. And the format is documented with detail on the UN's UNECE site (yes, that's a lot and hard to read).
The tricky part is to get the information out of that and into your application (and verifying it's valid, leave alone creating good error messages). If you really plan to write a comlete parser out of nothing for all that in any language, then: No, there is no easy way to do this. Nor is there for any other flexible data representation. That is a difficult task and always will be.
But here's an idea: if you are into XML that much (or any other "modern technology" as you like to call it...). It would be a relatively easy task to write some program that converts EDIFACT messages into some unified XML-EDIFACT-Format (which is a pretty horrible thing and would most likely freak me out). You can convert every EDIFACT segment into one XML tag, maybe like this:
ERC+A7V:1:AMD'
IFT+3+NO MORE FLIGHTS'
In XML:
<segment qualifier="ERC">
<element>
<component>A7V</component>
<component>1</component>
<component>AMD<component>
</element>
</segment>
<segment qualifier="IFT">
<element>
<component>3</component>
</element>
<element>
<component>NO MORE FLIGHTS</component>
</element>
</segment>
Then you can unleash the power of your XML tools and libraries on it to validate/evaluate it.
You could also do it more specific, like this:
<segment_ERC>
<element>
<component>A7V</component>
<component>1</component>
<component>AMD<component>
</element>
</segment_ERC>
<segment_IFT>
<element>
<component>3</component>
</element>
<element>
<component>NO MORE FLIGHTS</component>
</element>
</segment_IFT>
This could make validation via XSD easier. You can get of course as specific as you want with this conversation, but you would sooner or later come to a point, where you would need to put information on the structure of your currently parsed message into the converter (since it is not trivial to know which segments are nested into other segments grouping them. There's not just UNG
, UNH
and such, but also some segment groups that you don't see directly).
Still, you will have to create specific evaluation programs/schemas/whatevers for the messages you receive, according to the EDIFACT-handbooks you should get as documentation.
I suggest searching and perusing through GitHub or SourceForge repos. A quick search
with keywords: +EDIFACT +D96A provided several libraries to choose from.
In fact this looks promising for your case:
- Bots open source edi translator, http://sourceforge.net/projects/bots/. Project's description says it's a complete translator for EDI (Electronic Data Interchange).
You could always evaluate and check out Oracle B2B 11g which is part of Oracle SOA Suite 11gR1:
- http://www.oracle.com/technetwork/middleware/soasuite/downloads/downloads-085394.html#11g.
It has UN/EDIFACT OTD library which I guess you could use at least for parsing.
Generally your best bet is to pick up existing library and either port it to NAV or use through
external interface where data flows into your NAV database. If you're able to call .NET code then a plethora of existing libraries should exist and simply by referencing assembly gets you there. As it I'm not familiar with NAV development but using some sort of REST/JSON whatever your data transfer object calling mechanism is should be possible - where your component B does the heavy job and your NAV component pulls parsed UN/EDIFACT messages through your XML interface.
There was another similar question and couple answers as well that could suit you as well:
Is there any good open source EDIFACT parser in Java?.
edifact navision x12 xml edi d96a
Cheers!