Invoke MiSys Equation API From .NET


This article explains how to invoke MiSys Equation API (or any AS/400 program in general) through IBM i Access
for Windows component. The code is about calling an RPG compiled program (or
any OS/400 command) on IBM AS/400 iSeries server from .NET application


MiSys Equation is the core banking system at one of my client, hosted on an iSeries server. we
need to expose Equation API/commands as .NET Services for any application to consume them regardless of the platform.
BizTalk and WCF is the platform for our middleware SOA implementation. IBM iSeries Access to Windows is a library from IBM to connect to iSeries application over TCP protocol.
This walk through describes how to expose MiSys Equation functionality as .NET library. we need to build a WCF or BizTalk service on top of this library method to expose it as web service.

Code Walk through

1. Install IBM iSeries Access to Windows. Also check for service packs
at this URL

2. Create a new Console Application project in Visual Studio

3. Add Project Reference to cwbx.dll ActiveX from C:\Program Files
(x86)\IBM\Client Access\Shared

4. Add the attached API.cs file to your project

5. Now, we are going to connect to iSeries. we need to provide iSeries Server IP/Name, User Name and Password to connect.

//code snippet from attached API.cs

AS400System as400 = new AS400SystemClass()

Program program = new Program(); // iSeries Program (PGM)  

as400.Define(""); //Server Name/IP
program.system  = as400;
program.system.UserID =User;
program.system.Password = Password;

//Connect to execute Remote commands only

6. Once we are connected to iSeries, we need to initialize
liability(context) with Equation application. This context specifies to which Equation application instance we are going to connect, as there could be multiple application instances running on the server.
Parameters.Append() is used to defined the parameters and their length. All the parameters will be passed as a Byte array and the response will be a Byte array as well.

program.LibraryName = "KAPBASELIB";
program.ProgramName = "KAPUNLIBL"; 

StringConverter stringConverter = new StringConverterClass();
ProgramParameters parameters = new ProgramParametersClass();

parameters.Append("Env", cwbrcParameterTypeEnum.cwbrcInput, 3);
parameters.Append("A1", cwbrcParameterTypeEnum.cwbrcInput,4); 

parameters["Env"].Value = stringConverter.ToBytes("DEV");//Equation Instance
parameters["A1"].Value = stringConverter.ToBytes("*DFT");//default value 


7. Next step is to define and assign values to In and Out parameters and call Equation
API. you need to consult MiSys Equation Journal File Documentation to check for parameters length and whether they are Input or Output parameters

program.ProgramName = "H46HMR";//Inquiry API Wrapper
ProgramParameters parameters = new ProgramParametersClass();

SetInParameter(ref parameters, "EPGM",10, "H68EER");//Bal Inq Function identifier
SetInOutParameter(ref parameters, "DSAIF",3000, "00001xxxxx"); //Account No. 


8. Final step is to parse the response received from Equation. As you can see in the above code, DSAIF is input/output parameter and will have the response from Equation in the form of Byte array. we need to parse the byte array through StringConverter helper method

_response.Bytes = parameters[2].Value;

StringConverter stringConverter = new StringConverterClass();
stringConverter.Length = 0; // Use all bytes in source byte array to build string
string str = stringConverter.FromBytes(_response.Fields["HZCUN"].Value);

Points of Interest

couple of points worth noting

1. Input and Output parameters are Byte array. i.e. you need to take
care of order of parameters when using parameters.append()

2. use StringConverter, PackedConverter helper methods to convert
from Byte array to string

see the attached zip file for a sample implementation for Account
Balance Inquiry API.

Thanks to Joe Rattz for this article, which was starting point for me.


42 Responses to “Invoke MiSys Equation API From .NET”

  1. Helder Soares Says:

    Hi Usman,

    I cant read you article at Code Project “invoking Equation API from .NET”

    Can you tell me where can I check you article.

    Many thks,

    Helder Soares
    (from Portugal)

    • Usman Shaheen Says:

      Hi Helder ,

      The article on code project is not approved yet, so I posted it here on my blog.
      If you cannot access the attached file, just send me an email, I’ll send you that file.

      • Helder Soares Says:

        thanks for your reply 😉
        I cant download your sample! Can you please send me for my Email (helder.soares[at]gmail[dot]com)

        I need to build one WCF Adapter for Biztalk to improve my communication with Misys Equation API.
        Thanks, your article was great help!

      • rajon Says:

        Dear Usman,
        I am trying to call API.But i could not access the attached file.Please send me the file by email.It will be very helpful for me.
        my email address-;

      • Inash Says:

        Appreciate if you could email the file. Thanks

  2. Mashrur Says:

    Hi Usman,
    Great article! I am dying to see your code, but unfortunately cant download it. If possible, could you please email [m4shrur[at]gmail[dot]com] me the code?
    Thanks in advance

  3. Jake Says:

    i have the following code which is passes two parameters to a as400 cl program but i get an error when i run it what am i doing wrong?

    Dim system As New cwbx.AS400System()
    Dim str As New cwbx.StringConverter

    system.UserID = “qsecofr”
    system.Password = “password”
    system.IPAddress = “”
    Dim program As New cwbx.Program
    program.LibraryName = “QGPL”
    program.ProgramName = “PASSWORDCH”
    Dim parmlength As Integer
    parmlength = 10
    Dim paramters As New cwbx.ProgramParameters
    paramters.Append(“USER”, cwbx.cwbrcParameterTypeEnum.cwbrcInput, 10)
    paramters.Append(“PASSWD”, cwbx.cwbrcParameterTypeEnum.cwbrcInput, 10)
    ‘ paramters[“USER”].vALUE=cwbx.stringConverter.ToBytes(“TCBOPR”)\
    paramters(“USER”).Value = str.ToBytes(“pinkda”)
    paramters(“PASSWD”).Value = str.ToBytes(“tcbopr”)
    ‘ Try

    ‘Catch ex As Exception
    ‘For Each er As cwbx.Error In system.Errors
    ‘Call MsgBox(“Err.ToString()”)
    ‘ Console.WriteLine(Err.ToString())

    ‘End Try

  4. Usman Shaheen Says:

    Hi Jake,

    what is the exact error you’re getting?
    do you have cwbx.Error populated or have an exception in your program? details of the error will help us to find the cause

    Usman Shaheen

  5. mahesh Says:

    Hi Usman
    Need your help. I am looking for documents or mannuals for Equation/3. Next week I am attending interview on Eq/3.
    six years before I have developed application to interface with Eq/3 in RPGLE but I forgot all these . To refresh my knowledge . Please send me some link or documents

    Thanks in advance

  6. hasan hadid Says:

    Hi Usman,

    I am currently in charge of application development in a bank that utilizes Equation 3.9. I tried to run your code after converting to but did not succeed and could not access the attached file. I will be gratefull if can you send it to me on my email



  7. Ram Says:

    Dear Usman/All

    Usman or anyone who got the API.cs file, can you please send it to saprouzy[at]

    Thanks alot.

  8. Syed Hasan Says:

    Hello Usman,

    Need your help. I want to use equation APIs in visual studio. Please forward me API.cs file whihc you mentioned at your blog. Also not very much familiar with visual studio if you suggest me or forward any document/manual/web site to learn visual studio .

    Thanks in advance

    Syed Hasan

  9. yousef Ibrahem Says:

    Dear Usman/ALL

    Usman or anyone who got the API.cs file, could you please send it to

    Thanks alot.

  10. Omen Says:

    Usman or anyone who has the API.cs file, could you please send it to

  11. Antonio Says:

    Hi Usman,

    Where can I get the the file API.cs.

    Thanks in advance.

  12. Michael Says:

    Dear Mr. Usman,

    could you please send the file (API.cs) to my email


  13. Antonio Carvalho Says:

    Hi Usman,
    where can I get the code ? Could you please send me the code to my email (

    Thank you,

  14. SS Says:


    Can you please send me the parameters you’re using to call H71DER?


  15. Eduardo Correia Says:

    Hi Usman,

    Can you please also email me the file api.cs (


  16. Marcus Says:

    Hi Usman,

    Great article! I’ve been looking for help on this subject for a long time. Can you please send me a copy of the example files and the API.cs file? My e*mail is mubi99[at]gmail[dot]com…


  17. Anonymous Says:

    pls also send me the source file @

  18. Anonymous Says:

    Dear Usman,
    Raheel here. Hope you will be doing fine. I need your API.CS and also Account Balance Inquiry API. Kindly you or someone else send me. My email is It will be appreciated.


  19. bboyzapri Says:

    Helo Usman,
    I’ve try the same code in java, but it’s return error as below :
    Filename QCEEMSG
    ID CEE9901
    Library QSYS
    Error Text Application error. RNX9001 unmonitored by H56HMR at statement *N, instruction X’0000′.
    Severity 30
    Type 15
    Help Cause . . . . . : The application ended abnormally because an exception occurred and was not handled. The name of the program to which the unhandled exception is sent is H56HMR H56HMR _QRNP_PEP_H56HMR. The program was stopped at the high-level language statement number(s) *N at the time the message was sent. If more than one statement number is shown, the program is an optimized ILE program. Optimization does not allow a single statement number to be determined. If *N is shown as a value, it means the real value was not available. Recovery . . . : See the low level messages previously listed to locate the cause of the exception. Correct any errors, and then try the request again.

    Could you give some advice about this error?
    Thanks in advance

  20. faleh Says:

    can you send me the API.cs code please, i couldnt download it.

  21. Alaa Says:

    Hi Usman,

    Nice Article.

    However, have you thought about the connection pooling and multi-threading support for cwbx dll, i think it does not support the connection pooling and multiple calls into the dll will stack up one after the other until they are all executed?

    any ideas about this?


  22. Usman Shaheen Says:

    Hi Alaa,

    we implemented Asyn pattern in our .net code to improve performance where multiple API calls were involved, each API call is invoked in a separate thread. Also a common data area can be reused for subsequent Equation calls

  23. Anonymous Says:

    Hi Usman,
    I saw your article above and it’s really great. But I would request something else – not sure if it is possible with you or not. I need a documentation of the Application/Business.
    Never mind if you are not in a position to share.
    Thanks & Regards

  24. Najeeb Says:

    Dear Usman,

    Could you please send me the APIs?

    Email address is

    Many thanks


  25. w-z-art Says:

    Dear Mr. Usman,

    Could you please send the file (API.cs) to


  26. Mohamed Azmy Says:

    could someone please send the the missing API.cs to


  27. Moris Says:

    Dear Mr. Usman,

    could you please send the file (API.cs) to my email morisbozzetto[at]gmail[dot]com ?


  28. Mohammed Frahim Says:

    Dear Usman,

    Could you please send the related documentation with misys equation to I will really appreciate your help.

  29. Bil Says:


    I am trying to call Equation ITA API from java.
    DGZH181 should be passed as a parameter of the API call through DSAIM. DGZH181 contains a lot of fields. Should I create a class for DGZH181 fill the values of fields then pass it to the API as object of this class?
    Should I initialize all fields of DGZH181 or the obligatory one only? How to place them in DGZH181?

    I couldn’t find the sample you attached. If it is not available can you send it plz to

    Do you have a sample of ITA or similar one?

    Thank you in advance.

  30. Shony Baby Says:

    USMAN sir. I tried your code in my bank. I was able to connect to iseries server. but i dont know how to perform balance inquiry commands. can you provide me documentation on that. my email is

  31. Thomas Says:

    Hi there, is there an API for account basic details enquiry,

  32. Kamran Says:

    Hi Usman, Can you send the cs file to kamranjaka{at}

  33. Nidal Says:

    Hi Usman,
    Could you please send me the API.cs class file to
    thank you in advance

  34. Khan Says:

    Hi Usman,
    Thanks for sharing the useful stuff. Could you please send me cs to


  35. Jono Says:

    Hi Usman, Can you send the cs and the zip file for a sample implementation for Account Balance Inquiry API to

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: