Browse not displaying data on 1st click

phat.andz

New Member
Hi all,

Secondary browse showing no results on first click

I'm writing a simple little tool that queries our Progress 9.1c db for certain information.

It takes a user input (in frame 1), runs a query and shows results in a read-only browse (in frame 2).

Then, if the user clicks on a line in this primary 'browse', it runs a secondary query based on data in the first, and displays the results in a secondary browse (frame 3).

My problem is that the secondary browse shows no results the first time the user clicks on a line in the primary. However, it shows the expected results the second time that line is clicked upon.

It doesn't seem to matter which trigger event I use, this behaviour does not change. The only way I can fool the user into thinking it works properly is by running the same query twice in the trigger block, separated only by an ENABLE ALL for the appropriate frame. This seems like poor programming however, so I must be doing something wrong.

Would someone be kind enough to take a quick look at the following snippet of code and see if there is an glaring error on my part? Many thanks to anyone who reads this post :biggrin:


<code snippet>

/* Query1/Brwse1/Brwse1-Frame ****************************/

DEFINE QUERY Query1 FOR Table1 FIELDS (Fields),
Table2 FIELDS (Fields)
SCROLLING.

DEFINE BROWSE Brwse1
QUERY Query1 NO-LOCK NO-WAIT
DISPLAY Table1.Field FORMAT "x(9)" LABEL "ColumnLabel"
Table2.Field FORMAT "x(9)" LABEL "ColumnLabel"
WITH SIZE 128 BY 6
EXPANDABLE
LABEL-FONT 17
SEPARATORS.


ASSIGN BROWSE Brwse1:pOPUP-MENU = MENU Brwse1-Menu:Handle.

DEFINE FRAME Brwse1-Frame
Brwse1
WITH SIDE-LABELS
AT ROW 8 COL 1
SIZE 128 BY 6
FONT 4
NO-BOX.

/* Query2/Brwse2/Brwse2-Frame ****************************/

/* Define buffers for the 2 tables re-used in Query2, to avoid conflicts with Query1 */
DEFINE BUFFER Table1a FOR Table1.
DEFINE BUFFER Table2a FOR Table2.

DEFINE QUERY Query2 FOR Table1a FIELDS (Fields),
Table2a FIELDS (Fields)
SCROLLING.

DEFINE BROWSE Brwse2
QUERY Query2 NO-LOCK NO-WAIT
DISPLAY Table1.Field FORMAT "x(9)" LABEL "ColumnLabel"
Table2.Field FORMAT "x(9)" LABEL "ColumnLabel"

WITH SIZE 128 BY 6
EXPANDABLE
MULTIPLE
LABEL-FONT 17
SEPARATORS.

ASSIGN BROWSE Brwse2:pOPUP-MENU = MENU Brwse2-Menu:Handle.

DEFINE FRAME Brwse2-Frame
Brwse2
WITH SIDE-LABELS
AT ROW 16 COL 1
SIZE 128 BY 6
FONT 4
NO-BOX.


...

/* Control Triggers *************************************************************************/

...


ON RETURN OF txtSrchVal <user input text box>
DO:
DEFINE VARIABLE lReturnValue AS LOGICAL.
txtSrchVal = txtSrchVal:SCREEN-VALUE.

OPEN QUERY Query1 FOR
EACH Table1
WHERE Table1.Field1 = "Ripley"
AND
Table1.Field2 = INTEGER(txtSrchVal) NO-LOCK,
EACH Table2 LEFT OUTER-JOIN OF
Table1
WHERE Table2.Field1 = Table1.Field1 NO-LOCK

BY
Table1.Field1
BY Table1.Field2.

ENABLE ALL WITH FRAME Brwse1-Frame.
ENABLE ALL WITH FRAME DEFAULT-FRAME.
CURRENT-WINDOW:TITLE = "Sales Order Mini-tracker" + " - " + txtSrchVal.

APPLY "TAB":U TO btnSrchVal.
lReturnValue = winRB:LOAD-MOUSE-POINTER("ARROW").
END.

...

ON LEFT-MOUSE-CLICK OF BROWSE Brwse1

DO:

EACH Table1a
WHERE Table1a.Field1 = Table1.Field2
NO-LOCK,
EACH Table2a LEFT OUTER-JOIN OF
Table1a
WHERE Table2a.Field1 = Table1a.Field1 NO-LOCK

BY
Table1a.Field1
BY Table1a.Field2.

ENABLE ALL WITH FRAME Brwse2-Frame.

END.




Thanks again, and have a very happy Christmas holiday :)

Andz.
 

gcampbell

Member
I think that you want to use the 'VALUE-CHANGED' event on Browse-1 to re-open query-2. An example from an AppBuilder produced code would look like:

ON VALUE-CHANGED OF BROWSE-1 IN FRAME DEFAULT-FRAME DO:
{&OPEN-QUERY-BROWSE-2}
END.

Where {&OPEN-QUERY-BROWSE-2} would basically look like:

OPEN QUERY BROWSE-2 FOR EACH Invoice WHERE Invoice.CustNum = Customer.CustNum NO-LOCK INDEXED-REPOSITION.

Later,
Gordon
 

phat.andz

New Member
Hi Gordon,

Thanks for your response. I accidenatlly cut out the line in my code that opens 'query2', doh!! The code snippet now reads as shown at the end of this post.

Anyway, I tried using the VALUE-CHANGED trigger as you suggest, but the behaviour persists (THIS-BEHAVIOUR:pERSISTENT = YES!). It just doesn't make sense to me, it doesn't work on the first click but does the second.

Any other thoughts would be huuuugely appreciated!

Andz.




<code snippet>

/* Query1/Brwse1/Brwse1-Frame ****************************/

DEFINE QUERY Query1 FOR Table1 FIELDS (Fields),
Table2 FIELDS (Fields)
SCROLLING.

DEFINE BROWSE Brwse1
QUERY Query1 NO-LOCK NO-WAIT
DISPLAY Table1.Field FORMAT "x(9)" LABEL "ColumnLabel"
Table2.Field FORMAT "x(9)" LABEL "ColumnLabel"
WITH SIZE 128 BY 6
EXPANDABLE
LABEL-FONT 17
SEPARATORS.


ASSIGN BROWSE Brwse1:pOPUP-MENU = MENU Brwse1-Menu:Handle.

DEFINE FRAME Brwse1-Frame
Brwse1
WITH SIDE-LABELS
AT ROW 8 COL 1
SIZE 128 BY 6
FONT 4
NO-BOX.

/* Query2/Brwse2/Brwse2-Frame ****************************/

/* Define buffers for the 2 tables re-used in Query2, to avoid conflicts with Query1 */
DEFINE BUFFER Table1a FOR Table1.
DEFINE BUFFER Table2a FOR Table2.

DEFINE QUERY Query2 FOR Table1a FIELDS (Fields),
Table2a FIELDS (Fields)
SCROLLING.

DEFINE BROWSE Brwse2
QUERY Query2 NO-LOCK NO-WAIT
DISPLAY Table1.Field FORMAT "x(9)" LABEL "ColumnLabel"
Table2.Field FORMAT "x(9)" LABEL "ColumnLabel"

WITH SIZE 128 BY 6
EXPANDABLE
MULTIPLE
LABEL-FONT 17
SEPARATORS.

ASSIGN BROWSE Brwse2:pOPUP-MENU = MENU Brwse2-Menu:Handle.

DEFINE FRAME Brwse2-Frame
Brwse2
WITH SIDE-LABELS
AT ROW 16 COL 1
SIZE 128 BY 6
FONT 4
NO-BOX.


...

/* Control Triggers *************************************************************************/

...


ON RETURN OF txtSrchVal <user input text box>
DO:
DEFINE VARIABLE lReturnValue AS LOGICAL.
txtSrchVal = txtSrchVal:SCREEN-VALUE.

OPEN QUERY Query1 FOR
EACH Table1
WHERE Table1.Field1 = "Ripley"
AND
Table1.Field2 = INTEGER(txtSrchVal) NO-LOCK,
EACH Table2 LEFT OUTER-JOIN OF
Table1
WHERE Table2.Field1 = Table1.Field1 NO-LOCK

BY
Table1.Field1
BY Table1.Field2.

ENABLE ALL WITH FRAME Brwse1-Frame.
ENABLE ALL WITH FRAME DEFAULT-FRAME.
CURRENT-WINDOW:TITLE = "Sales Order Mini-tracker" + " - " + txtSrchVal.

APPLY "TAB":U TO btnSrchVal.
lReturnValue = winRB:LOAD-MOUSE-POINTER("ARROW").
END.

...

ON LEFT-MOUSE-CLICK OF BROWSE Brwse1

DO:

OPEN QUERY Query2 FOR
EACH Table1a
WHERE Table1a.Field1 = Table1.Field2
NO-LOCK,
EACH Table2a LEFT OUTER-JOIN OF
Table1a
WHERE Table2a.Field1 = Table1a.Field1 NO-LOCK

BY
Table1a.Field1
BY Table1a.Field2.

ENABLE ALL WITH FRAME Brwse2-Frame.

END.



 

gcampbell

Member
The following code illustrates how to do what you want to do. I'm using 9.1E but the same logic should apply. For this example, when running, enter 'U' and hit the 'go' button. You will see that both browsers are automatically populated. By changing the customer row, the invoice browser is also automatically updated.

Later,
Gordon


&ANALYZE-SUSPEND _VERSION-NUMBER UIB_v9r12 GUI
&ANALYZE-RESUME
/* Connected Databases
sports2000 PROGRESS
*/
&Scoped-define WINDOW-NAME C-Win
&ANALYZE-SUSPEND _UIB-CODE-BLOCK _CUSTOM _DEFINITIONS C-Win
/*------------------------------------------------------------------------
File:
Description:
Input Parameters:
<none>
Output Parameters:
<none>
Author:
Created:
------------------------------------------------------------------------*/
/* This .W file was created with the Progress AppBuilder. */
/*----------------------------------------------------------------------*/
/* Create an unnamed pool to store all the widgets created
by this procedure. This is a good default which assures
that this procedure's triggers and internal procedures
will execute in this procedure's storage, and that proper
cleanup will occur on deletion of the procedure. */
CREATE WIDGET-POOL.
/* *************************** Definitions ************************** */
/* Parameters Definitions --- */
/* Local Variable Definitions --- */
/* _UIB-CODE-BLOCK-END */
&ANALYZE-RESUME

&ANALYZE-SUSPEND _UIB-PREPROCESSOR-BLOCK
/* ******************** Preprocessor Definitions ******************** */
&Scoped-define PROCEDURE-TYPE Window
&Scoped-define DB-AWARE no
/* Name of first Frame and/or Browse and/or first Query */
&Scoped-define FRAME-NAME DEFAULT-FRAME
&Scoped-define BROWSE-NAME br-cust
/* Internal Tables (found by Frame, Query & Browse Queries) */
&Scoped-define INTERNAL-TABLES Customer Invoice
/* Definitions for BROWSE br-cust */
&Scoped-define FIELDS-IN-QUERY-br-cust Customer.CustNum Customer.Name
&Scoped-define ENABLED-FIELDS-IN-QUERY-br-cust
&Scoped-define QUERY-STRING-br-cust FOR EACH Customer ~
WHERE Customer.Name BEGINS cCustName NO-LOCK INDEXED-REPOSITION
&Scoped-define OPEN-QUERY-br-cust OPEN QUERY br-cust FOR EACH Customer ~
WHERE Customer.Name BEGINS cCustName NO-LOCK INDEXED-REPOSITION.
&Scoped-define TABLES-IN-QUERY-br-cust Customer
&Scoped-define FIRST-TABLE-IN-QUERY-br-cust Customer

/* Definitions for BROWSE br-invoice */
&Scoped-define FIELDS-IN-QUERY-br-invoice Invoice.Invoicenum ~
Invoice.InvoiceDate Invoice.OrderNum Invoice.Amount Invoice.TotalPaid
&Scoped-define ENABLED-FIELDS-IN-QUERY-br-invoice
&Scoped-define QUERY-STRING-br-invoice FOR EACH Invoice ~
WHERE Invoice.CustNum = Customer.CustNum NO-LOCK INDEXED-REPOSITION
&Scoped-define OPEN-QUERY-br-invoice OPEN QUERY br-invoice FOR EACH Invoice ~
WHERE Invoice.CustNum = Customer.CustNum NO-LOCK INDEXED-REPOSITION.
&Scoped-define TABLES-IN-QUERY-br-invoice Invoice
&Scoped-define FIRST-TABLE-IN-QUERY-br-invoice Invoice

/* Definitions for FRAME DEFAULT-FRAME */
/* Standard List Definitions */
&Scoped-Define ENABLED-OBJECTS btn-Go cCustName br-cust br-invoice
&Scoped-Define DISPLAYED-OBJECTS cCustName
/* Custom List Definitions */
/* List-1,List-2,List-3,List-4,List-5,List-6 */
/* _UIB-PREPROCESSOR-BLOCK-END */
&ANALYZE-RESUME


/* *********************** Control Definitions ********************** */
/* Define the widget handle for the window */
DEFINE VAR C-Win AS WIDGET-HANDLE NO-UNDO.
/* Definitions of the field level widgets */
DEFINE BUTTON btn-Go
LABEL "Go"
SIZE 7.4 BY 1.14.
DEFINE VARIABLE cCustName AS CHARACTER FORMAT "X(256)":U
LABEL "Filter Where Name BEGINS"
VIEW-AS FILL-IN
SIZE 14 BY 1 NO-UNDO.
/* Query definitions */
&ANALYZE-SUSPEND
DEFINE QUERY br-cust FOR
Customer SCROLLING.
DEFINE QUERY br-invoice FOR
Invoice SCROLLING.
&ANALYZE-RESUME
/* Browse definitions */
DEFINE BROWSE br-cust
&ANALYZE-SUSPEND _UIB-CODE-BLOCK _DISPLAY-FIELDS br-cust C-Win _STRUCTURED
QUERY br-cust NO-LOCK DISPLAY
Customer.CustNum FORMAT ">>>>9":U
Customer.Name FORMAT "x(30)":U WIDTH 56
/* _UIB-CODE-BLOCK-END */
&ANALYZE-RESUME
WITH NO-ROW-MARKERS SEPARATORS SIZE 70.6 BY 5.05 ROW-HEIGHT-CHARS .62 EXPANDABLE.
DEFINE BROWSE br-invoice
&ANALYZE-SUSPEND _UIB-CODE-BLOCK _DISPLAY-FIELDS br-invoice C-Win _STRUCTURED
QUERY br-invoice NO-LOCK DISPLAY
Invoice.Invoicenum FORMAT "zzzzzzzzz9":U
Invoice.InvoiceDate FORMAT "99/99/9999":U
Invoice.OrderNum FORMAT "zzzzzzzzz9":U
Invoice.Amount FORMAT "->>,>>9.99":U
Invoice.TotalPaid FORMAT "->>,>>9.99":U WIDTH 18.2
/* _UIB-CODE-BLOCK-END */
&ANALYZE-RESUME
WITH NO-ROW-MARKERS SEPARATORS SIZE 70.6 BY 7.29 EXPANDABLE.

/* ************************ Frame Definitions *********************** */
DEFINE FRAME DEFAULT-FRAME
btn-Go AT ROW 2.14 COL 49.4
cCustName AT ROW 2.19 COL 32.6 COLON-ALIGNED
br-cust AT ROW 3.52 COL 6.6
br-invoice AT ROW 9 COL 6.6
WITH 1 DOWN NO-BOX KEEP-TAB-ORDER OVERLAY
SIDE-LABELS NO-UNDERLINE THREE-D
AT COL 1 ROW 1
SIZE 80 BY 16.

/* *********************** Procedure Settings ************************ */
&ANALYZE-SUSPEND _PROCEDURE-SETTINGS
/* Settings for THIS-PROCEDURE
Type: Window
Allow: Basic,Browse,DB-Fields,Window,Query
Other Settings: COMPILE
*/
&ANALYZE-RESUME _END-PROCEDURE-SETTINGS
/* ************************* Create Window ************************** */
&ANALYZE-SUSPEND _CREATE-WINDOW
IF SESSION:DISPLAY-TYPE = "GUI":U THEN
CREATE WINDOW C-Win ASSIGN
HIDDEN = YES
TITLE = "<insert window title>"
HEIGHT = 16
WIDTH = 80
MAX-HEIGHT = 16
MAX-WIDTH = 80
VIRTUAL-HEIGHT = 16
VIRTUAL-WIDTH = 80
RESIZE = yes
SCROLL-BARS = no
STATUS-AREA = no
BGCOLOR = ?
FGCOLOR = ?
KEEP-FRAME-Z-ORDER = yes
THREE-D = yes
MESSAGE-AREA = no
SENSITIVE = yes.
ELSE {&WINDOW-NAME} = CURRENT-WINDOW.
/* END WINDOW DEFINITION */
&ANALYZE-RESUME


/* *********** Runtime Attributes and AppBuilder Settings *********** */
&ANALYZE-SUSPEND _RUN-TIME-ATTRIBUTES
/* SETTINGS FOR WINDOW C-Win
VISIBLE,,RUN-PERSISTENT */
/* SETTINGS FOR FRAME DEFAULT-FRAME
*/
/* BROWSE-TAB br-cust cCustName DEFAULT-FRAME */
/* BROWSE-TAB br-invoice br-cust DEFAULT-FRAME */
IF SESSION:DISPLAY-TYPE = "GUI":U AND VALID-HANDLE(C-Win)
THEN C-Win:HIDDEN = no.
/* _RUN-TIME-ATTRIBUTES-END */
&ANALYZE-RESUME

/* Setting information for Queries and Browse Widgets fields */
&ANALYZE-SUSPEND _QUERY-BLOCK BROWSE br-cust
/* Query rebuild information for BROWSE br-cust
_TblList = "sports2000.Customer"
_Options = "NO-LOCK INDEXED-REPOSITION"
_Where[1] = "Customer.Name BEGINS cCustName"
_FldNameList[1] = sports2000.Customer.CustNum
_FldNameList[2] > sports2000.Customer.Name
"Name" ? ? "character" ? ? ? ? ? ? no ? no no "56" yes no no "U" "" ""
_Query is NOT OPENED
*/ /* BROWSE br-cust */
&ANALYZE-RESUME
&ANALYZE-SUSPEND _QUERY-BLOCK BROWSE br-invoice
/* Query rebuild information for BROWSE br-invoice
_TblList = "sports2000.Invoice"
_Options = "NO-LOCK INDEXED-REPOSITION"
_Where[1] = "Invoice.CustNum = Customer.CustNum"
_FldNameList[1] = sports2000.Invoice.Invoicenum
_FldNameList[2] = sports2000.Invoice.InvoiceDate
_FldNameList[3] = sports2000.Invoice.OrderNum
_FldNameList[4] = sports2000.Invoice.Amount
_FldNameList[5] > sports2000.Invoice.TotalPaid
"TotalPaid" ? ? "decimal" ? ? ? ? ? ? no ? no no "18.2" yes no no "U" "" ""
_Query is NOT OPENED
*/ /* BROWSE br-invoice */
&ANALYZE-RESUME



/* ************************ Control Triggers ************************ */
&Scoped-define SELF-NAME C-Win
&ANALYZE-SUSPEND _UIB-CODE-BLOCK _CONTROL C-Win C-Win
ON END-ERROR OF C-Win /* <insert window title> */
OR ENDKEY OF {&WINDOW-NAME} ANYWHERE DO:
/* This case occurs when the user presses the "Esc" key.
In a persistently run window, just ignore this. If we did not, the
application would exit. */
IF THIS-PROCEDURE:pERSISTENT THEN RETURN NO-APPLY.
END.
/* _UIB-CODE-BLOCK-END */
&ANALYZE-RESUME

&ANALYZE-SUSPEND _UIB-CODE-BLOCK _CONTROL C-Win C-Win
ON WINDOW-CLOSE OF C-Win /* <insert window title> */
DO:
/* This event will close the window and terminate the procedure. */
APPLY "CLOSE":U TO THIS-PROCEDURE.
RETURN NO-APPLY.
END.
/* _UIB-CODE-BLOCK-END */
&ANALYZE-RESUME

&Scoped-define BROWSE-NAME br-cust
&Scoped-define SELF-NAME br-cust
&ANALYZE-SUSPEND _UIB-CODE-BLOCK _CONTROL br-cust C-Win
ON VALUE-CHANGED OF br-cust IN FRAME DEFAULT-FRAME /* Browse 1 */
DO:
{&OPEN-QUERY-br-invoice}
END.
/* _UIB-CODE-BLOCK-END */
&ANALYZE-RESUME

&Scoped-define SELF-NAME btn-Go
&ANALYZE-SUSPEND _UIB-CODE-BLOCK _CONTROL btn-Go C-Win
ON CHOOSE OF btn-Go IN FRAME DEFAULT-FRAME /* Go */
DO:
ASSIGN FRAME {&FRAME-NAME}
cCustName.
{&OPEN-QUERY-br-Cust}
{&OPEN-QUERY-br-Invoice}
END.
/* _UIB-CODE-BLOCK-END */
&ANALYZE-RESUME

&UNDEFINE SELF-NAME
&ANALYZE-SUSPEND _UIB-CODE-BLOCK _CUSTOM _MAIN-BLOCK C-Win

/* *************************** Main Block *************************** */
/* Set CURRENT-WINDOW: this will parent dialog-boxes and frames. */
ASSIGN CURRENT-WINDOW = {&WINDOW-NAME}
THIS-PROCEDURE:CURRENT-WINDOW = {&WINDOW-NAME}.
/* The CLOSE event can be used from inside or outside the procedure to */
/* terminate it. */
ON CLOSE OF THIS-PROCEDURE
RUN disable_UI.
/* Best default for GUI applications is... */
PAUSE 0 BEFORE-HIDE.
/* Now enable the interface and wait for the exit condition. */
/* (NOTE: handle ERROR and END-KEY so cleanup code will always fire. */
MAIN-BLOCK:
DO ON ERROR UNDO MAIN-BLOCK, LEAVE MAIN-BLOCK
ON END-KEY UNDO MAIN-BLOCK, LEAVE MAIN-BLOCK:
RUN enable_UI.
IF NOT THIS-PROCEDURE:pERSISTENT THEN
WAIT-FOR CLOSE OF THIS-PROCEDURE.
END.
/* _UIB-CODE-BLOCK-END */
&ANALYZE-RESUME

/* ********************** Internal Procedures *********************** */
&ANALYZE-SUSPEND _UIB-CODE-BLOCK _PROCEDURE disable_UI C-Win _DEFAULT-DISABLE
PROCEDURE disable_UI :
/*------------------------------------------------------------------------------
Purpose: DISABLE the User Interface
Parameters: <none>
Notes: Here we clean-up the user-interface by deleting
dynamic widgets we have created and/or hide
frames. This procedure is usually called when
we are ready to "clean-up" after running.
------------------------------------------------------------------------------*/
/* Delete the WINDOW we created */
IF SESSION:DISPLAY-TYPE = "GUI":U AND VALID-HANDLE(C-Win)
THEN DELETE WIDGET C-Win.
IF THIS-PROCEDURE:pERSISTENT THEN DELETE PROCEDURE THIS-PROCEDURE.
END PROCEDURE.
/* _UIB-CODE-BLOCK-END */
&ANALYZE-RESUME
&ANALYZE-SUSPEND _UIB-CODE-BLOCK _PROCEDURE enable_UI C-Win _DEFAULT-ENABLE
PROCEDURE enable_UI :
/*------------------------------------------------------------------------------
Purpose: ENABLE the User Interface
Parameters: <none>
Notes: Here we display/view/enable the widgets in the
user-interface. In addition, OPEN all queries
associated with each FRAME and BROWSE.
These statements here are based on the "Other
Settings" section of the widget Property Sheets.
------------------------------------------------------------------------------*/
DISPLAY cCustName
WITH FRAME DEFAULT-FRAME IN WINDOW C-Win.
ENABLE btn-Go cCustName br-cust br-invoice
WITH FRAME DEFAULT-FRAME IN WINDOW C-Win.
{&OPEN-BROWSERS-IN-QUERY-DEFAULT-FRAME}
VIEW C-Win.
END PROCEDURE.
/* _UIB-CODE-BLOCK-END */
&ANALYZE-RESUME

 

phat.andz

New Member
Gordon,

Thanks ever so much for trying to help me out. Sadly I don't have AppBuilder, which makes the listing you've given me pretty difficult to interpret and use to improve the code I have. So, I've implemented a quick and dirty fix - I've set the trigger event to fire up that secondary browse to be Left-Button-Down and Left-Button-Up. This way, the block is called twice when a row is clicked on just once, and the results appear as expected (just with a slight flicker where the first instance is blank).

Clumsy? Yes of course, but I'll try to improve upon it 'next time'!

Bye for now!

Andz.
 

hopea

New Member
try this

use the screen-value of the fields from the first browse to query the records in the 2nd browse
 
Top