• The Four Hundred
  • Subscribe
  • Media Kit
  • Contributors
  • About Us
  • Contact
Menu
  • The Four Hundred
  • Subscribe
  • Media Kit
  • Contributors
  • About Us
  • Contact
  • Determining the Value of Built-in I/O Functions

    February 28, 2007 Hey, Ted

    What follows is a question that I have paraphrased from the emails of various readers of this august publication, who all seem to be encountering a similar issue: “Is it possible to view the value returned by built-in functions, such as %EOF and %FOUND, when working in the green-screen, full-screen debugger?”

    The short answer is “No.” The debugger will not show you the result of any function, built-in or user-defined, unless that function is defined to the debugger. (See Undocumented Debugger Function.) The reason for this behavior is that a function is not a variable. A variable is a section of memory, and as such, is easily queried for its current value. A function is executable code that runs when the function is invoked.

    However, that does not mean that there is no way to determine the value that an I/O function returns. You just have to go about it another way.

    Let’s consider the following trivialized example program snippet.

    Fitembl    if   e           k disk
                                                       
    D Itnbr           s             15a                
                                                       
     /free                                             
         chain itnbr itemblmc;                         
         if %found(itembl);
            DoWhatever();
         else;
            DoWhateverElse();
         endif;
    

    After the chain operation, %FOUND is either true (*ON) or false (*OFF). The same is true for %ERROR.

    Here’s another example:

    FMyInfo    if   e           k disk            
    FQSysPrt   o    f  132        printer
                                                  
     /free                                        
         *inlr = *on;                             
         dow '1';                                 
            read myinfo;                          
            if %eof(myinfo);                   
               leave;                             
            endif;                                
            except pline;                         
         enddo;                                   
         return;                                  
    

    After the read, the %EOF and %ERROR functions are updated with true/false values.

    I have heard it said that there’s no need to be able to view the returned values of the functions, since a person can determine how the functions behaved by watching the path of execution. That’s a good point, and that’s what I usually do. But there are times that I would not allow a section of code to execute if I knew what the function had returned, or I would have plugged a value in order to force the program to continue in some other direction. (I assume that those who have asked me this question have similar motives for wanting to know the result of a function call.)

    I know of two methods you can use to see a function’s return value. Here’s the more obvious one first.

    Method 1: Store the function’s return value in a variable, like this.

    FMyInfo    if   e           k disk            
    FQSysPrt   o    f  132        printer         
                                                  
    D eof             s               n           
                                                  
     /free                                        
         *inlr = *on;                             
         dow '1';                                 
            read myinfo;                          
            eof = %eof(myinfo);                   
            if eof;                               
               leave;                             
            endif;                                
            except pline;                         
         enddo;                                   
         return;                                  
     /end-free                                    
                                                  
    OQSysPrt   e            pline       1         
    O                       name                  
    O                       age           4  +0001
    

    This method is by no means rocket science. Store the result of the %EOF function into variable EOF, then view the value of EOF. Besides being able to view the result of the %EOF function, you can alter the course of program execution by changing the value of the EOF variable before it is tested.

     eval eof = '1' 
    

    Method 2: Check the status subfield of the file information data structure.

    FMyInfo    if   e           k disk    infds(MyInfoDS)
    FQSysPrt   o    f  132        printer                
                                                         
    D MyInfoDS        ds                                 
    D  MyInfoStatus     *status                          
                                                         
     /free                                               
         *inlr = *on;                                    
         dow '1';                                        
            read myinfo;                                 
            if %eof(myinfo);                             
               leave;                                    
            endif;                                       
            except pline;                                
         enddo;                                          
         return;                                         
     /end-free                                           
                                                         
    OQSysPrt   e            pline       1                
    O                       name                         
    O                       age           4  +0001       
    

    Add an INFDS keyword to the F spec of the file whose I/O status you want to test, and key the name of a data structure as the keyword’s value. In this case, the data structure is MyInfoDS. Create the data structure and include a status subfield, defined with the literal *STATUS in the “from” entry field of the D spec.

    When the program performs an I/O operation to MyInfo, the file information data structure will be updated. If the I/O is successful, the status subfield gets set to all zeros. If a READx operation hits beginning or end of file, the status becomes 11. A failed CHAIN (random read) returns a status code of 11. Status codes of 1000 or above indicate errors. See the iSeries Information Center for more about status codes.

    –Ted

    RELATED RESOURCES

    Undocumented Debugger Function

    iSeries Information Center, Status Code section



                         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
    OCEAN User Group

    OCEAN TechCon25 Online

    It’s an Exciting Time for IBM i !

    July 16 & 17, 2025 – ONLINE

    Two virtual days of learning, presented by an outstanding group of IBM’ers and IBM Champions, featuring leading-edge topics.

    FREE for OCEAN members!

    Register NOW!

    Annual (12-month) Individual OCEAN Memberships are $80 and a Corporate Membership is $250. A Corporate Membership would allow your entire company to have full access to the OCEAN website & video library and to attend OCEAN events at member rates. Act now because rates are increasing on August 1, 2025.

    Share this:

    • Reddit
    • Facebook
    • LinkedIn
    • Twitter
    • Email

    Sponsored Links

    COMMON:  Join us at the 2007 conference, April 29 – May 3, in Anaheim, California
    Computer Keyes:  Rapidly convert *SCS printer files into black and white of full color PDF documents
    Patrick Townsend & Associates:  Alliance AES/400 - database field encryption

    Books on Sale at the IT Jungle Store: 30 Percent Off for 30 Days

    The System i Pocket RPG & RPG IV Guide: List Price, $69.95; Sale Price, $49.00
    The iSeries Pocket Database Guide: List Price, $59.00; Sale Price, $41.00
    The iSeries Pocket Developers' Guide: List Price, $59.00; Sale Price, $41.00
    The iSeries Pocket SQL Guide: List Price, $59.00; Sale Price, $41.00
    The iSeries Pocket Query Guide: List Price, $49.00; Sale Price, $34.00
    The iSeries Pocket WebFacing Primer: List Price, $39.00; Sale Price, $27.00
    Migrating to WebSphere Express for iSeries: List Price, $49.00; Sale Price, $34.00
    iSeries Express Web Implementer's Guide: List Price, $59.00; Sale Price, $41.00
    Getting Started with WebSphere Development Studio for iSeries: List Price, $79.95; Sale Price, $56.00
    Getting Started With WebSphere Development Studio Client for iSeries: List Price, $89.00; Sale Price, $62.00
    Getting Started with WebSphere Express for iSeries: List Price, $49.00; Sale Price, $34.00
    WebFacing Application Design and Development Guide: List Price, $55.00; Sale Price, $38.00
    Can the AS/400 Survive IBM?: List Price, $49.00; Sale Price, $34.00
    The All-Everything Machine: List Price, $29.95; Sale Price, $21.00
    Chip Wars: List Price, $29.95; Sale Price, $21.00

    BROWNtech Streamlines Access to County Records What’s IBM Cooking Up for RPG and the Web?

    Leave a Reply Cancel reply

Volume 7, Number 8 -- February 28, 2007
THIS ISSUE SPONSORED BY:

Patrick Townsend & Associates
Profound Logic Software
WorksRight Software

Table of Contents

  • Determining the Value of Built-in I/O Functions
  • Customize the Tab Key in WDSc
  • Admin Alert: Better Subsystem Throughput Via Multiple Job Queues, Part One

Content archive

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

Recent Posts

  • With Power11, Power Systems “Go To Eleven”
  • With Subscription Price, IBM i P20 And P30 Tiers Get Bigger Bundles
  • Izzi Buys CNX, Eyes Valence Port To System Z
  • IBM i Shops “Attacking” Security Concerns, Study Shows
  • IBM i PTF Guide, Volume 27, Number 26
  • Liam Allan Shares What’s Coming Next With Code For IBM i
  • From Stable To Scalable: Visual LANSA 16 Powers IBM i Growth – Launching July 8
  • VS Code Will Be The Heart Of The Modern IBM i Platform
  • The AS/400: A 37-Year-Old Dog That Loves To Learn New Tricks
  • IBM i PTF Guide, Volume 27, Number 25

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