Example: Call CL command stored procedures

It is possible to run iSeries™ server commands by using stored procedures. The two examples that are provided here apply to ODBC programs.

Simply call Execute Command (QCMDEXC) to run the command. The process is relatively simple, but ensure that you include all of the zeros in the length parameter. Use the Remote Command API as an alternative.

The first example enables the powerful SQL tracing facility that writes data into the joblog for the job running the SQL (in this case, the server job).

The second example overcomes a restriction in SQL: its limited ability to work with multi-member files. You cannot create a multi-member file through CREATE TABLE. However, the following example shows you how to access with ODBC anything but the first member of a file that is created through DDS:

	 Dim hStmt                  As Long

	 rc = SQLAllocHandle(SQL_HANDLE_STMT, ghDbc, hStmt)
	  If rc <> SQL_SUCCESS Then
		 Call DspSQLError(SQL_HANDLE_DBC, ghDbc, "Problem: Allocating Debug Statement Handle")
	 End If

	 ' Note that the string within single quotes 'STRDBG UPDPROD(*YES)' is exactly 20 bytes
	 cmd = "call qsys.qcmdexc('STRDBG UPDPROD(*YES)',0000000020.00000)"

	 ' Put the iSeries job in debug mode
	 rc = SQLExecDirect(hStmt, cmd, SQL_NTS)
	 If rc <> SQL_SUCCESS Then
		 Call DspSQLError(SQL_HANDLE_STMT, hStmt, "Problem: Start Debug")
	 End If
  
	 rc = SQLAllocHandle(SQL_HANDLE_STMT, ghDbc, ovrhstmt)
	 If rc <> SQL_SUCCESS Then
		 Call DspSQLError(SQL_HANDLE_DBC, ghDbc, "Problem: Allocating Override Statement Handle")
	 End If

 ' Note that the string within single quotes 'OVRDBF FILE(BRANCH)... OVRSCOPE(*JOB)' 
    is exactly 68 bytes
   cmd = "call qsys.qcmdexc('OVRDBF FILE(BRANCH) TOFILE(HOALIB/BRANCH) MBR(FRANCE) 
                                                 OVRSCOPE(*JOB)',0000000068.00000)"

	 ' Override the iSeries file to point to the 'france' member
	 rc = SQLExecDirect(hStmt, cmd, SQL_NTS)
	 If rc <> SQL_SUCCESS Then
		 Call DspSQLError(SQL_HANDLE_STMT, hStmt, "File Override")
	 End If