Easy to Create, Easy to Change - Easy to use!

Command::

Export to variable file name



Parameters


Returns/Result


Examples


Example 4 - Exporting to variable file name.

The DQL export will normally just export to a fixed file name. This can be a little limiting but there is a hack/work around that is not well known.

You can use a GLOBAL variable as the parameter for the filename, but it is AWKWARD so don't try to think yourself as it will only work if you do it exactly as outlined here. Normal temp variable won't work, any direct derivation won't work and any change to the global variable inside the exporting DQL will not work!!!

you will need to set the global variable in a control procedure, and then call the exporting procedure from the control Procedure.

CTR_Procedure:

define global "exportfile" text 150 .

global exportfile := getvar("ExportFile") .

run procedure ExportDQL .

Export_Procedure:

define global "exportfile" text 150 .

for MainData ;

list records

RecordID ;

TransactionDescription .

for SubData named "ole" with RecordID=Maindata RecordID ;

list records

Text ;

Value ;

Currency ;

CurrencyValue ;

Rate .

end

end

--export to "c:\blat\export.txt" .

export to global exportfile .

RecordID~TransactionDescription ~Text ~Value ~Currency ~CurrencyValue ~Rate

.items ole

@f[1,1]~@f[1,2]~@f[2,1]~@f[2,2]~@f[2,3]~@f[2,4]~@f[2,5]

.end

Reference

export

Type

Processing Command

Purpose

The export command exports data from the current application to an external file. The export command functions like choosing File>>Export in User View.

Syntax

export to " FILENAME "

.form headerTEXT | FIELDNAME

.items@f[FORM NUMBER, FIELD NUMBER, FIELD LENGTH]@f[FORM NUMBER, FIELD NUMBER, FIELD LENGTH]...

.form trailerTEXT

.end

In this syntax example, the brackets are required; optional parameters are shown in italics.

Usage

The export command must be preceded in a script by a list records command that specifies the source table and the fields to be exported. The numeric parameters included in the export command refer to the sequential listing of the form(s) and field(s) included in the preceding list records command.

The export command lets you include the following formatting commands: .form header, .items, .form trailer, and .end. Items listed under the .form header, .form trailer, and .end commands print only once in the output file DataEase generates. Items listed under the .items formatting command, print multiple times, once for each record processed.

Example 1

for MEMBERS ;

list records

MEMBER ID in order ;

CARDNO. ;

TOTALDUE .

end

export to "MEMBDATA.TXT" .

.form header

Member ID~ Card No.~ Total Due

.items

@f[1,1]~ @f[1,2]~ @f[1,3]

.end

 

This example generates a variable length delimited ASCII file. Each record begins on a new line and each field value is separated by a tilde (~) character.

This example tells DataEase: (1) process all the MEMBERS records, listing the MEMBER ID in order, the credit CARD NO., and the total membership dues, (2) export the same data to a file called MEMBDATA.TXT, (3) include a header record in the export file that lists the column names.

Example 2

for MEMBERS ;

list records

LAST NAME .

for RESERVATIONS

list records

TOTALDUE .

end

end

export to "a: \MEMTOTAL.TXT" .

.form header members .items

.form header reservations

@f[1,1]~ @f[2,1]

.end

 

This example tells DataEase to: (1) process all the records in the MEMBERS table, listing the LAST NAME of each member, (2) for each MEMBERS record processed, list the TOTAL DUE value from all the related RESERVATIONS records, and (3) export the data to a variable length delimited ASCII file called MEMTOTAL.TXT located on disk drive "A". The syntax @f[2,1] refers to form 2 (RESERVATIONS), field 1 (TOTAL DUE).

Example 3

for MEMBERS ;

list records

MEMBERID in order ;

CARDNO. ;

TOTALDUE .

end

export to "MEMBDATA.TXT" .

.form header

.items

@f[1,1,5]@f[1,2,20]@f[1,3,7]

.end

 

This example generates a fixed length ASCII file and includes the same data as in Example 1.

The third digit in the field specification indicates the length of the field.

See Also


On the forum about Export to variable file name

On the blog about Export to variable file name