SQ Lnames in RPG

Hi Experts,

After creating several tables with SQL (because of the naming I have to use), I have in my Data Library files with names as CUST_00001 and PROD_00001 (as expected),
The field names in the files from DB2 site, are numbered CDTA_00001, CDTA_00002 etc.  (also as expected),

I prefer to have the SQL field names in my SQLRPGLE program, so that I can create a readable (maintainable) program, is there a way to manage that?

Thanks
LVL 17
MurpheyApplication ConsultantAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Gary PattersonVP Technology / Senior Consultant Commented:
Use the ALIAS keyword on your F-specs, DCL-F, or external data structure definition to pull in long column names for native RPG I/O.  

http://www.rpgpgm.com/2014/11/using-alias-for-longer-field-names.html

Embedded SQL can reference either short name or long name.

I'll note that you can also create long names in DDS for PF, LF, DSPF, and PRTF files using the DDS ALIAS keyword.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
lcohanDatabase AnalystCommented:
If you did not created the tables with an alieas already as shown here: https://www.itjungle.com/2011/11/16/fhg111611-story02/ then as far as I'm aware you have few options:
1. more painful...to recreate the tables with the alias name included so you can use that instead of actual anagrammed column name_number
2. create a view on each table where you use the alias name in the view AS the column name from the table.
0
Gary PattersonVP Technology / Senior Consultant Commented:
You can also control the short name (system name) that is assigned to tables and views using the FOR SYSTEM NAME clause on CREATE TABLE, CREATE VIEW, CREATE INDEX, and CREATE GLOBAL TEMPORARY TABLE:

CREATE OR REPLACE VIEW
PRODLIB/COMPARE_YEARS_2012_AND_2011
FOR SYSTEM NAME COMP_12_11
AS SELECT …
 
https://www.ibm.com/developerworks/mydeveloperworks/wikis/home/wiki/IBM+i+Technology+Updates/page/Direct+control+of+system+names+for+tables,+views+and+indexes
1
MurpheyApplication ConsultantAuthor Commented:
That was a simple solution :-)
THANKS !!!!!

The DDS Alias is not an option (in this case) because I received a load of SQL creation scripts from the remote server, and using these saves a lot of time
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
SQL

From novice to tech pro — start learning today.