Reformat Edifact

Reformat Edifact

4
NewbieNewbie
4

    May 10, 2017#1

    Hello world!
    I've downloaded the Edifact wordfile for UltraEdit and now got highlighting. But is there a quick way to re-format EDI data from one long line into multi-line that is a bit easier on the eye, and works better with compare? (UE 24.00.0.73 x64)

    6,675585
    Grand MasterGrand Master
    6,675585

      May 10, 2017#2

      What is Edifact?

      Can you post a code block from file as it looks like after opening and how this code block should look like after reformatting?

      There is definitely no Edifact specific feature implemented in UltraEdit. But UltraEdit is highly customizable. So it is perhaps possible to use built-in feature for reformatting a selection (or entire file) with customization of the wordfile and/or use a customized UltraEdit macro/script for reformatting Edifact files.
      Best regards from an UC/UE/UES for Windows user from Austria

      4
      NewbieNewbie
      4

        May 10, 2017#3

        This is what I receive:

        Code: Select all

        UNA:+.? 'UNB+UNOA:3+STUFF123:ZZZ+Organi:ZZZ+170510:1400+115001014++++++T'UNH+1+INVOIC:D:96A:UN++20170510:145946'BGM+381:::LOREAL EDI+1231446206+9'DTM+137:20170510:102'PAI+::30'FTX+REG+++SOME12 SUPPLIER:SA:768000:EUR'FTX+AAB+++En cas de règlement sous 8 jours, escompte 0,3%.:45 jours, fin de mois'FTX+PMD+++En cas de retard de paiement, le créancier sera tenu au paiement d?'une indemnité forfaitaire pour frais de recouvrement égale à 40 euros. Le non-respect de la date de paiement entraîne des pénalités à un taux égal à trois fois le taux de l?'intérêt légal.'RFF+ON:TEST07'DTM+171:20170510:102'RFF+VN:1171099266'NAD+BY+3087252++Company SA+Some Street Addr 12+Some City 2133AB++12300+FR'NAD+SE+ZZZ_TH++Some Supplier Name  A.S. Test:Some Supplier Nam:Random Street Name 123ABC++City CCC++12300+FR'FII+RB+FR1234567891234567891234567+BNP Paribas:25:20:BNPAFRPPCST'RFF+XA:Lalala Lala'RFF+VA:FR22222222222'RFF+GN:123 111 222 44444'RFF+ALV:AAA AAAAAAAAAA'[email protected]:EM'NAD+IV+3103788++La Lala SA:MCD501:ETS CORPORATE SERVICE COMPTABILITE+8-12 IMPASSE BARBIER+CLICHY CEDEX++12313+FR'RFF+VA:FR11111111111'RFF+IT:3103788'NAD+DP+++A aaaaa SA+Nnn AAaaaT Aaaaaaaa+aaaaaa aaaa aaaa++12330+FR'CUX+2:EUR:4'PAT+3'DTM+13:20170630:102'LIN+1++10246131:EN'IMD+E+ANM+:::X30 aaaaaaaaa aaaCM² aaaaaaaaaaaa'QTY+47:2.000:PCE'DTM+11:20170510:102'MOA+203:182.00'MOA+66:182.00'MOA+128:182.00'PRI+AAA:91.00:::1:PCE'PRI+AAB:91.00:::1:PCE'TAX+7+VAT+++:::0.00'LIN+2++11111111:EN'IMD+E+ANM+:::X5 llllllll rrrrrrr rrrrr rrrrrrrr'QTY+47:2.000:PCE'DTM+11:20170510:102'MOA+203:55.08'MOA+66:55.08'MOA+128:55.08'PRI+AAA:27.54:::1:PCE'PRI+AAB:27.54:::1:PCE'TAX+7+VAT+++:::0.00'UNS+S'CNT+2:2'MOA+125:237.08'MOA+128:237.08'MOA+124:0.00'UNT+51+1'UNZ+1+115001014'
        And I want it transformed to:

        Code: Select all

        UNA:+.?'
        UNB+UNOA:3+STUFF123:ZZZ+Organi:ZZZ+170510:1400+115001014++++++T'
        UNH+1+INVOIC:D:96A:UN++20170510:145946'
        BGM+381:::LOREAL EDI+1231446206+9'
        DTM+137:20170510:102'
        PAI+::30'
        FTX+REG+++SOME12 SUPPLIER:SA:768000:EUR'
        FTX+AAB+++En cas de règlement sous 8 jours, escompte 0,3%.:45 jours, fin de mois'
        FTX+PMD+++En cas de retard de paiement, le créancier sera tenu au paiement d?'une indemnité forfaitaire pour frais de recouvrement égale à 40 euros. Le non-respect de la date de paiement entraîne des pénalités à un taux égal à trois fois le taux de l?'intérêt légal.'
        RFF+ON:TEST07'
        DTM+171:20170510:102'
        RFF+VN:1171099266'
        NAD+BY+3087252++Company SA+Some Street Addr 12+Some City 2133AB++12300+FR'
        NAD+SE+ZZZ_TH++Some Supplier Name A.S. Test:Some Supplier Nam:Random Street Name 123ABC++City CCC++12300+FR'
        FII+RB+FR1234567891234567891234567+BNP Paribas:25:20:BNPAFRPPCST'
        RFF+XA:Lalala Lala'
        RFF+VA:FR22222222222'
        RFF+GN:123 111 222 44444'
        RFF+ALV:AAA AAAAAAAAAA'
        [email protected]:EM'
        NAD+IV+3103788++La Lala SA:MCD501:ETS CORPORATE SERVICE COMPTABILITE+8-12 IMPASSE BARBIER+CLICHY CEDEX++12313+FR'
        RFF+VA:FR11111111111'
        RFF+IT:3103788'
        NAD+DP+++A aaaaa SA+Nnn AAaaaT Aaaaaaaa+aaaaaa aaaa aaaa++12330+FR'
        CUX+2:EUR:4'
        PAT+3'
        DTM+13:20170630:102'
        LIN+1++10246131:EN'
        IMD+E+ANM+:::X30 aaaaaaaaa aaaCM² aaaaaaaaaaaa'
        QTY+47:2.000:PCE'
        DTM+11:20170510:102'
        MOA+203:182.00'
        MOA+66:182.00'
        MOA+128:182.00'
        PRI+AAA:91.00:::1:PCE'
        PRI+AAB:91.00:::1:PCE'
        TAX+7+VAT+++:::0.00'
        LIN+2++11111111:EN'
        IMD+E+ANM+:::X5 llllllll rrrrrrr rrrrr rrrrrrrr'
        QTY+47:2.000:PCE'
        DTM+11:20170510:102'
        MOA+203:55.08'
        MOA+66:55.08'
        MOA+128:55.08'
        PRI+AAA:27.54:::1:PCE'
        PRI+AAB:27.54:::1:PCE'
        TAX+7+VAT+++:::0.00'
        UNS+S'
        CNT+2:2'
        MOA+125:237.08'
        MOA+128:237.08'
        MOA+124:0.00'
        UNT+51+1'
        UNZ+1+115001014'
        And realizing now that it should actually be easily solvable by regex:

        Code: Select all

        s/'/'\r\n/g

        6,675585
        Grand MasterGrand Master
        6,675585

          May 10, 2017#4

          Yes, that reformatting is easy to achieve with a replace all.

          As non regular expression replace all:

          Find what: '
          Replace with: '^p

          That's simple, but has a disadvantage. This replace inserts one more DOS/Windows line termination even If there is already a line termination after '.

          As UltraEdit regular expression replace all:

          Find what: '^([~^r^n]^)
          Replace with: '^p^1

          That's better than above because it does not insert carriage return (CR) and line-feed (LF) after ' if there is already a newline character after '.

          But it has also 2 disadvantages: If there is '' in file, it inserts CR+LF only between the two '', but none after '. And it does not append CR+LF to end of file if the file ends with '.

          As Perl regular expression replace all:

          Find what: '(?![\r\n])
          Replace with: '\r\n

          This expression has no disadvantages. It works always for inserting CR+LF after each ' where next character is whether a carriage return nor a line-feed which results in even appending CR+LF at end of file if there is none and file ends with ' as last character.

          The Perl regular expression replace all can be recorded into a macro which has a hotkey assigned for quick execution by key and which is stored into a macro file (with other macros) being configured for automatic load on startup of UltraEdit for being available immediately after starting UltraEdit.

          The UltraEdit macro code:

          Code: Select all

          InsertMode
          ColumnModeOff
          HexOff
          Top
          PerlReOn
          Find MatchCase RegExp "'(?![\r\n])"
          Replace All "'\r\n"
          
          But is also possible to write an UltraEdit script with the code below which is added to the Script List with a hotkey assigned to the script for quick execution at any time.

          Code: Select all

          if (UltraEdit.document.length > 0)  // Is any file opened?
          {
             // Define environment for this script.
             UltraEdit.insertMode();
             if (typeof(UltraEdit.columnModeOff) == "function") UltraEdit.columnModeOff();
             else if (typeof(UltraEdit.activeDocument.columnModeOff) == "function") UltraEdit.activeDocument.columnModeOff();
          
             var nLine = UltraEdit.activeDocument.currentLineNum;
             var nColumn = UltraEdit.activeDocument.currentColumnNum;
             
             // Move caret to top of the active file.
             UltraEdit.activeDocument.top();
          
             // Define the options for Perl regular expression replace all.
             UltraEdit.perlReOn();   
             UltraEdit.activeDocument.findReplace.mode=0;
             UltraEdit.activeDocument.findReplace.matchCase=true;
             UltraEdit.activeDocument.findReplace.matchWord=false;
             UltraEdit.activeDocument.findReplace.regExp=true;
             UltraEdit.activeDocument.findReplace.searchDown=true;
             UltraEdit.activeDocument.findReplace.searchInColumn=false;
             UltraEdit.activeDocument.findReplace.preserveCase=false;
             UltraEdit.activeDocument.findReplace.replaceAll=true;
             UltraEdit.activeDocument.findReplace.replaceInAllOpen=false;
          
             if(!UltraEdit.activeDocument.findReplace.replace("'(?![\\r\\n])","'\\r\\n"))
             {
                UltraEdit.activeDocument.gotoLine(nLine,nColumn);
             }
          }
          
          The script restores position of caret in active file if the Perl regular expression replace all has not inserted anywhere CR+LF.
          Best regards from an UC/UE/UES for Windows user from Austria

          4
          NewbieNewbie
          4

            May 11, 2017#5

            Wow, you went above and beyond on that! Thank you ever so much!

            6
            NewbieNewbie
            6

              Sep 28, 2018#6

              This topic is rather old, but there's a small flaw:

              In EDIFACT the ' may be masked with a ?, so you do not want to insert a line break after ?' and of course not if there are already line breaks in the file:

              Search:

              Code: Select all

              ([^\?]')([^\r\n])
              Replace with:

              Code: Select all

              $1\r\n$2
              Regards, Max