Discussion:
Streaming to a File
(too old to reply)
Rod Pope
2008-10-24 19:34:12 UTC
Permalink
I am attempting to add Electronic Data Interchange (EDI) capabilities to an existing purchase order, invoicing and shipping application. EDI specs provide detailed requirements for the interchange message (reminds me too much of the old teletype days). The messages are sent through Value Added Networks (VAN) similar to e-mail.

I have been successful in receiving EDI purchase orders (PO), parsing them with CASE statements and sending back a Functional Acknowledgment (FA) message in reply.

My problem is that the message "buffer" needs to be a continuous stream, with no intervening carriage returns, line feeds, etc. Using the following code snippet with multiple streaming operators leaves an extra carriage return (x0D) after each segment.

------------------------
* Following code builds a Functional Acknowledgment (FA) EDI file to be sent to True Value

clear
SET ALTERNATE TO "C:\FILE_FROM_MULTIPLE_LINES.TXT"
SET ALTERNATE ON

??"ISA*00* *00* *01*058006875 *14*006929681100 *"+SUBSTR(FADATE,3,6)+"*"+FATIME+"*U*00401*"+STR(memory->ISA_CN,9,0,"0")
??"*0*P*>~GS*FA*058006875*006929681100*"+FADATE+"*"+FATIME+"*"+STR(memory->GROUP_CN,9,0,"0")+"*X*004010~ST*997*"
??STR(memory->GROUP_CN,9,0,"0")+"~AK1*PO*"-GS06+"~AK9*A*1*1*1~SE*4*"+STR(memory->GROUP_CN,9,0,"0")
??"~GE*1*"+STR(memory->GROUP_CN,9,0,"0")+"~IEA*1*"+STR(memory->ISA_CN,9,0,"0")+"~"

SET ALTERNATE OFF
SET ALTERNATE TO
-----------------

I have gotten around this for the FA's by just making one big stream behind one operator. However, I now need to automate two new message streams, one for an Advanced Ship Notice (ASN) and one for the Invoice. These messages can have multiple line items based on the received PO and I need to loop in the code to generate them, causing multiple streaming operators and hence the unwanted carriage returns.

If the streaming operator (??) is designed to continue where the previous one left off (which works for a real printer), why the added character when I "print" to a file?

How do I get around this?

Thanks,

Rod
Jan Hoelterling
2008-10-24 20:20:59 UTC
Permalink
Rod,

I have written programs for EDI using the file object - use the write method
to just "keep writing" without getting a line break or anything like that. ?
is really an outdated way of doing this.

Let me know if you need more details.

Jan
Rod Pope
2008-10-24 20:58:32 UTC
Permalink
Jan,

Thanks, yes I would like more details. We've just switched from VdB7.1 to dBPlus 2.61.5. The app goes back to DBIII days so I'm sure this old dog needs to learn some new tricks.

Rod
Post by Jan Hoelterling
Rod,
I have written programs for EDI using the file object - use the write method
to just "keep writing" without getting a line break or anything like that. ?
is really an outdated way of doing this.
Let me know if you need more details.
Jan
Jan Hoelterling
2008-10-25 00:55:14 UTC
Permalink
Hi Rod,

you would open the file as follows:

oFile = new File()
oFile.Open("Filename.txt","W") // open for write

If there is a chance that the file could exist, you can test with:

if oFile.exists("Filename.txt")
msgbox("The file already exists")
// take appropriate action, i.e., delete, change file name, location,
etc.
endif

Then, to write to the file, you have two basic options:

oFile.Writeln("This is a line with CR/LF at the end")
(WriteLiNe)

or

oFile.Write("this will only write this string without any delimiters or
separators")

At the end, don't forget to

oFile.Close()
Release Object oFile
oFile = null

It should be pretty easy to convert the existing code - you would just
change the ?? to oFile.Write( <string or expression> )

Jan
Mervyn Bick
2008-10-25 09:31:09 UTC
Permalink
Post by Rod Pope
Jan,
Thanks, yes I would like more details. We've just switched from VdB7.1
to dBPlus 2.61.5. The app goes back to DBIII days so I'm sure this old
dog needs to learn some new tricks.
The little example program below my signature will do the trick. May this
old dog have a biscuit? <g>

As you will see it is as easy as the way we did things in the old dBase
III days but with MUCH more control. Mind you, there were the old low
level file functions back in those days and they weren't really that much
harder to use, just a little bit different to the way things work in the
file class.

I have taken your strings and arbitrarily broken them into manageable
lengths and then concatenated them into one long variable which gets
written to the file.

dBase Plus does not recognise "memory-><variable name>" but it does
recognise "m-><variable name>" so I have made the change. You may
actually find that you don't need the m-> but is does no harm.


Mervyn

***** Start of example program ********

//Temporary data for the program to use for testing.
//Use something closer to reality if you wish

FADATE = dtoc(date())
FATIME = ttoc(dttot(datetime()))
ISA_CN = 12345
GROUP_CN = 456789
GS06 = "gs06"


cFile = "STREAMTEXT.TXT"
fTxtStrm = new file()
fTxtStrm.create(cFile)

// create() overwrites an existing file without prompt.
//You can test for an existing file and use open() to append to it if
required
//If you use open() you will have to indicate that the file must be opened
for "W"
//as the default for open() is "read text file".
//The default for create() is "read and write text file" so I haven't
specified it.

cTxtStrm = "ISA*00* *00* *01*058006875
*14*006929681100 *"
cTxtStrm +=
SUBSTR(FADATE,3,6)+"*"+FATIME+"*U*00401*"+STR(M->ISA_CN,9,0,"0")
cTxtStrm += "*0*P*>~GS*FA*058006875*006929681100*"+FADATE+"*"+FATIME+"*"
cTxtStrm += STR(M->GROUP_CN,9,0,"0")+"*X*004010~ST*997*"
cTxtStrm += STR(M->GROUP_CN,9,0,"0")+"~AK1*PO*"-GS06+"~AK9*A*1*1*1~SE*4*"
cTxtStrm += STR(M->GROUP_CN,9,0,"0")+"~GE*1*"+STR(M->GROUP_CN,9,0,"0")
cTxtStrm += "~IEA*1*"+STR(M->ISA_CN,9,0,"0")+"~"
fTxtStrm.write(cTxtStrm)
fTxtStrm.close()

******* End of example program ********

Mervyn Bick
2008-10-24 20:24:07 UTC
Permalink
Post by Rod Pope
* Following code builds a Functional Acknowledgment (FA) EDI file to be sent to True Value
clear
SET ALTERNATE TO "C:\FILE_FROM_MULTIPLE_LINES.TXT"
SET ALTERNATE ON
??"ISA*00* *00* *01*058006875 *14*006929681100
*"+SUBSTR(FADATE,3,6)+"*"+FATIME+"*U*00401*"+STR(memory->ISA_CN,9,0,"0")
??"*0*P*>~GS*FA*058006875*006929681100*"+FADATE+"*"+FATIME+"*"+STR(memory->GROUP_CN,9,0,"0")+"*X*004010~ST*997*"
??STR(memory->GROUP_CN,9,0,"0")+"~AK1*PO*"-GS06+"~AK9*A*1*1*1~SE*4*"+STR(memory->GROUP_CN,9,0,"0")
??"~GE*1*"+STR(memory->GROUP_CN,9,0,"0")+"~IEA*1*"+STR(memory->ISA_CN,9,0,"0")+"~"
SET ALTERNATE OFF
SET ALTERNATE TO
-----------------
I have gotten around this for the FA's by just making one big stream
behind one operator. However, I now need to automate two new message
streams, one for an Advanced Ship Notice (ASN) and one for the Invoice.
These messages can have multiple line items based on the received PO and
I need to loop in the code to generate them, causing multiple streaming
operators and hence the unwanted carriage returns.
If the streaming operator (??) is designed to continue where the
previous one left off (which works for a real printer), why the added
character when I "print" to a file?
You don't say what version of dBase you're using.

If you are using dBase Plus you could do what you need quite simply with
the file class.

For older versions you would use the low level file functions fcreate(),
fwrite() and fclose() which are equivalent to the create(), write() and
close() methods of the file class.

Mervyn.
Geoff Wass [dBVIPS]
2008-10-25 05:35:06 UTC
Permalink
Post by Rod Pope
If the streaming operator (??) is designed to continue where the previous one left off (which works for a real printer), why the added character when I "print" to a file?
How do I get around this?
Thanks,
Rod
Rod,

I am not an expert on streaming output, but maybe ??? is needed instead
of ??.

The FILE object is by far the better way to go.
--
Geoff Wass [dBVIPS]
Montréal, Québec, Canada

.|.|.| dBASE info at http://geocities.com/geoff_wass |.|.|.
.|.|.| ---------------------------------------------------------- |.|.|.
.|.|.| IT Consultant http://Geoff_Wass.com |.|.|.
Loading...