13

I'm new to EDI, and I have a question.

I have read that you can get most of what you need about an EDI format by looking at the last 3 characters of the ISA line. This is fine if every EDI used line breaks to separate entities, but I have found that many are single line files with any number of characters used as breaks. I have noticed that the VERY last character in every EDI I've parsed is the break character. I've looked at a few hundred, and have found no exceptions to this. If I first grab that character, and use that to obtain the last 3 of the ISA line, should I reasonably expect that I will be able to parse data from an EDI?

I don't know if this helps, but the EDI 'types' in question tend to be 850, 875. I'm not sure if that is a standard or not, but it may be worth mentioning.

4

3 回答 3

15

edi 的交易类型并不重要(850 = 订单,875 = 杂货店)。在编写了一些 edi 解析器之后,我发现了以下几点:

您应该能够指望 ISA(和仅 ISA)是固定宽度(如果有记忆,则为 105 个字符)。去掉前 105 个字符。在那之后和第一次出现“GS”之前的所有内容都是您的行终止符(这可以是任何东西,包括一个 0x07 - 哔声 - 所以要注意您是否输出到标准输出进行调试,或者您可能会有一堆哔哔声出扬声器)。通常这是 1 或 2 个字符,有时可能更多(如果向您发送数据的人出于某种原因添加了额外的终止符)。一旦有了行终止符,就可以获得段(字段)分隔符。我通常会拉出 GS 行的第 3 个字符并使用它,尽管 ISA 行的第 4 个字符也应该可以工作。

另请注意,您可以获得包含多个 ISA 的文件。在这种情况下,您不能指望每个 ISA 中的行或字段分隔符相同。

另一件事.. edi 文件也有可能(再次,不确定其规范)具有可变长度的 ISA。这是非常罕见的,但我不得不适应它。如果发生这种情况,您必须将该行解析为其字段。ISA 中的最后一个字段只有一个字符长,因此您可以从中确定 ISA 的实际长度。如果是我,除非你看到类似的文件,否则我不会担心这个。这是一种罕见的情况。

我上面所说的可能不是“规范”的字母......也就是说,我不确定在同一个文件中使用不同的行分隔符是否合法,但在不同的 ISA 中,但在技术上是可能的我适应它,因为我必须处理以这种方式通过的文件。我使用的 edi 处理器每天处理超过 5000 个文件,其中包含超过 3000 个可能的数据源(所以我看到了很多奇怪的东西)。

最好的问候,唐

于 2010-01-22T14:51:56.990 回答
0

EDI 内容由段和元素组成。

要解析它,您需要先将其分解为段,然后是这样的元素(在 PHP 中):

<?php 

$edi = "YOUR EDIT STRING!";
$segment_delimeter = "~";
$element_delimeter = "*";

//First break it into segments
$segments = explode($segment_delimiter, $edi);

//Now break each segment into elements
$segs_and_elems = array();
foreach($segments as $segment){
    $segs_and_elems[] = explode(element_delimeter, $segment);
}

//To echo out what type of EDI this is for example:
foreach($segs_and_elems as $seg){
    if($seg[0] == "GS"){ echo($seg[1]); }
}

?>

希望这有助于您入门。

于 2014-12-01T21:17:36.000 回答
0

对于标头信息,以下 java 将让您非常容易地获得基本信息。C# 也有拆分,代码看起来非常相似

try {
    String sCurrentLine;
    fileContent = new BufferedReader(new FileReader(filePathName));

    sCurrentLine = fileContent.readLine();

    // get the delimiter after ISA, if you know your field delimiter just force it.
    // we look at lots of different senders messages so never sure what it will be.

    delimiterElement = sCurrentLine.substring(3,1); // Grab the delimiter they are using
    String[] splitMessage = sCurrentLine.split(delimiterElement,16); // to get the messages if everything is on one line of course
    senderQualifier = splitMessage[5]; //who sent something we need fixed qualifier
    senderID = splitMessage[6]; //who sent something we need fixed alias
    ISA = splitMessage[13]; // Control number
    testIndicator = splitMessage[15]; 
    dateStamp = splitMessage[9];  
    timeStamp = splitMessage[10];

    ... do stuff with the pieces of info ...
于 2016-09-23T12:16:06.620 回答