Bryan's RPG IV Journal
Error handling with QCMDEXC
Q: In your RPG IV Modules, Procedures & Service Programs presentation, there is an example showing how to use QCMDEXC in a prototype. If an error occurred while executing this code is there a way to handle it internally?
A: Here's an example of catching an error in this scenario...
If you wanted to catch a more specific error, positions 40-46 of the program status data structure holds the error message identifier:
A: Here's an example of catching an error in this scenario...
D Gocmd PR Extpgm('QCMDEXC')
D
3000 Const Options(*Varsize)
D 15 5 Const
D Cmd S 3000 Varying
/Free
Monitor;
Cmd = 'BAD COMMAND';
Gocmd(Cmd:%Len(Cmd));
On-error;
Dsply %Status; // Status = 0202 Command failed
Endmon;
/End-freeYou could also use the (e) extender on the CALLP to Gocmd, instead of using Monitor.If you wanted to catch a more specific error, positions 40-46 of the program status data structure holds the error message identifier:
D SDS Extpgm('QCMDEXC')
D Errmsgid 40 46Or, you could to receive a message from the command, maybe using an API in a wrapper procedure.
Log of Journal Entries |
|
Use this scrollable blog map to view other journal entries: |
|
| It is your responsibility to ensure procedures, techniques, and code used from this website are accurate and appropriate for your installation. No warranty or support is implied or expressed. |
![]() |
| Privacy and Email Policy |
| AS/400®, eServer, i5/OS, IBM i, Integrated Language Environment®, iSeries, OS/400®, RPG/400®, System i5, VisualAge®, and WebSphere® are trademarks of IBM Corporation. Note: IBM® System i is the latest member of the family of eServer iSeries. This site might refer to System i as System i5, iSeries, or AS/400. |
|
If you are having trouble navigating the menu at the top of this page, you may use the following scrollable site map instead: |
|
|











International visitors: