You are currently on IBM Systems Media’s archival website. Click here to view our new website.

IBM i > DEVELOPER > RPG

Alias Support in RPG


Back in September’s EXTRA, we discussed the file handling enhancements that were added to RPG in the V6 release. In that piece, we mentioned that the introduction of the QUALIFIED keyword for files opened the door for RPG to finally make use of long variable names for externally described files. These have been available to COBOL and SQL users for many years, but RPGers were locked in a 10-character world. As we noted at the time, that feature was added to RPG in the V7 release. Since many of our readers are now using V7, or shortly will be, we decided to review this new capability.

ALIAS Names

We find many RPGers are unaware of the long alternative names, at least until they start working with SQL. This is hardly surprising given that until now there was no way to make use of them in RPG programs.

So, let’s start with a quick refresher on how Alias names are defined. In DDS, the long name is defined with the ALIAS keyword as you can see in this simple example.

 * Sample DDS to demonstrate use of Alias names
A      R MYTABLE2R
A        CUSTNAME     30A     ALIAS(CUSTOMER_NAME)
A        STADDR       40A     ALIAS(STREET_ADDRESS)
A        CITY         20A
A        STATE        2A

Notice that not all fields must have an alias defined, only those where a longer name makes sense. Here’s the same basic table defined with SQL:

CREATE TABLE PARTNER400.MYTABLE (
     CUSTOMER_NAME FOR COLUMN CUSTNAME CHAR(30) NOT NULL,
     STREET_ADDRESS FOR COLUMN STADDR CHAR(40) NOT NULL,
     CITY CHAR(20) NOT NULL,
     STATE CHAR(2) NOT NULL )
     ;

Certainly a longer name like STREET_ADDRESS makes more sense (and requires less brain power to interpret) than a name like STADDR. Of course, for many of you even a name like STADDR will be more obvious than the names you use every day. Those would tend to include a two character “which file did this come from” prefix, resulting in a name more like CMSTADDR, which is much harder to decipher.

Jon Paris is a technical editor with IBM Systems Magazine and co-owner of Partner400.

Susan Gantner is a technical editor with IBM Systems Magazine and co-owner of Partner400.



Advertisement

Advertisement

2019 Solutions Edition

A Comprehensive Online Buyer's Guide to Solutions, Services and Education.

New and Improved XML-INTO

Namespace support makes the opcode a viable option

Authenticating on the Web

The finer points of OpenRPGUI, Part 1

The Microphone is Open

Add your voice: Should IBM i include open-source RPG tools?

IBM Systems Magazine Subscribe Box Read Now Link Subscribe Now Link iPad App Google Play Store
IBMi News Sign Up Today! Past News Letters