4D v16.3

EXPORT DATA

Home

 
4D v16.3
EXPORT DATA

EXPORT DATA 


 

EXPORT DATA ( fileName {; project {; *}} ) 
Parameter Type   Description
fileName  String in Full path name of the export file
project  Text variable, BLOB variable in Contents of the export project
in New contents of the export project (if the * parameter has been passed)
Operator in Displays the export dialog box and updates the project

The EXPORT DATA command exports data in the fileName file.4D can export data in the following formats: Text, Fixed length text, XML, SYLK, DIF, DBF (dBase), and 4D.

If you pass an empty string in fileName, EXPORT DATA displays the standard save file dialog box, allowing the user to define the name, type, and location of the export file. Once the dialog box has been accepted, the Document system variable contains the access path and the name of the file. If the user clicks Cancel, the execution of the command is stopped and the OK system variable is equal to 0.

The optional project parameter lets you use a project to export data. When you pass this parameter, the export is carried out directly, without any user intervention (unless you use the * option, see below). If you don’t pass this parameter, the export dialog box is displayed. The user can define the export parameters or load an existing export project.

An export project contains all the export parameters such as the tables and fields to export, delimiters, etc. In the project parameter, you can pass either a Text variable containing XML or a Text variable containing a reference to a pre-existing DOM element, or a BLOB. Projects may have been created by programming (XML format projects only) or by loading parameters that were previously defined in the export dialog box.In the latter case, you have two solutions available:

  • Use the EXPORT DATA command with an empty project parameter and the optional * parameter, then store the resulting project parameter in a Text or BLOB type field (see below). This solution allows you to save the project with the data file.
  • Save the project to disk, then load it for example by using the DOM Parse XML source command, and pass its reference in the project parameter

Compatibility note: Beginning with version 12 of 4D, export projects are encoded in XML. 4D can open export projects generated with previous 4D versions (BLOB format) but any projects created starting with v12 can no longer be opened with v11 or earlier versions. We now recommend that you use Text variables for handling export files.

The optional parameter *, if it is specified, forces the display of the export dialog box with the parameters defined in project. This feature allows you to use a predefined project, while still having the possibility to modify one or more of the parameters. Furthermore, the project parameter contains, after closing the export dialog box, the parameters of the “new” project. You can then store the new project in a Text field, on disk, etc.

If the export was successful, the OK system variable is set to 1.

This example illustrates the use of the EXPORT DATA command to export data in binary format.

  • This method makes a loop on all the database tables and calls the ExportBinary method:

 C_TEXT($ExportPath)
 C_LONGINT($i)
 $ExportPath:=Select folder("Please select the export folder:")
 If(Ok=1)
    For($i;1;Get last table number
       If(Is table number valid($i))
          ExportBinary(Table($i);$ExportPath+Table name($i);True)
       End if
    End for
 End if

  • Here is the code for the ExportBinary method:

 C_POINTER($1//table
 C_TEXT($2//path of destination file
 C_BOOLEAN($3//export all records
 C_LONGINT($i)
 C_TEXT($ref)
 $ref:=DOM Create XML Ref("settings-import-export")
  // Export the table "$1" in '4D' binary format, all the records or only the current selection
 DOM SET XML ATTRIBUTE($ref;"table_no";Table($1);"format";"4D";"all_records";$3)
  // Definition of fields to export
 For($i;1;Get last field number($1))
    If(Is field number valid($1;$i))
       $elt:=DOM Create XML element($ref;"field";"table_no";Table($1);"field_no";$i)
    End if
 End for
 EXPORT DATA($2;$ref)
 If(Ok=0)
    ALERT("Error during export of table "+Table name($1))
 End if
 DOM CLOSE XML($ref)

This example creates an empty project and stores the parameters set by the user in the export dialog box there:

 C_TEXT($exportParams)
 EXPORT DATA("DocExport.txt";$exportParams;*) //Display of the export dialog box

If the user clicks Cancel in the standard open file dialog box or in the export dialog box, the OK system variable is equal to 0. If the export was successful, the OK system variable is equal to 1.



See also 

EXPORT DIF
EXPORT SYLK
EXPORT TEXT
IMPORT DATA

 
PROPERTIES 

Product: 4D
Theme: Import and Export
Number: 666

The OK variable is changed by the commandThis command modifies the system Document variable

 
HISTORY 

Modified: 4D 2003
Modified: 4D v12

 
ARTICLE USAGE

4D Language Reference ( 4D v16)
4D Language Reference ( 4D v16.1)
4D Language Reference ( 4D v16.2)
4D Language Reference ( 4D v16.3)