Re: 4gl writing to a pure text file
Posted in 1994
Topics: Connectivity: ESQL/C, 4GL & Embedded SQL, Migration, Import/Export & Data Conversion
keithr@winternet.com (Keith Root) writes: >I have the need to create a flat ascii file for an off line application. >The file is fixed length, 192 characters. >What is the easiest/fastest way from a 4gl program to write to an ascii text >file? I have come up with some of the following. >1. use the run command to echo >> filea - after formatting rows >2. create table with 1 column (192 char) and format a variable in the 4gl > code and update/insert - unload and strip "|" (2 passes - seems messy) >can someone point me to doco (4GL - 4.01) or have any ideas?? >--------------------------------------------------------------------- >| Keith E. Root internet: keithr@winternet.com | >| National Business phone : 1-612-647-0143 | >| Data Systems, Inc. fax : 1-612-642-0913 | >| Microwaves will frizz your heirs! | >--------------------------------------------------------------------- Option 1 is possibly the easiest, however it you're dealing with a lot of output it can be significantly slow: We had a similar requirement, to produce a flat file of about 100,000 lines. A simple experiment: Create a C program file (eg. /tmp/test.c): main() { int i; for (i=0; ++i<500;) system("echo hello world >> /tmp/test.out"); } cc -o /tmp/test /tmp/test.c time /tmp/test real 0m20.54s user 0m0.47s sys 0m1.85s This essentially duplicates the process the 4GL code will be doing. This test shows that for 100,000 records, just running the echo will take more than an hour (this is on my home computer - 486/66 SVR4.2). Actually, on the production system this test showed that running the echo would have taken somewhat over 8 hours (ok, ok - so it's a dog-box and it has other work to do...). The reason it's so inefficient is that the 'RUN' command has to start up a new shell every time it's called, and starting new processes is quite 'expensive' in term of machine resources/time. You would usually not notice this (it you're not on a dog-box like ours), but if you try doing it a lot of times it all adds up... All this said, if the process is not expected to be run on a lot of rows and isn't run frequently, or the elapsed time doesn't matter, your option 1 is a reasonable way to go. Just don't tell our programmer, who got blasted for putting the 'RUN echo' command in a production program. And this in a program they knew was 'runtime-critical'. Some people have no idea. --------------------------- LiChuan Dunlop s925095@minyos.rmit.edu.aus ---------------------------