Have to say I like this as it this so much easier than using the C APIs called from a RPG program. SELECT * FROM TABLE(QSYS2.IFS_READ('/home/MyFolder/new_test.txt')) SELECT PATH_NAME,OBJECT_TYPE,CREATE_TIMESTAMPįROM TABLE (QSYS2.IFS_OBJECT_STATISTICS('/home/MyFolder'))Īnd see the contents of the new file using the IFS_READ: I can use the IFS_OBJECT_STATISTICS table function to confirm that the file was created: If I have a file name that does not exist in the folder given in the path name this procedure will create it.ĬALL QSYS2.IFS_WRITE('/home/MyFolder/new_test.txt', The existing file is deleted and replaced by new one which contains the new line. I am not worried about this as I cannot think of a scenario where I would need to write a binary string to a plain text file.Īs I mentioned previously if I wanted to replace the contents of the existing file I would just use REPLACE in the overwrite parameter. What would happen if I used the IFS_WRITE_BINARY procedure?ĬALL QSYS2.IFS_WRITE_BINARY('/home/MyFolder/test.txt', I am still going to use the IFS_READ table function to display the file's contents.Īs the file was created as a plain text file, not as UTF8, the line is added with the file's CCSID which results in a plain text line. This time I am going to use the IFS_WRITE_UTF8 procedure.ĬALL QSYS2.IFS_WRITE_UTF8('/home/MyFolder/test.txt', The overwrite parameter is optional, its default is to append a new line to the file. Providing I have the end of line parameter in my statement I can keep adding line to my file. Now I get the results I want, as the first statement just added a CRLF to the fifth line: In the first statement I am writing a null value to the file, which is two apostrophes next to each other ( '' ). Again I replace the file with my saved copy.Ġ1 CALL QSYS2.IFS_WRITE('/home/MyFolder/test.txt',Ġ2 CALL QSYS2.IFS_WRITE('/home/MyFolder/test.txt', Let me write a line to the file with just a CRLF character, and then write the line I want to add to the file. This must mean that the fifth line does not end with a character that IFS_WRITE understands as an end of line character. The line was appended to the end of the last line: Let me try to write again this time with the end of line character CRLF.Īlas, the same happened to the file as before.
#IFS FILE PC#
I deleted the file test.txt, and uploaded saved copy from my PC to the IFS folder.
![ifs file ifs file](https://slidetodoc.com/presentation_image/e960971a47d4f7c63fb00cdfbc450865/image-19.jpg)
The line was appended to the file, but not as a new line, just as a continuation of the last line. SELECT * FROM TABLE(QSYS2.IFS_READ('/home/MyFolder/test.txt'))ĬALL QSYS2.IFS_WRITE('/home/MyFolder/test.txt', When I use the IFS_READ table function it shows the file's contents: I am going to start by using the file I was reading yesterday: test.txt.
![ifs file ifs file](https://uploads-eu-west-1.insided.com/ifs-en/attachment/17765b68-a17a-4f65-bce5-bc29d9c07a32.png)
If I am writing to an existing file this is ignored.
#IFS FILE HOW TO#
Then it was how to read an IFS file, today will be the opposite writing to an IFS file. This post continues yesterday's theme of doing things to files in the IFS with SQL.