Save

See Also: Understanding File Buffers and DDO Field Buffers, Attach, Lock, Reread, SaveRecord

Purpose

To save changes made to a record buffer, including data from parent tables, to the database on disk. This command is usually not used when working with Data Dictionaries.

Syntax

Save {child-table} […{child-table}]

Child-table is the logical name or filelist number of the table being saved.

What It Does

Save first executes an internal Attach command (moving data for fields on which a relation is based from all parent tables into child-table) and then writes record buffer data to disk and updates all on line indexes for child-table. If the record buffer was active (contained an existing record) prior to the save, only data for fields whose data changed is written, and it is written back to the original record (recnum). If the record buffer was inactive, a new record is created.

Example

find ge boxcars by 2

If (Found) Begin

    Reread Boxcars

    Move sNewOwner to boxcars.owner

    Save boxcars

    Unlock

End

In this example, a record in the database table boxcars is found, the value of Variable sNewOwner is moved to Field owner, and the record is saved back to the table. The record will retain the same record number and all other fields will remain unchanged.

Clear boxcars

Move sId       To boxcars.id

Move sLocation To boxcars.location

Save boxcars

In this example, which starts with a clear record buffer, Data for two fields is moved to the record buffer for Database File boxcars, and a save to the boxcars database table is done. This will create a new record in the boxcars table, updating its indexes that use the two fields.

In the following example, boxcars is related to parent Database File locations. The relationship is established through Field zipcode in both tables, locations.zipcode and boxcar.zipcode (relating fields do not have to have the same name in their tables, but they may).

Clear boxcars locations

Move sId  to boxcars.id

Move sZip to locations.zipcode

Find Eq locations.zipcode

Save boxcars

Here, the buffers for both tables are cleared. Then data is moved to base a boxcars record on. Then data is moved to the location, but it is not accepted to boxcars.zipcode. It is accepted to locations.zipcode to enable the next statement (find eq locations.zipcode) to bring a locations record into its buffer (the locations record might contain a city name, a state name, a counter of the number of boxcars located there, etc.). Then the last statement, save boxcars, performs an attach, which moves the value of locations.zipcode to boxcars.zipcode, and the relationship between the two records is established in the data that is saved to disk. Hereafter, when the boxcars record is found and a relate done, the same location record will be found also.

Where child-table relates to one or more parent tables, and data in the field(s) on which such relationship(s) is (are) based may be changed, you must use save rather than saverecord, unless you include an attach with the saverecord.

Notes

 

Save this_table that_table

//is exactly the same as:

Save this_table

Save that_table