7.3 Setting Focus for the Subfile Component

If you leave the code as is, run the Customer Inquiry application, click Find, the Customer List subfile window of the COMPLIST component displays behind the other windows. To bring this window to the foreground, you give it FOCUS.

Follow these steps:

  1. To give the Customer List subfile window focus, you use another Component Reference part in the component CUSTINQ to set the VISIBLE and FOCUS attributes for the Customer List window CUSTLIST.
  2. Now double-click on this Component Reference part to open the Properties notebook and make the following changes:
  3. Click OK to save and close the Properties notebook.

This completes the definition for the Component Reference part. Now you need to complete the logic. You need to add an indicator that tells the Customer Inquiry application that the component COMPLIST is already started and to make the Customer List window CUSTLIST in component COMPLIST visible and give it focus.

You need to add some code to the action subroutine that is linked to the Find push button on the Customer Inquiry window CUSTINQ in the component Customer Inquiry CUSTINQ.

Follow these steps:

  1. Use the editor and locate the PRESS Event action subroutine for the Find push button.
  2. Add the following code to set the window CUSTLIST in component COMPLIST visible:
  3. CSRN01Factor1+++++++Opcode(E)+Factor2+++++++Result++++++++Len++D+HiLoEq
    C     'CRP1'        SETATR    'VISIBLE'     'REFATTR'
    C     'CRP1'        SETATR    '1'           'ATTRVALUE'
    
  4. To give the window focus add 2 more statements:
  5. CSRN01Factor1+++++++Opcode(E)+Factor2+++++++Result++++++++Len++D+HiLoEq
    C    'CRP1'         SETATR    'FOCUS'       'REFATTR'
    C    'CRP1'         SETATR    '1'           'ATTRVALUE'
    

Remember to save your source in the Editor.

Building and Running the Completed Application

Now build your application and run it.

Follow these steps:

  1. Now build the project by selecting Project > Build > Windows NT/95/98. If you receive any errors, you will need to fix the errors before you can continue.
  2. Click on the run icon . Enter your AS/400 user ID and password. The Customer Inquiry window appears.
  3. Click Find. The Select Customer window appears.
  4. Select and then double click on one of the records. The selected customer number should be in the Customer Number CUSTNO Entry field of the Customer Inquiry window.
  5. Click OK. The Customer Information window appears with the customer information. Click OK.
  6. On the Customer Inquiry Window, select File then Exit to end the application.
  7. Close the GUI Designer. Close any other VisualAge RPG windows that may still be open.
  8. Click on to indicate that you've done all the steps.

    This completes Exercise 7. You have a complete runnable application. Since this is your last exercise, before you close the tutorial, we recommend you do the Quiz.