Using IBM i? Need to create Excel, CSV, HTML, JSON, PDF, SPOOL reports? Learn more about the fastest and least expensive tool for the job: SQL iQuery.
The iQuery.ifsFile() UDF reads the specified IFS text file and returns one row for each "record" in the Text file. The basic output is similar to the DSPF CL command, but can be queried and re-directed to other formats.
The returned value is always a varchar(8192) value and my be re-cast using CAST or by wrapping the result in VARCHAR() with a different result column width. If the resulting text data is longer than 8192 characters, it is truncated.
iQuery.ifsFile( 'IFS text file name and path' )
The IFS Text File Name and Path parameter identifies the IFS text file to be queried. This can be a plain text file, CSV file, JSON, etc. If the file is from Microsoft Windows and it contains a BOM (Byte Order Mark) IFSFILE will attempt to detect the BOM and continue to render the rest of the file normally.
Column Name |
System Column Name |
Data Type | Description |
TEXTDATA | TEXTDATA | varchar(8192) | The IFS text file data from the IFS file. One row is returned for each "line" in the text file. |
The UDTF reads IFS text files as rows or lines. A line is everything up until a CR/LF or LF/CR pair. In addition, it also supports lines that end with a signel LF or CR symbol. Each line is returned as one row in the resultSet.
In this example, our sample COUNTRY.TXT file that contains a list of all countries followed by their abbreviation (separated by a semicolon) is queried using SQL iQuery IFSFILE() UDTF and is returned.
select * table(iQuery.ifsFile('/home/cozzi/country.txt')) text;
TEXTDATA
COUNTRY;ABBR
AFGHANISTAN;AF
ÅLAND ISLANDS;AX
ALBANIA;AL
ALGERIA;DZ
AMERICAN SAMOA;AS
ANDORRA;AD
ANGOLA;AO
ANGUILLA;AI
ANTARCTICA;AQ
ANTIGUA AND BARBUDA;AG