Kbase P25936: How to check if a specific record is valid before reposition
Autor |
  Progress Software Corporation - Progress |
Acesso |
  Público |
Publicação |
  5/27/2003 |
|
Status: Unverified
GOAL:
How to check if a specific record is valid before repositioning the RowObject's query
GOAL:
Repositioning through fetchRowIdent (data.p)
GOAL:
How to reposition a SmartDataObject after applying a filter on it
FIX:
If fetchRowIdent is called with unknown or nonexisting ROWID, the query is closed and the SDO will be in a bad state (fetchNext and Prev do not work). The application will need to call fetchRowident with a valid value or fetchFirst, fetchLast, or openQuery to get back to normal.
For this reason in several situation is useful to check whether the record is still valid before using fetchRowIdent.
For example you may need it when repositioning to a specific record after have applied a smartFilter. In this case the record could be not any more in the RowObject's query.
In order to achieve this you have to define a custom function in the SDO in which you test if the RowIdent is valid or not.
1) Right click on your SDO object.
2) Select "Edit Master"
3) On the SDO window, go to "Edit code" (Press CTRL-S)
4) Select Function from the Section Combo-Box.
5) Create a new function called "canFindRowIdent", returning a LOGICAL value. Code:
RETURNS LOGICAL
( INPUT pcRowIdent AS CHARACTER) :
/*------------------------------------------------------------------------------
Purpose:
Notes:
------------------------------------------------------------------------------*/
FIND FIRST rowobject WHERE rowobject.ROWIDENT = pcRowIdent NO-ERROR.
IF AVAILABLE rowobject THEN RETURN TRUE.
RETURN FALSE. /* Function return value. */
END FUNCTION.
Now in your application you may write:
IF currElementRowIdent <> ? THEN
IF (DYNAMIC-FUNCTION ('canFindRowIdent' IN h_dtables, currElementRowIdent)) THEN
DYNAMIC-FUNCTION ('fetchRowIdent' IN h_dtables, currElementRowIdent, '') NO-ERROR.
ELSE
MESSAGE "Cannot find this data"
VIEW-AS ALERT-BOX INFO BUTTONS OK.
Where h_dtables is the handle to the SDO.