[IMAGE]
[IMAGE][IMAGE]
Ron Turull
[IMAGE]
[IMAGE]
Outfiles are status quo on the iSeries, but did you know that SQL can produce them intrinsically? To have the results of a Select statement written to a database file (i.e., an outfile), specify the Select statement as part of an Insert statement. For example, to output the rows resulting from the following Select statement:
to an output file, use the following INSERT statement:
The library and outfile names you specify must already exist, and the file must have exactly six fields in the order specified on the select statement. However, the fields in the outfile do not have to have the same name as the ones on the SELECT statement, but they must have compatible attributes.
More Information
[IMAGE]
To create a file suitable for receiving the output from the above example, the following CREATE TABLE statement can be used:
To continue reading for free, register below or login
To read more you must become a member of Search400.com
');
// -->

font-family:"Trebuchet MS";
panose-1:0 2 11 6 3 2 2 2 2 2;
mso-font-charset:0;
mso-generic-font-family:auto;
mso-font-pitch:variable;
mso-font-signature:50331648 0 0 0 1 0;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{mso-style-parent:"";
margin:0in;
margin-bottom:.0001pt;
mso-pagination:widow-orphan;
font-size:12.0pt;
font-family:"Trebuchet MS";}
p.code, li.code, div.code
{mso-style-name:code;
mso-style-parent:"";
margin-top:0in;
margin-right:0in;
margin-bottom:12.0pt;
margin-left:0in;
mso-pagination:widow-orphan;
font-size:12.0pt;
font-family:"Courier New";}
@page Section1
{size:8.5in 11.0in;
margin:1.0in 1.25in 1.0in 1.25in;
mso-header-margin:.5in;
mso-footer-margin:.5in;
mso-paper-source:0;}
div.Section1
{page:Section1;}
-->
Create Table UCG/Cust_Out
(
name char(30),
addr1 char(30),
addr2 char(30),
city char(20),
state char(2),
zip
dec(5,0)
)
Alternatively, you can create an outfile with just a single character field long enough to hold the concatenation of all the fields in the select statement:
Then, modify the select statement to concatenate (i.e., attach one string to the end of another) all the fields together:
The concatenation operator (|| -- double bar) is used to attach one character field to another. The digits() function must be used on the zip field to convert the data from numeric to character.
To clear an outfile before running the INSERT statement (INSERT can only add records to a file), use the DELETE statement:
This is a simple DELETE statement where every row in file Cust_Out is deleted. Note: You can also use the DELETE statement to delete specific rows. Use the DROP statement to delete the entire file -- object and all.
-----------------------------------
About the author: Ron Turull is editor of Inside Version 5. He has more than 20 years' experience programming for and managing AS/400-iSeries systems.