In the previous article, I showed how to make a table and its columns more user-friendly for people who are not used to IBM i’s 10-character naming limitations. Let’s continue that process with a faster approach.
Let’s repeat the process we performed on the previous article for PFSTM, the Students table, so that I can show you how to do the renaming, or more accurately, double-naming process, in one step. The current Students table looks like Table 1.
|
Table Name |
Column Name |
Data Type |
Length |
Dec. Pos. |
Description |
|
PFSTM |
STID |
Integer |
|
|
Record ID (primary key) |
|
PFSTM |
STNM |
Char |
60 |
|
Student name |
|
PFSTM |
STDB |
Decimal |
8 |
0 |
Date of birth |
|
PFSTM |
STAD |
Char |
60 |
|
Home address |
|
PFSTM |
STPN |
Char |
15 |
|
Home phone number |
|
PFSTM |
STMN |
Char |
15 |
|
Mobile number |
|
PFSTM |
STEM |
Char |
60 |
|
Email address |
|
PFSTM |
STDL |
Char |
20 |
|
Driver's license |
|
PFSTM |
STSN |
Char |
11 |
|
Social security number |
|
PFSTM |
STSC |
Char |
1 |
|
Status |
|
PFSTM |
STCU |
Varchar |
18 |
|
Created by |
|
PFSTM |
STCT |
Timestamp |
|
|
Created on |
Table 1: The Students table structure
Again, we’re going to use DROP TABLE to get rid of the existing PFSTM:
DROP TABLE UMADB_CHP4.PFSTM;
And then we’ll issue a modified CREATE TABLE statement to create a table recognizable by its SQL and system names:
CREATE TABLE UMADB_CHP4.TBL_STUDENTS
FOR SYSTEM NAME PFSTM
(
STUDENT_ID FOR COLUMN STID INTEGER
PRIMARY KEY
GENERATED ALWAYS
AS IDENTITY(START WITH 1
INCREMENT BY 1)
, NAME FOR COLUMN STNM CHAR(60) CCSID 37 NOT NULL DEFAULT ''
, DATE_OF_BIRTH FOR COLUMN STDB DECIMAL(8, 0) NOT NULL DEFAULT 0
, HOME_ADDRESS FOR COLUMN STAD CHAR(60) CCSID 37 NOT NULL DEFAULT ''
, HOME_PHONE_NBR FOR COLUMN STPN CHAR(15) CCSID 37 NOT NULL DEFAULT ''
, MOBILE_NBR FOR COLUMN STMN CHAR(15) CCSID 37 NOT NULL DEFAULT ''
, EMAIL_ADDRESS FOR COLUMN STEM CHAR(60) CCSID 37 NOT NULL DEFAULT 'N/A'
, DRIVERS_LICENSE FOR COLUMN STDL CHAR(20) CCSID 37 NOT NULL DEFAULT 'N/A'
, SOCIAL_SEC_NBR FOR COLUMN STSN CHAR(11) CCSID 37 NOT NULL DEFAULT 'N/A'
, STUDENT_STATUS FOR COLUMN STSC CHAR(1) CCSID 37 NOT NULL DEFAULT '1'
, CREATED_BY FOR COLUMN STCU VARCHAR(18) DEFAULT USER
, CREATED_ON FOR COLUMN STCT TIMESTAMP DEFAULT CURRENT TIMESTAMP
)
RCDFMT PFSTMR
;
Here, the long names are truly descriptive: SOCIAL_SEC_NBR is a bit abbreviated, but it’s far more apparent than STSN. Note that I’ve added a FOR SYSTEM NAME PFSTM instruction (see the second line of the statement), which removes the need for a separate CREATE ALIAS statement. This is very practical, but not always possible: you can only do this if you use an SQL name that’s not a valid system name, as I mentioned before.
This table is particularly interesting because it has some moderately long names that users might or might not want to use. I’m bringing this up to show you that you can refer to short and long names on the same statement; the database engine will figure out to which column you’re referring and show the appropriate data. Here’s an example:
SELECT STUDENT_ID
, NAME
, STDB
, HOME_ADDRESS
, STPN
FROM UMADB_CHP4.TBL_STUDENTS
;
As you can see here, I’m using a mix of short and long names in this statement. This can be especially useful when the long names are too long or you’re in a hurry to get things done. The RPG programs will still work as before, because they “see” the column system names, which are the same as the “old” DDS field names. You (and your end users) get the best of both worlds with this simple technique, but keep in mind that you need to backup the table’s data before performing the DROP operation and restore it (using an INSERT statement with a nested SELECT, for instance) once you’ve created the table with the appropriate table and column names.
Time for Some Practice
By now, you’ve realized the power of longer and more descriptive names. Before changing the tables in your application, why don’t you practice with the rest of UMADB’s tables? If you’ve been following this series, you should have the complete set on the UMADB_CHP3 library by now.
There’s something I’ve neglected to mention, and it’s a bit important: naming conventions. I followed a simple naming convention for the table names, prefixing them with “TBL_”. I’ll do the same later with the views, using the “VIEW” prefix, and the indexes, resorting to the “Index” prefix. I followed a looser naming convention for the column names, but adhered to the so-called underscore convention: I used an underscore character (_) to separate the words in the column name. It’s a bit longer, but it’s far more clear than camel case, mainly because SQL tends to return column names in all caps when you query it. I followed a few other, more subtle conventions regarding the column names: for instance, all the ID and status columns were prefixed with the name of the table; whenever a table contains data from another table, I indicated where the data is coming from—for instance, there’s a “student name” column on the Grades table, so its long name is Student_Name.
With this information, you should be able to create all the tables on the UMADB database. That’s all for now. Next time, we will be talking about ways to make the database more accessible by hiding its complexity and mapping it in a user-friendly way.




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.
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:
LATEST COMMENTS
MC Press Online