In RPG (on IBM i / AS400), a Program Status Data Structure (PSDS) is used to automatically capture runtime information about the current job, program, errors, etc.
✅ Basic Syntax for PSDS
DCL-DS ProgramStatus PSDS;
*STATUS CHAR(5); // Error Status Code
*ROUTINE CHAR(10); // Failing Routine Name
*PARMS PACKED(3:0); // Number of parameters
*PGM CHAR(10); // Program Name
*STATUS CHAR(5); // Last error status
*OPMOD CHAR(10); // Program module
*PROC CHAR(10); // Procedure name (for ILE)
*MSGID CHAR(7); // Message ID of last error
*DATE CHAR(6); // Compilation Date
*TIME CHAR(6); // Compilation Time
*LUNAME CHAR(8); // Workstation device name
END-DS;
You can name the data structure anything, but it's marked as PSDS by the
PSDS
keyword.
📌 Commonly Used PSDS Fields
Field Name | Position | Description |
---|---|---|
*STATUS |
001–005 | Last error code (e.g., RNQ1216 ) |
*PGM |
010–019 | Program name |
*PARMS |
037–039 | Number of passed parameters |
*MSGID |
040–046 | Last message ID |
*ROUTINE |
246–255 | Routine name where error occurred |
*PROC |
281–290 | Procedure name (ILE only) |
*LUNAME |
366–373 | Workstation name |
✅ Example Use in Error Handling
DCL-DS MyPSSR PSDS;
*STATUS CHAR(5);
*PGM CHAR(10);
*MSGID CHAR(7);
*ROUTINE CHAR(10);
END-DS;
DCL-S ErrorFlag IND;
BEGSR *PSSR;
ErrorFlag = *ON;
// Optional: log or display the error using *STATUS or *MSGID
ENDSR;
🔍 Notes
-
The positions are fixed, especially in fixed-form RPG. In Free Form, you don't worry about positions explicitly but the compiler maps fields by position.
-
You can use
*STATUS
,*MSGID
, etc., directly in logic to check for errors, e.g., after file operations.