iSeries / AS400 FAQ : (Category) Programming : (Category) SQL : Can I use SQL in a CL program?
While one can’t directly embed SQL in a CL program, there are several techniques that allow one to process SQL statements. One method is to place the desired SQL statements (no SELECT!) in a source member and using IBM’s RUNSQLSTM command to process that source member. Another method is to use QMQRY to process SQL statements. A very old edition of News/400 has the basic concept described. Basically, QMQRY allows the use of substitution parameters in SQL statements, like SELECT NAME FROM CUSTMAST WHERE ZIP = &ZIP This gets compiled with CRTQMQRY and then run with STRQMQRY SETVAR((ZIP 02134)) The trick employed by the magazine article was to make the entire statement a variable! &STMT This gets run with STRQMQRY SETVAR((STMT SELECT * FROM CUSTMAST)) This works for very short statements, but QMQRY has a limit of 50 characters for each variable.
Related Questions
- iSeries / AS400 FAQ : (Category) Programming : (Category) CL : How can I get information out of a system message?
- iSeries / AS400 FAQ : (Category) Programming : (Category) SQL : How do I access a specific member with SQL?
- iSeries / AS400 FAQ : (Category) Programming : (Category) SQL : Can I use SQL in a CL program?