• The Four Hundred
  • Subscribe
  • Media Kit
  • Contributors
  • About Us
  • Contact
Menu
  • The Four Hundred
  • Subscribe
  • Media Kit
  • Contributors
  • About Us
  • Contact
  • Better Data Transfers

    March 24, 2004 Bruce Guetzkow

    [The code for this article is available for download.]

    I’ve been searching for ways to automate user tasks and, preferably, to have them initiated from the iSeries. One such task is transferring data between a network folder or the Integrated File System (IFS) and an externally described iSeries database file. But there are problems associated with using IBM’s Copy from Stream File (CPYFRMSTMF) and Copy to Stream File (CPYTOSTMF) commands. So I developed my own commands.

    When using the CPYFRMSTMF and CPYTOSTMF commands, the parameters and associated values are difficult to keep straight, and externally-described iSeries database files are not allowed with these commands. So I have developed two commands to be used as front-ends to the IBM commands. The commands I created, Copy From IFS File (CPYFRMIFS) and Copy To IFS File (CPYTOIFS), simplify the parameters and allow use of externally described iSeries database files.

    COPY FROM IFS FILE

    The CPYFRMIFS_CMD command transfers a file from the IFS to an iSeries database file. This command has six parameters:

    • Object In: the complete path of the file on the IFS to be transferred.

    • Object Out: the qualified name of the iSeries database file.

    • Member Out: the iSeries database file member to receive the data.

    • DB File Type: identifies whether the iSeries database file is a data file or a source file.

    • PC File Type: identifies the file system where the IFS file originated (Windows/Unix).

    • Member option: identifies whether the member is to be replaced or added to.

    The source code for the command processing program is CPYFRMIFSC_CLLE. I have broken the field declarations in this program into three groups: the parameters passed to the program, the fields used by the CPYFRMSTMF and SNDPGMMSG commands, and fields related to C-program “stat.”

    The program begins by parsing out the Object Out parameter into file (positions 1-10) and library (positions 11-20). Next, we convert the Object In parameter into a null-terminated string for use with C-program “stat.” Program “stat” is used to determine if the file specified in the Object In parameter exists. If the file exists, the return value is a binary value of zero (0). If the return value is not zero (file not found), the program sends escape message CPF9897 with the text “Object object-in does not exist” and the program terminates. Because this is an escape message, it can be monitored for in a calling program by using a MONMSG command.

    If the IFS file exists, the program checks to see if the database file and member exist. If not, the program again issues escape message CPF9897, this time with the text “Object library/file does not exist.” Again, MONMSG can be used to monitor for this message in a calling program.

    The program then changes special values *LIBL or *CURLIB to the actual library name needed later in the program by the CPYF command by first retrieving it, using the DSPFD command. The special values used for the DB File Type and PC File Type parameters are converted to the values used by the CPYFRMSTMF command.

    In addition to the library name, the previously executed DSPFD command also retrieved the length in bytes of the database file (Object Out). At this point, the program creates a “flat file” in library QTEMP of the same record length as the database file, since the CPYFRMSTMF command cannot copy directly to an externally described file. The CPYFRMSTMF command copies the data from the IFS to this “flat” version of the database file, using the parameters previously converted. Next, the data is copied again from the “flat” file to the actual database file. At this point the program is finished.

    COPY TO IFS FILE

    Now let’s move on to the Copy To IFS File command, CPYTOIFS_CMD. Basically, this command is nearly the reverse of the previous command. This command also has six parameters:

    • Object In: the qualified name of the iSeries database file.

    • Object Out: the complete path of the file on the IFS to be transferred.

    • Member Out: the iSeries database file member with the data to transfer.

    • DB File Type: identifies whether the iSeries database file is a data file or a source file.

    • PC File Type: identifies the file system where the IFS file originated (Windows/Unix).

    • Stream File option: identifies whether the stream file is to be created, replaced, or added to.

    The source code for the command processing program is CPYTOIFSC_CLLE. The field declarations are again broken down, as in the CPYFRMIFSC program.

    The program begins by parsing out the Object In parameter into file (positions 1-10) and library (positions 11-20). The program then checks to see if the database file and member exist. If not, the program again issues escape message CPF9897 with the text “Object library/file does not exist.” Again, MONMSG can be used to monitor for this message in a calling program.

    This program also uses C-program “stat” to determine if the IFS file exists, but only if the stream file option is *CREATE. I have decided that if I am attempting to create a file and it already exists, an error message should be sent (CPF9897: “Object object-out already exists, cannot be created”). If I am replacing or adding to a file and the file doesn’t exist, CPYTOSTMF will create it for me, so I don’t consider this an error condition.

    As before, special values *LIBL or *CURLIB are changed to the actual library name needed later in the program, by the CPYF command. The special values used for the DB File Type and PC File Type parameters are again converted to the values used by the CPYFRMSTMF command.

    As before, the program creates a “flat” file in library QTEMP of the same record length as the database file, since the CPYTOSTMF command cannot copy directly from an externally described file. This time the data is first copied to the “flat” file. Then the CPYTOSTMF command copies the data from this “flat” version of the database file to the IFS, using the parameters previously converted. This concludes this program.

    MEETING YOUR NEEDS

    Although the commands were originally developed to be used with files on the IFS, if you have configured your iSeries as part of a network, you also should be able to use these commands to transfer files between your iSeries and network folders. The path for a network file is /qntc/server-name/share-name/folder1/folder2/file.extension. This can be very useful if you prefer not to move network data to the IFS or if you want to transfer data to or from a remote location.

    So far these commands only allow a limited number of file transfer options. If these options are insufficient to meet all of your needs, you can easily add parameter values to the IFS commands and modify the programs accordingly. For example, save files also can be transferred using the stream file commands. By allowing a value of *SAVF for the DB File Type parameter and modifying the programs accordingly, you could simplify this type of transfer with the IFS commands. Whatever your specific needs are, these IFS commands will simplify your data transfer activities.

    Bruce Guetzkow has programmed on the AS/400 and iSeries since 1990, in manufacturing, distribution and other industries. He is currently the IS director at United Credit Service in Elkhorn, Wisconsin. E-mail: bruceg@unitedcreditservice.com

    Share this:

    • Reddit
    • Facebook
    • LinkedIn
    • Twitter
    • Email

    Tags:

    Sponsored by
    Maxava

    Disaster Recovery Strategy Guide for IBM i

    Practical tools to implement disaster recovery in your IBM i environment. Fully optimized to include cloud recovery, replication and monitoring options.

    Download NOW!

    Share this:

    • Reddit
    • Facebook
    • LinkedIn
    • Twitter
    • Email

    Chrono-Logic Offers Cross Reference Tool for LANSA Early Adopters Prep for New OS/400, iSeries, and Logical Partitions

    Leave a Reply Cancel reply

Content archive

  • The Four Hundred
  • Four Hundred Stuff
  • Four Hundred Guru

Recent Posts

  • IBM Unveils Manzan, A New Open Source Event Monitor For IBM i
  • Say Goodbye To Downtime: Update Your Database Without Taking Your Business Offline
  • i-Rays Brings Observability To IBM i Performance Problems
  • Another Non-TR “Technology Refresh” Happens With IBM i TR6
  • IBM i PTF Guide, Volume 27, Number 18
  • Will The Turbulent Economy Downdraft IBM Systems Or Lift It?
  • How IBM Improved The Database With IBM i 7.6
  • Rocket Celebrates 35th Anniversary As Private Equity Owner Ponders Sale
  • 50 Acres And A Humanoid Robot With An AI Avatar
  • IBM i PTF Guide, Volume 27, Number 17

Subscribe

To get news from IT Jungle sent to your inbox every week, subscribe to our newsletter.

Pages

  • About Us
  • Contact
  • Contributors
  • Four Hundred Monitor
  • IBM i PTF Guide
  • Media Kit
  • Subscribe

Search

Copyright © 2025 IT Jungle