Modernize AS400 iSeries Query – Convert to IBM i SQL

  • Home
  • /
  • Blog
  • /
  • Modernize AS400 iSeries Query – Convert to IBM i SQL

May 23, 2018

Convert QUERY to IBM i SQL

This week I be mainly…. working on a Casino System upgrade, dragging decades old code into the twenty first century. Old RPG3, RPG400, CLP programs and techniques using outdated OPNQRYF and QUERIES are fighting back tooth and nail. I love this schnizzle. 🙂

One of the techniques for upgrading/converting older QUERY400 reports to modern SQL format is IBM i’s very cool RTVQMQRY command.

I had completely forgotten about this technique (possibly because my 32k system 38 brain has a memory leak) but it was so simple and quick I had to write it down before I had a mental buffer overload.

IBM i QUERY

A while ago I made a QUERY400 for a Software Tester who wanted to see a hotel check-in date from an Agilysys LMS File (GIP) which stores dates in the 5 digit HYD (hundred year format). But, of course, our tester wanted to check the dates in human friendly USA standard date format (M/D/YY)

So I made a quick and dirty QUERY400 to basically list the dates, create a new mapped date showing it in *USA format:

Modernize AS400 iSeries Query - Convert to IBM i SQL
Modernize AS400 iSeries Query - Convert to IBM i SQL
Modernize AS400 iSeries Query - Convert to IBM i SQL
Modernize AS400 iSeries Query - Convert to IBM i SQL
Modernize AS400 iSeries Query - Convert to IBM i SQL

and then run the query and see a nice simple data screen like this:

Modernize AS400 iSeries Query - Convert to IBM i SQL

From QUERY to SQL

Now if we want to modernize our approach and do this with a SQL statement it’s as easy as pie!

We simply use the RTVQMQRY command to suck that QUERY400 definition and spit out a source file with a lovely SQL statement in it that looks like this:

RTVQMQRY QMQRY(LITTENN/GIPCHECK) SRCFILE(LITTENN/QSQLSRC) ALWQRYDFN(*YES)

and this generates this lovely piece of source code:

Modernize AS400 iSeries Query - Convert to IBM i SQL

which as  you can see, has this line of SQL in it:

SELECT ALL CIDTGI, CITMGI, DATE(CIDTGI+DAYS('12/31/1899')) AS
CHECKINDAT, CIAGGI, FNAMGI, KYDTGI 
FROM LMDTA15/GIP T01 
WHERE CIDTGI > 0

and we can run that in SQL to see the exact same result.

So, next time a grey haired AS400 developer tells you that it’s a QUERY and it can’t be changed… you can raise an eyebrow and mutter about IBM i RTVQMQRY.  🙂

NickLitten


IBM i Software Developer, Digital Dad, AS400 Anarchist, RPG Modernizer, Shameless Trekkie, Belligerent Nerd, Englishman Abroad and Passionate Eater of Cheese and Biscuits.

Nick Litten Dot Com is a mixture of blog posts that can be sometimes serious, frequently playful and probably down-right pointless all in the space of a day.

Enjoy your stay, feel free to comment and remember: If at first you don't succeed then skydiving probably isn't a hobby you should look into.

Nick Litten

related posts:

  • Hello from Abel Willium, Great Blog!

    IBM i Modernization can help businesses in many ways. With the power of modernization, any business can enrich its customer experience. And there is no need to explain the immense importance of security and reliability it offers. The blog adds something new to my existing stock of knowledge.

    Thanks.

  • {"email":"Email address invalid","url":"Website address invalid","required":"Required field missing"}

    Subscribe NOW
    7-day free trial

    Take This Course with ALL ACCESS

    Unlock your Learning Potential with instant access to every course and all new courses as they are released.
     [ For Serious Software Developers only ]

    Online Learning for IBM i Software Technology Professionals

    “The more that you read, the more things you will know. The more that you learn, the more places you’ll go.” – Dr. Seuss

    >