Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

print on a file without report

Status
Not open for further replies.

samtg

Programmer
Jul 22, 2003
8
MA
Hi,
i have a small problem. i have an array that contains n columns and i want to write the content of this array to a file with a pipe separator without using report.
Thanks a lot
 
samtg:

The first question I would ask, is why not use a report. OK, you have your reasons:

1) How about loading your array into a temp table and use the informix unload command?

unload to "/tmp/file.unl" select * from temp_table

This syntax works in 4GL as well isql/dbaccess.

You can even make it a little dynamic:


FUNCTION test_function(table_name, file_name)
DEFINE
sel_string CHAR(80),
file_name CHAR(10),
emp_no CHAR(12),
table_name CHAR(15)

LET sel_string = "select * from ", table_name"

# override the default | if you want to
UNLOAD TO file_name DELIMITER ":" sel_string
IF sqlca.sqlcode != 0
THEN
display "unload problem"
ELSE
display "unload count: ", sqlca.sqlerrd[3]
END IF
END FUNCTION

2) Build strings from the array, and echo it to a file:

main

define
str1 CHAR(10),
str2 CHAR(10),
run_str CHAR(30)

let str1="1|2|3|"
let str2="4|5|6|"

run "rm -f file.unl"
let run_str="echo \"", str1 clipped, "\" >> file.unl"
run run_str
let run_str="echo \"", str2 clipped, "\" >> file.unl"
run run_str
end main

3) Informix 4GL is brain dead when communicating with the OS. I've developed callable "C" functions that will also do this job. Check out the FAQ over in the Informix Online
forum if you're interested.

Regards,


Ed
 
Thank a lot odded.
Best regards.
Have a nice day.
 
Thank a lot olded.
Best regards.
Have a nice day.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top