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. I deleted the file test.txt, and uploaded saved copy from my PC to the IFS folder. 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. END_OF_LINE: Is not supported if IFS_WRITE_BINARY is used.REPLACE An existing file is replaced, deleted and a new one created.NONE If the file already exists nothing happens.APPEND If the file in the path name exists add to the end of the file.If IFS_WRITE_UTF8 is used the CCSID will default to 1208, for the others it will be the partition's default If I am writing to an existing file this is ignored. FILE_CCSID: CCSID used when writing to a file.PATH_NAME: Path name to the file that will be written to.IFS_WRITE: Write plain text to the IFS fileĪll of these procedure have the same parameters:.Having played with this this is so much easier using these new SQL procedures.Īs with the IFS read table function there are three different SQL procedures to write to an IFS file: Prior to these TRs I had used C APIs embedded in a RPG program. This was added in the latest round of Technology Refreshes, IBM i 7.4 TR3 and 7.4 TR3. 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.
0 Comments
Leave a Reply. |