How to insert a record using DBU

One caveat: it is usually a good idea to make a backup of any file before making updates. Maintaining backup copies of files and source members can be simplified by creating a library for exactly this purpose (safelib, savfil, svsrc, xlib, etc.)

Make sure DBU is in your library list. If not you must add it;

ADDLIBLE lib(DBU80) position(*AFTER QTEMP)

Next, from a command line type DBU and press F4=prompt and enter the file (object name) and normally the library name and optionally the member name and press Enter so the data is displayed.

Now position the file to a record similar to the one you want to insert. The DBU display can be toggled between single record and multiple record modes with F21 or by typing SGL or MULT in the control field. The file can be positioned to a particular record by typing *RRN in the control field and keying the relative record number (also known as the "arrival sequence" mode) or by typing *KEY for keyed files and pressing F6 to enter the position to key fields. The utility also has a search function that can be used to find the location of the desired record. Once your record is located and the file display is positioned to the correct location go to the single record mode with F21.

Next, Press F4 = DBU field selection
The Auto Dup field is displayed and is normally defaults to RMV. Change it to SEL.
Select/Remove field Auto Dup.......SEL

Press F10 = Action
Mode = 1. Add (since auto-dup was set to SEL your previous record will still be displayed - you can now change the data - with special attention given to key fields if the file is keyed)

Press Enter An informational message alerts that you are about to *add* a record.
Press Enter
Last step = check the result. The new record should now be available.

Note: in order to avoid duplicate keys just change the key field(s) before pressing Enter in Add mode. Obviously you must have sufficient authority to add records in order to use this method.

Here are a couple of alternative methods for those not fortunate enough to have DBU or when the situation dictates adding a large number of records.

CPYF method: using a couple of copy file statements. First do a CPYF to a new file using *CREATE and just selecting the records you want to add. CPYF allows selecting records based on record numbers, character tests, or field tests. For example, to select record(s) based on field testing;

CPYF FROMFILE(basefile) TOFILE(newfile) MBROPT(*ADD) CRTFILE(*YES) INCREL((*IF YEAR *EQ '2010'))

Since the new records are formatted exactly as the base file there is no need for *NOCHK nor should *MAP/*DROP be necessary. This example also assumes that the file only contains one member which is most often the case. If the file is memberized use the CPYF FROMMBR and TOMBR parameters. These newly copied records can then be changed with a file editor, SQL, or DFU. After the update(s) then a second copy file is used to add the new record(s) back to the target file with MBROPT(*ADD) CRTFILE(*NO) specified.

SQL method: similarly, using two files - and STRSQL and doing INSERT selecting all records for the new subset, then UPDATE the new table and finally INSERT the new records back to the original file.


Much more information regarding DBU can be found at the company's website; Prodata DBU 8.0 website