• The Four Hundred
  • Subscribe
  • Media Kit
  • Contributors
  • About Us
  • Contact
Menu
  • The Four Hundred
  • Subscribe
  • Media Kit
  • Contributors
  • About Us
  • Contact
  • Guru: Wow! I Could Have Had Long Column Names! – Take 2

    October 23, 2017 Ted Holt

    In 1990, three computer science professors named Gorla, Benander, and Benander wrote about debugging effort in COBOL programs. Among their claims was that debugging is easier if variable names were between 10 and 16 characters long. The original native data definition facilities allowed variable names up to 10 characters, but nowadays we can define alias names that Gorla, Benander, and Benander would be proud of.

    It is common in many DB2 for i shops to have physical files with field names of six characters or less. This practice dates to predecessor systems, such as the System/36, for which the programming language of choice was RPG II. Replacing short field names with longer ones is impractical in many cases, but if you are in this situation, you can easily add alias column names.

    Adding Alias Names to Physical Files

    Adding alias field names is easy with DDS-described files. Use the ALIAS keyword and run the Change Physical File (CHGPF) command.

    Here’s part of the DDS for a file named NCUST.

    R CUSTREC            
      COMPANY        3P 0
      CUSTID         7P 0
      NAME          20A  
      CRDLMT         7P 2
    

    Here’s the same DDS after alias names have been added.

    R CUSTREC                                          
      COMPANY        3P 0 
      CUSTID         7P 0       ALIAS(CUSTOMER_ACCOUNT)
      NAME          20A 
      CRDLMT         7P 2       ALIAS(CREDIT_LIMIT)
    

    Here’s the necessary CHGPF command.

    CHGPF FILE(MYLIB/NCUST) SRCFILE(MYLIB/QDDSSRC)
    

    Let me add a few points.

    First, the record level ID does not change when you add aliases. You will not have to recompile the programs that use the file.

    Second, logical files that use the same record format that the physical file does will also have the new aliases. Logical files that do not use the same record format will not have the aliases.

    Third, most native interfaces cannot use the aliases. For example, Copy File (CPYF) must refer to CRDLMT, not CREDIT_LIMIT.

    CPYF FROMFILE(NCUST) . . . INCREL((*IF CRDLMT *LE 250))
    

    The RPG IV and COBOL compilers can use aliases. In RPG, add the ALIAS keyword to the file definition (F spec or DCL-F).

    FNCust     if   e             disk    alias
    
    dcl-f  NCust  alias;
    

    COBOL programs use the DD option of the COPY directive.

    environment division.
    input-output section. 
        select Customer-file assign database-ncust.
    
    data division. 
    file section. 
    fd  Customer-file. 
    01  copy dd-custrec-i of ncust.
    

    Adding Alias Names to SQL Tables

    It is also possible to add alias names to SQL tables. To do so, use CREATE OR REPLACE TABLE, a fairly new option for the CREATE TABLE statement.

    Assume table NCUSTOMERS was created with the short names that had been in use for decades.

    create table ncustomers
       ( Company     dec(3),
         CustID      dec(7),
         Name        char(20),
         CrdLmt      dec(7,2),
      primary key (Company, CustID))
    

    Here’s how to add the alias names.

    create or replace table ncustomers
    (Company                            dec(3),
     CustomerAccount for column CustID  dec(7),
     Name                               char(20),
     CreditLimit     for column CrdLmt  dec(7,2) )
    

    The system column names and definitions are the same as before. Only the SQL column names (i.e. the aliases) have changed.

    Any views over this table will not automatically get the alias names. You’ll have to recreate those views.

    It’s been almost six years since I last wrote about aliases. I’m glad to see that some things have changed for the better in the meantime.

    RELATED STORIES

    Debugging Effort Estimation Using Software Metrics

    Wow! I Could Have Had Long Column Names!

    Share this:

    • Reddit
    • Facebook
    • LinkedIn
    • Twitter
    • Email

    Tags: Tags: FHG, Four Hundred Guru, IBM i, RPG, SQL

    Sponsored by
    WorksRight Software

    Do you need area code information?
    Do you need ZIP Code information?
    Do you need ZIP+4 information?
    Do you need city name information?
    Do you need county information?
    Do you need a nearest dealer locator system?

    We can HELP! We have affordable AS/400 software and data to do all of the above. Whether you need a simple city name retrieval system or a sophisticated CASS postal coding system, we have it for you!

    The ZIP/CITY system is based on 5-digit ZIP Codes. You can retrieve city names, state names, county names, area codes, time zones, latitude, longitude, and more just by knowing the ZIP Code. We supply information on all the latest area code changes. A nearest dealer locator function is also included. ZIP/CITY includes software, data, monthly updates, and unlimited support. The cost is $495 per year.

    PER/ZIP4 is a sophisticated CASS certified postal coding system for assigning ZIP Codes, ZIP+4, carrier route, and delivery point codes. PER/ZIP4 also provides county names and FIPS codes. PER/ZIP4 can be used interactively, in batch, and with callable programs. PER/ZIP4 includes software, data, monthly updates, and unlimited support. The cost is $3,900 for the first year, and $1,950 for renewal.

    Just call us and we’ll arrange for 30 days FREE use of either ZIP/CITY or PER/ZIP4.

    WorksRight Software, Inc.
    Phone: 601-856-8337
    Fax: 601-856-9432
    Email: software@worksright.com
    Website: www.worksright.com

    Share this:

    • Reddit
    • Facebook
    • LinkedIn
    • Twitter
    • Email

    A Skills Shortage Solution Alert Vision Adds Security To HA Management Service

    Leave a Reply Cancel reply

TFH Volume: 27 Issue: 69

This Issue Sponsored By

  • Fresche Solutions
  • HelpSystems
  • HiT Software, Inc. a BackOffice Associates Company
  • Computer Keyes
  • T.L. Ashford

Table of Contents

  • Advice For The Power Systems Shop That Has To Buy Now
  • Vision Adds Security To HA Management Service
  • Guru: Wow! I Could Have Had Long Column Names! – Take 2
  • A Skills Shortage Solution Alert
  • Big Blue Profits, Poised For The Power9

Content archive

  • The Four Hundred
  • Four Hundred Stuff
  • Four Hundred Guru

Recent Posts

  • POWERUp 2025 –Your Source For IBM i 7.6 Information
  • Maxava Consulting Services Does More Than HA/DR Project Management – A Lot More
  • Guru: Creating An SQL Stored Procedure That Returns A Result Set
  • As I See It: At Any Cost
  • IBM i PTF Guide, Volume 27, Number 19
  • IBM Unveils Manzan, A New Open Source Event Monitor For IBM i
  • Say Goodbye To Downtime: Update Your Database Without Taking Your Business Offline
  • i-Rays Brings Observability To IBM i Performance Problems
  • Another Non-TR “Technology Refresh” Happens With IBM i TR6
  • IBM i PTF Guide, Volume 27, Number 18

Subscribe

To get news from IT Jungle sent to your inbox every week, subscribe to our newsletter.

Pages

  • About Us
  • Contact
  • Contributors
  • Four Hundred Monitor
  • IBM i PTF Guide
  • Media Kit
  • Subscribe

Search

Copyright © 2025 IT Jungle