User talk:Stuart Gathman
EDILoader is very limited in what it can parse. The main difficulty is that qualifiers are ignored. For instance, suppose our input contains
DTM*063*20140402 DTM*001*20140818 REF*CR*EDIUN
Our EDIFormat contains:
DTM C:001 F:DateCancel
The "constant" element 001 is ignored, and the wrong date is loaded into the DateCancel field. To fix this without a total rewrite of EDILoader, I implemented segment reordering. EDILoader looks at the "Mandatory" flag for constant elements. If mandatory, and they don't match, EDILoader looks ahead for a matching element and segment name. If it finds one, it is moved to the front, and processing for that segment restarts. If it doesn't find one, it moves on to the next EDIFormat_line, as if the segment name didn't match. The effect is as if the segments were reordered.
Caveat, if 2 or more constant elements are marked "Mandatory", there can be a loop if there is no input segment matching both elements. It moves the first record matching the first mandatory element to the front and restarts, then moves the first record matching the second mandatory element to the front and restarts. Then the first element doesn't match again, and we start over. To fix this, we should just loop over all the EDIFormat_lineelements and match all the mandatory constants in one go. However, all the cases encountered so far are like DTM, with only one constant that needs to be matched.
Except when there is an array of them. For instance, the PO1 segment has an array of up to 10 qualifier,identifier pairs. Suppose our input contains
Our EDIFormat contains
F:LineNo F:QtyRequested C:UN F:PriceList C:XX C:EN F:UPC C:IB F:ISBN
Oh no! It loads the ISBN into the UPC field and blank into the ISBN field! So instead, the 10 element array beginning at PO106 uses the match and swap logic. It looks ahead to the EN pair, and moves that to the front. Now both the EN and IB identifiers get loaded into the correct fields.
I could not think of a way to mark the 10 element array in PO1 with existing EDIFormat data, so I just hardwired it into EDILoader for now.