I have a problem retrieving the delivery date from .txt-file sent with EDI.
My customers have to opportunity to set the line in a .txt-file:
'DTM+76:20160702:102
when they order something from the website to set delivery date for future deliveries.
I want to get the date (in this case 2016-07-02) and set it to the deliveryDate-variable (and then set it in the database).
I am thinking about using Scanner in java to see if the file contains the text "DTM:76" and then read the date-part of the line like Find a string (or a line) in a txt File Java . Is it possible/effective with EDI or is there a better way to do it?
The best solution for me would be something like this:
if (DTM+76:YYYYMMDD::102 exists)
{
//set the deliveryDate by getting only YYYYMMDD from DTM:76:20160702:102
deliveryDate= get..("20160702");
}
Info about EDI and delivery dates: http://www.gs1.org/sites/default/files/docs/eancom/ean02s4/part2/insdes/053.htm https://www.stylusstudio.com/edifact/D96A/ORDERS.htm
Any suggestions?
When we parse EDIFACTs, we split the EDIFACT into segments, then elements, then components using regular expressions like so:
String edi = "UNH+..."; // full edifact as string here
// split EDIFACT string into segments
String[] segments = edi.split("(?<!\?)'");
// loop through segments to find one beginning with DTM+
// lets assume its 3rd segment in array
String dtmSegment = segments[2];
// split DTM segment to get its elements
String[] dtmElements = dtmSegment.split("(?<!\?)\+");
// get date, time, period element
String dtmElement = dtmElements[1];
// split dtmElement to get date/time/period components
String[] dtmComponents = dtmElement.split("(?<!\?):");
// get date/time/period component value
String deliveryDate = dtmComponents[1];
Note: that when the full EDIFACT is split into segments, the segment delimiter '
is removed from each segment String. The same applies when splitting elements and components into individual Strings.