Let's add the necessary RPG logic to make use of the Customer Information window you have just redesigned.
First you create a new action subroutine (Customer Inquiry). Remember that the action subroutine for the EXIT push button in the Customer Inquiry window has already been added. However, you have to add some logic for the OK push button.
If the Customer Inquiry (CUSTINQ) window is closed, double-click on the CUSTINQ icon to open it. You are now switching from the Customer Information window to the Customer Inquiry window.
You can now add the code to read from the database file and display the data in the Customer Inquiry window. The first step is to define the DB2/400 file definition to the application.
Follow these steps:
Except for the remote keyword, all
entries are the same when compared with ILE RPG on AS/400.
Changing a Subroutine for the OK Push Button (Customer Inquiry).
You now add the logic for the press event of the OK push button on the Customer Inquiry CUSTINQ window.
Here is what the logic will do: (The steps are described below.)
Before you proceed to define the logic for this
subroutine, you may want to remove the six lines of code from the previous exercise that
allowed you to see how events and actions work. If you still want the entry field to
change color, do not remove the relevant code in this action subroutine.
Follow these steps:
*...1....+....2....+....3....+....4....+....5....+....6....+....7....+. CSRN01Factor1+++++++Opcode(E)+Factor2+++++++Result++++++++Len++D+HiLoEq C READ 'CUSTINQ'
CSRN01Factor1+++++++Opcode(E)+Factor2+++++++Result++++++++Len++D+HiLoEq C 'CUSTNO' GETATR 'TEXT' CUSTNO
CSRN01Factor1+++++++Opcode(E)+Factor2+++++++Result++++++++Len++D+HiLoEq C CUSTNO CHAIN CUSTOML3 50
CSRN01Factor1+++++++Opcode(E)+Factor2+++++++Result++++++++Len++D+HiLoEq C If *IN50 = *OFF
The 50 in the above statement corresponds to the error indicator in the CHAIN statement.
CSRN01Factor1+++++++Opcode(E)+Factor2+++++++Result++++++++Len++D+HiLoEq C SHOWWIN 'CUSTINFO'
CSRN01Factor1+++++++Opcode(E)+Factor2+++++++Result++++++++Len++D+HiLoEq C WRITE 'CUSTINFO'
CSRN01Factor1+++++++Opcode(E)+Factor2+++++++Result++++++++Len++D+HiLoEq C ENDIF
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' C Write 'CustInfo' C EndIf C ENDACT *
Adding an Action Subroutine for the OK Push Button (Customer Information)
You need to add some code to make the Customer Information window CUSTINFO invisible, because it should disappear after the OK push button is selected.
If the Customer Information window is closed, double-click on the CUSTINFO icon in the VisualAge RPG window.
Follow these steps:
CSRN01Factor1+++++++Opcode(E)+Factor2+++++++Result++++++++Len++D+HiLoEq C INFOOK BEGACT PRESS CUSTINFO C 'CUSTINFO' Setatr 0 'VISIBLE' C ENDACT
You may want to close all the design windows at this
point. To close a design window, double-click the left mouse button in the top left-hand
corner of the window. You can also close the editor in the same way.