29
Fri, Nov
0 New Articles

The API Corner: So You Want to Know About Display Files

APIs
Typography
  • Smaller Small Medium Big Bigger
  • Default Helvetica Segoe Georgia Times

The QDFRTVFD API provides pretty much everything you could want to know about a display file.

 

When developing an application program, I tend to avoid hard-coding program values such as the limit value of a FOR operation. For instance, rather than hard-coding a FOR X TO 10, I might replace the 10 with an appropriate built-in, such as %size(Y), %len(Y), %elem(Y), etc. If Y has to double in size in the future, I much prefer changing the definition of Y and allowing a recompile of the program to take care of the details of loop control rather than having to search through the code and perhaps changing one or more occurrences of 10 to 20.

 

While recently presenting to a user group, a question came up concerning one part of a program where I had chosen to hard-code a value—in this case, the size of a subfile page that I was loading one page at a time. This hard-coding was similar to the approach I took in the article "Monocasing Character Data" a few months ago where, as shown below, I initialized the variable SizeOfSFLPage to the size of a subfile page (12) and then used this variable for loop control.

 

dSizeOfSFLPage    s              5u 0 inz(12) 

GetNxtMsgs(SizeOfSFLPage);              

for myX = 1 to (NbrMsgsToGet + 1);

    …

endfor;

 

The question raised was whether or not this hard-coded initialization of SizeOfSFLPage to 12 can be avoided. As this would be a very short article indeed if the answer was "no," you can safely assume that there is an API to provide a program, at run time, the page size for a subfile. The API is Retrieve Display File Description (QDFRTVFD) and is documented here.

 

Reviewing the API documentation, you will quickly see that there is a whole lot more information available to you than just the SFLPAG value. The API can, in fact, appear to be quite daunting in terms of all the structures, substructures, and field definitions. Fortunately, the API is not that difficult to use as long as you utilize the provided documentation and know the type of information you are looking for.

 

Here is a sample program that displays the SFLPAG value for subfile control record format MSG_CTL of display file VINING/FNDMSGSDF, which happens to be the display file and subfile used in the previous "Monocasing Character Data" article.

 

h dftactgrp(*no)                                           

                                                           

dSFLPagSiz        pr            10i 0                      

d QualDspF                      20    const                 

d RcdFmtName                    10    const                

                                                           

dRcdFmt           s             10    inz('MSG_CTL')       

dPagSiz           s             10i 0                      

dMsg              s             50                         

dWait             s              1                         

                                                           

dQualDspF         ds                                       

d DspFName                      10    inz('FNDMSGSDF')     

d DspFLib                       10    inz('VINING')        

                                                           

 /free                                                     

                                                                    

  PagSiz = SFLPagSiz(QualDspF :RcdFmt);                            

                                                                   

  select;                                                          

     when PagSiz > 0;                                              

          Msg = 'The subfile page size for ' + %trimr(RcdFmt) +    

                ' is ' + %char(PagSiz);                            

     when PagSiz = -1;                                              

          Msg = 'Record format ' + %trimr(RcdFmt) + ' not found';  

     when PagSiz = -2;                                             

          Msg = 'Record format ' + %trimr(RcdFmt) +                

                ' is not SFLCTL';                                  

     other;                                                        

          Msg = 'Unexpected return value ' + %char(PagSiz) +       

                ' encountered';                                    

  endsl;                                                           

                                                                   

  dsply Msg ' ' Wait;                                          

                                                                

  *inlr = *on;                                                 

  return;                                                      

                                                               

 /end-free                                                      

                                                               

pSFLPagSiz        b                                            

dSFLPagSiz        pi            10i 0                          

d QualDspF                      20    const                    

d RcdFmtName                    10    const                    

                                                               

dRtvDspFD         pr                  extpgm('QDFRTVFD')       

d RcvVar                         1    options(*varsize)        

d LenRcvVar                     10i 0 const                    

d Format                         8    const                    

d QualDspF                      20    const                    

d ErrCde                              likeds(QUSEC)             

                                                                

dX                s             10i 0                           

dRtnValue         s             10i 0                           

                                                                 

dBasePtr          s               *                             

dBaseInf          ds                  likeds(QDFFBASE)          

d                                     based(BasePtr)            

                                                                 

dFileInfPtr       s               *                             

dFileInf          ds                  likeds(QDFFINFO)          

d                                     based(FileInfPtr)         

                                                                 

dRcdFmtTblPtr     s               *                             

dRcdFmtTblInf     ds                  likeds(QDFARFTE)          

d                                     based(RcdFmtTblPtr)       

                                                                

dRcdFmtPtr        s               *                           

dRcdFmtInf        ds                  likeds(QDFFRINF)        

d                                     based(RcdFmtPtr)        

                                                              

dSFLCtlPtr        s               *                           

dSFLCtlRcd        ds                  likeds(QDFFSFCR)        

d                                     based(SFLCtlPtr)        

                                                              

dSFLCtlEPtr       s               *                           

dSFLCtlEnt        ds                  likeds(QDFFSFHR)        

d                                     based(SFLCtlEPtr)       

                                                              

dInlRcvVar        ds                  qualified               

d BytRtn                        10i 0                         

d BytAvl                        10i 0                         

                                                              

dSFLCtlFmt        c                   x'20'                   

                                                                     

 /copy qsysinc/qrpglesrc,qdfrtvfd                                     

 /copy qsysinc/qrpglesrc,qusec                                       

                                                                     

 /free                                                               

                                                                      

  QUSBPrv = 0;                                                       

                                                                     

  RtvDspFD(InlRcvVar :%size(InlRcvVar) :'DSPF0100' :QualDspF :QUSEC);

  BasePtr = %alloc(InlRcvVar.BytAvl);                                

                                                                     

  RtvDspFD(BaseInf :InlRcvVar.BytAvl :'DSPF0100' :QualDspF :QUSEC);  

                                                                      

  FileInfPtr = BasePtr + BaseInf.QDFFINOF;                           

                                                                     

  RcdFmtTblPtr = FileInfPtr + FileInf.QDFFDFLO;                      

  for X = 1 to BaseInf.QDFFFRCS;                                     

      if RcdFmtTblInf.QDFARFNM = RcdFmtName;                      

         leave;                                                   

      else;                                                        

         RcdFmtTblPtr += %size(RcdFmtTblInf);                     

      endif;                                                      

  endfor;                                                         

                                                                   

  if X <= BaseInf.QDFFFRCS;                                       

     RcdFmtPtr = FileInfPtr + RcdFmtTblInf.QDFARFOF;              

                                                                  

     if %bitand(%subst(RcdFmtInf.QDFBITS09 :1 :1) :SFLCtlFmt) =   

          SFLCtlFmt;                                              

                                                                  

        SFLCtlPtr = RcdFmtPtr + RcdFmtInf.QDFFRAOF;               

        SFLCtlEPtr = SFLCtlPtr + %size(SFLCtlRcd);                

        RtnValue = SFLCtlEnt.QDFFSFPG;                            

     else;                                                        

        RtnValue = -2;               

     endif;                            

  else;                               

     RtnValue = -1;                   

  endif;                              

                                      

  dealloc BasePtr;                    

  return Rtnvalue;                    

                                      

 /end-free                            

                                      

pSFLPagSiz        e                                                    

                    

The program starts by calling the procedure SFLPagSiz, passing two parameters: the qualified name of a display file and the name of a subfile control record format. The SFLPagSiz procedure defines a return value where a positive value represents the size of the subfile page and a negative value an error condition. The two defined errors are -1 for a record format name that is not found in the display file and -2 for a record format that is not a subfile control record. More severe errors, such as the display file itself not being found, would result in an escape message being sent as explained in the following paragraph.

 

The SFLPagSiz procedure first sets the API error code structure Bytes provided field to 0, indicating that errors encountered by an API are to be returned as escape messages. The procedure then calls the QDFRTVFD API twice. As display files can contain many record formats, with each record format defining many possible fields and conditions, it's difficult to guess how much information about any given display file is available. The first call to the API is simply to determine how large the display file description is. For this reason, a receiver variable (InlRcvVar) of minimal size is used for the first call. This receiver variable is 8 bytes in size, just large enough to access the size of the *DSPF (variable QDFFSIZE, which I refer to as InlRcvVar.BytAvl in the program), which is provided in bytes 5 through 8 as seen in the QSYSINC definition of the QDFFBASE structure below.

 

DQDFFBASE         DS                                             

D*                                  Base File Section (QDFFBASE)

D*                                  Base file structure.  This is

D*                                  the first structure and is  

D*                                  located at offset zero of the

D*                                  returned data.              

D QDFFRETN                1      4B 0                           

D*                                  Length of the returned data.

D QDFFSIZE                5      8B 0                           

D*                                  Size of the display file    

D*                                  description.                

 

Having initially called QDFRTVFD to obtain the size of the display file information, the program then allocates the necessary amount of storage using the %alloc built-in and receives back a return value pointer to the allocated storage. This pointer, BasePtr, is defined as the basing pointer for the structure BaseInf, with BaseInf being defined like QDFFBASE as shown below. The program now calls QDFRTVFD the second time, this time passing a receiver variable InlRcvVar.BytAvl bytes in size, which is large enough to receive back all information related to the display file.

 

dBasePtr          s               *                             

dBaseInf          ds                  likeds(QDFFBASE)          

d                                     based(BasePtr)            

                                                                  

I will point out that the sample program is making a simplifying assumption with this second call to the QDFRTVFD API—namely, that no one is recreating the display file between the first and second call to QDFRTVFD. If the display file is recreated with more record formats and/or more fields than existed for the first call to the API, then the second call may still not receive all of the display file information. If this is a concern, then the program can replace the second call to QDFRTVFD with a do loop, which is exited when the returned BaseInf.QDFFSIZE value is less than or equal to the returned BaseInf.QDFFRETN value. Within the do loop, the program could use %realloc to reallocate the storage associated with BasePtr to the most recent BaseInf.QDFFSIZE value and call QDFRTVFD again with this reallocated storage as the receiver variable.

 

Having received all of the display file information that is available, it's now time to find just what the SFLPAG size value is. Most system APIs return fewer than three structures within the API receiver variable, and how to navigate across the returned structures is generally pretty obvious. Navigating most of the structures returned by the QDFRTVFD API is, on the other hand, anything but obvious. But as mentioned previously, the API documentation can certainly make your life easier in this regard, especially if you know what you want.

 

In our case, we're looking for the SFLPAG value of a subfile control record. So if we go to the API documentation found here and do a find (Ctrl+F) on the string SFLPAG, we will be brought to a page looking like the following.

 

061511ViningQDFRTVFDscreenshot

Figure 1: This is the Subfile Control Entry documentation. (Click image to enlarge.)

 

As seen from the preceding screen shot, a subfile page value can be found at offset 2 of the subfile control entry structure QDFFSFHR where there can be one or more occurrences (the ARRAY(*) reference) of the structure, depending on how many subfile record formats are defined within the display file. Looking at the QSYSINC/QRPGLESRC include member QDFRTVFD, which is copied into the SFLPagSize procedure using /copy, we find the structure QDFFSFHR and the field QDFFSFPG defined. Note that the documented API structure and field names won't always be the same as the QSYSINC names; for instance, WDFFSFPG has been renamed in QSYSINC to QDFFSFPG, but searching on the structure (or format) name will generally get you to the right location in order to determine the appropriate QSYSINC names. Within the sample program, the structure SFLCtlEnt is defined as LIKEDS(QDFFSFHR) and BASED(SFLCtlEPtr) as shown below.

 

dSFLCtlEPtr       s               *                           

dSFLCtlEnt        ds                  likeds(QDFFSFHR)        

d                                     based(SFLCtlEPtr)       

                                                              

The API documentation shows that the QDFFSFHR structure is defined at variable WDFFSFPM of structure QDFFSFCR, so, assuming for the moment that we can get to QDFFSFCR, access to QDFFSFHR can be accomplished by adding the offset of WDFFSFPM to the starting address of QDFFSFCR. Looking at the documentation for QDFFSFCR, we find that it can be accessed by adding the displacement WDFFRAOF found in structure QDFFRINF to the starting address of QDFFRINF; looking at the documentation for QDFFRINF, we find that it can be accessed by adding the displacement WDFARFOF found in structure QDFARFTE to the starting address of QDFARFTE; looking at the documentation for QDFARFTE, we find that it can be accessed by adding the displacement WDFFDFLO found in structure QDFFINFO to the starting address of QDFFINFO; looking at the documentation for QDFFINFO, we find that it can be accessed by adding displacement WDFFINOF in structure QDFFBASE to the starting address of QDFFBASE; and looking at the documentation for QDFFBASE, we find that this is the first structure returned in the receiver variable of the QDFRTVFD API, which has a starting address value represented by the pointer variable BasePtr.

 

In the same manner as QDFFSFHR, all of the API structures referenced in the previous paragraph are defined within the sample program using LIKEDS and BASED. This use of pointers and based variables is not required in order to use the QDFRTVFD API, but is certainly easier (for me anyway) than using an approach such as %subst. With the previous paragraph as a "roadmap" to aid in our navigating of the various QDFRTVFD structures, the following bolded code demonstrates the use of the roadmap (where we reverse the previously listed order as we're starting from QDFFBASE rather than QDFFSFHR).

 

  FileInfPtr = BasePtr + BaseInf.QDFFINOF;                           

                                                                      

  RcdFmtTblPtr = FileInfPtr + FileInf.QDFFDFLO;                      

  for X = 1 to BaseInf.QDFFFRCS;                                     

      if RcdFmtTblInf.QDFARFNM = RcdFmtName;                       

         leave;                                                   

      else;                                                       

         RcdFmtTblPtr += %size(RcdFmtTblInf);                     

      endif;                                                       

  endfor;                                                         

                                                                  

  if X <= BaseInf.QDFFFRCS;                                       

     RcdFmtPtr = FileInfPtr + RcdFmtTblInf.QDFARFOF;              

                                                                  

     if %bitand(%subst(RcdFmtInf.QDFBITS09 :1 :1) :SFLCtlFmt) =   

          SFLCtlFmt;                                               

                                                                  

        SFLCtlPtr = RcdFmtPtr + RcdFmtInf.QDFFRAOF;               

        SFLCtlEPtr = SFLCtlPtr + %size(SFLCtlRcd);                

        RtnValue = SFLCtlEnt.QDFFSFPG;                             

 

You might notice that there are a few stops along the road. The "for X = 1 to BaseInf.QDFFFRCS" loop is needed as there can be multiple record formats defined within a display file. This loop allows us to find the record format of interest, where QDFFFRCS is the number of record formats defined in the display file and QDFARFNM is the name of a record format found in the display file. If this FOR loop is exited with X being greater than QDFFFRCS, then the searched-for record format name (RcdFmtName) is not defined within the display file and the variable RtnValue is set to -1, representing an error condition.

 

The second stop along the road is to verify that the record format found in the display file is in fact a subfile control record. This is accomplished by the check "if %bitand(%subst(RcdFmtInf.QDFBITS09 :1 :1) :SFLCtlFmt) = SFLCtlFmt." Per the documentation for variable WDFFRFLG of structure QDFFRINF, the third bit of WDFFRFLG is "on" when the record format contains the SFLCTL keyword. You might notice that WDFFRFLG is a case where the QSYSINC name, QDFBITS09, is quite different from the documentation name of WDFFRFLG. Resolving this naming difference, however, is straightforward.

 

At this point, the procedure sets the RtnValue variable to the SFLPAG value 12 (which is located at SFLCtlEnt.QDFFSFPG), deallocates the previously allocated storage for the API receiver variable (which is why SFLCtlEnt.QDFFSFPG was copied to RtnValue as SFLCtlEnt is Based on the previously allocated—and now deallocated—BasePtr addressed storage), and returns the RtnValue value to the calling procedure. The caller then displays either the SFLPag size or some appropriate error text and ends. So, rather than hard-coding a subfile page size as I did in the earlier article with…

 

dSizeOfSFLPage    s              5u 0 inz(12) 

                                           

…I could have dynamically accessed the SFLPAG value using the SFLPagSiz procedure, avoiding program maintenance with respect to the subfile page size.

 

At this point, I do want to point out that I am not recommending that developers stop hard-coding SFLPAG values within their applications and start using a procedure such as SFLPagSiz. For the vast majority of the application software I write, I will choose to continue to hard-code such values, and most likely you should do likewise. But when developing tools to aid you in the running of your system, keep in mind that an API such as QDFRTVFD is available and can, at runtime, be used quite effectively in determining display file characteristics. The SFLPagSiz procedure provides you with one example of how you can navigate the wealth of information available to you and your applications.

 

As usual, if you have any API questions, send them to me at This email address is being protected from spambots. You need JavaScript enabled to view it.. I'll see what I can do about answering your burning questions in future columns.

as/400, os/400, iseries, system i, i5/os, ibm i, power systems, 6.1, 7.1, V7, V6R1

Bruce Vining

Bruce Vining is president and co-founder of Bruce Vining Services, LLC, a firm providing contract programming and consulting services to the System i community. He began his career in 1979 as an IBM Systems Engineer in St. Louis, Missouri, and then transferred to Rochester, Minnesota, in 1985, where he continues to reside. From 1992 until leaving IBM in 2007, Bruce was a member of the System Design Control Group responsible for OS/400 and i5/OS areas such as System APIs, Globalization, and Software Serviceability. He is also the designer of Control Language for Files (CLF).A frequent speaker and writer, Bruce can be reached at This email address is being protected from spambots. You need JavaScript enabled to view it.. 


MC Press books written by Bruce Vining available now on the MC Press Bookstore.

IBM System i APIs at Work IBM System i APIs at Work
Leverage the power of APIs with this definitive resource.
List Price $89.95

Now On Sale

BLOG COMMENTS POWERED BY DISQUS

LATEST COMMENTS

Support MC Press Online

$

Book Reviews

Resource Center

  • SB Profound WC 5536 Have you been wondering about Node.js? Our free Node.js Webinar Series takes you from total beginner to creating a fully-functional IBM i Node.js business application. You can find Part 1 here. In Part 2 of our free Node.js Webinar Series, Brian May teaches you the different tooling options available for writing code, debugging, and using Git for version control. Brian will briefly discuss the different tools available, and demonstrate his preferred setup for Node development on IBM i or any platform. Attend this webinar to learn:

  • SB Profound WP 5539More than ever, there is a demand for IT to deliver innovation. Your IBM i has been an essential part of your business operations for years. However, your organization may struggle to maintain the current system and implement new projects. The thousands of customers we've worked with and surveyed state that expectations regarding the digital footprint and vision of the company are not aligned with the current IT environment.

  • SB HelpSystems ROBOT Generic IBM announced the E1080 servers using the latest Power10 processor in September 2021. The most powerful processor from IBM to date, Power10 is designed to handle the demands of doing business in today’s high-tech atmosphere, including running cloud applications, supporting big data, and managing AI workloads. But what does Power10 mean for your data center? In this recorded webinar, IBMers Dan Sundt and Dylan Boday join IBM Power Champion Tom Huntington for a discussion on why Power10 technology is the right strategic investment if you run IBM i, AIX, or Linux. In this action-packed hour, Tom will share trends from the IBM i and AIX user communities while Dan and Dylan dive into the tech specs for key hardware, including:

  • Magic MarkTRY the one package that solves all your document design and printing challenges on all your platforms. Produce bar code labels, electronic forms, ad hoc reports, and RFID tags – without programming! MarkMagic is the only document design and print solution that combines report writing, WYSIWYG label and forms design, and conditional printing in one integrated product. Make sure your data survives when catastrophe hits. Request your trial now!  Request Now.

  • SB HelpSystems ROBOT GenericForms of ransomware has been around for over 30 years, and with more and more organizations suffering attacks each year, it continues to endure. What has made ransomware such a durable threat and what is the best way to combat it? In order to prevent ransomware, organizations must first understand how it works.

  • SB HelpSystems ROBOT GenericIT security is a top priority for businesses around the world, but most IBM i pros don’t know where to begin—and most cybersecurity experts don’t know IBM i. In this session, Robin Tatam explores the business impact of lax IBM i security, the top vulnerabilities putting IBM i at risk, and the steps you can take to protect your organization. If you’re looking to avoid unexpected downtime or corrupted data, you don’t want to miss this session.

  • SB HelpSystems ROBOT GenericCan you trust all of your users all of the time? A typical end user receives 16 malicious emails each month, but only 17 percent of these phishing campaigns are reported to IT. Once an attack is underway, most organizations won’t discover the breach until six months later. A staggering amount of damage can occur in that time. Despite these risks, 93 percent of organizations are leaving their IBM i systems vulnerable to cybercrime. In this on-demand webinar, IBM i security experts Robin Tatam and Sandi Moore will reveal:

  • FORTRA Disaster protection is vital to every business. Yet, it often consists of patched together procedures that are prone to error. From automatic backups to data encryption to media management, Robot automates the routine (yet often complex) tasks of iSeries backup and recovery, saving you time and money and making the process safer and more reliable. Automate your backups with the Robot Backup and Recovery Solution. Key features include:

  • FORTRAManaging messages on your IBM i can be more than a full-time job if you have to do it manually. Messages need a response and resources must be monitored—often over multiple systems and across platforms. How can you be sure you won’t miss important system events? Automate your message center with the Robot Message Management Solution. Key features include:

  • FORTRAThe thought of printing, distributing, and storing iSeries reports manually may reduce you to tears. Paper and labor costs associated with report generation can spiral out of control. Mountains of paper threaten to swamp your files. Robot automates report bursting, distribution, bundling, and archiving, and offers secure, selective online report viewing. Manage your reports with the Robot Report Management Solution. Key features include:

  • FORTRAFor over 30 years, Robot has been a leader in systems management for IBM i. With batch job creation and scheduling at its core, the Robot Job Scheduling Solution reduces the opportunity for human error and helps you maintain service levels, automating even the biggest, most complex runbooks. Manage your job schedule with the Robot Job Scheduling Solution. Key features include:

  • LANSA Business users want new applications now. Market and regulatory pressures require faster application updates and delivery into production. Your IBM i developers may be approaching retirement, and you see no sure way to fill their positions with experienced developers. In addition, you may be caught between maintaining your existing applications and the uncertainty of moving to something new.

  • LANSAWhen it comes to creating your business applications, there are hundreds of coding platforms and programming languages to choose from. These options range from very complex traditional programming languages to Low-Code platforms where sometimes no traditional coding experience is needed. Download our whitepaper, The Power of Writing Code in a Low-Code Solution, and:

  • LANSASupply Chain is becoming increasingly complex and unpredictable. From raw materials for manufacturing to food supply chains, the journey from source to production to delivery to consumers is marred with inefficiencies, manual processes, shortages, recalls, counterfeits, and scandals. In this webinar, we discuss how:

  • The MC Resource Centers bring you the widest selection of white papers, trial software, and on-demand webcasts for you to choose from. >> Review the list of White Papers, Trial Software or On-Demand Webcast at the MC Press Resource Center. >> Add the items to yru Cart and complet he checkout process and submit

  • Profound Logic Have you been wondering about Node.js? Our free Node.js Webinar Series takes you from total beginner to creating a fully-functional IBM i Node.js business application.

  • SB Profound WC 5536Join us for this hour-long webcast that will explore:

  • Fortra IT managers hoping to find new IBM i talent are discovering that the pool of experienced RPG programmers and operators or administrators with intimate knowledge of the operating system and the applications that run on it is small. This begs the question: How will you manage the platform that supports such a big part of your business? This guide offers strategies and software suggestions to help you plan IT staffing and resources and smooth the transition after your AS/400 talent retires. Read on to learn: