× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



Hi, Joel:

You could use the CL CALL command to implement a very simple syntax for "embedded SQL" in CL programs, like this:

CALL SQL ( SELECT DISTINCT * FROM 'QGPL/QAUOOPT' )

:Leverage what the CALL command provides by writing a little "SQL" program that concatenates all of its arguments, (e.g. using *BCAT), to form the SQL query string to pass to your RUNSQL command (or the one now provided by IBM.)

To ease the use of single-quotes, use a "special value" of *QUOTE, that tells the SQL program to "en-quote" the next argument ... so in this case:

CALL PGM(SQL) PARM( SELECT * FROM 'QGPL/QAUOOPT' +
WHERE OPTION = *QUOTE &OPT )

the value of &OPT will have single-quotes around it in the query string.

This SQL program is trivial to write in C, and also fairly easy to do in ILE RPG IV, and is even possible in ILE CL (CLLE), although slightly more work.

Let me know if you want to see a working example of this technique, and I can post examples at code.midrange.com ...

Also, it is easy to create a iuser-defined "SQL" command, so the syntax would now look like this in your CL programs that use SQL:

SQL (SELECT DISTINCT * FROM 'QGPL/QAUOOPT')
or
SQL (SELECT * FROM 'QGPL/QAUOOPT' +
WHERE OPTION = *QUOTE &OPT)

I can post the command definition source, along with working examples of the CPP (command processing program) for the proposed SQL command, at code.midrange.com, if anyone is interested. :-)

All the best,

Mark S. Waterbury

> On 5/11/2012 3:01 PM, Stone, Joel wrote:
There MUST be a better method of coding SQL in a CL source member.
...(snip)...
Thanks!

As an Amazon Associate we earn from qualifying purchases.

This thread ...

Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.