Computing.Net > Forums > Unix > EDI Message

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

EDI Message

Reply to Message Icon

Name: Fouad
Date: January 26, 2009 at 02:43:23 Pacific
OS: AIX 5.2
CPU/Ram: 4/8GB
Product: Ibm / P5
Subcategory: General
Comment:

I have a basic Unix knowledge.
I need a script to check and edit a big Invoice file(EDI Message).
First the script shall make a small ajustment to the SDT segment.We need to add an ‘A’ at the end of the SDT segment for all flows which don’t denote POP shipments (POP shipments easy to recognize by despatch number which is the RAD number in the EDI message : RAD POP090107). The begining of the file look like follow:

//ODETT//INVGM
UNB 090114
MID 00001918 090114
SDT012837259
BDT01315000737
PAI EUR 090202
RAD 37062241 081223
CSG01184
CSG02

SDT012837259 to be changed into SDT012837259A when The "RAD" number without "POP" at the begining.

Second this big message shall be splittet in two files at a special position.
Please let me know if you need more information.

Thnaks in advance




Sponsored Link
Ads by Google

Response Number 1
Name: nails
Date: January 26, 2009 at 23:07:46 Pacific
Reply:

I can not give you a complete solution because you don't tell what starts the invoice and what ends it. You need to post more of your data file.

The following sed command adds an "A" to the end of any line (which has optional spaces) that starts with the SDT

sed '/^SDT/s/[ ]*$/A/' datafile.txt

The second part of your requirement is more difficult. The way I read it is that you don't want to append the "A" if a string starting with "RAD" is 3 lines below the line starting with SDT.

In shell, this is difficult to do since you have to read ahead of the file until you hit the "RAD" string or the end of the invoice.

Personally, I think it's easier to reverse the file so you read the "RAD" string first which tells you whether or not to add the "A".

Of course, when the processing is done, reverse the file.

That's the best I can do until you reply.


0

Response Number 2
Name: Fouad
Date: January 27, 2009 at 05:07:46 Pacific
Reply:

Hi Nails,
the begining of this file look like that:
//ODETT//INVGM
UNB 090106
MID 00000047 090106
SDT012837259
BDT01315000737
PAI EUR 090106
RAD POP081204 081204
CSG0172261
CSG02
ARD0113268023
PRI 000000001NTP000000000000000
ARD0113268176
PRI 000000001NTP000000000000000
.....
.....
//ODETT//INVGM
UNB 090106
MID 00000046 090106
SDT012837259
BDT01315000737
PAI EUR 090106
RAD 000081113 081113
CSG0172261
CSG02
ARD0113268019
PRI 000000001NTP000000000000000
ARD0113268022
PRI 000000001NTP000000000000000
RAD POP081114 081114
CSG0172261
CSG02
ARD0113268186
.....
..... and so on till the end of the file.

If you need the complete file I can provide it to you.

Like you see there is alot off SDT and RAD segments. But like I told you we need to change(edit) the SDT number only when the "RAD" string number(3 lines below)do not content the "POP" segment at the begining.

You're right it is may be simple if we beginn to read first the RAD string.

Any replay is welcome.

Thanks in advance.

Fouad


0

Response Number 3
Name: nails
Date: January 27, 2009 at 07:41:02 Pacific
Reply:

I have some questions:

1) I'm assuming this string marks the start of an invoice:

//ODETT//INVGM

2) How big is the data file, how many invoices typically?

3) Is this statement correct:

DO NOT add an "A" to the end of the "SDT" string if the invoice contains a string starting with "RAD"


0

Response Number 4
Name: Fouad
Date: January 27, 2009 at 09:10:16 Pacific
Reply:

to 1) it's true
to 2) ~24 invoices(sometimes less and sometimes more)
to 3) not exactely: DO NOT add an "A" to the end of the "SDT" string if the number after the "RAD" string (3 lines below) do content the "POP" segment at the begining. Example
-RAD POP081204 081204--> DO NOT
-RAD 000081113 081113 --> DO


0

Response Number 5
Name: nails
Date: January 27, 2009 at 12:06:05 Pacific
Reply:

As I said, I reversed the invoice file so I could sample the "RAD" & "RAD POP" lines before processing the "SDT" line. Obviously, this won't work if the order is reversed.

I used perl to reverse the file and then reverse it back once processing is complete. If you don't want to use perl, check out this article for other reverse options:

http://www.samag.com/documents/s=97...

newdatafile file contains the desired output.

#!/bin/ksh

rm -f intdatafile intdatafile2
perl -we 'print reverse <>' datafile > intdatafile

newinv=0
while read line
do
  case $line in
     \/\/ODETT\/\/INVGM*)
       newinv=0;;
  esac

  case "$line" in
     RAD*)
       newinv=1;;
  esac

  case "$line" in
     "RAD POP"*)
       newinv=0;;
  esac

  if [[ $newinv -eq 1 ]]
  then
     case "$line" in
        SDT*)
            newline="$line"A;;
                *)
            newline="$line";;
     esac
  else
     newline="$line"
  fi
  echo "$newline"
done < intdatafile > intdatafile2
# reverse back
perl -we 'print reverse <>' intdatafile2 > newdatafile


0

Related Posts

See More



Response Number 6
Name: Fouad
Date: January 28, 2009 at 03:07:14 Pacific
Reply:

Hi Nails,

I used "awk" to to reverse the file and then reverse it back once processing is complete and it is working.
But he result was not correct because this scripts added an "A" to the end of every "SDT" string aside from the "RAD" segment number type(with POP or without).
Have you an idea what is going wrong?

Many thanks


0

Response Number 7
Name: nails
Date: January 28, 2009 at 08:43:19 Pacific
Reply:

I went back and checked my work and it's correct. I'm using Solaris 9 where you are using AIX.

I'm assuming that you copied my script exactly so it looks like the comparisons in the case statements aren't working.

You can post the code you are using and I'll look at it, but I'm assuming it's the same.

I can rewrite this in awk, but I can't get to it until tonight.

Then, again, what about your data? I'm looking for "RAD POP". Do you have something like "RAD POP"?


0

Response Number 8
Name: Fouad
Date: January 28, 2009 at 09:26:42 Pacific
Reply:

Like you say I did not change the script only by the file reverse and back. The script looks like follow:

#!/bin/ksh

#reverse the file
awk '{ a[NR]=$0 } END { for(i=NR; i; --i) print a[i] } ' indatafile_full > indatafile_full2

#Make the needed change when it is necessary
newinv=0
while read line
do
case $line in
FTX*)
newinv=0;;
esac

case "$line" in
RAD*)
newinv=1;;
esac

case "$line" in
"RAD POP"*)
newinv=0;;
esac

if [[ $newinv -eq 1 ]]
then
case "$line" in
SDT*)
newline="$line"A;;
*)
newline="$line";;
esac
else
newline="$line"
fi
echo "$newline"
done < indatafile_full2 > indatafile_full3
# reverse back
awk '{ a[NR]=$0 } END { for(i=NR; i; --i) print a[i] } ' indatafile_full3 > newdatafile_4

I have also changed the begining of the file:
from \/\/ODETT\/\/INVGM*) to FTX*)because when the file is inversed it begins with the "FTX" string.

The big file contents two differents RAD strings; for exemple somthing like this:
RAD 0000000055363 081208
or
RAD POP081209 081209

We need to add an "A" to the end of every "SDT" string only by the first case(witout "POP")

The script you send me add an "A" in both cases!

Any suggestion?


0

Response Number 9
Name: nails
Date: January 28, 2009 at 09:48:47 Pacific
Reply:

You said the \/\/ODETT\/\/INVGM marks the change of the invoice. It shouldn't matter just because the file is reversed.

Is there a string beginning with FTX for each invoice also also? I don't see it in the data set you provided.

I was going to rewrite the comparisons for you, but I won't until I have a better idea of the data you are using.


0

Response Number 10
Name: Fouad
Date: January 29, 2009 at 01:48:01 Pacific
Reply:

The Invoice beginn like this:
//ODETT//INVGM
UNB 090106
MID 00000047 090106
SDT012837259
BDT01315000737
PAI EUR 090106
RAD POP081204 081204
CSG0172261
CSG02
ARD0113268023
PRI 000000001NTP000000000000000
ARD0113268176
....
....
and end like that:
....
VAT 0019.000000000000003.8
TLR -00000000019.98-00000000023.76
FTX Debit note retro active price adjustments

and then beginnt the next Invoice segment:
//ODETT//INVGM
UNB 090106
MID 00000043 090106
SDT012837259
BDT01315000737
PAI EUR 090106
RAD POP080722 080722
CSG0172261
....
.....
TLR -00000022234.24-00000026458.79
FTX Debit note retro active price adjustments.

And so on. Like you see the beginn of the Invoice Segement is"//ODETT//INVGM"
and the end is " FTX Debit ...."

I thaught wenn we reverse the file the "FTX" string will mark the beginn of the invoice segement and in this case I remplace in your script the string "//ODETT//INVGM" with "FTX".
But any way the script does not work properly in both cases; it add an "A" to the end of EVERY "SDT" string aside from the "RAD" segment number type(with POP or without).

Sorry for the confusion Nails.

Is ther any possibilty to send the invoice file?


0

Sponsored Link
Ads by Google
Reply to Message Icon






Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Unix Forum Home


Sponsored links

Ads by Google


Results for: EDI Message

Error Message www.computing.net/answers/unix/error-message/7076.html

DT Messaging www.computing.net/answers/unix/dt-messaging/2446.html

Show popup messages to NT user from UNIX www.computing.net/answers/unix/show-popup-messages-to-nt-user-from-unix/3379.html