RealHeavyDude
Well-Known Member
I've been able to find the code sample - and - yesterday I forgot that the columns get removed from the browse widget when you set it's query attribute to NULL ...
Here's a working code sample (this time it's syntax checked ...):
Here's a working code sample (this time it's syntax checked ...):
HTH, RealHeavyDude.&SCOPED-DEFINE QUERY-WHERE 'FOR EACH cfr_InstrumentId NO-LOCK, FIRST cfr_InstrumentIdScheme NO-LOCK WHERE cfr_InstrumentIdScheme.instrumentIdScheme_obj = cfr_InstrumentId.instrumentIdScheme_obj INDEXED-REPOSITION':U
DEFINE VARIABLE hBrowse AS HANDLE NO-UNDO.
DEFINE VARIABLE hQuery AS HANDLE NO-UNDO.
DEFINE VARIABLE hInstrumentId AS HANDLE NO-UNDO.
DEFINE VARIABLE hInstrumentIdScheme AS HANDLE NO-UNDO.
DEFINE VARIABLE hField AS HANDLE NO-UNDO.
DEFINE VARIABLE cFieldList AS CHARACTER NO-UNDO.
DEFINE VARIABLE cFieldName AS CHARACTER NO-UNDO.
DEFINE VARIABLE cTableName AS CHARACTER NO-UNDO.
DEFINE VARIABLE iField AS INTEGER NO-UNDO.
DEFINE VARIABLE lOkay AS LOGICAL NO-UNDO.
/* Assign the variables we need later */
ASSIGN hBrowse = BROWSE {&BROWSE-NAME}:HANDLE
hInstrumentId = BUFFER cfr_InstrumentId:HANDLE
hInstrumentIdScheme = BUFFER cfr_InstrumentIdScheme:HANDLE
cFieldList = '{&FIELDS-IN-QUERY-{&BROWSE-NAME}}'. /* Pre-Processor containing the fields */
/* Eventually clean-up the dynamic query */
IF VALID-HANDLE ( ghQuery ) THEN DO:
IF ghQuery:IS-OPEN THEN
ghQuery:QUERY-CLOSE ( ).
DELETE OBJECT ghQuery.
ASSIGN ghQuery = ?.
END.
/* Create the dynamic query */
CREATE QUERY ghQuery.
ghQuery:SET-BUFFERS ( hInstrumentId, hInstrumentIdScheme ).
ASSIGN lOkay = ghQuery:QUERY-PREPARE ( {&QUERY-WHERE} ) NO-ERROR.
IF lOkay THEN DO:
/* Close the query that is currently attached to the browse widget when it is valid */
ASSIGN hQuery = hBrowse:QUERY.
IF VALID-HANDLE ( hQuery ) THEN
hQuery:QUERY-CLOSE ( ).
/* Switch the queries */
ASSIGN hBrowse:QUERY = ?.
ASSIGN hBrowse:QUERY = ghQuery.
/* Need to set the expandable attribute of the browse to FALSE, otherwise the first added column will fill the widget */
ASSIGN hBrowse:EXPANDABLE = FALSE.
/* Populate the browse widget with the fields as they were */
DO iField = 1 TO NUM-ENTRIES ( cFieldList, ' ':U /* List is seperated by blanks */ ):
/* Extract the field and table names from the list */
ASSIGN cFieldName = ENTRY ( 2, ENTRY ( iField, cFieldList, ' ':U ), '.':U )
cTableName = ENTRY ( 1, ENTRY ( iField, cFieldList, ' ':U ), '.':U ).
/* Grab the handle to the buffer field from the corresponding buffer */
IF cTableName = 'cfr_InstrumentId':U THEN
ASSIGN hField = hInstrumentId:BUFFER-FIELD ( cFieldName ).
ELSE IF cTableName = 'cfr_InstrumentIdScheme':U THEN
ASSIGN hField = hInstrumentIdScheme:BUFFER-FIELD ( cFieldName ).
/* Now add the field to the browse widget */
IF VALID-HANDLE ( hField ) THEN
hBrowse:ADD-LIKE-COLUMN ( hField ).
END. /* Populate the browse widget with the fields as they were */
/* Open the query */
ASSIGN hBrowse:EXPANDABLE = TRUE.
ghQuery:QUERY-OPEN ( ).
END.
&UNDEFINE QUERY-WHERE