IFS_WRITE, IFS_WRITE_BINARY, and IFS_WRITE_UTF8 procedures
The IFS_WRITE, IFS_WRITE_BINARY, and IFS_WRITE_UTF8 procedures write data to an integrated file system stream file. The data can be written as character, binary, or UTF-8 data. Data can be either replaced or appended for an existing file, or a new file can be created.
Up to 2 gigabytes of data can be written by one call to this procedure. It can contain embedded end of line characters, or the procedure can append end of line characters to the input data.
Authorization: The caller must have:
- For objects not in the QSYS.LIB file system when the stream file exists and is not being replaced:
- Execute (*X) data authority to each directory preceding the stream file being written and
- Write (*W) data authority to the stream file
- For objects not in the QSYS.LIB file system when the stream file does not exist or is being replaced:
- Execute (*X) data authority to each directory preceding the stream file being written and
- Write and Execute (*WX) authority to the parent directory of the stream file
- For objects in the QSYS.LIB file system when the object exists and is not being replaced:
- Execute (*X) data authority to each directory preceding the object being written and
- For a *SAVF object, Read, Write, and Execute (*RWX) data authority to the object
- For all other object types, Write (*W) data authority to the object
- Execute (*X) data authority to each directory preceding the object being written and
- For objects in the QSYS.LIB file system when the object does not exist or is being replaced:
- Execute (*X) data authority to each directory preceding the object being written and
- For a *SAVF object, Read and Execute and Add (*RX and *ADD) data authority to the parent directory of the object
- For a physical file member, Add (*ADD) data authority to the parent directory of the object
- For all other object types, *OBJMGT or *OBJALTER authority to the parent directory of the object
- Execute (*X) data authority to each directory preceding the object being written and
The schema is QSYS2.
- path-name
- A character or graphic string that defines the path name for the file to be written. If an absolute path name is not specified, the current working directory is used in combination with the relative path name to resolve to the object.
- line
- A character or graphic string containing the data to be written to the stream file at path-name. It can be up to 2 gigabytes long.
- file-ccsid
- An integer value that specifies the CCSID to be used when creating a new stream file. This parameter is ignored when appending to an existing file.
- overwrite
- A character or graphic string that specifies whether the write operation appends to the stream
file, replaces the stream file, or fails when a stream file with the specified name already exists.
- APPEND
- The data in line is added to the end of the existing stream file. If the stream file does not exist, it is created. This is the default.
- NONE
- The write operation fails if the stream file exists.
- REPLACE
- The data in line replaces the existing stream file if it exists. An existing stream file is deleted and a new stream file is created. The CCSID of the stream file might change. If the stream file does not exist, it is created.
- end-of-line
- A character or graphic string that specifies the end of line characters to write to the stream file after line is written. When using IFS_WRITE_BINARY, end of line characters are never appended, so this parameter must have a value of NONE.
Examples
- Create a stream file which contains a list of all of the libraries on the system, one per line.
The file is created in job CCSID.
The QSYS2.IFS_READ table function can be used to read the contents of the generated stream file.BEGIN -- Make sure output file is empty to start CALL QSYS2.IFS_WRITE(PATH_NAME =>'/tmp/library_names', LINE => '', OVERWRITE => 'REPLACE', END_OF_LINE => 'NONE'); -- Add lines to the output file FOR SELECT OBJNAME AS LIBNAME FROM TABLE(QSYS2.OBJECT_STATISTICS('*ALLSIMPLE', 'LIB')) DO CALL QSYS2.IFS_WRITE(PATH_NAME => '/tmp/library_names', LINE => LIBNAME); END FOR; END;
SELECT * FROM TABLE(QSYS2.IFS_READ('/tmp/library_names'));
- Create a UTF-8 (CCSID 1208) stream file which contains a UTF-8 Byte Order Mark (BOM) and the
string
'Hello'.
CALL QSYS2.IFS_WRITE_BINARY(PATH_NAME => '/usr/utf8file', LINE => BLOB(X'EFBBBF48656C6C6F'), FILE_CCSID => 1208, OVERWRITE => 'REPLACE' );