Error handling
This looks good. If you have time left, you can add some error handling.
Handling a record not found condition
The feedback parameter will tell you whether the record access for the customer number has been successful. If the customer exists in the database, it returns a 0. Otherwise, the customer number will be returned.
Return to the pagehandler code:
-
Right-click the white space in the page designer and select Edit Page Code.
Add the if statement as shown in Listing 3:
-
You compare variable feedback to zero
-
If it is not zero
-
Use the built-in
seterror function to write an error message. You concatenate the wrong customer number in the error message.
-
You set the data structure
cds to blank, so older output gets erased from the page.
Listing 3. Add the if statement
call "GETDATAE" (cinput, cds, feedback);
if (feedback != "0")
SysLib.seterror("Customer number " + cinput + " not valid"0;
cds = " ";
end
|
The error message displays in the message control that has been added by default to the page when you added the customer number input field, as shown in Figure 43.
-
Save the changes.
-
Run the application again.
Figure 43. Error message
Debugging the RPG program
If there are problems with calling the program on IBM I, you can use the built-in workbench integrated debugger to debug the RPG program when it gets invoked from EGL.
To do this, perform the following steps, as shown in Figure 44.
-
Switch to the Remote System Explorer perspective.
-
Expand the connection to the System i5 server, or create a new connection.
-
Create a filter for the EGLLABBV7xx library.
-
Expand the EGLLABV7xx library.
-
Locate the GETDATAE program.
-
Right-click the program and f select Debug (Service Entry) > Set Service Entry point.
Figure 44. Prepare to debug the program
You will see a message telling you that the Service entry Point is set successfully, as shown in Figure 45.
-
Click OK.
Figure 45. iSeries Debug Message
In the RSE perspective, a new view gets added. This view shows all service entry points on the system, as shown in Figure 46, and it also allows you to work with these Service Entry points.
-
Go back to the Web perspective
Now run the CALLEGL001R.jsp again.
-
Enter a valid customer number, such as
0010200.
-
Click the callRPG button.
Figure 46. View showing service points
The debug perspective will display with the RPG source loaded.
-
Set a breakpoint where you think it is needed (in Figure 47, it is set after the
chain statement). To set a breakpoint, double-click in the grey column next to the line numbers.
-
Click the debugger run button.
Figure 47. Set a breakpoint
If the chain was successful, the data will show in the variable monitor, as shown in Figure 48.
-
Click the run button again to end the program.
Figure 48. Variables view
You could also debug the EGL source by performing these steps.
-
Set a break point in the CALLEGL001R.egl source, as shown in Figure 49. Open the source in the editor, which is integrated with the debugger and allows you to set breakpoints.
Figure 49. Set a breakpoint in the source
-
Then start it like you normally do, but instead of selecting Run on Server, perform the following steps:
-
Select Debug on server
-
Enter a customer number
-
Click the CallRPG button
The workbench switches to the debug perspective, as shown in Figure 50.
Figure 50. Debug perspective
The perspective looks similar to what you've seen before, but now it shows the EGL source.
-
If the Service entry point is still active, and if you specify run in the EGL debug session, the debug perspective will show the RPG debug views, as shown in Figure 51.
Figure 51. Debug perspective
You have completed this lab exercise.
|