Is there a really simple way to process EDIFACT for example D96A?

user1315373 picture user1315373 · Jul 2, 2012 · Viewed 18k times · Source

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?

Answer

kratenko picture kratenko · Oct 24, 2012

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.