HOT TIPS: Database (5 Tips)

  • Smaller Small Medium Big Bigger
  • Default Helvetica Segoe Georgia Times


Redefining Records Without Changing File

I recently had to read a file in a CL program that wasn't defined in a very user-friendly manner. It was a packaged software file that was on a S/36, then converted to the AS/400. Therefore, the file's DDS described the file as follows:


The package software used a data structure to redefine the CNTDTA portion. This data contained both numeric and HEX data. I couldn't figure out how to read the file with the field CNTDTA containing HEX CLP kept giving various error messages. So, this is the solution that I arrived at and it worked!

I created a PF format for use in my CL program. I gave it a unique name (different than the file's name) and defined the data that I needed as follows:

 KEYDTA 8 A DTEDTA 4 0 (defaults to packed, it didn't like 4 0S) JNKDTA 40 

Then, in my CL program I used the following commands:

 OVRDBF FILE(mynew PF format name) + TOFILE(existing file name) LVLCHK(*NO) RCVF 

I had a numeric CL variable declared for the DTEDTA field. I was then able to manipulate the hex/packed data as I needed. It worked great!

- Cynthy Johnson

Non-Keyed Physical Files

When you need a primary access path over a physical file, do not key the physical file. Create a logical access path over the physical instead. This gives you more flexibility. If you need to change the primary access path, you don't have to save the data to a hold file. If the access path becomes damaged, you lessen the risk of the actual data being damaged. Also, if you need to bypass rebuilding the access path you can remove the logical file member (a little hard to do with a physical if you need to keep the data).

- William MacKenzie Picou

What Programs Use a File?

The following procedure provides a cross-reference of all programs which use certain file(s):

Initially, perform the following two steps:

1. Create a CL program which contains the following command:

 DSPPGMREF PGM(Yourlib/*ALL) OUTPUT(*OUTFILE) + OUTFILE(Yourlib/Youroutfile) (After initially running this program, add a statement to clear your outfile immediately before the DSPPGMREF command.) 

2. Create a query over your outfile.

Each time you need a cross-reference listing, perform the following three steps:

1. Call the CL program.

2. Run the DSPDBR command on the physical file(s) you are interested in to determine the names of all dependent logical files.

3. Modify the query to select records for the physical as well as the logical files and then run the query.

- Lois Reed

The File Reference File

The AS/400 keeps a reference file with an entry for each file on the system. The file can be queried to list the files in file name order or library order. The file is called QADB-XREF and is found in QSYS. Each record contains the fields shown:

AS/400 Reference File Field Names

 DBXFIL File name DBXLIB Library name DBXDIC Dictionary name DBXOWN Owner Name DBXTXT Text DBXATR Attribute (PF, LF, TB, VW, IX0 DBXLNK "E" if externally described "P" if program described DBXSQL "I" if IDDU "S" if SQL "C" if CRTDTTADCT "X" if Migrated Blank = no link DBXTYP "D" if Data, "S" if Source DBXNFL Number of fields DBXNKF Number of key fields DBXRDL Maximum record length DBXIDV Internal file definition for dictionary 

As you can see, this file can be useful in locating information by file, library, or owner. There are a multitude of useful reports that you can create from this file.

- Alon Fluxman

Indexing Mixedcase Fields

When a logical file is keyed on a field which contains mixedcase (that is, a mixture of uppercase and lowercase), it doesn't always sort the way you might want it to. The reason for this is that lowercase letters always come before uppercase letters in the EBCDIC collating sequence. So what you end up with is lowercase "a" through "z" followed by uppercase "A" through "Z".

To correct this problem, the field can be translated to uppercase before being indexed. The way to accomplish this is to use the logical file DDS keyword RENAME and TRNTBL as shown:


 ... 1 ...+... 2 ...+... 3 ...+... 4 ...+... 5 ...+... 6 ...+ A R CTREC PFILE(CATGRY) A CTDESC A CTCAPS I RENAME(CTDESC) A TRNTBL(QSYSTRNTBL) A K CTCAPS ... 1 ...+... 2 ...+... 3 ...+... 4 ...+... 5 ...+... 6 ...+ 

Field CTDESC contains a mixedcase text. Field CTCAPS contains a capitalized version of CTDESC. Notice that the file is keyed on CTCAPS. When the file is read in keyed sequence and field CTDESC is presented, the data appears to be more naturally sorted. All records starting with uppercase or lowercase "A" will be together, followed by all records starting with "B", and so on.

- Robin Klima