Use monitor message and on-error in ILE RPG

Example how-to use monitor and on-error (note *file on-error). Also example to convert 8 digit date to *ISO format.

Note explicitly defined indt8 is defined as packed numeric 8.0. my8date is defined as 10 alpha which expects *ISO format.

d WkDate S                            D
*
*
c                    monitor
c     *USA           Move       indt8       WkDate
c     *ISO           Move       WkDate      my8date
c                    on-error
c                    eval       WkDate = %date('1900-01-01':*ISO)
c                    eval       my8date =*zeros
c                    endmon
*
c                    monitor
c                    write      invfile                  88
c                    on-error   *file
c                    endmon

Using on-error with no parameters will monitor for all error messages (similar to CPF0000 in your CL procedures).

It is also possible to monitor for specific status errors. *Program (program-error status codes) range is 00100 to 00999. *File (file-error status codes) range is 01000 to 09999.

c                    monitor
c                    on-error   00202

One caveat that might be obvious but one should use 'monitor' judiciously because many errors need to be brought to the attention of the programmer and not simply ignored. Once the error is known the programmer may then want to add code to handle the situation more gracefully.


You can research the actual INFDS codes using the IBM Knowledge Center:

http://www-01.ibm.com/support/knowledgecenter/ssw_ibm_i_61/rzasd/sc092508152.htm  (6.1)

http://www-01.ibm.com/support/knowledgecenter/ssw_ibm_i_71/rzasd/sc092508135.htm  (7.1)