It is important to dump and reload data definitions and table contents while developing applications and maintaining databases. You can dump and load table data using:
  • The DataAdminService class.
  • The IDataFile utility from the OpenEdge.DataAdmin package.

For details on how to perform the dump and load operations in the OpenEdge database, see "Dumping and Loading" in Manage the OpenEdge Database.

The following code shows how to dump the customer and salesrep tables when connected to the sports2000 database:
BLOCK-LEVEL ON ERROR UNDO, THROW.
/* *************************** Definitions ******************** */ 
USING OpenEdge.DataAdmin.DataAdminService FROM PROPATH.
USING OpenEdge.DataAdmin.Error.DataAdminErrorHandler FROM PROPATH. 
USING OpenEdge.DataAdmin.IDataAdminService FROM PROPATH.
USING OpenEdge.DataAdmin.IDataFile FROM PROPATH.
USING OpenEdge.DataAdmin.Internal.Util.TableDataWriter FROM PROPATH. 
USING OpenEdge.DataAdmin.Lang.Collections.IIterator FROM PROPATH. 
USING OpenEdge.DataAdmin.Util.ITableExportUtility FROM PROPATH. 
USING Progress.Lang.Error FROM PROPATH.
USING OpenEdge.DataAdmin.Util.UtilityFactory FROM PROPATH.
/* ******************** Preprocessor Definitions ****************** */ 
DEFINE VARIABLE service AS IDataAdminService NO-UNDO.
DEFINE VARIABLE dataWriter AS ITableExportUtility NO-UNDO. 
DEFINE VARIABLE iterator AS IIterator NO-UNDO.
DEFINE VARIABLE dumpfile AS IDataFile NO-UNDO.
service = NEW DataAdminService(?). dataWriter = CAST (NEW
UtilityFactory():GetUtility("TableExportUtility"),ITableExportUtility). 
dataWriter:LogStatus = TRUE. 
dataWriter:Directory = <dump-directory-location>. 
dataWriter:OverwriteFiles = TRUE.

dataWriter:Tables:Add(service:GetTable("customer")). 
dataWriter:Tables:Add(service:GetTable("salesrep")).

service:ExecuteUtility(dataWriter).

iterator = dataWriter:Files:Iterator(). 
DO WHILE Iterator:hasNext():
	dumpfile = CAST(iterator:Next(),IDataFile).
	MESSAGE dumpfile:Table:name dumpfile:FileName dumpfile:ProcessedNumRows 
	VIEW-AS ALERT-BOX.
END.

The code starts the DataAdminService instantiating the TableExportUtility using the UtilityFactory:GetUtility. It then passes the instance to the DataAdminService:ExecuteUtility to dump the data. After the execution, the code uses the Files:Iterator to loop through the IDataFile instances to gather information about details and status of the dump operation.

The code example adds tables to the table collection of the utility for processing two specific tables, customer and salesrep, while performing the dump operation. It uses the GetTable() method from the DataAdminService to add the customer table object to the instance as follows:

dataWriter:Tables:Add(service:GetTable("customer")).
Note: If no object is added to the tables collection, all the tables are dumped to the specified directory.

The following table lists the properties used in the dump table data code along with their descriptions:

Property Description
LogStatus It instructs the chosen utility to record the dump status to the files collection.
Directory It is the directory path where the data must be written for the dump operation. You must give this location before you run the code. If you leave the dataWriter.Directory field blank, the tables get dumped into the current working directory.
OverwriteFiles

If set to TRUE, this property overwrites all the .d files existing in the dump location for the respective table.

If set to the default value of FALSE, it throws an error when one or more of the .d files exist in the dump location.

The following code loads the table data from the specified directory:

BLOCK-LEVEL ON ERROR UNDO, THROW.

USING OpenEdge.DataAdmin.DataAdminService FROM PROPATH.
USING OpenEdge.DataAdmin.Error.DataAdminErrorHandler FROM PROPATH. 
USING OpenEdge.DataAdmin.IDataAdminService FROM PROPATH.
USING OpenEdge.DataAdmin.IDataFile FROM PROPATH.
USING OpenEdge.DataAdmin.Lang.Collections.IIterator FROM PROPATH. 
USING OpenEdge.DataAdmin.Util.ITableImportUtility FROM PROPATH. 
USING OpenEdge.DataAdmin.Util.UtilityFactory FROM PROPATH.
USING Progress.Lang.Error FROM PROPATH.

/* ******************** Preprocessor Definitions ****************** */ 
DEFINE VARIABLE service	AS IDataAdminService	NO-UNDO.
DEFINE VARIABLE dataReader AS ITableImportUtility NO-UNDO. 
DEFINE VARIABLE iterator AS IIterator	NO-UNDO.
DEFINE VARIABLE dumpfile AS IDataFile	NO-UNDO. 
DEFINE VARIABLE TableCount AS INTEGER NO-UNDO.

service = NEW DataAdminService(?). 

dataReader = CAST (NEW
UtilityFactory():GetUtility("TableImportUtility"),ITableImportUtility).
dataReader:LogStatus = TRUE. 
dataReader:Directory = "dump-directory-location". 
dataReader:AcceptableErrorPercentage = 0. 
dataReader:IgnoreMissingDirectories = FALSE.


service:ExecuteUtility(dataReader).

iterator = dataReader:Files:Iterator(). 
DO WHILE Iterator:hasNext():
	dumpfile = CAST(iterator:Next(),IDataFile).
	MESSAGE "Table: "	dumpfile:table:name SKIP 
	"File name: "	dumpfile:FileName SKIP 
	"Expected num rows: " dumpfile:ExpectedNumRows SKIP
	"Loaded num rows:	" dumpfile:ProcessedNumRows SKIP 	
	"Any error: "		dumpfile:AnyError SKIP
	"Error message: "	dumpfile:ErrorMessage SKIP 
	VIEW-AS ALERT-BOX.
END.
MESSAGE "Attempted to Load " dataReader:Files:count "files" 
VIEW-AS ALERT-BOX.

CATCH e AS Error:
	NEW DataAdminErrorHandler():error(e). 
	SESSION:EXIT-CODE = 42.
END CATCH.

FINALLY:
	DELETE OBJECT service.
END

The code starts the DataAdminService instantiating the TableImportUtility using the UtilityFactory:GetUtility. It then passes the instance to the DataAdminService:ExecuteUtility to load the data. After the execution, the code uses the Files:Iterator to loop through the IDataFile instances for gathering information about details and status of the load operation.

The following table lists the properties used in the code along with their descriptions:
Property Description
LogStatus It instructs the chosen utility to record the load status to the files collection.
Directory It is the directory from where the data must be read for the load operation. You must give this location before you run the code. If you leave the DataReader.Directory field blank, the tables get loaded from the current working directory.
AcceptableErrorPercentage

It is the percentage of error that is acceptable per .d file.

0─Stops the load of .d file on first error.

>0─Continues the load of .d file till the error percentage reaches.

100─Continue the load operation and ignores the errors, if any.

IgnoreMissingDirectories

If set to TRUE, this property ignores the missing tenant and group table directories.

If set to the default value of FALSE, it throws an error in the event of missing directories and halt the loading operation.

Note:
  • You can add tables to the table collection of the utility for processing only the specific tables while performing the load operation. Use the GetTable() method from the DataAdminService to add the table object as follows:
    dataWriter:Tables:Add(service:GetTable("customer")).
  • If IDataFile:AnyError returns FALSE, the data is presumed to have been loaded.
  • IDataFile:ExpectedNumRows reads and returns the total number of rows to be processed from the .d trailer for the load operation. However, it is possible to load the data from the .d file without a trailer, in which case the IDataFile:ExpectedNumRows does not return any value.
  • IDataFile:ProcessedNumRows returns the value of the actual number of rows loaded from the .d trailer for the load operation.

  • IDataFile:ErrorMessage records the top-level error message.
  • The .e file records detailed errors for a failed load operation. You can locate this file using the IDataFile:Filename.
  • You can use the ValidateOnly property of the ITableDataUtility and set it to TRUE to perform a validation request that only checks for:
    • The availability of files and directories
    • If the load execution can be completed.