Navigation:  Reference > Commands >

Export Records

Print this Topic Previous pageReturn to chapter overviewNext page

 

This command will write records to a non-TAS file.  Within this single command you can accomplish many tasks that would normally take many more lines of code and time to execute.

 

 

EXPORT fn/v/e1, fn/v/e2,..., fn/v/ex Required - The fields in the record that are being exported.  You may also create expressions that can be exported.

 

MEM If you are exporting from an array in memory instead of a standard file include this option in the command.

 

FILE file_num Required - The number/handle of the file to be used.  If you do not include this option, the program will look for a default search file set in the SRCH (Search File) command.  If that hasn't been previously set, the program will report an error and the command will be skipped.  This entry will override any default value set in the SRCH command.

 

       NOTE:  You must enter something here as a place marker, so put '' (double single quotes) for this option if you want to use the SRCH file.

 

KEY key_expr Set this to the appropriate value to read the records in the file in the correct order.  If you do not include this option, the program will look for a default key set in the SRCH command.  If a default key hasn't been previously set the program will report an error and the command will be skipped.  This entry will override any default value set in the SRCH command.

 

START f/c/e1,f/c/e2,...,f/c/ex The value to use as the beginning record.  This is similar to doing a FINDV (Find Record) before the command.  If the index you're searching on has multiple segments you may list the proper value for each segment, separating them with commas.  This will allow you to specify the exact type for each of the segments.  For example, suppose you're searching on an index that has two segments:  a 5 character alpha and an I type field.  Each record you want has the same alpha but the I field will change, and is in order.  In the first record the I type field has a value of 0.  The following would find the first record for that group, if it exists:

 

               start 'ABCDE',0!

 

       Notice that we separate the values with a comma.  The only requirement is that the values be of the same type (and size) as the segments in the key.  In this case we put the I type constant specifier (!) after the 0 to make sure that it is passed as an I type field.

 

SCOPE

       scope - This option may help determine how many records are exported.  The options are:  A (All), F (First), N (Next) and R (Rest).  For more information about the scope specifier please see the general information at the beginning of this chapter.

 

       f/c/e - If scope is set to N or F this is the number of records to export.

 

       An example of this would be:

 

               ... SCOPE A...                //all records in the file.  This is the default scope value.

 

               ... SCOPE N 20 ...        //the next 20 records in the file

 

FOR lexpr You would use this option to restrict the records exported in this command.  If the expression did not resolve to .TRUE. the record would not be exported.    In this option, the search continues until the program reaches the end of file and then will quit.  Any legal expression that resolves to .TRUE. or .FALSE. can be used.

 

       An example of this would be:

 

               ... FOR (x=100) .and. (y=200) ...

       

WHILE lexpr This option also restricts the records exported.  However, the first time the expression resolves to .FALSE., the program stops reading records and continues to the next command.  Here's the benefit of this option:  if the program is reading records in a certain order (by a specific key) and the expression returns .FALSE. then the program knows that all the appropriate records have been exported and there is no need to continue.  For example:  You want to read all the invoice records for a specific customer.  The first record for that customer is found in the invoice file either by using the start_value option within this command, or through the FINDV (Find Record) command before executing this command.  Then the WHILE expression would be:

 

               INV_CUST_CODE = CUSTOMER_CODE

 

       (This assumes that there is a field called INV_CUST_CODE in the invoice file and a like field in the customer file called CUSTOMER_CODE.  The KEY option must be set to the proper value so that the records are exported in CUSTOMER_CODE order, or you must have set the SRCH command previous to this command.)  When the first invoice record for the next customer is read the program will stop deleting records.

 

       NOTE:  If there is no START value you must set the scope value to R or N xxx.  If you do not do this, the program will find the first record in the file and the WHILE expression will probably fail the first time.  However, if the START option is used you can ignore this requirement.

 

CNTR fn/v This is an I type field that will be used for passing the number of records read, and the current array number, to your program.  You can also use this to count the number of records read.

 

NUM fn/vRequired (if Mem is specified) - If MEM is specified, this is the number of elements in the array to be exported.

 

TO f/c/e Required - The name of the file you are exporting to.  Must include the entire path, if any, and any extension.  The program will use the exact name you enter.

TYPE f/c/e Required - The type of file you are exporting to.  The options are:

 

       D - dBASE III+

       L - delimited

       F - fixed length/SDF

       X - text

 

       Don't forget:  this option entry needs to be a constant ('L', or 'D', etc.) or a field that contains a single character that matches one of the above.

 

       NOTE:  In dBASE III+ format the program will create the header information automatically.  You do need to remember that maximum field name sizes in dBase III+ are 10 characters and they are 15 in TAS.  When we create the dBase III+ file we truncate the trailing 5 characters.  You might want to take that into consideration when you are assigning field names if you are going to export to this format regularly.

 

DLM f/c/e If you choose the delimited ('L') type of file, you can also choose a delimiter character.  If you don't specify this value the program will put commas (,) between each field and surround alpha fields with quotes ("xxx").

 

TQ f/c/eText Qualifier If you choose the delimited ('L') type of file, you can also choose a Text Qualifier character the default is a quote ("). TheText Qualifier is represented by the decimal value of the character you want to use. Example using decimal value of chr(39) will make the qualifier a single quote (')  Use the chr()  function  to place the value for the TC.

 

       NOTE: If you want no  text qualifier set this value to 255. By using this option your output file would be considered a CSV type file. This feature only available ver 7.2 or later.        

 

APND f/c/e 'Y' or 'N' - Normally the EXPORT command will create a new file each time it is run.  However, you may choose to add records to an existing file by selecting this option.  The full option is APND 'Y' to append records to a current file and APND 'N' to create a new file (this is the default action and need not be specified).

 

       NOTE:  The program doesn't check to make sure that the previous records are in the same format.

 

DISPEach time a record is read the program will redisplay the screen fields, if you specify this option.  This will slow down the operation of this command, depending on how many fields are displayed on the screen.

 

NAME f/c/eAdds field names to DBF exported file field names are "fieldname1,fieldname2,,,"

 

       NOTE: This is required if you use mem. You do need to remember that maximum field name sizes in dBase III+ are 10 characters and they are 15 in TAS.

 

 

COMMENTS

If the WHILE option is used you must watch out for the proper setting of the SCOPE, and/or START options also.  If everything is supposedly set properly and yet no records are being exported, make sure that the proper first record is in memory prior to the execution of this command or that correct use has been made of the START option.  If a record is not active when this command is executed nothing will be exported.  You can use the START option instead of a FINDV (Find Record) to make sure that a record is active.

 

 

 

SEE ALSO

IMPORT FLIST

 

Example

Here is an example of an export command the reason I put this here is to show how to update a progress bar on one of these commands... This would work for Import wflistf and wlistm commands and delAll would even work on scan commands .

export flist prt_fld_fptr file @enter_hndl key @fsKeyNum for chkfilter() scope A cntr Reccntr type type_exp dlm delimiter_zn apnd apnd_yn to path_name TQ chr(39)

func ChkFilter

 '@pbRecCount.Position' = RecCntr   // This updates my progress bar

  if .not. Filt_dn then ret true

  Ret &Filt_Exp_Ptr

 

 

 

 

 

 


Page url: http://www.cassoftware.com/tas/manual/exportrecords.htm