Kbase 19996: ADM2 - How to Search Records in a SmartDataBrowser (SDB)
Autor |
  Progress Software Corporation - Progress |
Acesso |
  Público |
Publicação |
  10/16/2008 |
|
Status: Verified
GOAL:
How to Search Records in a SmartDataBrowser (SDB) using PUBLISH and SUBSCRIBE
FACT(s) (Environment):
Progress 9.x
FIX:
Search based on the Customer.name field of the Sports database. The following example communicates by publishing and subscribing to events.
This example uses the Sports database. The SmartObjects used are:
- SmartWindow
- SmartDataObject
- SmartDataBrowser
- Simple SmartObject
Follow these steps:
1) Create a SmartDataObject, selecting the Customer table and some available fields. This example uses cust-num, discount, name, and number. The fields can either be updateable or nonupdateable.
2) Create a SmartDataBrowser, specifying the previously built SmartDataObject.
3) Create a Simple SmartObject and place a BUTTON and a FILL-IN on the Simple SmartObject.
4) Instantiate all these SmartObjects and accept all the default link suggestions.
Next, add the following code to the various SmartObjects:
Simple SmartObject
/* Code the following for the button of the Simple SmartObject.*/
DO:
PUBLISH "searchfor" (FILL-IN:SCREEN-VALUE).
END.
This trigger code publishes an event named "searchfor". At this point, you don't know which SmartObject is interested in this event. You are announcing to any interested SmartObject that an event has been published.
SmartDataObject
/* Code the following in an InitializeObject override */
/* procedure, before the RUN SUPER statement. */
SUBSCRIBE TO "searchfor":u ANYWHERE RUN-PROCEDURE "searchquery":u.
This trigger code subscribes to the event "searchfor". To process the "searchfor" event, create an internal procedure for the SmartDataObject called "searchquery" that receives the passed selection criteria and repositions the SmartDataObject query to the requested record:
PROCEDURE searchquery:
DEFINE INPUT PARAMETER cSearch AS CHAR NO-UNDO.
DEFINE VARIABLE pcrowident AS CHAR NO-UNDO.
FIND FIRST customer WHERE customer.NAME BEGINS csearch NO-LOCK NO-ERROR.
IF AVAILABLE(customer) THEN
DO:
ASSIGN pcrowident = STRING(ROWID(customer)).
DYNAMIC-FUNCTION ('fetchrowident':u, INPUT pcrowident, ?).
END.
END PROCEDURE.
Now, run the application and enter the name of a Company you wish to search for. Click the button and the appropriate record is selected.