Search code examples
c#dllodbcrpgle

How to set library list using cwbx.dll and AS400System class from C# to IBM i (iSeries)


I use client access driver to make sql calls to IBM i (an iSeries). When using the driver I can specify a library list that will be used when issuing sql commands/functions.

I now need to access an iSeries from C# and make calls to CL/RPGLE programs. I found that I can create an AS400System object after adding a reference to cwbx.dll. However, I am not sure how to set a library list and am having trouble finding documentation on cwbx.dll. Has anyone else been able to use this object to set a library list?


Solution

  • Per this doc: "CWBX.DLL (The Programmatic interface) allows to do Data Transfer operations programmatically"

    That's not what you're wanting to do.

    You probably want to use the DB2 for i .NET provider.

    Documentation for the provider is installed when you select "Programmer's Toolkit" during the IBm iAccess installation.

    Did a little more digging, documentation for CWBX.DLL can be found in:
    C:\Program Files (x86)\IBM\Client Access\MRI2924\cwbx.hlp

    It doesn't appear that you can manipulate the library list for a command. Only a data transfer via the DatabaseUserLibraryList object.

    The recommended way to call RPGLE / CL from .NET would be call them as an SQL stored procedure. Technically, given the object based nature of the OS, every *PGM (or procedure in a *SRVPGM) object on the box is already a stored procedure and can be called implicitly using the SQL call command. However, it's beneficial and recommended to explicitly define the RPG / CL interface to the DB using the CREATE PROCEDURE statement with the EXTERNAL NAME clause as shown below.

    example from this article

    Assume you have a *PGM named CUSTINFO, with the following program interface (aka *ENTRY PLIST)

    D CustInfo         PI
    D  CustNo                    5P 0
    D  Name                     15A
    D  City                     25A
    D  State                     2A 
    D  Active                    1P 0
    

    Where CustNo is input, the rest of the parms are used as output. Then you can explicitly define this program as an SQL stored procedure simply by running the following:

    CREATE PROCEDURE GetCustInfo    
     (IN CustNo DEC (5,0), OUT Name CHAR (15), OUT City CHAR(25), 
     OUT St CHAR(2), OUT Act DEC(1,0))
     EXTERNAL NAME MYLIB/CUSTINFO   
     LANGUAGE RPGLE 
     PARAMETER STYLE GENERAL
    
    • note I used the term "program interface". Technically it's the entry point or mainline procedure interface