Mapping File I/O Feedback Data Structures

A map of the INFDS can be used to simplify program code.

IBM offers a mechanism for RPG application program to access system database file information. The file information data structure (INFDS), must be unique for each file and defined in the same scope as the file. For global files, the INFDS must be defined in the main procedure. For files local to a subprocedure, the INFDS must be defined in the Definition specifications of the subprocedure. Furthermore, the INFDS must be defined with the same storage type, automatic or static, as the file it is associated with.

Externally Defined INFDS

A simple way of defining a data structure is to reference an external file description. The DDS below describes the fields of the PSDS for use in any RPG program. Making a map of the PSDS standardizes defining the DS subfields in RPG programs. Adopting the map as a standard means that all programs using the external map are coded to respond to the same field names. This makes it easy to interpret the code when it is time to maintain a program.

      ****************************************************************
      * File Name    - ISIDBFDS                                      *
      *                                                              *
      * Function     - This was designed to serve as an external     *
      *                data structure to define the file information *
      *                data structure for database files.            *
      *                                                              *
      * Programmer   - Steve Croy                                    *
      ****************************************************************
      ****************************************************************
      *                   Modification log                           *
      *                                                              *
      *   Date    Programmer      Description                        *
      *                                                              *
      ****************************************************************

     A          R RISIDBF                   TEXT('Database INFDS')
     A            DBFNAM         8          COLHDG('File' 'Name')
     A            DBFOPN         1          COLHDG('File' 'Open')
     A            DBFEND         1          COLHDG('File' 'End')
     A            DBFSTS         5S 0       COLHDG('File' 'Status')
     A            DBCODE         6          COLHDG('RPG' 'OPCODE')
     A            DBRRTN         8          COLHDG('RPG' 'Routine')
     A            DBRSTM         8          COLHDG('RPG' 'Statement')
     A            DBRNAM         8          COLHDG('Record' 'Format')
     A            DBPMSG         7          COLHDG('CPF' 'Msg ID')
     A            DBPINS         4          COLHDG('PGM' 'Instruction')
     A            DBF001        14          COLHDG('Undefined')
     A            DBFINP         2S 0       COLHDG('Input')
     A            DBFOUT         2S 0       COLHDG('Output')
     A            DBFMOD         2S 0       COLHDG('Mode')
     A            DBF002         4          COLHDG('Undefined')
     A            DDFODP         2          COLHDG('ODP' 'Type')
     A            DBXNAM        10          COLHDG('External' 'File Name')
     A            DBFLIB        10          COLHDG('File' 'Library')
     A            DBF003        22          COLHDG('Undefined')
     A            DBFLEN         4B 0       COLHDG('Record' 'Length')
     A            DBF004         2          COLHDG('Undefined')
     A            DBFMBR        10          COLHDG('File' 'Member')
     A            DBF005         8          COLHDG('Undefined')
     A            DBFTYP         4B 0       COLHDG('File' 'Subtype')
     A            DBF006         7          COLHDG('Undefined')
     A            DBFRCD         8B 0       COLHDG('Record' 'Count')
     A            DBFACC         2          COLHDG('Access' 'Type')
     A            DBFDUP         1          COLHDG('Allow' 'Dupe')
     A            DBFSRC         1          COLHDG('Source' 'File')
     A            DBUFCB        10          COLHDG('User' 'FC' 'Blk')
     A            DBFBOV        10          COLHDG('FC' 'Blk' 'Ovr')
     A            DBF007        27          COLHDG('Undefined')
     A            DBFOST         4B 0       COLHDG('DBF' 'Open' 'Sts')
     A            DBFLAG         1          COLHDG('File' 'Flags')
     A            DBOPID         2          COLHDG('Open' 'ID')
     A            DBMAXR         8B 0       COLHDG('Max' 'Records')
     A            DBF008       177          COLHDG('Undefined')
     A            DBRRN#         8B 0       COLHDG('Relative' 'Record')
     A            DBF009       112          COLHDG('Undefined')
                                                  

Using the Mapped DS

The code snippett below illustrateS using the INFDS. The indicated the data structure is named DBFBK. This example from IBM provides a glimpse of the information available using the database specific INFDS.

  DCL-F MYFILE DISK(*EXT) INFDS(DBFBK);

   DCL-DS DBFBK;
     FDBK_SIZE     INT(10)    POS(367);    // Current line num
     JOIN_BITS     INT(10)    POS(371);    // JFILE bits
     LOCK_RCDS     INT(5)     POS(377);    // Nbr locked rcds
     POS_BITS      CHAR(1)    POS(385);    // File pos bits
     DLT_BITS      CHAR(1)    POS(384);    // Rcd deleted bits
     NUM_KEYS      INT(5)     POS(387);    // Num keys (bin)
     KEY_LEN       INT(5)     POS(393);    // Key length
     MBR_NUM       INT(5)     POS(395);    // Member number
     DB_RRN        INT(10)    POS(397);    // Relative-rcd-num
     KEY           CHAR(2000) POS(401);    // Key value (max size 2000)
   END-DS;                                                                                                                           

The INFDS can be a valuable debugging tool. Having the data structued defined can show the compiler information which tells a software engineer file member used and the relative record number could aid debugging the code.