ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

Call CMD by QCMDEXC via ODBC

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Call CMD by QCMDEXC via ODBC

    Dear community,

    I have a c# program which shall execute a CMD called IT001CMD on my iSeries (V7R1).
    The CMD is located in the library BEMOBJ.

    I'd like to call the CMD using QCMDEXC via ODBC connection.

    So I try to execute the following SQL-statement:

    Call QSYS.QCMDEXC('BEMOBJ/IT001CMD', 0000000015.00000)

    When I execute the SQL-statement in the OS/400-SQL-Environment all works fine.

    But it still prompts error CPF0006 when using the c# programm and i cannot understand why this error is prompted.

    Code:
    static public int StartLabelGenerator()
            {
                OdbcConnection oConn = new OdbcConnection(ConnectionString);
                oConn.Open();
                String sqlcmd;
    
                sqlcmd = "Call QSYS.QCMDEXC('BEMOBJ/IT001CMD', " + ("BEMOBJ/IT001CMD".Length).ToString("0000000000.00000").Replace(",", ".") + ")";
             
                OdbcCommand oCmd = new OdbcCommand(sqlcmd, oConn);
    
                try
                {
                    int i = oCmd.ExecuteNonQuery(); return i;
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message); return 0;
                }
                finally
                {
                    oCmd.Dispose();
                    oConn.Close();
                }
           
            }
    The CMD starts a CL-PGM which starts a RPGLE-PGM that generates a list of address labels.

    Please help me to fix this problem.

    Thank you very much in advance.

    Kind regards,

    Sascha

  • #2
    Re: Call CMD by QCMDEXC via ODBC

    Make sure the library list is set correctly.

    ... and use the SQL Stored Procedure located in the QSYS2 library instead of calling the QCMDEXC API directly.
    When using this Stored procedure, you can pass a string expression and the length of this expression without this messy length definition:

    QSYS2.QCmdExc('CLCommand', Length(CLCommand);

    Birgitta

    Comment


    • #3
      Re: Call CMD by QCMDEXC via ODBC

      Originally posted by B.Hauser View Post
      Make sure the library list is set correctly.

      ... and use the SQL Stored Procedure located in the QSYS2 library instead of calling the QCMDEXC API directly.
      When using this Stored procedure, you can pass a string expression and the length of this expression without this messy length definition:

      QSYS2.QCmdExc('CLCommand', Length(CLCommand);

      Birgitta

      Hello Birgitta,
      thank you very much for your help.

      Unfortunately the failure was due to the library list. Now I have bound the CMD to a CL-PGM which initially fixes the library list and then runs the RPGLE-PGM.
      Good to know that there is also a QCMDEXC in QSYS2 as Stored Procedure version

      Comment

      Working...
      X