Consultor Eletrônico



Kbase P124531: How do I dump a table with no indexes active?
Autor   Progress Software Corporation - Progress
Acesso   Público
Publicação   27/08/2010
Status: Verified

GOAL:

How do I dump a table with no indexes active?

GOAL:

How do I dump a table with an inactive primary index?

GOAL:

How do I dump a table without using any indexes?

FACT(s) (Environment):

All Supported Operating Systems
Products / Versions

FIX:

The following code dumps all records from a table to <tablename>.d without using any indexes
*/
DEFINE VARIABLE iRecID AS INTEGER NO-UNDO.
DEFINE VARIABLE TotalBlocks AS INTEGER NO-UNDO.
DEFINE VARIABLE RecPerBlock AS INTEGER NO-UNDO.
DEFINE VARIABLE iTemplate AS RECID NO-UNDO.
DEFINE VARIABLE TableName AS CHARACTER NO-UNDO.
DEFINE VARIABLE i AS INTEGER NO-UNDO.
DEFINE VARIABLE r AS ROWID NO-UNDO.
&SCOP TableName Customer
/* Find which storage area the table is located in. */
FIND FIRST _File WHERE _File-Name = "{&TableName}" NO-LOCK.
FIND FIRST _StorageObject WHERE _Object-number = _File-Number NO-LOCK.
FIND FIRST _Area WHERE _StorageObject._Area-number = _Area._Area-number.
FIND FIRST _AreaStatus WHERE _AreaStatus-AreaNum = _StorageObject._Area-number
NO-LOCK.
ASSIGN TotalBlocks = _AreaStatus-Hiwater.
ASSIGN RecPerBlock = EXP(2,_Area-recbits).
/* Find the record template */
ASSIGN iTemplate = _Template.
FUNCTION IntToHex RETURNS ROWID (iRowid AS INTEGER).
/* This function accepts an integer input parameter and converts it to a
hexadecimal equivalent (ROWID) */
DEFINE VARIABLE sHex AS CHARACTER INITIAL "0x" NO-UNDO.
DEFINE VARIABLE SixTeen8 AS INTEGER INITIAL 268435456 NO-UNDO.
/* SixTeen8 is 16 to the 8th power */
DEFINE VARIABLE iDigit AS INTEGER NO-UNDO.

DO WHILE SixTeen8 >= 1:
ASSIGN iDigit = TRUNCATE(iRowid / SixTeen8, 0)
sHex = sHex + (IF iDigit < 10 THEN STRING(iDigit)
ELSE IF iDigit = 10 THEN "a"
ELSE IF iDigit = 11 THEN "b"
ELSE IF iDigit = 12 THEN "c"
ELSE IF iDigit = 13 THEN "d"
&nb.sp; ELSE IF iDigit = 14 THEN "e"
ELSE "f")
iRowid = iRowid - (iDigit * SixTeen8)
SixTeen8 = SixTeen8 / 16.
END. /* Do while Sixteen8 >= 1 */
RETURN TO-ROWID(sHex).
END. /* FUNCTION IntToHex */

OUTPUT TO {&tableName}.d.
FIND _file "{&tableName}" NO-LOCK.
DO i = 1 TO (TotalBlocks * RecPerBlock):
r = IntToHex(i). /* Convert to HEX for ROWID */
FIND {&tableName} WHERE ROWID({&tableName}) = r NO-LOCK NO-ERROR.
IF AVAILABLE {&tableName} AND i <> INTEGER(_File._TEMPLATE) THEN
EXPORT {&tableName}.
END.
MESSAGE "Finished dumping all {&tableName} records " SKIP
"without using any indexes to {&tableName}.d"
VIEW-AS ALERT-BOX INFO BUTTONS OK.

.