Writing a load program

After you have determined how much space your database requires and allocated data sets for it, you can load the database.

The load process

Loading the database is done using an initial load program. Initial load programs must be batch programs, since you cannot load a database with an online application program. It is your responsibility to write this program.

Basically, an initial load program reads an existing file containing your database records. Using the DBD, which defines the physical characteristics of the database, and the load PSBs, the load program builds segments for a database record and inserts them into the database in hierarchical order.

The following figure shows the load process.

Figure 1. The load process
Input for initial load program: existing files (tapes or data entry, IMS.DBDLIB, and IMS.PSBLIB. Output of initial load program: loaded database.

If the data to be loaded into the database already exists in one or more files, merge and sort the data, if necessary, so that it is presented to the load program in correct sequence. Also, if you plan to merge existing files containing redundant data into one database, delete the redundant data, if necessary, and correct any data that is wrong.

The following figure illustrates loading a database using existing files.

Figure 2. Loading a database using existing files
Merge existing data. Clean and format data. Sort data. Run initial load program. Output of initial load program: initial load errors, initial load report, and database.

After you have defined the database, you load it by writing an application program that uses the ISRT call. An initial load program builds each segment in the program's I/O area, then loads it into the database by issuing an ISRT call for it. ISRT calls are the only DL/I requests allowed when you specify PROCOPT=L in the PCB. The only time you use the L option is when you initially load a database. This option is valid only for batch programs.

Restriction: A PSB that includes a PCB statement that specifies PROCOPT=L cannot contain other PCB statements that specify PROCOPT values of A, D, G, I, or R.

If the database being loaded is registered with DBRC, DBRC authorization is also required for all databases that are logically related to the database being loaded. If DBRC is active when the database is loaded, DBRC sets the image copy status for this database to IC NEEDED in the DBDS record in the RECON data set.

The FIRST, LAST, and HERE insert rules do not apply when you are loading a database, unless you are loading an HDAM database. When you are loading a HDAM database, the rules determine how root segments with non-unique sequence fields are ordered. If you are loading a database using HSAM, the same rules apply.

Recommendation: Load programs do not need to issue checkpoints.

Most comprehensive databases are loaded in stages by segment type or by groups of segment types. Because there are usually too many segments to load using only one application program, you need several programs to do the loading. Each load program after the first load program is technically an add program, not a load program. Do not specify L as the processing option in the PCB for add programs. You should review any add type of load program written to load a database to ensure that the program's performance will be acceptable; it usually takes longer to add a group of segments than to load them.

For HSAM, HISAM, HIDAM, and PHIDAM, the root segments that the application program inserts must be pre-sorted by the key fields of the root segments. The dependents of each root segment must follow the root segment in hierarchical sequence, and must follow key values within segment types. In other words, you insert the segments in the same sequence in which your program would retrieve them if it retrieved in hierarchical sequence (children after their parents, database records in order of their key fields).

If you are loading an HDAM or PHDAM database, you do not need to pre-sort root segments by their key fields.

When you load a database:

  • If a loaded segment has a key, the key value must be in the correct location in the I/O area.
  • When you load a logical child segment, the I/O area must contain the logical parent's concatenated key, followed by the logical child segment to be inserted.
  • After issuing an ISRT call, the current position is just before the next available space following the last segment successfully loaded. The next segment you load will be placed in that space.
Recommendation: You should always create an image copy immediately after you load, reload, or reorganize the database.