You can enhance your application that you built in the previous exercise. The run-time error problem can be fixed.
When you ran your application, a run-time error displayed when you clicked OK in the Customer Inquiry window CUSTINQ the second time. This is because the SHOWWIN operation code is executed again which attempts to Create the Customer Information window again. Since it is already created, the run-time error occurs. The run-time error displays because you have not coded any error handling in the application.
A typical technique in RPG is to use an error indicator on the operation code to handle the error, and then use a conditional statement to handle the error depending on the state of the error indicator.
The logic inside the IF condition uses the SETATR operation code to make the Customer Information window CUSTINFO visible and to give it focus if the SHOWWIN error indicator is on indicating the window is already loaded. Remember that clicking OK on the Customer Inquiry window made this window visible.
Follow these steps:
*...1....+....2....+....3....+....4....+....5....+....6....+...7....+. CSRN01Factor1+++++++Opcode(E)+Factor2+++++++Result++++++++Len++D+HiLoEq * C PSBOK BEGACT PRESS CUSTINQ * C Read 'CustInq' C CustNo Chain CustomL3 50 * C If *IN50 = *OFF C ShowWin 'CustInfo' 51 C Eval %Setatr('CustInfo':'CustInfo':'Visible')=1 C Eval %Setatr('CustInfo':'CustInfo':'Focus')=1 C Write 'CustInfo' C EndIf * C ENDACT *
Remember to save the change in the Editor before you build your application again.
Running the Application
Now you can run the improved application.
Follow these steps.