Question

sql using CL on the Iseries

Asked by: dprice7

Anbody doing SQL in a CL on the Iseres?

thanks in advance,

Don

This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2005-03-17 at 16:47:54ID21355416
Tags

cl

,

sql

,

iseries

,

using

Topic

Programming for iSeries / AS400

Participating Experts
3
Points
125
Comments
8

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. CLS for C++
    I was wondering, is there a CLS (clearscreen places cursor at the top left) command for C++? fred (real name)
  2. Returning Results from a CL Program
    I know very little about IBM's DB2 database, but I am working with the DBA of one of our clients to integrate their AS/400 with our SQL Server. We have a full integration system set up so that our web server can read data from the AS/400 utilizing Client/iSeries ODBC Access....
  3. CLS-compliant?
    I am receiving an error message: C:\Inetpub\wwwroot\retail2002\Controls\Accounts\AddressEdit.ascx.cs(216): Argument type 'MSXML2.DOMDocument40' is not CLS-compliant What does this mean?
  4. CALLING CL PROGRAM AND PASSING VARIABLES USING …
    Hello and thank you for you help in advance. I am using Notes/Domino LotusScript and I need to call a CL program on the AS400. I want to pass a text value to the CL program and receive a text value back. I know that I cannot call an RPG program directly. I have used clien...

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.

Join the Community

Answers

 

by: tliottaPosted on 2005-03-17 at 18:32:14ID: 13571340

Don:

Yes, yes and no.

That is, CL and SQL don't exactly go together; but there are a couple ways to get it to work.

Easiest is via the RUNSQLSTM command. It will execute an SQL statement or a series of statements delimited by semi-colons (";"). The troubles are that (1) the statement must be in a source file member and (2) only statements that can executed immediately are allowed.

There's a more technical explanation of that second part, but I don't have a decent link for it off the top of my head. One critical result is that there's no good way of using a SELECT statement directly via RUNSQLSTM such as you might in interactive SQL, i.e., the STRSQL command.

After RUNSQLSTM, there is STRQMQRY. Now, this also needs a source member to hold the SQL statement and it further needs to be compiled into a *QMQRY object.

But it has a very useful saving grace -- the source is allowed to have a whole bunch of "substitution variables" that get substituted into the 'statement' at run-time. While that only seems useful in general, it becomes seriously useful when you discover that _any_ part of the statement can be replaced by a substitution value.

Consider first:

  SELECT &a FROM &b

That means you can choose both your column list and your table list at run-time. Those values would be passed in as parameters to the STRQMQRY command. Not bad.

But now consider this:

  &a&b&c&d&e&f

The _entire statement_ is nothing but a series of  substitution variables. That is, you can pass in a series of parameter values that string together to create the actual SQL statement on the fly.

There are a couple odd tricks. First, a substitution _value_ cannot be more than 55 characters in length. Second, the substitution variable names are case-sensitive -- when you pass the variable name into STRQMQRY along with the value, you have to pass the name in the proper case. Finally, if you want an SQL statement that will contain quotes, e.g.:

  SELECT a,b,c FROM mylib/myfile WHERE a='A1B2'

...then you need to be careful in how you construct the substitution values for the STRQMQRY command parameters.

Fortunately, most of this has already been done for you. You can run internet searches for SQL and CL and find examples that you can download. I have an odd example at my web site though it's primarily for demonstration because the processing is REXX.

You can look it over at < http://zap.to/tl400 >. Look in the Files section under REXX RunSQL. It provides a RUNSQL command that essentially lets you pass an SQL statement in as a parameter. It breaks the string into 55 character values and passes them into a STRQMQRY command. It also provides for output types of *OUTFILE and *PRINT as well as to the display.

For many displays, I most often use just:

  RUNQRY  *n  mylib/myfile

It's on all AS/400s. If you try to prompt it and use some of the advanced parameters, you'll need Query/400 installed.

Also note that CL can make use of OPNQRYF along with RCVF to process database records.

Tom

 

by: dprice7Posted on 2005-03-17 at 19:08:30ID: 13571482

Tom,

I actually already have used both of these before.

Was talking more about using straight sql as in functions, procedures etc.. SPL in a CL source member.

I have seen it in high level languages like RPG and Cobol but not in CL.

According to IBM there should be a way.

Don

 

by: ShadowProgrammerPosted on 2005-03-18 at 01:18:15ID: 13572720

Here it a link to a utility to allow you to run SQL statements from within a CL program.

http://www.as400pro.com/servlet/sql.tipView?key=159&category=SQL

The only thing you can't do with this is return selected records to the CL program for individual processing - but I get round this by building/populating a work file and then process each record in the work file.

instead of "select * from dbfile where x=y", you would "insert into workfile select * from dbfile where x=y" then process the records in workfile.

But otherwise you can do want you want as normal SQL.

NB. You can run this from a command line and "select..." will display the records on screen

Tony.

 

by: tliottaPosted on 2005-03-18 at 10:45:33ID: 13577265

Don:

Sorry, the question is common at the level I answered.

Technically, I suppose one could consider that calling the Process Extended Dynamic SQL (QSQPRCED) API would be an example of using SQL in CL. I think the only serious issue would be setting up pointers to host variables in the SQLDA or getting into advanced options for package creation when using format SQLP0400.

As with many APIs, the trick is to figure out how to manipulate a pointer data type.

But I suspect you're wanting something more like embedded SQL in RPG or other languages.

Well, since there is no SQL pre-compiler for CL, there are no commands such as CRTSQLCLI nor CRTSQLCL. I'd sure be interested in hearing how IBM ever expects it to be done if it isn't something such as QSQPRCED (or RUNSQLSTM or STRQMQRY).

You don't happen to have a reference where IBM implies CL and SQL?

Tom

 

by: tliottaPosted on 2005-03-19 at 16:52:13ID: 13584094

Don:

Another idea just came to mind if you have V5R2. (Maybe 5.1 too; not certain.)

 ==>  DSPUSRPRF USRPRF(*ALL) OUTPUT(*OUTFILE)
            OUTFILE(mylib/USRP)

 ==>  QSH CMD('db2 ''select * from mylib.usrp''')

The recent db2 utility in QShell can give some useful effects, especially when combined with other QShell utilities in a sequence of commands.

Tom

 

by: tliottaPosted on 2005-03-22 at 19:04:23ID: 13608052

More on QShell and db2 command...

Instead of the QSH command to invoke the db2 command utility, how about:

 ==>  call QZDFMDB2  ('select UPUPRF from mylib.usrp')

The QShell utilities all have programs behind them. In this case, the db2 utility goes through a symbolic link to program QSYS/QZDFMDB2 once QShell is installed under V5R2. Most of those programs can be called directly by passing separate parms instead of QShell command-line switches.

This has some possibilities. Cool.

I do various things by tracking the symbolic links to their programs and calling them directly. It just came to mind that this one might be useful to others.

While SELECT might not be the best choice for a direct call rather than indirect through QShell due to formatting in a terminal session, other SQL verbs could give excellent results perhaps.

Tom

 

by: daveslaterPosted on 2005-03-23 at 06:57:33ID: 13612025

Hi
I am just going to add a bit of weight to Tom’s comments.
When using SQL in RPG / Cobol etc.. there is a separate compiler – well pre compiler – that converts the high-level SQL into API calls.

There are also some IMB supplied definitions that are automatically copies as part of the compile process.

Once the original source is converted it is then compiled via the standard language compiler.

Dave

 

by: tliottaPosted on 2005-03-23 at 11:17:50ID: 13614924

Dave:

Though perhaps off-topic, the relationship between the code that comes out of the RPG SQL pre-compiler and the RPG compiler itself seems worth examining. (Similarly for COBOL SQL or other HLL.) This is most interesting in the case of earlier OPM RPG since the pointer data type is relatively new but RPG SQL has been around for a while.

Someday I'd like to take the intermediate source code from an SQL pre-compile and transfer it to a system that doesn't have the SQL Developer kit installed. If I compile and run, will I get errors either at compile-time or run-time?

It's not necessary to have the DevKit installed in order to run an SQL RPG program, so compile-time seems where trouble would be. But I'm not sure how the RPG compiler itself would know what any problem would be.

Therefore, if OPM RPG can compile without pointers and then run, it _seems_ possible that the various structures and calls to SQL functions could be written in CL.

Tom

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...