Navigation:  Reference > Commands >

Read Records To An Array

Print this Topic Previous pageReturn to chapter overviewNext page

 

The command is used for reading a group of records into array fields in memory.  Within this single command you can accomplish many tasks that would normally take many more lines of code and time to execute.

 

RDA fn/v/e1, fn/v/e2,..., fn/v/ex Required - The fields in the record that are being read.  You may also create expressions that can be transferred to the receiving (TO) fields.  The first field in this list is paired to the first field in the TO list, the second to the second, etc.  There must be the same number of fields in this list as in the TO list.

 

       NOTE:  You cannot use constants in the from list but you can use expressions.  For example, you can read the record number for each record into an array of record numbers by using the RCN() function as one of the from fields and the appropriate R type array field as the corresponding to field.

 

 

TO fn/v1, fn/v1,..., fn/vx Required - These are the recipient fields.  They must be array fields of the same type as the respective from (RDA) field.  The first from field is paired with the first TO field, the second to the second, etc.  There must be the same number of TO fields as from fields.

 

 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 read.  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 delete.

 

       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 read in this command.  If the expression did not resolve to .TRUE. the record would not be read.    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 read.  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 read 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 deleted 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 reading 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.

 

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.

 

 

COMMENTS

If the WHILE filter option is used you must be careful to set scope and/or the START value options properly.  If you think you've set everything properly and yet no records are being read, 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 value option.  The last record read before exiting the command is still in the record buffer after the program leaves this command.

 

You must make sure you won't exceed the number of elements in the array.  If there is a chance this might happen, you should use the scope to insure this doesn't happen.  For example:

 

       ... scope n 300 ...

 

This would limit the command to the next 300 records in the file.

 

 

SEE ALSO

WRTA SORTA UPDTA REMVA

 

 


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