Program Status Data Structure in RPG AS400

Program Status Data Structure in RPG AS400
Program Status Data Structure in RPG AS400,PSDS in RPGIV, PSDS, data structure, ds,program status data structure.
Program Status Data Structure in RPG AS400

Introduction to Program Status Data Structure

It is identified by the PSDS keyword for a free form definition or S specified in 23 positions in fixed format RPG. It provides program exception/error information available to the program.

The PSDS must be defined in the main source section so that there are only one PSDS available per module. A PSDS contains predefined subfields.

Using PSDS in RPGLE Fixed, /Free and Fully Free format

RPG Code in Fixed format for program status data structure in RPG AS400
      * Program status data structure                                                             
      * program exception available to rpg program (1 psds per module)                            
                                                                                                  
     D psds1          SDS                                                                         
     D proc_name         *proc                                                  * module/program  
      * 1 to 10 position, 10 chars                                                                
     D pgm_status        *status                                                * status code     
      * 11 to 15 position, (5,0) zoned decimal                                                    
     D pgm_prvstatus          16     20S 0                                      * Prev. status    
     D src_listing            21     28                                         * src. list line  
     D routine           *routine                                               * routine         
      * 29 to 36 position, 8 chars                                                                
      * *INIT  --> program initialization                                                         
      * *DETL  --> detail lines                                                                   
      * *GETIN --> get input record                                                               
      * *TOTC  --> Total calculations                                                             
      * *TOTL  --> Total lines                                                                    
      * *DETC  --> Detail calculations                                                            
      * *OFL   --> Overflow lines                                                                 
      * *TERM  --> Program ending                                                                    
      * *ROUTINE --> name of program or procedure called (first 8 chars)                             
     D parms             *parms                                                 * no. of parms pass  
      * 37 to 39 position, (3,0) zoned decimal                                                       
     D excptype               40     42                                         * exception type     
      * CPF --> operating system exception                                                           
      * MCH --> machine exception                                                                    
     D excpnum                43     46                                         * exception number   
      * CPF --> CPF message number                                                                   
      * MCH --> MCH message number                                                                   
     D reserved1              47     50                                         * reserved           
     D workarea               51     80                                         * internal use by    
                                                                                * ILE RPG compiler   
     D pgmlib                 81     90                                         * prgram library     
     D excpdata               91    170                                         * exception data     
     D excpcause             171    174                                         * exception that     
                                                                                * cause RNX9001      
     D filename              175    184                                         * file name on whic  
                                                                                *h last file operati 
                                                                                *on occur updated on 
                                                                                *ly when error occur   
     D unused                185    190                                         * unused               
     D date                  191    198                                         * date(*date format)   
     D yy                    199    200S 0                                      * first two digits     
                                                                                * of 4 digit year      
     D filenametrn           201    208                                         * file name truncate   
                                                                                * (175-184 pos above   
     D statusinfo            209    243                                         * status info on las   
                                                                                *t file used           
     D jobname               244    253                                         * job name             
     D username              254    263                                         * user name            
     D jobnumber             264    269                                         * job number           
     D date2                 270    275S 0                                      * date (udate format   
                                                                                * pgm running          
                                                                                * (191-198 pos above   
     D pgmrundate            276    281S 0                                      * date of pgm runnin   
     D time                  282    287S 0                                      * time (hhmmss)        
                                                                                * pgm running          
     D date3                 288    293                                         * date (udate format   
                                                                                * pgm compiled         
     D time2                 294    299                                         * time (hhmmss)      
                                                                                * pgm compiled       
     D cmplevel              300    303                                         * compiler level     
     D srcfile               304    313                                         * src file name      
     D srclib                314    323                                         * src lib name       
     D srcmbr                324    333                                         * src file member    
     D pgmproc               334    343                                         * pgm containing     
                                                                                * procedure          
     D modproc               344    353                                         * module containing  
                                                                                * procedure          
     D srcid                 354    355B 0                                      * src id match the   
      * binary  2 (5i,0)                                                                             
                                                                                * statement number   
                                                                                * from pos 21-28     
     D srcid2                356    357B 0                                      * src id match the   
      * binary  2 (5i,0)                                                                             
                                                                                * statement number   
                                                                                * from pos 228-235   
     D curuserprf            358    367                                         * current user profi 
     D exterrorcd            368    371I 0                                      * external error cod 
      * Integer (10,0)                                                                                
     D elements              372    379I 0                                      * elements set by XM  
      * Integer (20,0)                                                                                
                                                                                *L-INTO or DATA-INTO  
     D internaljobid         380    395                                         * internal job id     
     D systemname            396    403                                         * system name         
     D unused2               404    429                                         * unused              
 
     C                   SETON                                        LR                                                                                                      
                                                                                                                                                                                                                                                         
RPG Code in /Free format for program status data structure in RPG AS400
                           
      * Program status data structure                                                             
      * program exception available to rpg program (1 psds per module)                            
                                                                                                  
     D psds1          SDS                                                                         
     D proc_name         *proc                                                  * module/program  
      * 1 to 10 position, 10 chars                                                                
     D pgm_status        *status                                                * status code     
      * 11 to 15 position, (5,0) zoned decimal                                                    
     D pgm_prvstatus          16     20S 0                                      * Prev. status    
     D src_listing            21     28                                         * src. list line  
     D routine           *routine                                               * routine         
      * 29 to 36 position, 8 chars                                                                
      * *INIT  --> program initialization                                                         
      * *DETL  --> detail lines                                                                   
      * *GETIN --> get input record                                                               
      * *TOTC  --> Total calculations                                                             
      * *TOTL  --> Total lines                                                                    
      * *DETC  --> Detail calculations                                                            
      * *OFL   --> Overflow lines                                                                 
      * *TERM  --> Program ending                                                                    
      * *ROUTINE --> name of program or procedure called (first 8 chars)                             
     D parms             *parms                                                 * no. of parms pass  
      * 37 to 39 position, (3,0) zoned decimal                                                       
     D excptype               40     42                                         * exception type     
      * CPF --> operating system exception                                                           
      * MCH --> machine exception                                                                    
     D excpnum                43     46                                         * exception number   
      * CPF --> CPF message number                                                                   
      * MCH --> MCH message number                                                                   
     D reserved1              47     50                                         * reserved           
     D workarea               51     80                                         * internal use by    
                                                                                * ILE RPG compiler   
     D pgmlib                 81     90                                         * prgram library     
     D excpdata               91    170                                         * exception data     
     D excpcause             171    174                                         * exception that     
                                                                                * cause RNX9001      
     D filename              175    184                                         * file name on whic  
                                                                                *h last file operati 
                                                                                *on occur updated on 
                                                                                *ly when error occur   
     D unused                185    190                                         * unused               
     D date                  191    198                                         * date(*date format)   
     D yy                    199    200S 0                                      * first two digits     
                                                                                * of 4 digit year      
     D filenametrn           201    208                                         * file name truncate   
                                                                                * (175-184 pos above   
     D statusinfo            209    243                                         * status info on las   
                                                                                *t file used           
     D jobname               244    253                                         * job name             
     D username              254    263                                         * user name            
     D jobnumber             264    269                                         * job number           
     D date2                 270    275S 0                                      * date (udate format   
                                                                                * pgm running          
                                                                                * (191-198 pos above   
     D pgmrundate            276    281S 0                                      * date of pgm runnin   
     D time                  282    287S 0                                      * time (hhmmss)        
                                                                                * pgm running          
     D date3                 288    293                                         * date (udate format   
                                                                                * pgm compiled         
     D time2                 294    299                                         * time (hhmmss)      
                                                                                * pgm compiled       
     D cmplevel              300    303                                         * compiler level     
     D srcfile               304    313                                         * src file name      
     D srclib                314    323                                         * src lib name       
     D srcmbr                324    333                                         * src file member    
     D pgmproc               334    343                                         * pgm containing     
                                                                                * procedure          
     D modproc               344    353                                         * module containing  
                                                                                * procedure          
     D srcid                 354    355B 0                                      * src id match the   
      * binary  2 (5i,0)                                                                             
                                                                                * statement number   
                                                                                * from pos 21-28     
     D srcid2                356    357B 0                                      * src id match the   
      * binary  2 (5i,0)                                                                             
                                                                                * statement number   
                                                                                * from pos 228-235   
     D curuserprf            358    367                                         * current user profi 
     D exterrorcd            368    371I 0                                      * external error cod 
      * Integer (10,0)                                                                                
     D elements              372    379I 0                                      * elements set by XM  
      * Integer (20,0)                                                                                
                                                                                *L-INTO or DATA-INTO  
     D internaljobid         380    395                                         * internal job id     
     D systemname            396    403                                         * system name         
     D unused2               404    429                                         * unused              
                                                                                                      
                                                                                                      
      /Free                                                                                           
          *INLR  = *ON;                                                                               
      /End-Free                                                                                                                                                        
RPG Code in Fully Free format for program status data structure in RPG AS400
**FREE                                                              
  //Program status data structure                                   
  //program exception available to rpg program (1 psds per module)  
dcl-ds psds1 psds;                                                  
  proc_name *proc; // module/program                                
      // 1 to 10 position, 10 chars                                 
  pgm_status *status;  // status code                               
      // 11 to 15 position, (5,0) zoned decimal                     
  pgm_prvstatus zoned(5);// Prev. status                            
  src_listing   char(8); // src. list line                          
  routine *routine; // routine                                      
     // 29 to 36 position, 8 chars                                  
     // *INIT  --> program initialization                           
     // *DETL  --> detail lines                                     
     // *GETIN --> get input record                                 
     // *TOTC  --> Total calculations                               
     // *TOTL  --> Total lines                                      
     // *DETC  --> Detail calculations                              
     // *OFL   --> Overflow lines                                   
     // *TERM  --> Program ending                                                                  
     // *ROUTINE --> name of program or procedure called (first 8 chars)                           
  parms *parms;  // no. of parms pass                                                              
     // 37 to 39 position, (3,0) zoned decimal                                                     
  excptype  char(3); //  exception type                                                            
     // CPF --> operating system exception                                                         
     // MCH --> machine exception                                                                  
  excpnum  char(4);//exception number                                                              
     // CPF --> CPF message number                                                                 
     // MCH --> MCH message number                                                                 
  reserved1 char(4);// reserved                                                                    
  workarea  char(30); // internal use by ILE RPG compiler                                          
  pgmlib  char(10);   // prgram library                                                            
  excpdata char(80);  // exception data                                                            
  excpcause char(4);  //exception that cause RNX9001                                               
  filcname char(10); // file name on whicc last file operation occur updated only when error occur 
  unused  char(6);   //unused                                                                      
  date char(8);    //date(*date format)                                                            
  yy zoned(2);    //first two digits of 4 digit year                                               
  filenametrn char(8); // file name truncate 175-184 pos above                                     
  statusinfo  char(35); // status info on last file used                      
  jobname     char(10);  // job name                                          
  username  char(10);  // user name                                           
  jobnumber zoned(6);  //job number                                           
  date2     zoned(6);  // date (udate format  pgm running (191-198 pos above  
  pgmrundate zoned(6); // date of pgm running                                 
  time zoned(6);   //  time (hhmmss) pgm running                              
  date3 char(6); // date (udate format  pgm compiled                          
  time2 char(6); // time (hhmmss) pgm compiled                                
  cmplevel char(4); // compiler level                                         
  srcfile char(10); // src file name                                          
  srclib  char(10); // src lib name                                           
  srcmbr  char(10); //src file member                                         
  pgmproc char(10); // pgm containing procedure                               
  modproc char(10); // module containing procedure                            
  srcid  bindec(2);  // src id match the statement number from pos 21-28      
  srcid2 bindec(2);  // src id match the statement number from pos 228-235    
     // binary  2 (5i,0)                                                      
  curuserprf char(10);  // current user profi                                 
  exterrorcd  int(10);  // external error cod                                 
     // Integer (10,0)                                       
  elements int(20);  //elements set by XML-INTO or DATA-INTO 
     // Integer (20,0)                                       
  internaljobid char(16); //internal job id                  
  systemname  char(8); // system name                        
  unused2 char(6); //unused                                  
end-ds;                                                      
          *INLR  = *ON;                                                                                        

compile the RPG source code using option 14 or CRTBNDRPG command.

PSDS data in debug

                             Evaluate Expression                              
                                                                              
Previous debug expressions                                                    
                                                                              
> EVAL psds1                                                                  
  PROC_NAME OF PSDS1 = 'RPGLE7    '                                           
  PGM_STATUS OF PSDS1 = 00000.                                                
  PGM_PRVSTATUS OF PSDS1 = 00000.                                             
  SRC_LISTING OF PSDS1 = '00000000'                                           
  ROUTINE OF PSDS1 = '*DETC   '                                               
  PARMS OF PSDS1 = 000.                                                       
  EXCPTYPE OF PSDS1 =    .                                                    
  EXCPNUM OF PSDS1 = '    '                                                   
  RESERVED1 OF PSDS1 = '0000'                                                 
  WORKAREA OF PSDS1 = '                              '                        
  PGMLIB OF PSDS1 = 'EASYCLASS1'                                              
  EXCPDATA OF PSDS1 =                                                         
            ....5...10...15...20...25...30...35...40...45...50...55...60 
       1   '                                                            '  
      61   '                    '                                          
  EXCPCAUSE OF PSDS1 = '    '                                              
  FILENAME OF PSDS1 = '          '                                         
  UNUSED OF PSDS1 = '      '                                               
  DATE OF PSDS1 = '12162021'                                               
  YY OF PSDS1 = 20.                                                        
  FILENAMETRN OF PSDS1 = '        '                                        
  STATUSINFO OF PSDS1 = '                                   '              
  JOBNAME OF PSDS1 = 'QPAD185722'                                          
  USERNAME OF PSDS1 = 'EASYCLASS '                                         
  JOBNUMBER OF PSDS1 = '284920'                                            
  DATE2 OF PSDS1 = 121621.                                                 
  PGMRUNDATE OF PSDS1 = 121621.                                            
    TIME OF PSDS1 = 204908.                              
  DATE3 OF PSDS1 = '122320'                            
  TIME2 OF PSDS1 = '191945'                            
  CMPLEVEL OF PSDS1 = '0001'                           
  SRCFILE OF PSDS1 = 'RPGLE     '                      
  SRCLIB OF PSDS1 = 'EASYCLASS1'                       
  SRCMBR OF PSDS1 = 'RPGLE7    '                       
  PGMPROC OF PSDS1 = 'RPGLE7    '                      
  MODPROC OF PSDS1 = 'RPGLE7    '                      
  SRCID OF PSDS1 = 6448.                               
  SRCID2 OF PSDS1 = 6448.                              
  CURUSERPRF OF PSDS1 = 'EASYCLASS '                   
  EXTERRORCD OF PSDS1 = 0                              
  ELEMENTS OF PSDS1 = 0                                
    INTERNALJOBID OF PSDS1 = ' █ █  █ xÀ%██v██'         
  SYSTEMNAME OF PSDS1 = 'PUB400  '                    
  UNUSED2 OF PSDS1 = '                          '     
 

Using PSDS with *PSSR to catch program exception in RPGLE

We will do exceptional handling in RPGLE using PSDS and PSSR subroutine.

  • PSDS with *PSSR catch program exceptions in RPG IV
  • Related Post

    1 comment

    1. It does not appear that free format allows a program information DS to be externally defined. Probably same issue with file information DS although I have not tried that yet. We have external files that defined the fields for many IBM related data structures.
    © AS400 and SQL Tricks. All rights reserved. Developed by Jago Desain