The &NDBADD verb is used to add records to an NDB. The fields for the new records must be named on the &NDBADD statement, along with their values. Not all fields need to be supplied. For the database manager, only those fields with the attribute NULLFIELD = NO need be supplied-this includes the sequence key, if one is defined.
If you only need to supply a few fields on the &NDBADD statement, code it as follows:
&NDBADD dbname DATA name1 = value1 name2 = value2 ...
If you need to supply a large number of fields, or you are not sure of the exact content of the new record (for example, table driven systems), the second format of the &NDBADD verb can be used:
&NDBADD dbname START &NDBADD dbname DATA name1 = value1 &NDBADD dbname DATA name2 = value2 &NDBADD dbname DATA name3 = value3 &NDBADD dbname DATA name4 = value4 &NDBADD dbname END
This syntax allows a record of any length to be created.
The fields need not be in any order, and the collection of &NDBADD statements need not be adjacent. For example, a loop could be used, with complex substitution, to build the list of field names and values:
&NDBADD MYNDB START &I = 1 &DOWHILE &I LE &NFLDS &VALUE = &NDBQUOTE &FV&I &NDBADD MYNDB DATA &FN&I = &VALUE &I = &I + 1 &DOEND &NDBADD MYNDB END -* this statement calls the DBMS
In this example, you loop through a table of field names and values, adding each field.
Following the &NDBADD, or &NDBADD END, if you are using START/DATA/END, the &NDBRC system variable contains 0 if no errors were encountered. If not 0, an error response indicates the problem, and &NDBERRI might have additional information. An error message is also displayed unless &NDBCTL MSG=NO is in effect.
If the response is 0, &NDBRID contains the RID assigned to the new record. This RID can be used in other &NDB statements to refer to the new record.
| Copyright © 2011 CA. All rights reserved. | Tell Technical Publications how we can improve this information |