4.4 Adding RPG Logic to the Application

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:

  1. Select Project from the VisualAge RPG window.
  2. Select the Edit source code menu choice to invoke the editor.
  3. Select Edit from the menu bar of the editor, and then select Locate.
  4. From the submenu, select the Program spec choice.
  5. Position your mouse cursor on the H spec.
  6. Select Edit from the editor menu bar, and then select Insert Prompt.
  7. Select the Select option.
  8. Select the F-File description radio button. Click OK. The prompt window for an F-File description appears.
  9. Enter the following values:
  10. Except for the remote keyword, all entries are the same when compared with ILE RPG on AS/400.

  11. Select OK to create an F-File description and then select Cancel to close the F-File description window.
  12. To save your input, select File from the menu bar, and then select Save.
  13. Close the editor by double-clicking the left mouse button in the upper left-hand corner of the editor window.

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.)

  1. Retrieve data from a field in the first window, Customer Inquiry.
  2. Retrieve data from the database file.
  3. Display the second window, Customer Information.
  4. Display data from the database file in the second window, Customer Information.

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. Using the pop-up menu from the OK push button bring up the action subroutine for the PRESS event. You should see the code you created in an earlier exercise that changed the Entry field color.
  2. To retrieve the Customer Number entered in the CUSTNO Entry field you can define a READ operation or a GETATR operation for the Text attribute of the CUSTNO field. Only code one of these operations in your action subroutine.
  3. After obtaining the value of the CUSTNO field, you now have to chain to the database file CUSTOML3. Add the CHAIN statement, and place an indicator value of 50 in the HI value column. You may want to use F4 to help you move to the right column for this indicator.
  4. 
    CSRN01Factor1+++++++Opcode(E)+Factor2+++++++Result++++++++Len++D+HiLoEq
    C     CUSTNO        CHAIN     CUSTOML3                           50
    
  5. You may want to add a conditional statement like the following:
  6. 
    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.

  7. You have to code a SHOWWIN operation code to display your second window, Customer Information. The code for this is:
  8. 
    CSRN01Factor1+++++++Opcode(E)+Factor2+++++++Result++++++++Len++D+HiLoEq
    C                   SHOWWIN   'CUSTINFO'
    
  9. You also have to retrieve data from the RPG program to display it in the Customer Information window CUSTINFO. The code for this is:
  10. 
    CSRN01Factor1+++++++Opcode(E)+Factor2+++++++Result++++++++Len++D+HiLoEq
    C                   WRITE     'CUSTINFO'
    
  11. If you included an IF statement for checking the CHAIN indicator, you must add an ENDIF statement to your code.
  12. 
    CSRN01Factor1+++++++Opcode(E)+Factor2+++++++Result++++++++Len++D+HiLoEq
    C                   ENDIF
    
  13. To save your work, select File from the menu bar, and then select Save. Your completed code should look like the following:
  14. 
    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
     *
    
  15. Close the editor by double-clicking the left mouse button in the upper left-hand corner of the Editor window.

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:

  1. Add code to the PRESS event for the OK push button in the Customer Information window CUSTINFO.
  2. Add a statement to SET the VISIBLE ATTRIBUTE for the Customer Information window CUSTINFO to 0.
  3. 
    CSRN01Factor1+++++++Opcode(E)+Factor2+++++++Result++++++++Len++D+HiLoEq
    C     INFOOK        BEGACT    PRESS         CUSTINFO
    C     'CUSTINFO'    Setatr    0             'VISIBLE'
    C                   ENDACT
    
  4. Save this action subroutine.

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.

Click on to indicate that you've done all the steps.