Consultor Eletrônico



Kbase P108197: How to find the availability, lock and current-changed status of a record given a table name and a q
Autor   Progress Software Corporation - Progress
Acesso   Público
Publicação   26/08/2005
Status: Unverified

GOAL:

How to find the availability and lock status of a record given the table name, a field name, a comparison operation and a value?

FIX:

The following two sample procedures demonstrate how to send table name and other dynamic query string components as input parameters to an external procedure and receive the availability, lock and current-changed status of a specific record as output from called procedure :
1. caller.p. This procedure calls callee.p to get the availability, locking status, current-changed status of a record given its table name, a field name, a comparison operation and a comparison value:
DEFINE VARIABLE cTableName AS CHARACTER NO-UNDO.
DEFINE VARIABLE cFieldName AS CHARACTER NO-UNDO.
DEFINE VARIABLE cOperation AS CHARACTER NO-UNDO.
DEFINE VARIABLE cValue AS CHARACTER NO-UNDO.
DEFINE VARIABLE cResult AS CHARACTER NO-UNDO.
ASSIGN
cTableName = "Customer"
cFieldName = "CustNum"
cOperation = "EQ"
cValue = "11".
RUN Callee.p(
INPUT cTableName,
INPUT cFieldName,
INPUT cOperation,
INPUT cValue,
OUTPUT cResult
).
MESSAGE cResult
VIEW-AS ALERT-BOX INFO BUTTONS OK.
2. callee.p: This procedure builds a dynamic query based on the received information and returns the availability, locking and current-changed status of the specified record:
/* Define input and output parameters */
DEFINE INPUT PARAMETER pcTableName AS CHARACTER NO-UNDO.
DEFINE INPUT PARAMETER pcFieldName AS CHARACTER NO-UNDO.
DEFINE INPUT PARAMETER pcOperation AS CHARACTER NO-UNDO.
DEFINE INPUT PARAMETER pcValue AS CHARACTER NO-UNDO.
DEFINE OUTPUT PARAMETER pcResult AS CHARACTER NO-UNDO.
/* Define local variables */
DEFINE VARIABLE cLegalOperations AS CHARACTER NO-UNDO.
DEFINE VARIABLE hQuery AS HANDLE NO-UNDO.
DEFINE VARIABLE hTableBuffer AS HANDLE NO-UNDO.
DEFINE VARIABLE cQueryString AS CHARACTER NO-UNDO.
/* Check that the Criterion is a legal Comparison Operations */
ASSIGN
cLegalOperations = "EQ,GE,GT,LE,LT,NE".
IF LOOKUP ( pcOperation , cLegalOperations, ',' ) = 0 THEN DO:
ASSIGN
pcResult = pcOperation + " is not a legal Comparison Operations.".
RETURN.
END.
/* Construct the query string */
ASSIGN
cQueryString = "FOR EACH " +
pcTableName +
" NO-LOCK " +
" WHERE " +
pcFieldName + " " +
pcOperation + " " +
QUOTER(pcValue).
/* Create the Dynamic Query and open it for the given buffer */
CREATE BUFFER hTableBuffer FOR TABLE pcTableName.
CREATE QUERY hQuery.
hQuery:SET-BUFFERS(hTableBuffer).
hQuery:QUERY-PREPARE(cQueryString).
hQuery:QUERY-OPEN.
IF hQuery:QUERY-OFF-END THEN DO:
ASSIGN
pcResult = "There are no records in " + pcTableName + " meeting the speci.fied Criterion.".
RETURN.
END.
hQuery:GET-FIRST(SHARE-LOCK, NO-WAIT).
ASSIGN
pcResult = " The record specified is: ".
IF hTableBuffer:AVAILABLE THEN DO:
pcResult = pcResult + " AVAILABLE ".
IF hTableBuffer:LOCKED THEN
pcResult = pcResult + " LOCKED ".
IF hTableBuffer:CURRENT-CHANGED THEN
pcResult = pcResult + " CURRENT-CHANGED ".
END.
ELSE
pcResult = pcResult + " NOT AVAILABLE ".
RETURN..