In this section, you apply a few of the things you just learned to add a dynamic browse to the procedure with the dynamic temp-table.

To extend the sample procedure with a dynamic browse:

  1. Open the h-testDynTT.p procedure and save a new version of it as h-testDynBrowse.p.
  2. Add a variable definition at the top for a browse handle and also a frame definition for a frame to hold the browse:
    DEFINE VARIABLE hBrowse AS HANDLE NO-UNDO.
    DEFINE FRAME BrowseFrame WITH SIZE 80 BY 10.
  3. Remove the REPEAT block from the procedure that walks through the temp-table records using the dynamic query and displays them. Instead, you display them in a dynamic browse.
  4. Add a CREATE BROWSE statement after the QUERY-PREPARE. It will be the only object in the frame, so it can be at ROW 1 and COLUMN 1. Its WIDTH needs to be slightly less than the frame to allow for the frame border. Parent it to the frame and assign the dynamic query to it. Make it SENSITIVE and VISIBLE, and give it SEPARATORS between columns but no ROW-MARKERS at the beginning of the row:
    CREATE BROWSE hBrowse
      ASSIGN ROW = 1 COL = 1
        WIDTH = 79 DOWN = 10
        FRAME = FRAME BrowseFrame:HANDLE
        QUERY = hQuery
        SENSITIVE = YES
        SEPARATORS = YES
        ROW-MARKERS = NO
        VISIBLE = YES.
  5. To get started, try adding all the columns from the temp-table buffer except for a handful that you exclude, using this statement:
    hBrowse:ADD-COLUMNS-FROM(hTTBuf,
      "SalesRep,Country,address,Address2,State").

    Note that you cannot pass the dynamic temp-table name as the table identifier for this method. Even though you do give the temp-table a name when you prepare it, that name is not available to the method. You must pass the handle to a buffer for the temp-table, either its DEFAULT-BUFFER-HANDLE or another buffer you defined for it.

  6. Enable everything in the frame and wait for the user to close the window so that the user can manipulate the browse when the window comes up. Add these lines to the end of the procedure:
    ENABLE ALL WITH FRAME BrowseFrame.
    WAIT-FOR CLOSE OF CURRENT-WINDOW.
  7. Run the procedure. You should see all the Customers in New Hampshire with all the fields except the ones you excluded:

To try adding specific columns to the browse:

  1. Remove the ADD-COLUMNS-FROM method and instead add these four statements to add these four columns to the empty browse:
    hBrowse:ADD-LIKE-COLUMN(hTTBuf:BUFFER-FIELD("Sequence")).
    hBrowse:ADD-LIKE-COLUMN(hTTBuf:BUFFER-FIELD("CustNum")).
    hBrowse:ADD-LIKE-COLUMN(hTTBuf:BUFFER-FIELD("Name")).
    hBrowse:ADD-LIKE-COLUMN(hTTBuf:BUFFER-FIELD("RepName")).
  2. Run the procedure again. You should see just the four columns you specified: