• 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
    Raz-Lee Security

    Start your Road to Zero Trust!

    Firewall Network security, controlling Exit Points, Open DB’s and SSH. Rule Wizards and graphical BI.

    Request Demo

    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

  • Public Preview For Watson Code Assistant for i Available Soon
  • COMMON Youth Movement Continues at POWERUp 2025
  • IBM Preserves Memory Investments Across Power10 And Power11
  • Eradani Uses AI For New EDI And API Service
  • Picking Apart IBM’s $150 Billion In US Manufacturing And R&D
  • FAX/400 And CICS For i Are Dead. What Will IBM Kill Next?
  • Fresche Overhauls X-Analysis With Web UI, AI Smarts
  • Is It Time To Add The Rust Programming Language To IBM i?
  • Is IBM Going To Raise Prices On Power10 Expert Care?
  • IBM i PTF Guide, Volume 27, Number 20

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