• The Four Hundred
  • Subscribe
  • Media Kit
  • Contributors
  • About Us
  • Contact
Menu
  • The Four Hundred
  • Subscribe
  • Media Kit
  • Contributors
  • About Us
  • Contact
  • Add a Record to Any File

    August 24, 2011 Bruce Guetzkow

    Note: The code accompanying this article is available for download here.

    Sometimes it is handy to be able to write simple data records to a file from a CLLE module/program without having to write additional programs or procedures. Since IBM has not provided a direct way to do this as part of the operating system, here is a simple method that you can install and use in a matter of minutes.

    I’ve seen several examples over the years of ways to add a record to any file. Usually a temporary file is involved using a program-described file in the current flavor of RPG. The data in the temporary file is then added to your file using the COPY FILE (CPYF) command without checking the format: FMTOPT(*NOCHK). While this approach works, it adds a bit of unnecessary overhead to the process.

    Instead I use a simple REXX (REstructured eXtended eXecutor) procedure. The example code that follows (code is also available here) shows the REXX procedure INSERTRCD.

    /* ========================================================================== */
    /* Retrieve Input Parms                                                       */
    /* ========================================================================== */
    parse arg libr file member script
    
    /* ========================================================================== */
    /* Override Standard Output to File Specified                                 */
    /* ========================================================================== */
    
    cmd = 'OVRDBF FILE(STDOUT) TOFILE(' ||,
          strip(libr) || '/' || strip(file) ||,
          ') MBR(' || strip(member) ||,
          ') OVRSCOPE(*JOB)'
    cmd
    
    /* ========================================================================== */
    /* Write Script to Standard Output                                            */
    /* ========================================================================== */
    say script
    
    /* ========================================================================== */
    /* Delete Override                                                            */
    /* ========================================================================== */
    cmd = 'DLTOVR FILE(STDOUT) LVL(*JOB)'
    cmd
    
    /* ========================================================================== */
    /* Exit Procedure                                                             */
    /* ========================================================================== */
    exit
    

    The procedure begins (“parse arg”) by receiving input from the caller. Calling routines must pass four values to the procedure: libr (library), file, member, and script (properly formatted data to be inserted into file).

    Next the Override with Data Base File (OVRDBF) command is constructed using the first three input parameters so that REXX will know where to place the output.

    After this command is executed, the data passed to this procedure is written to the specified file (“say script”). REXX has no concept of record formats or file lengths. You must properly format the data in the “script” variable before calling the INSERTRCD procedure. Too much data will be truncated; too little will be padded with blanks. Just remember the saying: Garbage In, Garbage Out!

    Once the data has been written, the Delete Override (DLTOVR) command is constructed and executed and the procedure is “exit”-ed. That’s it! Since REXX is interpreted, not compiled, there are no programs to compile (other than the callers).

    To install this REXX procedure you will need a source physical file named QREXSRC. If you don’t have one, create it with the Create Source Physical File (CRTSRCPF) command with the default length of 92. The source code in the first example (also found here) is the only source needed and should be copied to a member named INSERTRCD.

    To execute this procedure use the Start REXX Procedure (STRREXPRC) command as follows:

    STRREXPRC 	SRCMBR(INSERTRCD)
    			SRCFILE(yourlib/QREXSRC)
    			PARM('libr file member script')
    

    Let’s see an example of the INSERTRCD procedure in action. Suppose you had a physical file called MYLOG in library MYLIB with the following two fields:

    • MYDATE in YYYYMMDD format (10 S 0)
    • MYSTATUS (1 A)

    If today is August 9, 2011, and I want to add a log record with a Status of “A” from my CLLE module, here is how the command would look:

    STRREXPRC 	SRCMBR(INSERTRCD)
    			SRCFILE(yourlib/QREXSRC)
    			PARM('MYLIB MYLOG *FIRST 20110809A')
    

    REXX parses through the single parameter and, unless instructed otherwise, extracts the parameter values as delimited by the space character. Notice that I did not specify a member name, but used the value “*FIRST” as this is a valid value for the OVRDBF command. I could also have used “*LIBL” as the library value, or any other valid value for OVRDBF.

    You can also use “*LIBL” or “*CURLIB” in place of “yourlib” on the SRCFILE parameter if your library list is structured properly. However, when using “*LIBL”, the system will locate the first QREXSRC file that it finds, and whether it has the specified member or not, so use this with caution. You can use the Monitor Message (MONMSG) command to monitor for errors as needed in the caller. Because this procedure is so basic, monitoring for CPF0000 is the easiest as this will catch ALL errors. For this procedure, any error means that the data was not written to your file.

    REXX is a powerful, underutilized tool in the programmer arsenal. Used judiciously, it can turn an otherwise awkward task into something simple and elegant.

    Bruce Guetzkow, an independent IBM i programming consultant with GmanTech Consulting in southeastern Wisconsin, is a firm believer in practical programming. For over 25 years he has developed applications for IBM systems from mainframe to System/36 to IBM i on Power. You can read his Website blog, follow him on Twitter (@gmantechi), or catch him at a meeting of the Wisconsin Midrange Computer Professional Association (WMCPA), where he is the current webmaster. Send your questions or comments for Bruce to Ted Holt via the IT Jungle Contact page.



                         Post this story to del.icio.us
                   Post this story to Digg
        Post this story to Slashdot

    Share this:

    • Reddit
    • Facebook
    • LinkedIn
    • Twitter
    • Email

    Tags:

    Sponsored by
    DRV Technologies, Inc.

    Get More from Your IBM i

    Many users today struggle to get at the data they need on the IBM i. When users get reports, they look like they were formatted some time last century.

    Some organizations are still printing pre-printed forms and checks on impact printers.

    How often do operators log on to their system to look for messages they hope they don’t find?

    All of these scenarios can affect users’ perception of the IBM platform negatively, but there are simple solutions.

    DRV Technologies Inc. develops innovative solutions that help customers get more from their IBM i systems.

    Solutions include:

    • SpoolFlex spool conversion & distribution
    • FormFlex electronic forms
    • SecureChex MICR laser check printing
    • MessageFlex system monitoring

    FlexTools streamline resources, improve efficiency and enable pro-active system management.

    Better software, better service, DRV Tech.

    Learn how you can get more from your IBM i at www.drvtech.com

    Call 866 378-3366 for a Free Demonstration

    Share this:

    • Reddit
    • Facebook
    • LinkedIn
    • Twitter
    • Email

    Sponsored Links

    PowerTech:  2011 Security Event of the Year. September 22–23 in Las Vegas. RVSP today!
    CCSS:  Create a real-world definition of a high availability environment. Get the Best Practice guide.
    Townsend Security:  View the recorded Webcast: Secure Managed File Transfers for the IBM i

    IT Jungle Store Top Book Picks

    BACK IN STOCK: Easy Steps to Internet Programming for System i: List Price, $49.95

    The iSeries Express Web Implementer's Guide: List Price, $49.95
    The iSeries Pocket Database Guide: List Price, $59
    The iSeries Pocket SQL Guide: List Price, $59
    The iSeries Pocket WebFacing Primer: List Price, $39
    Migrating to WebSphere Express for iSeries: List Price, $49
    Getting Started with WebSphere Express for iSeries: List Price, $49
    The All-Everything Operating System: List Price, $35
    The Best Joomla! Tutorial Ever!: List Price, $19.95

    Island Pac Signs Two Retailers to Software Deals Field-Level Encryption Handles Security Compliance for Collections Firm

    Leave a Reply Cancel reply

Volume 11, Number 24 -- August 24, 2011
THIS ISSUE SPONSORED BY:

SEQUEL Software
WorksRight Software
System i Developer

Table of Contents

  • An Indicator By Any Other Name
  • Add a Record to Any File
  • Admin Alert: Two PC5250 Configuration Secrets

Content archive

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

Recent Posts

  • IBM Tweaks Some Power Systems Prices Down, Others Up
  • Disaster Recovery: From OS/400 V5R3 To IBM i 7.4 In 36 Hours
  • The Disconnect In Modernization Planning And Execution
  • Superior Support: One Of The Reasons You Pay The Power Systems Premium
  • IBM i PTF Guide, Volume 25, Number 13
  • IBM i Has a Future ‘If Kept Up To Date,’ IDC Says
  • When You Need Us, We Are Ready To Do Grunt Work
  • Generative AI: Coming to an ERP Near You
  • Four Hundred Monitor, March 22
  • IBM i PTF Guide, Volume 25, Number 12

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 © 2023 IT Jungle