Mapping Program Status Data Structures

The PSDS can be used to create exception management in a program.

IBM offers a mechanism for RPG application program to access system information available to the program. The program status data structure (PSDS) can be defined, allowing the program view and manage exception/error information. The PSDS has been limited to the main source section of the application; therefore, there is only one PSDS per module.

Externally Defined PSDS

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    - SCPSTSPF                                          *
      *                                                                  *
      * FUNCTION     - THIS FILE WAS DESIGNED TO SERVE AS AN EXTERNAL    *
      *                DATA STRUCTURE TO DEFINE THE PROGRAM STATUS       *
      *                DATA STRUCTURE.                                   *
      *                                                                  *
      * PROGRAMMER   - STEVE CROY        99/99/99                        *
      ********************************************************************
      ********************************************************************
      *                   MODIFICATION LOG                               *
      *                                                                  *
      *   DATE    PROGRAMMER      DESCRIPTION                            *
      *                                                                  *
      ********************************************************************
     A          R RSCPSTS                   TEXT('PROGRAM STATUS DS')
     A            PRGNAM        10          COLHDG('PROGRAM' 'NAME')
     A            STATUS         5S 0       COLHDG('PROGRAM' 'STATUS')
     A            PRVSTS         5S 0       COLHDG('PREVIOUS' 'STATUS')
     A            SRCSMT         8          COLHDG('SOURCE' 'STATEMT')
     A            ROUTIN         8          COLHDG('RPG' 'ROUTINE')
     A            PARMS          3S 0       COLHDG('NBR OF' 'PARMS')
     A            MSGID          7          COLHDG('MSG ID')
     A            INSBNR         4          COLHDG('INSTRUCTION')
     A            MSGWRK        30          COLHDG('WORK' 'AREA')
     A            PGMLIB        10          COLHDG('PROGRAM' 'LIBRARY')
     A            MSGTXT        80          COLHDG('MSG' 'TEXT')
     A            EXCNBR         4          COLHDG('EXCEPTION' 'NBR')
     A		  FILERR        10	    COLHDG('FILE IN' 'ERROR')
     A            UNUSED1        6	    COLDHG('UNUSED')
     A            ENTDAT         8	    COLHDG('DATE' ENTERED')
     A            DATCEN         2S 0       COLDHDG('CENTURY') 
     A            ERRFIL         8          COLHDG('ERROR' 'FILE')
     A            ERRINF        35          COLHDG('ERROR' 'DATA')
     A            JOBNAM        10          COLHDG('JOB' 'NAME')
     A            USER          10          COLHDG('USER' 'NAME')
     A            JOBNBR         6          COLHDG('JOB' 'NUMBER')
     A            JOBDAT         6S 0       COLHDG('JOB' 'DATE')
     A            SYSDAT         6S 0       COLHDG('SYS' 'DATE')
     A            SYSTIM         6S 0       COLHDG('SYS' 'TIME')
     A            PGMDAT         6S 0       COLHDG('PGM' 'TIME')
     A            PGMTIM         6S 0       COLHDG('PGM' 'TIME')
     A            CMPLVL         4          COLHDG('COMPILER' 'LVL')
     A            SRCFIL        10          COLHDG('SOURCE' 'FILE')
     A            SRCLIB        10          COLHDG('SOURCE' 'LIB')
     A            SRCMBR        10          COLHDG('SOURCE' 'MEMBER')
     A            PGMPRC	10	    COLHDG('PGM' 'PROC')
     A		  PGMMOD	10	    COLHDG('PGM' 'MOD')
     A		  SRCSTBN	 2B	    COLHDG('BIN' 'SRCSTMT')
     A		  SRCIDBN	 2B	    COLHDG('BIN' 'SRCID')    
     A		  CURPRF	10	    COLHDG('CURR' 'USRPRF')
     A		  EXTERR	 4B	    COLHDG('EXT' 'ERR')
     A		  XMLELM     	 8B	    COLHDG('XML' 'ELEMENTS')
     A		  INTJOB	16	    COLHDG('INTERNAL' 'JOB ID')
     A		  SYSID	 	 8	    COLHDG('SYSTEM' 'NAME')
     A		  UNDEF1 	50	    COLHDG('UNUSED')



Using the Mapped DS

The code snippetts below illustrate using the mapped PSDS. N* indicated the data structure is not named. But the fields are available to the program. In the subprocedure GETMESSAGE. The program uses the MONITOR block to trap excetions. If an error occurs, the messsge, the message file, and the message text from the PSDS is sent to the program message queue for display.

      ********************************************************************                          
      *                   Modification log                               *                          
      *                                                                  *                          
      *   Date    Programmer      Description                            *                          
      *                                                                  *                          
      ********************************************************************                          
                                                                                                    
     //------------ File section -----------------------------------------                          
       Dcl-F SC0320DF WORKSTN             UsrOpn                                                    
                                          SFILE(SC0320S1:RRNSI)                                     
                                          INFDS(DSPDS) ;                                            
                                                                                                    
     //------------ Data Structures --------------------------------------                          
                                                                                                    
      /copy qrpglesrc,SCMAPS_pr   
       Dcl-DS *N    ExtName('SCPSTSPF') PSDS End-DS        ;
       Dcl-DS DSPDS ExtName('SCDSPFPF')      End-DS        ;
       Dcl-DS functionkey     extname('SCKEYSPF') qualified end-DS;                                                                                                                                                                                                          
       Dcl-DS OBJECT    extname('SCOBJSPF')           end-DS;                                       
       Dcl-DS before    extname('SCOBJSPF') qualified end-DS;                                       
       Dcl-DS after     extname('SCOBJSPF') qualified end-DS;                                       
  
.
.
.                                                                                                  
       //*=====================================================================                     
       Dcl-Proc getMessage ;                                                                        
         Dcl-PI getMessage               ;                                                          
                thisMsg    char(7) const ;                                                          
         end-PI ;                                                                                   
                                                                                                    
            msgID = thisMsg ;                                                                       
            msgdta = *BLANKS;                                                                       
            msg = *BLANKS;                                                                          
            msgf = dftMsgFile;                                                                      
                                                                                                    
           MONITOR;                                                                                 
              RtvMessage(msgid:msgf:msgdta:msg);                                                    
              msgtxt = msg;                                                                         
           ON-ERROR;                                                                                
              msgf = errFil;                                                                        
          ENDMON;                                                                                   
                                                                                                    
           msgRlq = '*SAME' ;                                                                       
           msgdta =  msgtxt;                                                                        
           msgpgm = PRGNAM;                                                                         
                                                                                                    
           SndMessage(msgid : msgF: msgdta : msgrlq : msgpgm);                                      
           MessageToDisplay = *ON;                                                                  
                                                                                                    
          Return ;                                                                                  
                                                                                                    
       END-Proc getMessage ; 
.
.
.                                                                                                                                                                         

The PSDS can be a valuable debugging tool. Having the data structued defined can show the compiler information which tells a software engineer when the program was created and from the specific source member of the object in debug mode.