开发者

EDIFACT macro (readable message structure)

I´m working within the EDI area and would like some help with a EDIFACT macro to make the EDIFACT files more readable.

The message looks like this:

data'data'data'data'

I would like to have the macro converting the stru开发者_如何学Ccture to:

data'
data'
data'
data'

Pls let me know how to do this. Thanks in advance!

BR Jonas


If you merely want to view the files in a more readable format, try downloading the Softshare EDI Notepad. It's a fairly good tool just for that purpose, it supports X12, EDIFACT and TRADACOMS standards, and it's free.


Replacing in VIM (assuming that the standard EDIFACT separators/escape characters for UNOA character set are in use):

:s/\([^?]'\)\(.\)/\1\r\2/g

Breaking down the regex:
\([^?]'\) - search for ' which occurs after any character except ? (the standard escape character) and capture these two characters as the first atom. These are the last two characters of each segment.
\(.\) - Capture any single character following the segment terminator (ie. don't match if the segment terminator is already on the end of a line)

Then replace all matches on this line with a new line between the segment terminator and the beginning of the next segment.

Otherwise you could end up with this:

...
FTX+AAR+++FORWARDING?: Freight under Vendor?'
s care.'
NAD+BY+9312345123452'
CTA+PD+0001:Terence Trent D?'
Arby'
...

instead of this:

...
FTX+AAR+++FORWARDING?: Freight under Vendor?'s care .'
NAD+BY+9312345123452'
CTA+PD+0001:Terence Trent D?'Arby'
...


Is this what you are looking for?

Option Explicit

Dim stmOutput: Set stmOutput = CreateObject("ADODB.Stream")
stmOutput.Open
stmOutput.Type = 2 'adTypeText
stmOutput.Charset = "us-ascii"

Dim stm: Set stm = CreateObject("ADODB.Stream")
stm.Type = 1 'adTypeBinary
stm.Open
stm.LoadFromFile "EDIFACT.txt"

stm.Position = 0
stm.Type = 2 'adTypeText
stm.Charset = "us-ascii"

Dim c: c = ""
Do Until stm.EOS
  c = stm.ReadText(1)
  Select Case c
    Case Chr(39)
      stmOutput.WriteText c & vbCrLf
    Case Else
      stmOutput.WriteText c
  End Select
Loop


stm.Close
Set stm = Nothing

stmOutput.SaveToFile "EDIFACT.with-CRLF.txt"
stmOutput.Close
Set stmOutput = Nothing

WScript.Echo "Done."
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜