26
Tue, Nov
1 New Articles

Database Design Flexibility for the Future

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

Planning and forethought are key elements in designing a database that is easy to work with and easy to expand. Putting together a feasible and workable relational database is not an easy task. It is similar to piecing together a puzzle in order to have one complete, concise, and manageable unit. Much thought must go into the design of the relational database to ensure ease of use and ease of expansion.

IBM has supplied what I feel is one of the most powerful relational databases in existence in DB2/400. The company has also supplied very powerful and easy-to-use database manipulation devices in the form of RPG/400, COBOL/400, and SQL/400. How you use these tools to make your lives easier is up to you. You can build your database with the future in mind, or you can paint yourself into a corner by not thinking ahead.

Breaking the Database Down into Manageable Units

As the industry has progressed from using flat files to using relational database architecture, one thing that has certainly evolved is the way files are broken down into their unique elements. For example, order entry information was commonly stored in a single flat file containing both header and detail information in each record. Each line of this file could include static information for invoices, for example, in the form of customer number, invoice number, and order date as well as detail information such as item and quantity ordered.

In a relational database, this information is broken down into header and detail files. One header record appears for one or more detail records. The key for the detail file contains a unique identifier for the header information, such as invoice number, followed by the detail line number. But what is stopping you from taking this to the limit? Only your imagination and database design capabilities.

Suppose your users request the ability to input special instructions for each detail line. How would you handle this? A simple solution may be to put four 40-character fields

in the detail file called Text1, Text2, Text3, and Text4. For input, you simply display a window with the four fields into which the user can enter the special instructions.

Now, this may work fine…or you may find yourself in trouble if the user later says that there is not enough room for some of the instructions in only four 40-character fields.

A better solution may be to build an order detail description file one level below the detail file, keyed by order number, detail line number, and special instruction sequence. For each detail record, there can be at least one special instruction detail line. Then, users can enter as many instructions as they want in a window subfile, instead of being limited to a window that allows only four lines of text (see Figure 1).

On the other hand, there are times when adding multiple and relatively similar fields to a file will be a good choice. One example of this would be any monthly figure, such as monthly sales. We all know that there will never be more than twelve months in a year, so creating a separate detail file to hold these monthly sales files may be overkill. If these fields are defined as 12 different elements in the file, they can also be easily renamed into an array for easy manipulation. (For more information, see “Common Sense Normalization,” MC, September 1995.)

Mastering Master Files

The design phase usually yields master files, such as Customer Master File or Item Master File, to hold static information about these unique entities. Creating master files for this type of information is more obvious, since they are the base of the entire database. But, all too often, no master files are created for other, less obvious information.

Take, for example, a shipping method code in an order header file. You may have such codes as F to represent Federal Express shipment and U to represent UPS shipment. These codes are most likely explained in the text portion of the field definition in the DDS. For reporting purposes, the SELECT statement in each RPG program translates each code into a description that’s more meaningful to the user than the code itself. But what happens when you add a new shipping-method code? You most likely won’t change the DDS text for the field right away, if at all, but you do have to go in and add a line to the SELECT statement in all the reports and displays using this field.

A better method is to create a master file for shipping-method codes. In this file, include the code, the code description, and any other static information associated with a shipping method. Then, when you implement a new shipping method, you simply add a record to this master file. Users can also easily perform this task by using an entry/update program, so no programmer assistance is required. In addition, accessing the code description or any other code-related information is as easy as a CHAIN to the master file. This method also makes data validation more accurate, because you can perform a simple CHAIN to the master file to determine whether a user has entered an invalid shipping method code. It also allows the output of reports to be more descriptive, as the user will see the code description instead of just the code (see Figure 2).

Your applications will be more versatile if you use master files for each type of code in your database. Even if you think a code will be only a simple Y (yes) or N (no), setting up a master file for it eliminates rewriting applications that use this field if, by chance, Y and N are suddenly not the only two choices. Of course, sometimes a simple Y or N is all you will need. Since RPG III limits you to 50 files in a program, grouping these types of fields by application into a control file may be your best solution.

Another plus to creating master files for codes is the ability to display a list of codes during the entry portion of an interactive application. The user simply prompts on the code field and selects from the list. This will be especially helpful for new employees who don’t know the code structure and want to know which shipping method code to use.

Physical Files—to Key or Not to Key

Ever since I entered this business, I’ve heard arguments both for and against the keying of physical files. But I’ve never heard a really good argument against it or a really good argument for it. On the one hand, the key used on a physical file is usually unique and won’t have to be changed. On the other hand, by using a logical with the unique key you would have used on the physical, you may save time if the key to the database changes.

As an example, let’s look at an Item Master File. The item number in the database will always be a unique key. You will never have more than one item with the same number, so why not key the physical file by item number? There’s a good reason not to do it that way.

One day, circumstances may require that you change the key to all of your files. For example, perhaps your company merges with another, and the new entity wants to use your existing software but remain separate from the original company. This new company may also want to set up items with the same item numbers as the existing company. You may think about using two different libraries to separate the data, but you’d quickly realize that you would be limiting yourself in the long run. After all, what if another company forms? The best solution is to add a company number field to your files, which will always be the lowest-level key. So, in the case of the Item Master File, the unique key will be company number, then item number.

You now realize why uniquely keying your physical file may create problems. If you simply leave the physical unkeyed, you have to change only the logical file that contains the unique item number key, thereby avoiding the “song and dance” of copying the data to a temp file, creating the new physical, and copying the data from the temp file to the new file with CPYF, specifying FMTOPT(*MAP *DROP).

Referencing Fields for Easy Maintenance

After you’ve designed your database—and before you start entering DDS for your files—create a field reference file to help organize the multitude of fields. A field reference file is a simple concept and a neat way to organize your fields. Create this file the same way you would create a physical file. Include all the fields from your database design, and their sizes and descriptions. Adding default editing and column headings will also help when using Query/400. Compile this file with the MBR(*NONE) option, since this file will not contain any data. Indicate the reference file using the REF(lib/file) keyword in your DDS, and reference each field using the REFFLD (field) keyword (see Figure 3). The reference file will never contain data; it’s just a better way to keep your field definitions all in one place.

Now, when I say “create a reference field for every field in every file,” I don’t mean that literally. What I mean is that you should create a field for every unique field. Each invoice number will have only one entry, which will be referenced by the invoice number field in at least your order header and order detail files. This way, if you ever have to make a change to your invoice number, you simply change the reference file and then recompile the DDS for any file that uses that reference field.

Remember that the field reference file is only as helpful as you make it. If you suddenly start referencing fields in this file that were not meant to be used for that purpose, you are setting yourself up for a fall. An example of this might be referencing the invoice number field for the customer number. They’re both 7,0, so why not? Well, your company grows, and suddenly you need to expand the customer number to 9,0. See my point? If you reference fields only for their intended purpose, things will work out fine. Use judgment, and don’t make decisions in haste.

It may be beneficial to make more than one field reference file. Breaking up reference fields by application may help you make changes that affect one application but not another. (For more information, see “Build Your Own Data Dictionary,” MC, July
1997.)

Using Selective Logical Files Limits You

I have never been a big fan of using selective logical files. (Selective logical files select only certain data from the physical file. An example would be a logical file that selects from the item master file only items that have a quantity on hand of greater than zero.) For one thing, anytime this file changes, your system may experience a bigger performance hit because of this “dynamic selection.” Another problem is that the key to this logical file may be the same as the key to another logical file. I have heard of shops that create a new logical file that’s specific for the information they want to select when they want to run a report—instead of using something like Open Query File (OPNQRYF). I have heard of shops that have over 200 logical files over the same physical file. And a lot of those logicals are repetitive because, once a shop has a lot of logical files, it’s easier to create a new one than to look for one that might satisfy the selection.

Again, you must use your best judgment. There may be cases when using a selective logical file will seem like the right thing to do, but why take that chance? Let your programs do the selecting.

Using Change Physical File

The Change Physical File (CHGPF) command has been updated in V3R2, and it makes our lives much easier. The updates allow you to change a file’s field descriptions by specifying where to find the new DDS source. To use this command in the most simple case using externally described files, you simply need to input two things: the location of the file to be changed and the location of the DDS to use to change the file.

CHGPF FILE(filename) +

SRCFILE(library/sourcefile)

The system takes care of re-creating the physical file, along with any related logical files. In my opinion, it also seems to perform much more quickly than the Copy File (CPYF) command.

(For more information on CHGPF, see “The NEW Dynamics of CHGPF,” MC, June 1997.)

Measure Twice, Cut Once

Database design is not something to be done in haste. A good, solid, expandable relational database takes forethought and patience. It is easy to be in a hurry to finish a project and take shortcuts. But it takes longer to fix a problem than it does to simply do the job right the first time. The more Band-Aids you use in database design, or even application design, the more your problems will snowball.

Whenever you hear the phrase “that will never happen,” chances are that it will. Keep the future in sight, and never rule out possibilities simply because some situation has never happened before or because you are in a unique business. Not only will you be making your job more difficult in the future, but you will also be limiting the capabilities of your company.

References

OS/400 DB2/400 Database—An Overview (SC41-3700-00, CD-ROM QBKAUB01) OS/400 DDS Reference (SC41-3712-00, CD-ROM QBKAUI01)

Order Header File (ORDHDRPF)

A R RORDHDR

A OHCUST 7P 0 TEXT(‘CUSTOMER NUMBER’)

A COLHDG(‘Customer Number’)

A OHPO 15A TEXT(‘PO NUMBER’)

A COLHDG(‘PO Number’)

A OHINV 9P 0 TEXT(‘INVOICE NUMBER’)

A COLHDG(‘Invoice Number’)

A OHORDD 8S 0 TEXT(‘DATE’)

A COLHDG(‘Order Date’)

A OHDUED 8S 0 TEXT(‘DATE’)

A COLHDG(‘Due Date’)

A OHSHPM 2A TEXT(‘SHIPPING METHOD’)

A COLHDG(‘Shipping Method’)

Order Detail File (ORDDETPF)

A R RORDDET

A ODINV 9P 0 TEXT(‘INVOICE NUMBER’)

A COLHDG(‘Invoice Number’)

A ODLINE 5P 0 TEXT(‘LINE NUMBER’)

A COLHDG(‘Detail Line Number’)

A ODITEM 15A TEXT(‘ITEM NUMBER’)

A COLHDG(‘Item Number’)

A ODQTYO 13P 3 TEXT(‘QUANTITY ORDERED’)

A COLHDG(‘Quantity Ordered’)

A ODQTYS 13P 3 TEXT(‘QUANTITY SHIPPED’)

A COLHDG(‘Quantity Shipped’)

Order Detail Special Instructions File (ODSINSPF)

A R RODSINS

A DIINV 9P 0 TEXT(‘INVOICE NUMBER’)

A COLHDG(‘Invoice Number’)

A DILINE 5P 0 TEXT(‘LINE NUMBER’)

A COLHDG(‘Detail Line Number’)

A DIISEQ 5P 0 TEXT(‘INSTRUCTION SEQUENCE’)

A COLHDG(‘Instruction Sequence’)

A DITEXT 40A TEXT(‘INSTRUCTION TEXT’)

A COLHDG(‘Instruction Text’)

Figure 1: Example of order header, detail, and special instructions DDS

Shipping Method Master File (SHPMSTPF)

A R RSHPMST

A SMSHPM 2A TEXT(‘SHIPPING METHOD’)

A COLHDG(‘Shipping Method’)

A SMDESC 30A TEXT(‘DESCRIPTION’)

A COLHDG(‘Description’)

A SMBCHG 9P 2 TEXT(‘BASE CHARGE’)

A COLHDG(‘Base Charge’)

Figure 2: Use master files, not RPG select statements, to intrepret codes

Reference File (REF)

A R RREF

A CUST 7P 0 TEXT(‘CUSTOMER NUMBER’)

A PO 15A TEXT(‘PO NUMBER’)

A INV 9P 0 TEXT(‘INVOICE NUMBER’)

A DATE 8S 0 TEXT(‘DATE’)

A SHPM 2A TEXT(‘SHIPPING METHOD’)

A LINE 5P 0 TEXT(‘LINE NUMBER’)

A ITEM 15A TEXT(‘ITEM NUMBER’)

A QTY 13P 3 TEXT(‘QUANTITY’)

Order Header File (ORDHDRPF) Using Reference File

A REF(*LIBL/REF)

A R RORDHDR

A OHCUST R COLHDG(‘Customer Number’)

A REFFLD(CUST)

A OHPO R COLHDG(‘PO Number’)

A REFFLD(PO)

A OHINV R COLHDG(‘Invoice Number’)

A REFFLD(INV)

A OHORDD R COLHDG(‘Order Date’)

A REFFLD(DATE)

A OHDUED R COLHDG(‘Due Date’)

A REFFLD(DATE)

A OHSHPM R COLHDG(‘Shipping Method’)

A REFFLD(SHPM)

Order Detail File (ORDDETPF) Using Reference File

A REF(*LIBL/REF)

A R RORDDET

A ODINV R COLHDG(‘Invoice Number’)

A REFFLD(INV)

A ODLINE R COLHDG(‘Detail Line Number’)

A REFFLD(LINE)

A ODITEM R COLHDG(‘Item Number’)

A REFFLD(ITEM)

A ODQTYO R COLHDG(‘Quantity Ordered’)

A REFFLD(QTY)

A ODQTYS R COLHDG(‘Quantity Shipped’)

A REFFLD(QTY)

Figure 3: Example of reference file using order header and detail files

BLOG COMMENTS POWERED BY DISQUS

LATEST COMMENTS

Support MC Press Online

$

Book Reviews

Resource Center

  • SB Profound WC 5536 Have you been wondering about Node.js? Our free Node.js Webinar Series takes you from total beginner to creating a fully-functional IBM i Node.js business application. You can find Part 1 here. In Part 2 of our free Node.js Webinar Series, Brian May teaches you the different tooling options available for writing code, debugging, and using Git for version control. Brian will briefly discuss the different tools available, and demonstrate his preferred setup for Node development on IBM i or any platform. Attend this webinar to learn:

  • SB Profound WP 5539More than ever, there is a demand for IT to deliver innovation. Your IBM i has been an essential part of your business operations for years. However, your organization may struggle to maintain the current system and implement new projects. The thousands of customers we've worked with and surveyed state that expectations regarding the digital footprint and vision of the company are not aligned with the current IT environment.

  • SB HelpSystems ROBOT Generic IBM announced the E1080 servers using the latest Power10 processor in September 2021. The most powerful processor from IBM to date, Power10 is designed to handle the demands of doing business in today’s high-tech atmosphere, including running cloud applications, supporting big data, and managing AI workloads. But what does Power10 mean for your data center? In this recorded webinar, IBMers Dan Sundt and Dylan Boday join IBM Power Champion Tom Huntington for a discussion on why Power10 technology is the right strategic investment if you run IBM i, AIX, or Linux. In this action-packed hour, Tom will share trends from the IBM i and AIX user communities while Dan and Dylan dive into the tech specs for key hardware, including:

  • Magic MarkTRY the one package that solves all your document design and printing challenges on all your platforms. Produce bar code labels, electronic forms, ad hoc reports, and RFID tags – without programming! MarkMagic is the only document design and print solution that combines report writing, WYSIWYG label and forms design, and conditional printing in one integrated product. Make sure your data survives when catastrophe hits. Request your trial now!  Request Now.

  • SB HelpSystems ROBOT GenericForms of ransomware has been around for over 30 years, and with more and more organizations suffering attacks each year, it continues to endure. What has made ransomware such a durable threat and what is the best way to combat it? In order to prevent ransomware, organizations must first understand how it works.

  • SB HelpSystems ROBOT GenericIT security is a top priority for businesses around the world, but most IBM i pros don’t know where to begin—and most cybersecurity experts don’t know IBM i. In this session, Robin Tatam explores the business impact of lax IBM i security, the top vulnerabilities putting IBM i at risk, and the steps you can take to protect your organization. If you’re looking to avoid unexpected downtime or corrupted data, you don’t want to miss this session.

  • SB HelpSystems ROBOT GenericCan you trust all of your users all of the time? A typical end user receives 16 malicious emails each month, but only 17 percent of these phishing campaigns are reported to IT. Once an attack is underway, most organizations won’t discover the breach until six months later. A staggering amount of damage can occur in that time. Despite these risks, 93 percent of organizations are leaving their IBM i systems vulnerable to cybercrime. In this on-demand webinar, IBM i security experts Robin Tatam and Sandi Moore will reveal:

  • FORTRA Disaster protection is vital to every business. Yet, it often consists of patched together procedures that are prone to error. From automatic backups to data encryption to media management, Robot automates the routine (yet often complex) tasks of iSeries backup and recovery, saving you time and money and making the process safer and more reliable. Automate your backups with the Robot Backup and Recovery Solution. Key features include:

  • FORTRAManaging messages on your IBM i can be more than a full-time job if you have to do it manually. Messages need a response and resources must be monitored—often over multiple systems and across platforms. How can you be sure you won’t miss important system events? Automate your message center with the Robot Message Management Solution. Key features include:

  • FORTRAThe thought of printing, distributing, and storing iSeries reports manually may reduce you to tears. Paper and labor costs associated with report generation can spiral out of control. Mountains of paper threaten to swamp your files. Robot automates report bursting, distribution, bundling, and archiving, and offers secure, selective online report viewing. Manage your reports with the Robot Report Management Solution. Key features include:

  • FORTRAFor over 30 years, Robot has been a leader in systems management for IBM i. With batch job creation and scheduling at its core, the Robot Job Scheduling Solution reduces the opportunity for human error and helps you maintain service levels, automating even the biggest, most complex runbooks. Manage your job schedule with the Robot Job Scheduling Solution. Key features include:

  • LANSA Business users want new applications now. Market and regulatory pressures require faster application updates and delivery into production. Your IBM i developers may be approaching retirement, and you see no sure way to fill their positions with experienced developers. In addition, you may be caught between maintaining your existing applications and the uncertainty of moving to something new.

  • LANSAWhen it comes to creating your business applications, there are hundreds of coding platforms and programming languages to choose from. These options range from very complex traditional programming languages to Low-Code platforms where sometimes no traditional coding experience is needed. Download our whitepaper, The Power of Writing Code in a Low-Code Solution, and:

  • LANSASupply Chain is becoming increasingly complex and unpredictable. From raw materials for manufacturing to food supply chains, the journey from source to production to delivery to consumers is marred with inefficiencies, manual processes, shortages, recalls, counterfeits, and scandals. In this webinar, we discuss how:

  • The MC Resource Centers bring you the widest selection of white papers, trial software, and on-demand webcasts for you to choose from. >> Review the list of White Papers, Trial Software or On-Demand Webcast at the MC Press Resource Center. >> Add the items to yru Cart and complet he checkout process and submit

  • Profound Logic Have you been wondering about Node.js? Our free Node.js Webinar Series takes you from total beginner to creating a fully-functional IBM i Node.js business application.

  • SB Profound WC 5536Join us for this hour-long webcast that will explore:

  • Fortra IT managers hoping to find new IBM i talent are discovering that the pool of experienced RPG programmers and operators or administrators with intimate knowledge of the operating system and the applications that run on it is small. This begs the question: How will you manage the platform that supports such a big part of your business? This guide offers strategies and software suggestions to help you plan IT staffing and resources and smooth the transition after your AS/400 talent retires. Read on to learn: