Using the same AS400 QRY in Dev, Test and Prod

  • Home
  • /
  • Blog
  • /
  • Using the same AS400 QRY in Dev, Test and Prod

August 17, 2022

Using the same AS400 QRY in Dev, Test and Prod

I had a good question from a subscriber today:

AS400 qry printer

We have a production environment and a test environment on our IBM i. We have processes in place to switch library lists depending on which environment we are in. We have issues where our test side processes and reports are inaccurate due to the queries that run behind the scenes. These queries are using the production environment libraries because there is no way to use *libl in the query. What options do we have to eliminate this issue?

This is a common situation that I’ve seen in many sites that use the good old AS400 and iSERIES Query functions.

The problem with old QUERY functions is that the library (Schema) for each file (table) is found at time of query creation and this library is attached to the query when it is created.

For example: if I create a query called QUERYNAME in my development library over a file called “CUSTOMERS“, it will look for a file called customers in the jobs *LIBL and set that file as the one that it is querying. If I move the query to another library it will still be scoped over the original version of “customers” even if there is a new version of “customers” in the new library.

We don’t want to recreate a different version of each query for each environment.

We dont have time to rewrite all these processes into SQL or RPG either.

Is there a way to force the test queries to use the test files?

Is an override in the CL a safe step or is there a better way?

The answer is YES

You could change the CL that use the RUNQRY statement.

RUNQRY QRY(QUERYNAME)

to

RUNQRY QRY(QUERYNAME) QRYFILE(*LIBL/CUSTOMERS) 

This forces the query to use the file from the *LIBL.

Now it will work in each environment, using the copy of CUSTOMERS that it finds in each environment

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:

{"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

>