Have the SQL statement as a txt member.
Use the RUNSQLSTM statement in your CL program.
RUNSQLSTM SRCFILE(MARIA/QSQLSRC) SRCMBR(SQLBATCH) +
Personally I use this approach when I want to execute SQL in batch.
This will work for SQL statements except for SELECTs.
If you need to run SELECT statements from a CL program, you can save the statement to a txt member. Run CRTQMQRY over the txt member to create a QMQRY object that you can run from a CL via STRQMQRY.
The “best” way is to call an embedded SQL program that runs the statements.
Next best is either RUNSQLSTM to execute SQL statements from a source member or STRQMQRY to execute compiled SQL statements. A RUNSQLSTM source member can have practically as many statements as you need, while STRQMQRY will consist of a single statement. However, a QM query can be very good at integrating CL variable values into the query statement. RUNSQLSTM allows for quick generation and execution; QM queries must be compiled. (Any system can compile them even without the SQL Dev Kit.)
If you don’t have the SQL Development Kit LPP, then embedded SQL programming is much more difficult. It must be done with the SQL CLI APIs. But if you’re already familiar with ODBC APIs, then you’ll be right at home.
If the SQL is complex and standard embedded SQL is unavailable, then REXX can run almost all useful SQL statements. REXX is always available and SQL can always be used with it.
There are many options. CL doesn’t support SQL directly, but any one or more of the options is almost always sufficient.
In i 7.1 (and i 6.1 with PTFs), the RUNSQL command can be used in CL to execute dynamic SQL statements.