The programmer can use this command to change the values in fields in a file in some or all records.
REPL fn/v1, fn/v2,..., fn/vx Required - This is the list of fields whose values will be replaced in this command.
If the MEM option is set then the program assumes that each field is an array field. In this command you must use regular array fields. When used in this option you would use just the field name portion, with no array element specified (ABC instead of ABC[X]). The program will automatically increment the array element number. You can specify the beginning array element number by setting this value in the NUM.
NOTE: A maximum of 80 fields/expressions/constants or any combination thereof may be included in a single field_list group.
WITH f/c/e1, f/c/e2,..., f/c/ex Required - These are the values that will be used as replacements. Each item on this list matches the item in the same position on the REPL list above.
MEM | If you are replacing values in a field array in memory instead of a standard file include this option in the command line. |
NUM fn/v | If the MEM option is included, then this is Required - If MEM is specified then this is the number of elements in the array to be replaced. |
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. |
NOTE: If you have specified MEM above (you are replacing values in array fields) then you can also set the starting array element number here. Normally, this would be 1 (0 is also set, automatically to 1), but can be set to a different value if desired. However, this will apply to ALL array fields in the list.
DISP | Each 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
This command provides you with an easy and quick method to replace the values in a group of fields from a file or an in memory array. This will also work with fixed length non-TAS files.
Page url: http://www.cassoftware.com/tas/manual/replacefieldsinfile.htm