Executing SQL Statements from CL Programs

Article ID: 17194

Q: Is it possible to execute SQL statements from within a CL program? If so, how do I do it?

A: Yes, you can run SQL statements from a CL program. To do so, you place your SQL statements in a source file member and then use command RunSQLStm (Run SQL Statements) to execute the statements in the member.

For example, suppose you wish to set field ProcFlag to value Y in all records found in file YourLib/YourFile. The following SQL statement accomplishes this:

Update YourLib/YourFile
  Set ProcFlag = 'Y'

Simply create a source member with the above SQL statement and issue the following command then in your CL program:

  RunSQLStm  SrcFile( YourLib/YourSrcF ) SrcMbr( YourMbr )

iSeries Network Professional members can read about a caveat regarding the use of SELECT in RunsSQLStm at http://www.iseriesnetwork.com/article.cfm?ID=6255.

You can read a how to use Query Management Queries (QMQRY) to execute SQL statements from a CL program here:
http://www.iseriesnetwork.com/article.cfm?ID=15027

ProVIP Sponsors

ProVIP Sponsors