Check Directories Before Process Runs
Q How can I check to see if a QNTC share is available programmatically? I have a process that needs to pull files off a remote server, and I need to check that everything is working correctly before starting the process. If there is an error, then I want cancel the whole process.
A Windows Networking can be temperamental. I've seen processes "hang" (wait for the network) when trying to access files/directories that are offline. Windows can sit suspended for a long time, because SMB (Server Message Block, the Windows file sharing protocol) isn't particularly well-designed when it comes to detecting which systems are online or offline.
If you want to read the directory first, the opendir() function is the best way to do that. If the directory isn't available, opendir() will return an error, although it might take awhile due to the way SMB works: if the computer was available, but recently went offline, opendir() will have to time out.
If you're just checking to see if a file exists, then access() is more efficient than opendir(), although if you have to read the directory anyway, you may as well call opendir().
An alternative solution to the file transfer problem is to use FTP instead.
—Scott Klement and Harry Edmondson, from the iPro Developer Forums
Expand XML String Length in RPG
Q I have a requirement to dump an XML string (up to 2 MB long) to a field variable in an RPG program on V5R4. Initially, we were passing the XML as parameters with a maximum length of 32767, but now we have a new requirement: increase the maximum to 2 MB. I have done many searches and find User Space as one option to make this happen, but I’m a little worried about the performance of reading and parsing the XML string from User Space. Is there instead a specific PTF update to enhance and use the features of extended length in D-specs that are available with V6R1?
A The maximum string length in RPG V5R4 and later is 65535. There is no PTF or other way around that, it's a hard limit. Your choices are to use a user space or a stream file.
User Space (USRSPC) performs better: The speed of reading a user space is the same as reading a variable. However, you’ll have to copy your data to get it from your parameter into your user space, which may affect performance a bit, unless the caller puts it into a user space in the first place.
Stream files are a bit slower but handle larger sizes (USRSPC is limited to 16 MB, while stream files aren’t), and stream files support different CCSIDs better (STMF can be tagged with a CCSID, whereas USRSPC can’t).
—Scott Klement, from the iPro Developer Forums
Automating FTPS Data Transfers
Q I have to transfer data using the FTPS (SSL-encrypted) protocol. The receiver of the data only supports this file transfer method. Is there a way to automate FTPS data-transfers with the IBM i? If so, what is the best way to do it?
A If you're using the IBM-supplied FTP client (the one included with the OS), then you can use the "batch FTP" method to send the data. Despite the name, it doesn't need to run in a batch job ¾it works interactively as well¾IBM simply uses the term "batch" to indicate that it's automated. You specify SECCNN(*SSL) on the FTPS command line to use SSL encryption. You can find the documentation in the Information Center at http://publib.boulder.ibm.com/infocenter/iseries/v5r3/index.jsp?topic=%2Frzaiq%2Frzaiqftpbatch.htm.
There are also 3rd party packages, such as Linoma's GoAnywhere, that would probably work better than the FTPS client included with the operating system, but, of course, there's a charge for these.
—Scott Klement and Tommy Holden, from the iPro Developer Forums
Limiting User Access to Jobs in QBATCH
Q I have user who wants to see if his job is running in QBATCH, but I don’t want to give him access to the WRKSBSJOB SBS(QBATCH) command just to see if his job is running or not. I also don’t want him to be able to control jobs or modify anything.
A Create a small CL program that executes the following commands, which result in a read-only display of spooled output from the WRKACTJOB command and then automatically clean up when the user exits the spool viewing session:
DSPSPLF FILE(QPDSPAJB) SPLNBR(*LAST)
DLTSPLF FILE(QPDSPAJB) SPLNBR(*LAST)
—Peder Udesen, from the iPro Developer Forums