Previous Topic: Build Field Definitions

Next Topic: Using &NDBSCAN Statements

Load the Data

You can now reload the data records. Each NDB record is represented by one type 21 record, n type 22 records, one for each non-null field, and one type 23 record.

Use &NDBADD START/DATA/END to load the records:

&FILE GET SEQ ARGS                  -* should be type 20
&IF .&1 NE .20 &THEN &GOTO .READERR -* bad
&NLOAD = 0                          -* num recs loaded
&OK = YES                           -* flag
&DOUNTIL &OK = NO                   -* rest of DB
   &FILE GET SEQ ARGS               -* get a record
   &IF .&1 = .22 &THEN &DO          -* field (most common)
      -* see note (1)               -* poss changes to
                                    -* data
      &NDBADD &DBNAME DATA +
      &3 = &Q4                      -* add the data
   &DOEND
   &ELSE &IF .&1 = .21 &THEN &DO    -* start of record
      &NDBADD &DBNAME START         -* start add of record
   &DOEND
   &ELSE &IF .&1 = .23 &THEN &DO    -* end record
      &NDBADD &DBNAME END           -* add the record
      &NLOAD = &NLOAD + 1           -* bump num recs
   &DOEND
   &ELSE &OK = NO                   -* otherwise exit
                                    -* until
   &LOOPCTL 1000                    -* prevent blowups
&DOEND
&IF .&1 NE .29 &THEN &GOTO .READERR -* unrecognized record
&IF &2 NE &NLOAD &THEN &GOTO .CNTERR
                                    -* record cnt mismatch

Note: Special code, to alter or skip certain fields for example, can be added here.

This completes the reload. All that is left is to close the files:

&NDBCLOSE &DBNAME
&FILE CLOSE &RLNAME

To flush the database buffers, and protect the reload, re-issue the NDB START with the NODEFER option:

NDB START &DBNAME NODEFER

This example procedure is in the NCL distribution library as member $NDBRELD. The code is basically as shown previously. See the source for more information.