Consultor Eletrônico



Kbase P117287: How to empty a table given its name?
Autor   Progress Software Corporation - Progress
Acesso   Público
Publicação   7/11/2006
Status: Unverified

GOAL:

How to empty a table given its name?

GOAL:

How to dynamically delete all records of a table given its name?

GOAL:

How to use a dynamic query to delete a set of records from a table given its name?

FIX:

The following procedure takes a table name as input and deletes all its records:
PROCEDURE DeleteThisTable :
/*------------------------------------------------------------------------------
Purpose:
Parameters: The name of the table whose records are to be deleted.
Notes: This procedure may be modified to delete records meeting certain conditions by introducing another input parameter specifying those conditions.
------------------------------------------------------------------------------*/
DEFINE INPUT PARAMETER ipcTableName AS CHARACTER NO-UNDO.
DEFINE VARIABLE hBufferHandle AS HANDLE NO-UNDO.
DEFINE VARIABLE hQueryHandle AS HANDLE NO-UNDO.
CREATE BUFFER hBufferHandle FOR TABLE ipcTableName.
CREATE QUERY hQueryHandle.
hQueryHandle:SET-BUFFERS(hBufferHandle ).
hQueryHandle:QUERY-PREPARE("for each " + ipcTableName + " NO-LOCK").
hQueryHandle:QUERY-OPEN.
REPEAT:
hQueryHandle:GET-NEXT().
IF hQueryHandle:QUERY-OFF-END THEN LEAVE.
DO TRANSACTION:
hQueryHandle:GET-CURRENT(EXCLUSIVE-LOCK).
hBufferHandle :BUFFER-DELETE ( ).
END. /* DO */
END. /* REPEAT */
END PROCEDURE.