Calling AS/400 (AS400) RPG Programs using .NET

IBM’s iSeries Client Access provides a library named cwbx.dll (you will find the DLL in this location : c:\Program Files\IBM\Client Access\Shared\ and you need to install the IBM Client – iSeries Access for Windows to find the DLL,  Install IBM iSeries Access to Windows. Also check for service packs updates if there any from this link.) , which makes it possible to call RPG programs running on an AS/400 from any Microsoft .NET application. Basically we have to call equation related enquiry and posting wrapper programs used in DB2 through our .NET application or component . There are scenarios where we may have to execute direct DB calls  as we are doing in TSQL/PLSQL instead solely depending on only Equation API enquiry calls. In such cases we have to use the same IBMDA400 data provider to establish the connection between the application and the Equation Database.

Each Posting APIs are wrapped by following ILE (Integrated Language Environment) programs as mentioned below:

  • X56H1R
  • X56HMR
  • H56HSR

In addition to the posting APIs each enquiry APIs are wrapped by an ILE program as mentioned below:

  • H46HMR

The input parameters that we should pass to the above mentioned wrappers are different to each other. In other words the parameters that we should pass for the posting programs are different than for the Inquiry program.

just refer this link for start up.

iSeries Access for Windows

101 Responses to “Calling AS/400 (AS400) RPG Programs using .NET”

  1. Hello,

    Please help with the parameter layouts for H56HSR or H56H1R for EQ 3.9 database I am really stuck. Would appreciate your help. many thanks Kennedy

  2. its the same parameter layout similar to the program H56H1R.

    Field Type Description
    @RPGM A(10) Function identifier
    @BRNM A(4) Input branch
    @USID A(4) User identifier
    @WSID A(4) Workstation identifier
    @JTT A(1) Function type
    DSAIM A(9999) Transaction serialisation

    @RREC A(1) Return code
    @RMES7 A(37) Error Message
    AOW A(740) Warning Messages
    @ETK A(4) Enigma transaction
    @ETN S(7,0) Enigma transaction number
    @AEXT A(1) Apply transaction during external input
    @AREC A(1) Apply transaction during recovery

    you can find the details in the Mysis documentation (Equation Journal File Definition EQ382).

    thanks.

  3. Hi!

    Do you have a working example for the “H46HMR” calling a Subfile Enquiry? like “H71DER” ?

    I’m really stuck on this.

    TIA,
    SS

  4. SS, yeah i do have the codes with me. I tried to email you but i couldn’t please email me.

    thanks,

  5. Hi,
    I am currently trying to test Equation 3.9 external online input API using VB.NET 2005, I am using ASI as a sample test but stuck in some decimal error showing in dump file. I will be greateful to you if you can help on this error.
    Regards,
    Hasan

  6. Hii Hasan,

    Decmial data error comes due to the invalid value that you are passing to the equation API. Please check individual values that you are passing, specifically make sure that you are using proper converters such as string converters, packed converters and zone converters when dealing with the data. can you please let me know how you are passing the values to the program?

    thanks,

    Ammar

  7. Hi!

    Do you have a working example for the “H56HSR” calling “GZH381” ?

    I’m really stuck on this.

    Thanks,

    BA

  8. sorry i dont have a working example for GZH381 API. but i do have samples for Inter Account Transfer, Standing Order posting, etc. what is the problem you are strucked with?

    thanks,

    Ammar

  9. we are calling the “GZH381” and also tried the “GZH601”

    we are doing it with the UTM83C and the KAPUNLIBL initialised, but we don get any response and the action does not take effect in equation.

    Can you help us?

    Thanks,

    Bruno

  10. Did you checked the log files? most of time it will generate log files if your program hits AS400. For your information this is my class constructor :

    public APIx()
    {

    Connect();
    InitializeContext(); // initialize Liability (context) for Equation

    program.LibraryName = “*LIBL”; //”EQLP”;

    setDataArea();

    }

    The Connect method implementation as below:

    ///

    /// Connect to AS400
    ///

    private static void Connect()
    {
    as400.Define(_AS400ServerName);
    program.system = as400;
    program.system.UserID = _AS400UserID;
    program.system.Password = _AS400Password;

    try
    {
    if (as400.IsConnected(cwbx.cwbcoServiceEnum.cwbcoServiceRemoteCmd) == 0) // Remote command service is connected
    {
    // Lost connection with the AS400. Disconnect, then reconnect.

    as400.Connect(cwbx.cwbcoServiceEnum.cwbcoServiceRemoteCmd);

    if (as400.IsConnected(cwbx.cwbcoServiceEnum.cwbcoServiceRemoteCmd) == 0) //still not able to connect
    {
    XLogger.Error(“API.Connect : Unable to connect to iSeries”, _ApplicationName);
    throw new Exception(“Unable to connect to iSeries”);
    }
    }

    }
    catch (Exception ex)
    {
    XLogger.Error(“API.Connect : Unable to connect to iSeries” + ex.Message, _ApplicationName);
    }

    }

    the InitializeContext method implementation is as follows:

    private static void InitializeContext()
    {
    program.LibraryName = “KAPBASELIB”;
    program.ProgramName = “KAPUNLIBL”;

    StringConverter stringConverter = new StringConverterClass();

    cwbx.ProgramParameters parameters = new ProgramParametersClass();

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

    parameters[“Env”].Value = stringConverter.ToBytes(_AS400Unit); //should come from config
    parameters[“A1”].Value = stringConverter.ToBytes(“*DFT”);//default value

    try
    {
    program.Call(parameters);

    }
    catch (Exception ex)
    {
    XLogger.Error(“API.InitializeContext Error : ” + ex.Message, _ApplicationName);
    HandleAS400Exception(ex);
    }

    }

    the setDataArea method implementation as follows:

    private static void setDataArea()
    {

    program.ProgramName = “UTM83C”;
    StringConverter stringConverter = new StringConverterClass();
    ProgramParameters parameters = new ProgramParametersClass();
    ProgramParameter programParameter = null;

    programParameter = parameters.Append(“X”, cwbrcParameterTypeEnum.cwbrcInput, 10);
    programParameter.Value = stringConverter.ToBytes(” “);
    program.Call(parameters);
    }

    As an example this is the way to post a account hold/unhold (GZJ401 – Account holds journal file) :

    public ErrorContext AddAccountHold(API.AccountHoldPostParams accountholdData, out string pastrReferenceNumber)
    {
    try
    {
    XLogger.Info(“API : AddAccountHold.. Started “, _ApplicationName);

    StringConverter strCnv = new StringConverterClass();
    PackedConverter pkdCnv = new PackedConverterClass();
    StringConverter stringConverter = new StringConverterClass();
    string strIsSuccess = “False”;

    PackedConverter packedConverterNORET = new PackedConverterClass();
    packedConverterNORET.DecimalPosition = 0;
    packedConverterNORET.Digits = 5;

    PackedConverter packedConverterFLEN = new PackedConverterClass();
    packedConverterFLEN.DecimalPosition = 0;
    packedConverterFLEN.Digits = 5;

    PackedConverter packedConverterRLEN = new PackedConverterClass();
    packedConverterRLEN.DecimalPosition = 0;
    packedConverterRLEN.Digits = 5;

    PackedConverter pkdConverter = new PackedConverterClass();

    //hold – J40ARRAAH
    //unhold – J40MRRMAH
    string strRPGMtoPass = “J40ARRAAH “;
    string strJTT = “A”;

    if (accountholdData.Holdnumber!=0)
    {
    Collection colAccountHoldsDetails = new Collection();

    colAccountHoldsDetails = API.GetAccountHoldDetails(accountholdData.Branchmnemonic + accountholdData.Customermnemonic + accountholdData.Accountsuffix, accountholdData.Holdnumber);

    if (colAccountHoldsDetails.Count > 0)
    {
    accountholdData.Responsibilitycode = colAccountHoldsDetails[0].ResponsibilityCode.Trim(); // “A00”; //Dept Code in the screen
    accountholdData.Holdreasoncode = colAccountHoldsDetails[0].HoldReasonCode.Trim();
    }

    strRPGMtoPass = “J40MRRMAH “;
    strJTT = “D”;
    }

    //H56HSR, H56H1R, H56H1RMAR
    program.ProgramName = “H56HSR “;

    var strucAddStandingOrder = new AccountHoldStructureClass();

    ProgramParameters parameters = new ProgramParametersClass();

    var varStructredData = strucAddStandingOrder.GetDSAIMStructure(accountholdData);

    parameters.Append(API.AccountHoldPostParams.strRPGM, cwbrcParameterTypeEnum.cwbrcInput, 10).Value = strCnv.ToBytes(strRPGMtoPass);
    parameters.Append(API.AccountHoldPostParams.strBRNM, cwbrcParameterTypeEnum.cwbrcInput, 4).Value = strCnv.ToBytes(_AS400UserBranch);
    parameters.Append(API.AccountHoldPostParams.strUSID, cwbrcParameterTypeEnum.cwbrcInput, 4).Value = strCnv.ToBytes(_AS400UserID);
    parameters.Append(API.AccountHoldPostParams.strWSID, cwbrcParameterTypeEnum.cwbrcInput, 4).Value = strCnv.ToBytes(_AS400WorkstationID);
    parameters.Append(API.AccountHoldPostParams.strJTT, cwbrcParameterTypeEnum.cwbrcInput, 1).Value = strCnv.ToBytes(strJTT);
    parameters.Append(API.AccountHoldPostParams.strDSAIM, cwbrcParameterTypeEnum.cwbrcInout, 9999).Value = varStructredData.Bytes;
    parameters.Append(API.AccountHoldPostParams.strRREC, cwbrcParameterTypeEnum.cwbrcOutput, 1).Value = strCnv.ToBytes(” “);
    parameters.Append(API.AccountHoldPostParams.strRMES7, cwbrcParameterTypeEnum.cwbrcOutput, 37).Value = strCnv.ToBytes(” “);
    parameters.Append(API.AccountHoldPostParams.strAOW, cwbrcParameterTypeEnum.cwbrcOutput, 740).Value = strCnv.ToBytes(” “);
    parameters.Append(API.AccountHoldPostParams.strETK, cwbrcParameterTypeEnum.cwbrcOutput, 4).Value = strCnv.ToBytes(” “);

    pkdCnv.Digits = 7;
    pkdCnv.DecimalPosition = 0;
    parameters.Append(API.AccountHoldPostParams.strETN, cwbrcParameterTypeEnum.cwbrcInout, 7).Value = pkdCnv.ToBytes(“0”);

    parameters.Append(API.AccountHoldPostParams.strAEXT, cwbrcParameterTypeEnum.cwbrcOutput, 1).Value = strCnv.ToBytes(“”);
    parameters.Append(API.AccountHoldPostParams.strAREC, cwbrcParameterTypeEnum.cwbrcOutput, 1).Value = strCnv.ToBytes(“”);

    program.Call(parameters);

    #region Structure
    StructureClass strut = new StructureClass();
    strut.Fields.Append(GZJ401Params.strGZWSID, 4);
    strut.Fields.Append(GZJ401Params.strGZDIM, 2);
    strut.Fields.Append(GZJ401Params.strGZTIM, 6);
    strut.Fields.Append(GZJ401Params.strGZSEQ, 4);
    strut.Fields.Append(GZJ401Params.strGZIMG, 1);
    strut.Fields.Append(GZJ401Params.strGZBBN, 4);
    strut.Fields.Append(GZJ401Params.strGZBNO, 6);
    strut.Fields.Append(GZJ401Params.strGZSFX, 3);
    strut.Fields.Append(GZJ401Params.strGZCUS, 6);
    strut.Fields.Append(GZJ401Params.strGZCLC, 3);
    strut.Fields.Append(GZJ401Params.strGZBRNM, 4);
    strut.Fields.Append(GZJ401Params.strGZACO, 3);
    strut.Fields.Append(GZJ401Params.strGZHRC, 3);
    strut.Fields.Append(GZJ401Params.strGZHDD1, 35);
    strut.Fields.Append(GZJ401Params.strGZHDD2, 35);
    strut.Fields.Append(GZJ401Params.strGZHDD3, 35);
    strut.Fields.Append(GZJ401Params.strGZHDD4, 35);
    strut.Fields.Append(GZJ401Params.strGZSTD, 7);
    strut.Fields.Append(GZJ401Params.strGZEXD, 7);
    strut.Fields.Append(GZJ401Params.strGZAMTH, 8);
    strut.Fields.Append(GZJ401Params.strGZCCY, 3);
    strut.Fields.Append(GZJ401Params.strGZHNO, 2);
    strut.Fields.Append(GZJ401Params.strGZINP, 7);
    strut.Fields.Append(GZJ401Params.strGZDLM, 7);
    strut.Fields.Append(GZJ401Params.strFiller, 9769);
    #endregion

    strut.Bytes = parameters[API.AccountHoldPostParams.strDSAIM].Value;

    pkdConverter.Digits = 3;
    pkdConverter.DecimalPosition = 0;

    string strRefernceNumber = pkdConverter.FromBytes(strut.Fields[GZJ401Params.strGZHNO].Value);

    strRefernceNumber = String.Format(@”{0:D3}”, Convert.ToInt32(strRefernceNumber));

    var status = ((byte[])parameters[API.AccountHoldPostParams.strRREC].Value)[0];
    var erroCode = strCnv.FromBytes(parameters[API.AccountHoldPostParams.strRREC].Value);
    var erroDescription = strCnv.FromBytes(parameters[API.AccountHoldPostParams.strRMES7].Value);

    string error = “”;
    decimal severity = 0;

    if (stringConverter.FromBytes(parameters[API.AccountHoldPostParams.strRMES7].Value).Trim() != “”)
    {
    var RMES7 = (byte[])parameters[API.AccountHoldPostParams.strRMES7].Value;
    GetErrorDetails(RMES7, out error, out severity);
    }

    if(stringConverter.FromBytes(parameters[API.AccountHoldPostParams.strRREC].Value) ==”R”)
    {
    strIsSuccess = “True”;
    }

    pastrReferenceNumber = strRefernceNumber;

    var context = new ErrorContext(strIsSuccess
    , stringConverter.FromBytes(parameters[API.AccountHoldPostParams.strETK].Value)
    , stringConverter.FromBytes(parameters[API.AccountHoldPostParams.strETN].Value)
    , stringConverter.FromBytes(parameters[API.AccountHoldPostParams.strRREC].Value)
    , error);

    switch (status)
    {
    case 217:
    XLogger.Info(“Equation.API : AddAccountHold.. Ended Successfully “, _ApplicationName);
    return context;
    case 198:
    XLogger.Error(“Equation.API.AddAccountHold … Error Code: ” + status + “, Description: ” + error + “, Severity: ” + severity, _ApplicationName);
    return context;
    default:
    XLogger.Error(“Equation.API.AddAccountHold … Error Code: ” + status + “, Description: ” + error + “, Severity: ” + severity, _ApplicationName);
    return context;
    }
    }
    catch (Exception ex)
    {
    XLogger.Error(“Equation.API.AddAccountHold … Exception: ” + ex, _ApplicationName);
    throw new Exception(“Equation General Exception : ” + ex.Message);
    }
    }

  11. Hi, my code is very similar to what you’ve posted above.

    However, whenever i perform a program call i’m getting this message: RNX9001 unmonitored by H56HSR at instruction X’0000 *N, MI X’0000′.

    This happens despite of the function identifier or content of DSAIM.

    Am i missing some sort of initialization?

    If, on the other hand, i use H56H1R instead of H56HSR, the program call simply returns the input message as output, and the transaction is not applied to equation.

    (btw, what are differences between using these two? H56H1R and H56HSR).

    Thanks,
    Miguel Mateus

  12. can you please let me know what you are passing for @RPGM? make sure the value that you are passing for the said parameter is correct. You can check about this with the AS400 developers in your company. As well as check the log for more error details. The wrappers H56H1R and H56HSR are same but H56HSR is the old one.

    thanks,

    Ammar

  13. Currently, i’m passing @RPGM=H60FMR (add/maintain address), also tried @RPGM=H60FMRCAA but the behaviour is the same regardless.

    Thanks,
    Miguel Mateus

  14. Hii Miguel,

    if you are getting the same error as above as you mentioned in your initial post, please try to call the same API using an online equation call. I have done the inquiry call for the Customer Address details API using H60EER (EPGM). Make sure you are using the proper converters at the time of preparing the data for the structure else you will get some abnormal errors. please try to see the log file. Most of time it will crash at the time of passing numeric values in case if you used packed converter instead of zoned converter and vice versa.

    thanks,

    Ammar

  15. Hi,
    I’m new to AS400 environment.
    I’m using H56H1R to call the operation G01ARR in equation APIs.

    I’m having the error KSM4234QUSER. The error KSM4234 means “No default branch for user &1”, but the system administrators told me that the user has a default branch.
    Can you help me solvind this problem?

    Thanks,

    Fernando

  16. Hii Fernando,

    if you are getting the error KSM4234 means they have not setupped the default branch properly. ask AS400 guys or the Admin guy to double check that they have given the branch for your logged in user. lets say, you are connecting with a user name Mark using the .NET application. as well as try to Login to AS400 console using the same user name and password. If you can be able to Login to console means no problem with the user but ask the administrator to set the BRANCH and LIMIT to the same user.

    thanks,

    Ammar

  17. Hi Ammar,

    The AS400 administrator set the default BRANCH for the user. (The user will be the one that i supply in the header right?).
    I actually can login to the console with no problem. I even can create customers with the console.

    thanks,

    Fernando

  18. Hi Ammar,

    I forget in the previous post… How can we setup the LIMIT and for what?

    thanks,

    Fernando

  19. Hii Fernando,

    its the account transfer limit (amount) for that particular user.

    thanks,

    Ammar

  20. Ammar,

    First of all, thanks for your quick answers.
    So far I had success in adding and modifying clients using the program G01ARR programs.

    But I still have a question. Is there any possibility of doing an enquiry for this module?

    Thanks,

    Fernando

    • Hi Fernando,

      May i ask how did you add the customer info using G01ARR cause i am having problem to add customer info and i dont know yet how to deal with DSAIM.

      Thanks in advance.

      Mark
      Newbie in AS400

  21. Hii Fernando,

    Good to hear that its working fine and Congrats on that. Hope you have the AS400 API documentations with you. So you just refer the documentation and you can find corresponding inquiry APIs for you to test. sorry i have not used any other APIs with related to clients or users. Most of time i have used APIs related to customer update, customer information update, account summary, last n transaction of a account, etc.

    thanks,

    Ammar

  22. Hello Ammar,

    I’m having a new problem, that perhaps we already passed.
    I’m trying to use the Equation Commitment Control API. I do the following start commitment control. Set user Commitment Boundry on, than when i try to do a Rollback, the following message shows up:
    CEE9901 – Erro de aplicação. RNX9001 não supervisionada por Q02HSR na instrução *N, MI X’0000′.

    Do you know why this happen and how I can solve this issue?

    Thanks,

    Fernando

    • Dear Fernando,

      sorry to say that i had no chance to work with the commitment control APIs in AS400. if you are strucked with the above error please try to contact the AS400 support.

      thanks,

      Ammar

  23. Hi Ammar,
    I need information about H15ARR and the DSAIM strucutre for this function. please help me.

    Thanks
    Best Regards
    Redi Tibuludji

    • Hii Redi,

      you can check with the AS400 API documentation about the H15ARR DSAIM structure. For the moment i don’t have the documentation with me. i will try to get you the structure earliest.

      thanks,

      Ammar

      • Hi Ammar,
        Thank you for your response, i can’t find which document explain that, can you help me which document should i refer to read. for your information we work in MiSys Equation 3.6 .

        Thanks
        Best Regards
        Redi Tibuludji

  24. Hii Redi,

    there should be a document named Journal File Definition.doc and a document to refer related to database definition of Equation named : Equation_Database_Definition_Manual.doc. if you dont have the document please let me know and will email you the same.

    thanks,

    Ammar

    • Hi Ammar,

      I tried to find the information about function H15ARR and the related DSAIM structure in our document (DB_FULL_DEFINITION_NEWUSER_EDBF36.DOC and FULL_JOURNAL_DEFINITION_NEWUSER_EJRF36.DOC), but i can’t find information i need. 😦 , and i tried to match the existing DSAIM (from the code) with those document, i also can’t find exactly which DSAIM, below the DSAIM structure i have:

      d @dsaim0 ds 4000
      d GZWSID 1 4
      d GZDIM 5 6 0
      d GZTIM 7 12 0
      d GZSEQ 13 16P 0
      d GZIMG 17 17
      d GZAB 18 21
      d GZAN 22 27
      d GZAS 28 30
      d GZBRNM 31 34
      d GZPBR 35 39
      d GZPSQ 40 42P 0
      d GZVFR 43 49 0
      d GZBRND 50 53
      d GZDRF 54 69
      d GZAMA 70 77P 0
      d GZAPP 78 79
      d GZTCD 80 82
      d GZCCY 83 85
      d GZSRC 86 87
      d GZUC1 88 90
      d GZUC2 91 93
      d GZNPE 94 96P 0
      d GZNR1 97 131
      d GZNR2 132 166
      d GZNR3 167 201
      d GZNR4 202 236
      d GZRFR 237 237
      d GZAUT 238 238
      d GZSSI 239 239
      d GZFRV 240 240
      d GZTTP 241 241
      d GZHSRL 242 257
      d GZHAMT 258 265P 0
      d GZAUTC 266 277
      d GZCED 278 278
      d GZCHQ 279 279
      d GZDRFN 280 288P 0
      d GZINW 289 289
      d GZRAU 290 290
      d GZEMN1 291 294
      d GZRAU1 295 295
      d GZEMN2 296 299
      d GZRAU2 300 300
      d GZEMN3 301 304
      d GZRAU3 305 305
      d GZEMN4 306 309
      d GZRAU4 310 310
      d GZMCH 311 311
      d GZTCCY 312 315
      d GZTAMA 315 322P 0
      d GZTCED 323 323
      d GZHCCY 324 326
      d GZEAN 327 346
      d GLAST 347 4000

      the problem, i don’t understand each field.

      Thank you very much.

      Best Regards
      Redi Tibuludji

      • Hii Redi,

        I will get back to you with the meaning of the above fields. anyhow i think as per the document you have to create your own structure based on the above fields.

        thanks,

        Ammar

      • Hii Redi,

        I have sent you the document with the field names. please check your email.

        thanks,

        Ammar

  25. Hi Ammar,

    Thank you very much.. your document is really help me.. I am glad you have this blog. thank you

    Best Regards
    Redi Tibuludji

  26. Hi Ammar,

    I have project to connect to Equation. Client gives a lot of documentations about Equation, but I can not find document that contains information about available API to call through wrapper API H46HMR (for inquiry) and H56HSR (for posting). Especially I need information about H68EER and H15ARR API. Please help me if you have document that contains information about the API.

    thanks,

    Kianaro

  27. Hii Kianaro,

    i have sent you the details and please check your email.

    thanks,

    Ammar

  28. Hi Ammar, thanks for your response, it really help me.

    BTW, what is document title contains the Equation available APIs?. I would ask my client that document, may be they forget to give it to me. It may be useful for future development.

    thanks,

    kianaro

  29. Hii Kianaro,

    sorry for the late reply. Yeah you can get the documentation from them. it usually will be with the AS400 team and the developers.

    if you need any further help please do let me know,

    thanks,

    Ammar

  30. Hi, Ammar. My name is dodo, would you like to send me some example code to use Equation API from vb.net?
    My email is dodoprawira@yahoo.com.

    Thx for your help,

    Dodo

    • Hii Dodo,

      please refer this link to get a basic understanding of calling a Equation API through ASP.NET. The code samples mentioned in the site is in C#. You can use online C# to VB.NET converters to accomplish what you are looking for. If time permits i will try to send you some sample codes in vb.net.

      thanks,

      Ammar

  31. Hi Ammar, Really appreciate your work on the AS400 as the resources are very rare on this. Could you please share me a sample on working with “H46HMR” API, i’m really stuck on this one. Please share few others samples as well on AS400 .net. Your help in this regard is very much appreciated. Thanks. My mail Id : chandruchiku@gmail.com

    • Hii Chandrashekar,

      The wrapper program “H46HMR” is used to inquire data from AS400. Assuming that you have the documentation related to AS400 APIs, i have emailed you a sample with related to last five transactions by passing the Account Number.

      thanks,

      Ammar

  32. Hi Ammar,

    Can you please give me a link where i can get the documentation for AS400. Also, can you please let me know what does this error signify. I got this while calling H56HSR. Error — RMES7 Value : KSM6275H18ARR

    Thanks,
    Chandrashekar

    • Hii Chandrashekar,

      Most of time you can request for the documentation from your application (AS400) team. Its okay and i will email you the documentation. The error message you have mentioned is because, there are some certain arguments we should pass to the program to execute. One of the argument was this RMES7 value. I will try to send you a sample for this.

      Thanks,

      Ammar

    • Hii Chandrashekar,

      As well as you can play around this RMES7 output parameter to get the exact error from equation as below:

      from your main class after calling the as400 program check for the output parameter RMES7.

      if (stringConverter.FromBytes(parameters[AccountToAccountPostParams.strRMES7].Value).Trim() != “”)
      {
      var RMES7 = (byte[])parameters[AccountToAccountPostParams.strRMES7].Value;
      GetErrorDetails(RMES7, out error, out severity); // please check the code below for this methods implementation.
      }

      // you have to call another equation api program to get the details of the error message.

      private static void GetErrorDetails( byte[] RMES7 , out string description , out decimal severity )
      {
      description = “”; severity = 0;
      if (RMES7.Length != 37) return;
      var bytes = new Bytes( RMES7 );

      try
      {
      StringConverter strCnv = new StringConverterClass();
      PackedConverter pkdCnv = new PackedConverterClass();
      pkdCnv.Digits = 2;
      pkdCnv.DecimalPosition = 0;

      program.ProgramName = “UTM02C”;

      ProgramParameters parameters = new ProgramParametersClass();
      parameters.Append( EquationErrorDetailsParams.strMSGID , cwbrcParameterTypeEnum.cwbrcInput , 7 ).Value = bytes.GetNext( 7 );
      parameters.Append( EquationErrorDetailsParams.strMSGDA , cwbrcParameterTypeEnum.cwbrcInput , 30 ).Value = bytes.GetNext( 30 );
      parameters.Append(EquationErrorDetailsParams.strMSGDT, cwbrcParameterTypeEnum.cwbrcOutput, 132).Value = strCnv.ToBytes(” “);
      parameters.Append(EquationErrorDetailsParams.strMSGSV, cwbrcParameterTypeEnum.cwbrcOutput, 2).Value = pkdCnv.ToBytes(“0”);

      program.Call(parameters);

      description = strCnv.FromBytes( parameters[EquationErrorDetailsParams.strMSGDT].Value );
      decimal.TryParse( pkdCnv.FromBytes( parameters[EquationErrorDetailsParams.strMSGSV].Value ) , out severity );
      }
      catch (Exception x)
      {
      XLogger.Error(“Equation.API.GetErrorDetails … Exception: ” + x, ApplicationName);
      throw;
      }
      }

  33. Hi Ammar,

    We stuck in account tranfer program H56HSR.H18ARRITA, i am getting “KSM2003Reference” in RMES7 fileld, Can you pls assist with your expertise. It would really help, if we get a sample code in java for the same…

    Thanks in advance

    Regards,
    Bhaskar

    • Hii Bhaskar,

      Based on the RMES7 fields seems some problem with the transaction reference (API field GZTREF) that you are passing. please check how you are passing the transaction reference for this account to account transfer. please find the structure class for the account to account transfer as below:

      public class AccounToAccounTransferStructureClass
      {
      private StructureClass strut;

      private static StringConverter strConverter;
      private static ZonedConverter zneConverter;
      private static PackedConverter pkdConverter;

      private class GZH181Params
      {
      public const string strGZWSID = “GZWSID”; // Workstation Id (?)
      public const string strGZDIM = “GZDIM”; // Day in month
      public const string strGZTIM = “GZTIM”; // Time, hhmmss
      public const string strGZSEQ = “GZSEQ”; // sequence number (?)
      public const string strGZIMG = “GZIMG”; // journal image (?)
      public const string strGZREF = “GZREF”;
      public const string strGZBRNM = “GZBRNM”;
      public const string strGZPBR = “GZPBR”;
      public const string strGZPSQ = “GZPSQ”;
      public const string strGZBRND = “GZBRND”;
      public const string strGZEAND = “GZEAND”;
      public const string strGZAB1 = “GZAB1”;
      public const string strGZAN1 = “GZAN1”;
      public const string strGZAS1 = “GZAS1”;
      public const string strGZVFR1 = “GZVFR1”;
      public const string strGZDRF1 = “GZDRF1”;
      public const string strGZAMA1 = “GZAMA1”;
      public const string strGZAPP1 = “GZAPP1”;
      public const string strGZTCD1 = “GZTCD1”;
      public const string strGZCCY1 = “GZCCY1”;
      public const string strGZSRC1 = “GZSRC1”;
      public const string strGZUC1 = “GZUC1”;
      public const string strGZUC2 = “GZUC2”;
      public const string strGZNR1 = “GZNR1”;
      public const string strGZNR2 = “GZNR2”;
      public const string strGZNR3 = “GZNR3”;
      public const string strGZNR4 = “GZNR4”;
      public const string strGZCED1 = “GZCED1”;
      public const string strGZMCH1 = “GZMCH1”;
      public const string strGZEANC = “GZEANC”;
      public const string strGZAB2 = “GZAB2”;
      public const string strGZAN2 = “GZAN2”;
      public const string strGZAS2 = “GZAS2”;
      public const string strGZVFR2 = “GZVFR2”;
      public const string strGZDRF2 = “GZDRF2”;
      public const string strGZAMA2 = “GZAMA2”;
      public const string strGZAPP2 = “GZAPP2”;
      public const string strGZTCD2 = “GZTCD2”;
      public const string strGZCCY2 = “GZCCY2”;
      public const string strGZSRC2 = “GZSRC2”;
      public const string strGZUC3 = “GZUC3”;
      public const string strGZUC4 = “GZUC4”;
      public const string strGZNR5 = “GZNR5”;
      public const string strGZNR6 = “GZNR6”;
      public const string strGZNR7 = “GZNR7”;
      public const string strGZNR8 = “GZNR8”;
      public const string strGZCED2 = “GZCED2”;
      public const string strGZMCH2 = “GZMCH2”;
      public const string strGZRRT = “GZRRT”;
      public const string strGZEXR = “GZEXR”;
      public const string strGZFONT = “GZFONT”;
      public const string strGZEXRH = “GZEXRH”;
      public const string strGZBAM1 = “GZBAM1”;
      public const string strGZOAM1 = “GZOAM1”;
      public const string strGZBAM2 = “GZBAM2”;
      public const string strGZOAM2 = “GZOAM2”;
      public const string strGZIEA = “GZIEA”;
      public const string strGZOID = “GZOID”;
      public const string strGZSOT = “GZSOT”;
      public const string strGZTREF = “GZTREF”;
      public const string strGZANMD = “GZANMD”;
      public const string strGZGDP = “GZGDP”;
      public const string strGZCRT = “GZCRT”;
      public const string strGZALL = “GZALL”;
      public const string strGZHOLD = “GZHOLD”;
      public const string strGZPDTE = “GZPDTE”;
      public const string strGZFOR = “GZFOR”;
      public const string strGZDRTY = “GZDRTY”;
      public const string strGZMRTY = “GZMRTY”;
      public const string strGZDTTY = “GZDTTY”;
      public const string strGZQTR = “GZQTR”;
      public const string strGZQTR2 = “GZQTR2”;
      public const string strGZQSTS = “GZQSTS”;
      public const string strGZQST2 = “GZQST2”;
      public const string strGZQRES = “GZQRES”;
      public const string strGZQRS2 = “GZQRS2”;
      public const string strGZQNQ = “GZQNQ”;
      public const string strGZQMSQ = “GZQMSQ”;
      public const string strGZQACT = “GZQACT”;
      public const string strGZQSCR = “GZQSCR”;
      public const string strGZQUID = “GZQUID”;
      public const string strGZUPTY = “GZUPTY”;
      public const string strGZQBAL = “GZQBAL”;
      public const string strGZQDTE = “GZQDTE”;
      public const string strGZQPTY = “GZQPTY”;
      public const string strGZQRRC = “GZQRRC”;
      public const string strGZQAID = “GZQAID”;
      public const string strGZQGRP = “GZQGRP”;
      public const string strGZQCHK = “GZQCHK”;
      public const string strGZQCHD = “GZQCHD”;
      public const string strGZQRED = “GZQRED”;
      public const string strGZQRET = “GZQRET”;
      public const string strGZQBID = “GZQBID”;
      public const string strGZQLVL = “GZQLVL”;
      public const string strGZQEVM = “GZQEVM”;
      public const string strFiller = “Filler”;
      }

      public AccounToAccounTransferStructureClass()
      {
      strut = new StructureClass();

      strut.Fields.Append(GZH181Params.strGZWSID, 4);
      strut.Fields.Append(GZH181Params.strGZDIM, 2);
      strut.Fields.Append(GZH181Params.strGZTIM, 6);
      strut.Fields.Append(GZH181Params.strGZSEQ, 4);
      strut.Fields.Append(GZH181Params.strGZIMG, 1);
      strut.Fields.Append(GZH181Params.strGZREF, 5);
      strut.Fields.Append(GZH181Params.strGZBRNM, 4);
      strut.Fields.Append(GZH181Params.strGZPBR, 5);
      strut.Fields.Append(GZH181Params.strGZPSQ, 3);
      strut.Fields.Append(GZH181Params.strGZBRND, 4);
      strut.Fields.Append(GZH181Params.strGZEAND, 20);
      strut.Fields.Append(GZH181Params.strGZAB1, 4);
      strut.Fields.Append(GZH181Params.strGZAN1, 6);
      strut.Fields.Append(GZH181Params.strGZAS1, 3);
      strut.Fields.Append(GZH181Params.strGZVFR1, 7);
      strut.Fields.Append(GZH181Params.strGZDRF1, 16);
      strut.Fields.Append(GZH181Params.strGZAMA1, 8);
      strut.Fields.Append(GZH181Params.strGZAPP1, 2);
      strut.Fields.Append(GZH181Params.strGZTCD1, 3);
      strut.Fields.Append(GZH181Params.strGZCCY1, 3);
      strut.Fields.Append(GZH181Params.strGZSRC1, 2);
      strut.Fields.Append(GZH181Params.strGZUC1, 3);
      strut.Fields.Append(GZH181Params.strGZUC2, 3);
      strut.Fields.Append(GZH181Params.strGZNR1, 35);
      strut.Fields.Append(GZH181Params.strGZNR2, 35);
      strut.Fields.Append(GZH181Params.strGZNR3, 35);
      strut.Fields.Append(GZH181Params.strGZNR4, 35);
      strut.Fields.Append(GZH181Params.strGZCED1, 1);
      strut.Fields.Append(GZH181Params.strGZMCH1, 1);
      strut.Fields.Append(GZH181Params.strGZEANC, 20);
      strut.Fields.Append(GZH181Params.strGZAB2, 4);
      strut.Fields.Append(GZH181Params.strGZAN2, 6);
      strut.Fields.Append(GZH181Params.strGZAS2, 3);
      strut.Fields.Append(GZH181Params.strGZVFR2, 7);
      strut.Fields.Append(GZH181Params.strGZDRF2, 16);
      strut.Fields.Append(GZH181Params.strGZAMA2, 8);
      strut.Fields.Append(GZH181Params.strGZAPP2, 2);
      strut.Fields.Append(GZH181Params.strGZTCD2, 3);
      strut.Fields.Append(GZH181Params.strGZCCY2, 3);
      strut.Fields.Append(GZH181Params.strGZSRC2, 2);
      strut.Fields.Append(GZH181Params.strGZUC3, 3);
      strut.Fields.Append(GZH181Params.strGZUC4, 3);
      strut.Fields.Append(GZH181Params.strGZNR5, 35);
      strut.Fields.Append(GZH181Params.strGZNR6, 35);
      strut.Fields.Append(GZH181Params.strGZNR7, 35);
      strut.Fields.Append(GZH181Params.strGZNR8, 35);
      strut.Fields.Append(GZH181Params.strGZCED2, 1);
      strut.Fields.Append(GZH181Params.strGZMCH2, 1);
      strut.Fields.Append(GZH181Params.strGZRRT, 3);
      strut.Fields.Append(GZH181Params.strGZEXR, 14);
      strut.Fields.Append(GZH181Params.strGZFONT, 1);
      strut.Fields.Append(GZH181Params.strGZEXRH, 8);
      strut.Fields.Append(GZH181Params.strGZBAM1, 8);
      strut.Fields.Append(GZH181Params.strGZOAM1, 8);
      strut.Fields.Append(GZH181Params.strGZBAM2, 8);
      strut.Fields.Append(GZH181Params.strGZOAM2, 8);
      strut.Fields.Append(GZH181Params.strGZIEA, 1);
      strut.Fields.Append(GZH181Params.strGZOID, 3);
      strut.Fields.Append(GZH181Params.strGZSOT, 1);
      strut.Fields.Append(GZH181Params.strGZTREF, 16);
      strut.Fields.Append(GZH181Params.strGZANMD, 6);
      strut.Fields.Append(GZH181Params.strGZGDP, 1);
      strut.Fields.Append(GZH181Params.strGZCRT, 1);
      strut.Fields.Append(GZH181Params.strGZALL, 1);
      strut.Fields.Append(GZH181Params.strGZHOLD, 1);
      strut.Fields.Append(GZH181Params.strGZPDTE, 7);
      strut.Fields.Append(GZH181Params.strGZFOR, 1);
      strut.Fields.Append(GZH181Params.strGZDRTY, 3);
      strut.Fields.Append(GZH181Params.strGZMRTY, 2);
      strut.Fields.Append(GZH181Params.strGZDTTY, 7);
      strut.Fields.Append(GZH181Params.strGZQTR, 2);
      strut.Fields.Append(GZH181Params.strGZQTR2, 2);
      strut.Fields.Append(GZH181Params.strGZQSTS, 5);
      strut.Fields.Append(GZH181Params.strGZQST2, 5);
      strut.Fields.Append(GZH181Params.strGZQRES, 5);
      strut.Fields.Append(GZH181Params.strGZQRS2, 5);
      strut.Fields.Append(GZH181Params.strGZQNQ, 1);
      strut.Fields.Append(GZH181Params.strGZQMSQ, 4);
      strut.Fields.Append(GZH181Params.strGZQACT, 2);
      strut.Fields.Append(GZH181Params.strGZQSCR, 1);
      strut.Fields.Append(GZH181Params.strGZQUID, 10);
      strut.Fields.Append(GZH181Params.strGZUPTY, 5);
      strut.Fields.Append(GZH181Params.strGZQBAL, 8);
      strut.Fields.Append(GZH181Params.strGZQDTE, 7);
      strut.Fields.Append(GZH181Params.strGZQPTY, 5);
      strut.Fields.Append(GZH181Params.strGZQRRC, 3);
      strut.Fields.Append(GZH181Params.strGZQAID, 10);
      strut.Fields.Append(GZH181Params.strGZQGRP, 10);
      strut.Fields.Append(GZH181Params.strGZQCHK, 2);
      strut.Fields.Append(GZH181Params.strGZQCHD, 2);
      strut.Fields.Append(GZH181Params.strGZQRED, 7);
      strut.Fields.Append(GZH181Params.strGZQRET, 6);
      strut.Fields.Append(GZH181Params.strGZQBID, 16);
      strut.Fields.Append(GZH181Params.strGZQLVL, 2);
      strut.Fields.Append(GZH181Params.strGZQEVM, 6);
      strut.Fields.Append(GZH181Params.strFiller, 9277);

      strConverter = new StringConverterClass();
      zneConverter = new ZonedConverterClass();
      pkdConverter = new PackedConverterClass();
      }

      public StructureClass GetDSASIStructure(API.AccountToAccountPostParams p)
      {
      strConverter.Length = 4;
      strut.Fields[GZH181Params.strGZWSID].Value = strConverter.ToBytes(p.WorkstationId);

      zneConverter.Digits = 2;
      zneConverter.DecimalPosition = 0;
      strut.Fields[GZH181Params.strGZDIM].Value = zneConverter.ToBytes(p.Day.ToString());

      zneConverter.Digits = 6;
      zneConverter.DecimalPosition = 0;
      strut.Fields[GZH181Params.strGZTIM].Value = zneConverter.ToBytes(p.Time.ToString(“HHmmss”));

      pkdConverter.Digits = 7;
      pkdConverter.DecimalPosition = 0;
      strut.Fields[GZH181Params.strGZSEQ].Value = pkdConverter.ToBytes(p.SequenceNumber.ToString());

      strConverter.Length = 1;
      strut.Fields[GZH181Params.strGZIMG].Value = strConverter.ToBytes(p.JournalImage);

      strConverter.Length = 5;
      strut.Fields[GZH181Params.strGZREF].Value = strConverter.ToBytes(p.Redundant);

      strConverter.Length = 4;
      strut.Fields[GZH181Params.strGZBRNM].Value = strConverter.ToBytes(p.Transferbranch);

      strConverter.Length = 5;
      strut.Fields[GZH181Params.strGZPBR].Value = strConverter.ToBytes(p.PostingGroupId);

      pkdConverter.Digits = 5;
      pkdConverter.DecimalPosition = 0;
      strut.Fields[GZH181Params.strGZPSQ].Value = pkdConverter.ToBytes(p.intReserved.ToString());

      strConverter.Length = 4;
      strut.Fields[GZH181Params.strGZBRND].Value = strConverter.ToBytes(p.BranchforwhomthetransactionIsbeingDone);

      strConverter.Length = 20;
      strut.Fields[GZH181Params.strGZEAND].Value = strConverter.ToBytes(p.DebitExternalAccount);

      strConverter.Length = 4;
      strut.Fields[GZH181Params.strGZAB1].Value = strConverter.ToBytes(p.DebitAccountBranch);

      strConverter.Length = 6;
      strut.Fields[GZH181Params.strGZAN1].Value = strConverter.ToBytes(p.DebitAccountBasicNo);

      strConverter.Length = 3;
      strut.Fields[GZH181Params.strGZAS1].Value = strConverter.ToBytes(p.DebitAccountSuffix);

      //”1100519″ “100524”
      string strteme = DateTime.Today.Date.ToString(“yyMMdd”);

      zneConverter.Digits = 7;
      zneConverter.DecimalPosition = 0;
      strut.Fields[GZH181Params.strGZVFR1].Value = zneConverter.ToBytes(“1″ + strteme);

      strConverter.Length = 16;
      strut.Fields[GZH181Params.strGZDRF1].Value = strConverter.ToBytes(p.DebitUserReference);

      p.DebitAmount = (Convert.ToDecimal(p.DebitAmount)*100).ToString();
      pkdConverter.Digits = 15;
      pkdConverter.DecimalPosition = 0;
      strut.Fields[GZH181Params.strGZAMA1].Value = pkdConverter.ToBytes(p.DebitAmount.ToString());

      strConverter.Length = 2;
      strut.Fields[GZH181Params.strGZAPP1].Value = strConverter.ToBytes(p.DebitAmountApplicationCode);

      strConverter.Length = 3;
      strut.Fields[GZH181Params.strGZTCD1].Value = strConverter.ToBytes(p.DebitTransactionCode);

      strConverter.Length = 3;
      strut.Fields[GZH181Params.strGZCCY1].Value = strConverter.ToBytes(p.DebitAccountCurrency);

      strConverter.Length = 2;
      strut.Fields[GZH181Params.strGZSRC1].Value = strConverter.ToBytes(p.DebitSundryReferenceCode);

      strConverter.Length = 3;
      strut.Fields[GZH181Params.strGZUC1].Value = strConverter.ToBytes(p.DebitUserCode1);

      strConverter.Length = 3;
      strut.Fields[GZH181Params.strGZUC2].Value = strConverter.ToBytes(p.DebitUserCode2);

      strConverter.Length = 35;
      strut.Fields[GZH181Params.strGZNR1].Value = strConverter.ToBytes(p.CreditNarrativeLine1);

      strConverter.Length = 35;
      strut.Fields[GZH181Params.strGZNR2].Value = strConverter.ToBytes(p.CreditNarrativeLine2);

      strConverter.Length = 35;
      strut.Fields[GZH181Params.strGZNR3].Value = strConverter.ToBytes(p.CreditNarrativeLine3);

      strConverter.Length = 35;
      strut.Fields[GZH181Params.strGZNR4].Value = strConverter.ToBytes(p.CreditNarrativeLine4);

      strConverter.Length = 1;
      strut.Fields[GZH181Params.strGZCED1].Value = strConverter.ToBytes(p.DebitCurrencyEditCode);

      strConverter.Length = 1;
      strut.Fields[GZH181Params.strGZMCH1].Value = strConverter.ToBytes(p.DebitMatchedObsoleteToday);

      strConverter.Length = 20;
      strut.Fields[GZH181Params.strGZEANC].Value = strConverter.ToBytes(p.CreditExternalAccount);

      strConverter.Length = 4;
      strut.Fields[GZH181Params.strGZAB2].Value = strConverter.ToBytes(p.CreditAccountBranch);

      strConverter.Length = 6;
      strut.Fields[GZH181Params.strGZAN2].Value = strConverter.ToBytes(p.CreditAccountBasicNo);

      strConverter.Length = 3;
      strut.Fields[GZH181Params.strGZAS2].Value = strConverter.ToBytes(p.CreditAccountSuffix);

      //”1100519” “100524”
      string strCreditValueDate = DateTime.Today.Date.ToString(“yyMMdd”);

      zneConverter.Digits = 7;
      zneConverter.DecimalPosition = 0;
      strut.Fields[GZH181Params.strGZVFR2].Value = zneConverter.ToBytes(“1” + strCreditValueDate);

      strConverter.Length = 16;
      strut.Fields[GZH181Params.strGZDRF2].Value = strConverter.ToBytes(p.CreditUserReference);

      p.CreditAmount = (Convert.ToDecimal(p.CreditAmount) * 100).ToString();
      pkdConverter.Digits = 15;
      pkdConverter.DecimalPosition = 0;
      strut.Fields[GZH181Params.strGZAMA2].Value = pkdConverter.ToBytes(p.CreditAmount.ToString());

      strConverter.Length = 2;
      strut.Fields[GZH181Params.strGZAPP2].Value = strConverter.ToBytes(p.CreditAmountApplicationCode);

      strConverter.Length = 3;
      strut.Fields[GZH181Params.strGZTCD2].Value = strConverter.ToBytes(p.CreditTransactionCode);

      strConverter.Length = 3;
      strut.Fields[GZH181Params.strGZCCY2].Value = strConverter.ToBytes(p.CreditAccountCurrency);

      strConverter.Length = 2;
      strut.Fields[GZH181Params.strGZSRC2].Value = strConverter.ToBytes(p.CreditSundryReferenceCode);

      strConverter.Length = 3;
      strut.Fields[GZH181Params.strGZUC3].Value = strConverter.ToBytes(p.CreditUserCode1);

      strConverter.Length = 3;
      strut.Fields[GZH181Params.strGZUC4].Value = strConverter.ToBytes(p.CreditUserCode2);

      strConverter.Length = 35;
      strut.Fields[GZH181Params.strGZNR5].Value = strConverter.ToBytes(p.DebitNarrativeLine1);

      strConverter.Length = 35;
      strut.Fields[GZH181Params.strGZNR6].Value = strConverter.ToBytes(p.DebitNarrativeLine2);

      strConverter.Length = 35;
      strut.Fields[GZH181Params.strGZNR7].Value = strConverter.ToBytes(p.DebitNarrativeLine3);

      strConverter.Length = 35;
      strut.Fields[GZH181Params.strGZNR8].Value = strConverter.ToBytes(p.DebitNarrativeLine4);

      strConverter.Length = 1;
      strut.Fields[GZH181Params.strGZCED2].Value = strConverter.ToBytes(p.CreditCurrencyEditCode);

      strConverter.Length = 1;
      strut.Fields[GZH181Params.strGZMCH2].Value = strConverter.ToBytes(p.CreditMatchedOrObsoleteToday);

      strConverter.Length = 3;
      strut.Fields[GZH181Params.strGZRRT].Value = strConverter.ToBytes(p.strReserved);

      strConverter.Length = 14;
      strut.Fields[GZH181Params.strGZEXR].Value = strConverter.ToBytes(p.Obsolete);

      strConverter.Length = 1;
      strut.Fields[GZH181Params.strGZFONT].Value = strConverter.ToBytes(p.FontIsTransfer);

      pkdConverter.Digits = 15;
      pkdConverter.DecimalPosition = 0;
      strut.Fields[GZH181Params.strGZEXRH].Value = pkdConverter.ToBytes(p.ExchangeRate.ToString());

      pkdConverter.Digits = 15;
      pkdConverter.DecimalPosition = 0;
      strut.Fields[GZH181Params.strGZBAM1].Value = pkdConverter.ToBytes(p.EquivalentAmountInBaseCurrencyDr.ToString());

      pkdConverter.Digits = 15;
      pkdConverter.DecimalPosition = 0;
      strut.Fields[GZH181Params.strGZOAM1].Value = pkdConverter.ToBytes(p.EquivalentAmountInUserCurrencyDr.ToString());

      pkdConverter.Digits = 15;
      pkdConverter.DecimalPosition = 0;
      strut.Fields[GZH181Params.strGZBAM2].Value = pkdConverter.ToBytes(p.EquivalentAmountInBaseCurrencyCr.ToString());

      pkdConverter.Digits = 15;
      pkdConverter.DecimalPosition = 0;
      strut.Fields[GZH181Params.strGZOAM2].Value = pkdConverter.ToBytes(p.EquivalentAmountInUserCurrencyCr.ToString());

      strConverter.Length = 1;
      strut.Fields[GZH181Params.strGZIEA].Value = strConverter.ToBytes(p.InterACTransferWithEquivalentAmountsFlag);

      strConverter.Length = 3;
      strut.Fields[GZH181Params.strGZOID].Value = strConverter.ToBytes(p.InterACTransferOptionId);

      strConverter.Length = 1;
      strut.Fields[GZH181Params.strGZSOT].Value = strConverter.ToBytes(p.StandingOrderTransfer);

      strConverter.Length = 16;
      strut.Fields[GZH181Params.strGZTREF].Value = strConverter.ToBytes(p.TransferReference); //p.TransferReference

      strConverter.Length = 6;
      strut.Fields[GZH181Params.strGZANMD].Value = strConverter.ToBytes(p.SystemGeneratedAccountMnemonic);

      strConverter.Length = 1;
      strut.Fields[GZH181Params.strGZGDP].Value = strConverter.ToBytes(p.GenericDealPosting);

      strConverter.Length = 1;
      strut.Fields[GZH181Params.strGZCRT].Value = strConverter.ToBytes(p.CourtOrder);

      strConverter.Length = 1;
      strut.Fields[GZH181Params.strGZALL].Value = strConverter.ToBytes(p.HoldWholeACBalance);

      strConverter.Length = 1;
      strut.Fields[GZH181Params.strGZHOLD].Value = strConverter.ToBytes(p.HoldOnQueue);

      zneConverter.Digits = 7;
      zneConverter.DecimalPosition = 0;
      strut.Fields[GZH181Params.strGZPDTE].Value = zneConverter.ToBytes(p.DateEntered.ToString());

      strConverter.Length = 1;
      strut.Fields[GZH181Params.strGZFOR].Value = strConverter.ToBytes(p.ForceToQueue);

      strConverter.Length = 3;
      strut.Fields[GZH181Params.strGZDRTY].Value = strConverter.ToBytes(p.DaysToRetryQueuedTran);

      strConverter.Length = 2;
      strut.Fields[GZH181Params.strGZMRTY].Value = strConverter.ToBytes(p.MonthsToRetryQueuedTran);

      zneConverter.Digits = 7;
      zneConverter.DecimalPosition = 0;
      strut.Fields[GZH181Params.strGZDTTY].Value = zneConverter.ToBytes(p.DateOfLastRetryOfQueuedTransaction.ToString());

      strConverter.Length = 2;
      strut.Fields[GZH181Params.strGZQTR].Value = strConverter.ToBytes(p.QueuedBy);

      strConverter.Length = 2;
      strut.Fields[GZH181Params.strGZQTR2].Value = strConverter.ToBytes(p.QueuedAgain);

      strConverter.Length = 5;
      strut.Fields[GZH181Params.strGZQSTS].Value = strConverter.ToBytes(p.QueueStatus);

      strConverter.Length = 5;
      strut.Fields[GZH181Params.strGZQST2].Value = strConverter.ToBytes(p.QueueStatus2);

      strConverter.Length = 5;
      strut.Fields[GZH181Params.strGZQRES].Value = strConverter.ToBytes(p.ReasonForQueuing);

      strConverter.Length = 5;
      strut.Fields[GZH181Params.strGZQRS2].Value = strConverter.ToBytes(p.ReasonForQueuing2);

      strConverter.Length = 1;
      strut.Fields[GZH181Params.strGZQNQ].Value = strConverter.ToBytes(p.AutomaticQueuing);

      pkdConverter.Digits = 7;
      pkdConverter.DecimalPosition = 0;
      strut.Fields[GZH181Params.strGZQMSQ].Value = pkdConverter.ToBytes(p.MaintenanceSequenceNumber.ToString());

      strConverter.Length = 2;
      strut.Fields[GZH181Params.strGZQACT].Value = strConverter.ToBytes(p.Action);

      strConverter.Length = 1;
      strut.Fields[GZH181Params.strGZQSCR].Value = strConverter.ToBytes(p.DisplayScreen);

      strConverter.Length = 10;
      strut.Fields[GZH181Params.strGZQUID].Value = strConverter.ToBytes(p.UserID);

      strConverter.Length = 5;
      strut.Fields[GZH181Params.strGZUPTY].Value = strConverter.ToBytes(p.UserPriorityCode);

      pkdConverter.Digits = 15;
      pkdConverter.DecimalPosition = 0;
      strut.Fields[GZH181Params.strGZQBAL].Value = pkdConverter.ToBytes(p.QueuedBalance.ToString());

      zneConverter.Digits = 7;
      zneConverter.DecimalPosition = 0;
      strut.Fields[GZH181Params.strGZQDTE].Value = zneConverter.ToBytes(p.QueuedDate.ToString());

      strConverter.Length = 5;
      strut.Fields[GZH181Params.strGZQPTY].Value = strConverter.ToBytes(p.PriorityCode);

      strConverter.Length = 3;
      strut.Fields[GZH181Params.strGZQRRC].Value = strConverter.ToBytes(p.Reason);

      strConverter.Length = 10;
      strut.Fields[GZH181Params.strGZQAID].Value = strConverter.ToBytes(p.AssignedToUser);

      strConverter.Length = 10;
      strut.Fields[GZH181Params.strGZQGRP].Value = strConverter.ToBytes(p.AuthorisationGroup);

      strConverter.Length = 10;
      strut.Fields[GZH181Params.strGZQGRP].Value = strConverter.ToBytes(p.AuthorisationGroup);

      zneConverter.Digits = 2;
      zneConverter.DecimalPosition = 0;
      strut.Fields[GZH181Params.strGZQCHK].Value = zneConverter.ToBytes(p.NumberOfCheckers.ToString());

      zneConverter.Digits = 2;
      zneConverter.DecimalPosition = 0;
      strut.Fields[GZH181Params.strGZQCHD].Value = zneConverter.ToBytes(p.TimesChecked.ToString());

      zneConverter.Digits = 7;
      zneConverter.DecimalPosition = 0;
      strut.Fields[GZH181Params.strGZQRED].Value = zneConverter.ToBytes(p.RequiredDate.ToString());

      zneConverter.Digits = 6;
      zneConverter.DecimalPosition = 0;
      strut.Fields[GZH181Params.strGZQRET].Value = zneConverter.ToBytes(p.RequiredTime.ToString());

      int intbatchAutonum = DateTime.Now.Hour + DateTime.Now.Minute + DateTime.Now.Second + DateTime.Now.Millisecond;
      string strbatchAutonum = “BATCH” + intbatchAutonum.ToString();
      strConverter.Length = 16;
      strut.Fields[GZH181Params.strGZQBID].Value = strConverter.ToBytes(strbatchAutonum);

      strConverter.Length = 2;
      strut.Fields[GZH181Params.strGZQLVL].Value = strConverter.ToBytes(p.AuthorisationLevel);

      strConverter.Length = 6;
      strut.Fields[GZH181Params.strGZQEVM].Value = strConverter.ToBytes(p.Events);

      strConverter.Length = 9277;
      strut.Fields[GZH181Params.strFiller].Value = strConverter.ToBytes(p.Filler.PadRight(9277));

      return strut;
      }
      }
      }

      make sure to initialize the API parameters as below else you have to face some strange errors from AS400. 🙂

      [Serializable]
      public class AccountToAccountPostParams
      {
      public enum PostTransactionType { Debit, Credit }

      #region Equation Post Params
      internal const string strRPGM = “RPGM”;
      internal const string strJTT = “JTT”;
      internal const string strETN = “@ETN”;
      internal const string strBRNM = “BRNM”;
      internal const string strUSID = “USID”;
      internal const string strWSID = “WSID”;
      internal const string strDSAIM = “DSAIM”;
      internal const string strRREC = “RREC”;
      internal const string strRMES7 = “RMES7”;
      internal const string strAOW = “AOW”;
      internal const string strETK = “ETK”;
      internal const string strAEXT = “AEXT”;
      internal const string strAREC = “AREC”;
      #endregion

      #region AccounttoAccount Post Params

      public string WorkstationId = “”;
      public int Day = DateTime.Now.Day;
      public DateTime Time = new DateTime(2010, 1, 1, 0, 0, 0);
      public int SequenceNumber = 0;
      public string JournalImage = “”;
      public string Redundant = “”;
      public string Transferbranch = “0001”; // have to pass as 0001 as the transfer branch
      public string PostingGroupId = “##MID”;
      public int intReserved = 0;
      public string BranchforwhomthetransactionIsbeingDone = “”;
      public string DebitExternalAccount = “”;
      public string DebitAccountBranch = “”;
      public string DebitAccountBasicNo = “”;
      public string DebitAccountSuffix = “”;
      //public DateTime DebitValueDate = new DateTime(2010, 5, 24, 0, 0, 0);
      public string DebitValueDate = strEquationSystemDate;
      public string DebitUserReference = “”;
      public string DebitAmount = “0”;
      public string DebitAmountApplicationCode = “”;
      public string DebitTransactionCode = “020”;
      public string DebitAccountCurrency = “”;
      public string DebitSundryReferenceCode = “”;
      public string DebitUserCode1 = “”;
      public string DebitUserCode2 = “”;
      public string DebitNarrativeLine1 = “”;
      public string DebitNarrativeLine2 = “”;
      public string DebitNarrativeLine3 = “”;
      public string DebitNarrativeLine4 = “”;
      public string DebitCurrencyEditCode = “”;
      public string DebitMatchedObsoleteToday = “”;
      public string CreditExternalAccount = “”;
      public string CreditAccountBranch = “”;
      public string CreditAccountBasicNo = “”;
      public string CreditAccountSuffix = “”;
      //public DateTime CreditValueDate = new DateTime(2010, 5, 31, 0, 0, 0);
      public string CreditValueDate = strEquationSystemDate;
      public string CreditUserReference = “”;
      public string CreditAmount = “0”;
      public string CreditAmountApplicationCode = “”;
      public string CreditTransactionCode = “520”;
      public string CreditAccountCurrency = “”;
      public string CreditSundryReferenceCode = “”;
      public string CreditUserCode1 = “”;
      public string CreditUserCode2 = “”;
      public string CreditNarrativeLine1 = “”;
      public string CreditNarrativeLine2 = “”;
      public string CreditNarrativeLine3 = “”;
      public string CreditNarrativeLine4 = “”;
      public string CreditCurrencyEditCode = “”;
      public string CreditMatchedOrObsoleteToday = “”;
      public string strReserved = “”;
      public string Obsolete = “”;
      public string FontIsTransfer = “”;
      public int ExchangeRate = 0;
      public int EquivalentAmountInBaseCurrencyDr = 0;
      public int EquivalentAmountInUserCurrencyDr = 0;
      public int EquivalentAmountInBaseCurrencyCr = 0;
      public int EquivalentAmountInUserCurrencyCr = 0;
      public string InterACTransferWithEquivalentAmountsFlag = “”; //Y
      public string InterACTransferOptionId = “”;
      public string StandingOrderTransfer = “”;
      public string TransferReference = “”;
      public string SystemGeneratedAccountMnemonic = “”;
      public string GenericDealPosting = “”;
      public string CourtOrder = “”;
      public string HoldWholeACBalance = “”;
      public string HoldOnQueue = “”;
      public string DateEntered = “0000000”;
      public string ForceToQueue = “”;
      public string DaysToRetryQueuedTran = “”;
      public string MonthsToRetryQueuedTran = “”;
      public string DateOfLastRetryOfQueuedTransaction = “0000000”;
      public string QueuedBy = “”;
      public string QueuedAgain = “”;
      public string QueueStatus = “”;
      public string QueueStatus2 = “”;
      public string ReasonForQueuing = “”;
      public string ReasonForQueuing2 = “”;
      public string AutomaticQueuing = “”;
      public int MaintenanceSequenceNumber = 0;
      public string Action = “”;
      public string DisplayScreen = “”;
      public string UserID = “”;
      public string UserPriorityCode = “”;
      public int QueuedBalance = 0;
      public string QueuedDate = “0000000”;
      public string PriorityCode = “”;
      public string Reason = “”;
      public string AssignedToUser = “”;
      public string AuthorisationGroup = “”;
      public int NumberOfCheckers = 0;
      public int TimesChecked = 0;
      public string RequiredDate = “0000000”;
      public string RequiredTime = “0000000”;
      public string BatchID = “”;
      public string AuthorisationLevel = “”;
      public string Events = “”;
      public string Filler = “”;
      #endregion

      }

      if you need any further help please let me know.

      thanks,

      Ammar

    • As well as if you need to know the exact error message from the AS400 please follow as below:

      from your main class after calling the as400 program check for the output parameter RMES7.

      if (stringConverter.FromBytes(parameters[AccountToAccountPostParams.strRMES7].Value).Trim() != “”)
      {
      var RMES7 = (byte[])parameters[AccountToAccountPostParams.strRMES7].Value;
      GetErrorDetails(RMES7, out error, out severity); // please check the code below for this methods implementation.
      }

      // you have to call another equation api program to get the details of the error message.

      private static void GetErrorDetails( byte[] RMES7 , out string description , out decimal severity )
      {
      description = “”; severity = 0;
      if (RMES7.Length != 37) return;
      var bytes = new Bytes( RMES7 );

      try
      {
      StringConverter strCnv = new StringConverterClass();
      PackedConverter pkdCnv = new PackedConverterClass();
      pkdCnv.Digits = 2;
      pkdCnv.DecimalPosition = 0;

      program.ProgramName = “UTM02C”;

      ProgramParameters parameters = new ProgramParametersClass();
      parameters.Append( EquationErrorDetailsParams.strMSGID , cwbrcParameterTypeEnum.cwbrcInput , 7 ).Value = bytes.GetNext( 7 );
      parameters.Append( EquationErrorDetailsParams.strMSGDA , cwbrcParameterTypeEnum.cwbrcInput , 30 ).Value = bytes.GetNext( 30 );
      parameters.Append(EquationErrorDetailsParams.strMSGDT, cwbrcParameterTypeEnum.cwbrcOutput, 132).Value = strCnv.ToBytes(” “);
      parameters.Append(EquationErrorDetailsParams.strMSGSV, cwbrcParameterTypeEnum.cwbrcOutput, 2).Value = pkdCnv.ToBytes(“0”);

      program.Call(parameters);

      description = strCnv.FromBytes( parameters[EquationErrorDetailsParams.strMSGDT].Value );
      decimal.TryParse( pkdCnv.FromBytes( parameters[EquationErrorDetailsParams.strMSGSV].Value ) , out severity );
      }
      catch (Exception x)
      {
      XLogger.Error(“Equation.API.GetErrorDetails … Exception: ” + x, ApplicationName);
      throw;
      }
      }

  34. Hi there have been following the comments up there and sounds interesting. I have been applying input using meridian messages through MQseries. I would like to try out the method using .net. are you able to email me a working copy of the sample application for inter-account transfers?

  35. Hii Mark, you can refer some of the above comments to understand how we can call an AS400 Account to Account transfer API through .net. For time being i will try to send an example which does the retrieval of account transaction history. thanks.

  36. thats for the responce, I have been able to do an enquiry but cant process a transaction ie inter-account transfer. I am not getting any dumps on or error messages: code below

    Imports System
    Imports System.Collections.Generic
    Imports System.Linq
    Imports System.Text
    Imports cwbx

    Public Class API
    Shared as400 As AS400System = New cwbx.AS400System
    Shared program As New cwbx.Program()

    Shared Sub New()
    Dim _AS400ServerName As String = “192.168.0.201”
    Dim _AS400UserID As String = “TRUSTOWN”
    Dim _AS400Password As String = “TRUSTOWN”
    as400.Define(_AS400ServerName)
    program.system = as400
    program.system.UserID = _AS400UserID
    program.system.Password = _AS400Password
    If as400.IsConnected(cwbx.cwbcoServiceEnum.cwbcoServiceRemoteCmd) = 0 Then
    as400.Connect(cwbx.cwbcoServiceEnum.cwbcoServiceRemoteCmd)
    If as400.IsConnected(cwbx.cwbcoServiceEnum.cwbcoServiceRemoteCmd) = 0 Then
    Throw New Exception(“Unable to connect to iSeries”)
    End If
    End If
    InitializeContext()
    End Sub

    Private Shared Sub SetInParameter(ByRef parameters As ProgramParameters, ByVal ParamName As String, ByVal Length As Integer, ByVal Value As String)
    parameters.Append(ParamName, cwbrcParameterTypeEnum.cwbrcInput, Length)
    Dim stringConverter As StringConverter = New cwbx.StringConverter
    stringConverter.Length = Length
    parameters(ParamName).Value = stringConverter.ToBytes(Value.PadRight(Length, ” “c))
    End Sub
    Private Shared Sub SetInOutParameter(ByRef parameters As ProgramParameters, ByVal ParamName As String, ByVal Length As Integer, ByVal Value As String)
    parameters.Append(ParamName, cwbrcParameterTypeEnum.cwbrcInout, Length)
    Dim stringConverter As StringConverter = New cwbx.StringConverter
    stringConverter.Length = Length
    parameters(ParamName).Value = stringConverter.ToBytes(Value.PadRight(Length, ” “c))
    End Sub
    Private Shared Sub SetOutParameter(ByRef parameters As ProgramParameters, ByVal ParamName As String, ByVal Length As Integer)
    parameters.Append(ParamName, cwbrcParameterTypeEnum.cwbrcOutput, Length)
    End Sub
    Private Shared Sub InitializeContext()
    program.LibraryName = “TBCBASELIB”
    program.ProgramName = “KAPUNLIBL”
    Dim stringConverter As StringConverter = New cwbx.StringConverter
    Dim parameters As cwbx.ProgramParameters = New cwbx.ProgramParameters
    parameters.Append(“Env”, cwbrcParameterTypeEnum.cwbrcInput, 3)
    parameters.Append(“A1”, cwbrcParameterTypeEnum.cwbrcInput, 4)
    parameters(“Env”).Value = stringConverter.ToBytes(“ZA1”)
    parameters(“A1”).Value = stringConverter.ToBytes(“*DFT”)
    Try
    program.[Call](parameters)
    Catch ex As Exception
    HandleException(ex)
    End Try

    ‘setDataArea()

    End Sub
    Private Shared Sub HandleException(ByVal ex As Exception)
    If as400.Errors.Count > 0 Then
    For Each [error] As cwbx.Error In as400.Errors
    Next
    End If
    If program.Errors.Count > 0 Then
    For Each [error] As cwbx.Error In program.Errors
    Next
    End If
    End Sub

    Public Shared Function TestInput() As String

    program.LibraryName = “KLIBZA1”
    program.ProgramName = “H56H1R”
    Dim parameters As cwbx.ProgramParameters = New cwbx.ProgramParameters

    Dim GZREF As String = ” ” ‘ Redundant A 18 – 22 5
    Dim GZBRNM As String = “9101” ‘Transfer branch A 23 – 26 4
    Dim GZPBR As String = “tests” ‘ Posting group id or user id, and group level A 27 – 31 5
    Dim GZPSQ As String = ” ” ‘ Reserved P 32 – 34 3 5 0
    Dim GZBRND As String = “9101” ‘ Branch for whom the transaction is being done A 35 – 38 4
    Dim GZEAND As String = ” ” ‘Debit external account A 39 – 58 20
    ‘9101 007198 700
    Dim GZAB1 As String = “9101” ‘ Debit account branch A 59 – 62 4
    Dim GZAN1 As String = “007198” ‘Debit account basic no A 63 – 68 6
    Dim GZAS1 As String = “700” ‘ Debit account suffix A 69 – 71 3
    Dim GZVFR1 As String = “1161012” ‘Debit value date S 72 – 78 7 7 0
    Dim GZDRF1 As String = “test ” ‘Debit user’s reference A 79 – 94 16
    Dim GZAMA1 As String = “-000000000050050.” ‘Debit amount P 95 – 102 8 15 0
    Dim GZAPP1 As String = ” ” ‘Application code; FX, MM, ” “, SW, CL, MS, CP, IR,A 103 – 104 2
    Dim GZTCD1 As String = “010” ‘ Debit transaction code A 105 – 107 3
    Dim GZCCY1 As String = “USD” ‘Debit account currency A 108 – 110 3
    Dim GZSRC1 As String = ” ” ‘Debit sundry reference code A 111 – 112 2
    Dim GZUC1 As String = ” ” ‘Debit user code 1 A 113 – 115 3
    Dim GZUC2 As String = ” ” ‘Debit user code 2 A 116 – 118 3
    Dim GZNR1 As String = ” ” ‘Debit narrative line 1 A 119 – 153 35
    Dim GZNR2 As String = ” ” ‘ Debit narrative line 2 A 154 – 188 35
    Dim GZNR3 As String = ” ” ‘ Debit narrative line 3 A 189 – 223 35
    Dim GZNR4 As String = ” ” ‘ Debit narrative line 4 A 224 – 258 35
    Dim GZCED1 As String = ” ” ‘ Debit currency edit code A 259 1
    Dim GZMCH1 As String = ” ” ‘ Debit matched/obsolete today A 260 1
    Dim GZEANC As String = ” ” ‘ Credit external account A 261 – 280 20
    ‘9101 000195 700
    Dim GZAB2 As String = “9101” ‘Credit account branch A 281 – 284 4
    Dim GZAN2 As String = “000195” ‘Credit account basic no A 285 – 290 6
    Dim GZAS2 As String = “700” ‘Credit account suffix A 291 – 293 3
    Dim GZVFR2 As String = “1100912” ‘Credit value date S 294 – 300 7 7 0
    Dim GZDRF2 As String = “test ” ‘Credit user’s reference A 301 – 316 16
    Dim GZAMA2 As String = ” 000000000050050.” ‘Credit amount P 317 – 324 8 15 0
    Dim GZAPP2 As String = ” ” ‘Application code; FX, MM, ” “, SW, CL, MS, CP, IR A 325 – 326 2
    Dim GZTCD2 As String = “510” ‘Credit transaction code A 327 – 329 3
    Dim GZCCY2 As String = “USD” ‘ Credit account currency A 330 – 332 3
    Dim GZSRC2 As String = ” ” ‘Credit sundry reference code A 333 – 334 2
    Dim GZUC3 As String = ” ” ‘Credit user code 1 A 335 – 337 3
    Dim GZUC4 As String = ” ” ‘Credit user code 2 A 338 – 340 3
    Dim GZNR5 As String = ” ” ‘Credit narrative line 1 A 341 – 375 35
    Dim GZNR6 As String = ” ” ‘Credit narrative line 2 A 376 – 410 35
    Dim GZNR7 As String = ” ” ‘Credit narrative line 3 A 411 – 445 35
    Dim GZNR8 As String = ” ” ‘Credit narrative line 4 A 446 – 480 35
    Dim GZCED2 As String = ” ” ‘Credit currency edit code A 481 1
    Dim GZMCH2 As String = ” ” ‘Credit matched/obsolete today A 482 1
    Dim GZRRT As String = ” ” ‘Reserved A 483 – 485 3
    Dim GZEXR As String = ” ” ‘ Obsolete A 486 – 499 14
    Dim GZFONT As String = ” ” ‘Fontis transfer? A 500 1
    Dim GZEXRH As String = ” 000000000000000.” ‘ Exchange rate P 501 – 508 8 15 9
    Dim GZBAM1 As String = ” 000000000000000.” ‘Equivalent amount in base currency – Dr P 509 – 516 8 15 0
    Dim GZOAM1 As String = ” 000000000000000.” ‘ Equivalent amount in user currency – Dr P 517 – 524 8 15 0
    Dim GZBAM2 As String = ” 000000000000000.” ‘Equivalent amount in base currency – Cr P 525 – 532 8 15 0
    Dim GZOAM2 As String = ” 000000000000000.” ‘Equivalent amount in user currency – Cr P 533 – 540 8 15 0
    Dim GZIEA As String = ” ” ‘Inter a/c transfer with equivalent amounts flag A 541 1
    Dim GZOID As String = ” ” ‘Inter a/c transfer option id A 542 – 544 3
    Dim GZSOT As String = ” ” ‘Standing order transfer? A 545 1
    Dim GZTREF As String = ” TESTATMTRAN” ‘Transfer reference A 546 – 561 16
    Dim GZANMD As String = ” ” ‘System generated account mnemonic A 562 – 567 6
    Dim GZGDP As String = ” ” ‘Generic deal posting A 568 1
    Dim GZCRT As String = ” ” ‘Court Order A 569 1
    Dim GZALL As String = ” ” ‘Hold whole a/c balance A 570 1
    Dim GZHOLD As String = ” ” ‘Hold on queue A 571 1
    Dim GZPDTE As String = “1100912” ‘Date entered S 572 – 578 7 7 0
    Dim GZFOR As String = ” ” ‘Force to queue A 579 1
    Dim GZDRTY As String = ” ” ‘ Days to retry queued tran. A 580 – 582 3
    Dim GZMRTY As String = ” ” ‘ Months to retry queued tran. A 583 – 584 2
    Dim GZDTTY As String = “0000000” ‘Date of last retry of queued transaction S 585 – 591 7 7 0
    Dim GZQTR As String = ” ” ‘Queued by A 592 – 593 2
    Dim GZQTR2 As String = ” ” ‘Queued again A 594 – 595 2
    Dim GZQSTS As String = ” ” ‘Queue status A 596 – 600 5
    Dim GZQST2 As String = ” ” ‘Queue status 2 A 601 – 605 5
    Dim GZQRES As String = ” ” ‘Reason for queuing A 606 – 610 5
    Dim GZQRS2 As String = ” ” ‘Reason for queuing 2 A 611 – 615 5
    Dim GZQNQ As String = ” ” ‘Automatic queuing A 616 1
    Dim GZQMSQ As String = “0000000” ‘Maintenance sequence number P 617 – 620 4 7 0
    Dim GZQACT As String = ” ” ‘Action A 621 – 622 2
    Dim GZQSCR As String = ” ” ‘ Display screen A 623 1
    Dim GZQUID As String = ” ” ‘User ID A 624 – 633 10
    Dim GZUPTY As String = ” ” ‘ User priority code A 634 – 638 5
    Dim GZQBAL As String = ” 000000000000000.” ‘Queued balance P 639 – 646 8 15 0
    Dim GZQDTE As String = “0000000” ‘Queued date S 647 – 653 7 7 0
    Dim GZQPTY As String = ” ” ‘ Priority code A 654 – 658 5
    Dim GZQRRC As String = ” ” ‘ Reason A 659 – 661 3
    Dim GZQAID As String = ” ” ‘Assigned to user A 662 – 671 10
    Dim GZQGRP As String = ” ” ‘Authorisation Group A 672 – 681 10
    Dim GZQCHK As String = ” ” ‘Number of checkers S 682 – 683 2 2 0
    Dim GZQCHD As String = ” ” ‘Times checked S 684 – 685 2 2 0
    Dim GZQRED As String = “0000000” ‘Required date S 686 – 692 7 7 0
    Dim GZQRET As String = ” ” ‘Required time S 693 – 698 6 6 0
    Dim GZQBID As String = ” ” ‘Batch ID A 699 – 714 16
    Dim GZQLVL As String = ” ” ‘Authorisation level A 715 – 716 2
    Dim GZQEVM As String = ” ” ‘Events A 717 – 722 6

    Dim _SendData As String =
    GZREF & _
    GZBRNM & _
    GZPBR & _
    GZPSQ & _
    GZBRND & _
    GZEAND & _
    GZAB1 & _
    GZAN1 & _
    GZAS1 & _
    GZVFR1 & _
    GZDRF1 & _
    GZAMA1 & _
    GZAPP1 & _
    GZTCD1 & _
    GZCCY1 & _
    GZSRC1 & _
    GZUC1 & _
    GZUC2 & _
    GZNR1 & _
    GZNR2 & _
    GZNR3 & _
    GZNR4 & _
    GZCED1 & _
    GZMCH1 & _
    GZEANC & _
    GZAB2 & _
    GZAN2 & _
    GZAS2 & _
    GZVFR2 & _
    GZDRF2 & _
    GZAMA2 & _
    GZAPP2 & _
    GZTCD2 & _
    GZCCY2 & _
    GZSRC2 & _
    GZUC3 & _
    GZUC4 & _
    GZNR5 & _
    GZNR6 & _
    GZNR7 & _
    GZNR8 & _
    GZCED2 & _
    GZMCH2 & _
    GZRRT & _
    GZEXR & _
    GZFONT & _
    GZEXRH & _
    GZBAM1 & _
    GZOAM1 & _
    GZBAM2 & _
    GZOAM2 & _
    GZIEA & _
    GZOID & _
    GZSOT & _
    GZTREF & _
    GZANMD & _
    GZGDP & _
    GZCRT & _
    GZALL & _
    GZHOLD & _
    GZPDTE & _
    GZFOR & _
    GZDRTY & _
    GZMRTY & _
    GZDTTY & _
    GZQTR & _
    GZQTR2 & _
    GZQSTS & _
    GZQST2 & _
    GZQRES & _
    GZQRS2 & _
    GZQNQ & _
    GZQMSQ & _
    GZQACT & _
    GZQSCR & _
    GZQUID & _
    GZUPTY & _
    GZQBAL & _
    GZQDTE & _
    GZQPTY & _
    GZQRRC & _
    GZQAID & _
    GZQGRP & _
    GZQCHK & _
    GZQCHD & _
    GZQRED & _
    GZQRET & _
    GZQBID & _
    GZQLVL & _
    GZQEVM

    SetInParameter(parameters, “@RPGM”, 10, “H18A”)
    SetInParameter(parameters, “@BRNM”, 4, “9101”)
    SetInParameter(parameters, “@USID”, 4, “TRUS”)
    SetInParameter(parameters, “@WSID”, 4, “TRUS”)
    SetInParameter(parameters, “@JTT”, 1, “A”)
    SetInParameter(parameters, “DSAIM”, 9999, _SendData)
    SetOutParameter(parameters, “@RREC”, 1)
    SetOutParameter(parameters, “@RMES7”, 37)
    SetOutParameter(parameters, “AOW”, 740)
    ‘SetInParameter(parameters, “@ETK”, 4, “”)
    ‘SetInParameter(parameters, “@ETN”, 7, “0000000”)
    SetInParameter(parameters, “@AEXT”, 1, “Y”)
    SetInParameter(parameters, “@AREC”, 1, “Y”)

    Try
    setDataArea()
    program.[Call](parameters)

    Catch ex As Exception
    MsgBox(ex.Message)
    End Try

    as400.Disconnect(cwbx.cwbcoServiceEnum.cwbcoServiceAll)
    End Function

    Private Shared Sub setDataArea()

    program.LibraryName = “KLIBZA1”
    program.ProgramName = “UTM83C”
    Dim stringConverter As StringConverter = New cwbx.StringConverter
    Dim parameters As cwbx.ProgramParameters = New cwbx.ProgramParameters
    parameters.Append(“X”, cwbrcParameterTypeEnum.cwbrcInput, 1)
    parameters(“X”).Value = stringConverter.ToBytes(“ZAI”)

    Try
    program.[Call](parameters)
    Catch ex As Exception
    HandleException(ex)
    End Try

    End Sub

    End Class

  37. Mark, you cant pass fresh string data to the fields which are in the API. for that please refer the AccounToAccounTransferStructureClass mentioned above in one of the comments. You have to use packed, string, zone converters based on the field type in the API. The AS400 used to generate some strange errors if you didnt pass the values properly such like decimal error, etc. Hence, make sure to use proper converters when passing data to the API program. I will try to send you a code sample hopefully.

  38. thanks for the prompt reply. let me try and correct what you have pointed out. But if you can send me a sample i would appriciate.

    Thanks.

  39. Hii Mark, i have sent you some sample codes and you can try with the same. thanks, Ammar.

  40. thanks i will update you on progress

  41. Hi Ammar,

    My name is Dinesh.
    I am really glad to see your blog about MIsys Equation. I need your help to know the basis understanding of Equation system and use of their API’s. if you have any documents and you can share that will be great help.

    Thanks & Regards,
    Dinesh

    • Hii Dinesh,

      I will email you the documentation what I have with me related to MiSys Equation.

      thanks,

      Ammar

      • Thanks you so much Ammar 🙂

      • Hi Ammar,

        I know nothing about AS400 but is required to do some coding on VB.net to connect to AS400 and call a CL program.
        I was referring to the http://www.netsplore.com/PublicPortal/Default.aspx?tabid=246 and managed to get something working.

        However, whenever (and getting more oftens) i debug till this line, the page not responding:
        Dim as400 As cwbx.AS400System = New cwbx.AS400SystemClass()

        i actually tried to disabled the userid that I used to established the connection and the iSeries actually prompted me so.
        Thus, I’m sure my connection params were alright.

        Just want to understand why i can manage to pass through the above line once… but subsequently when I debug again, the page just hand, it seems like waiting for something to come back.

        Please advise asap.

        Regards,

        Sarah

      • Hii Sarah,

        calling AS400 API program via .net is not easy as we think. its really a pain. you have to pass some default parameters to initialize the AS400 program. I have emailed you the class that i was using to call the AS400 program with the parameters that we should pass.

        thanks,

        Ammar

  42. Hi Ammar ,
    Did you try to call H56HSR program from websphere message broker ?
    Do you have a PCML files for H56HSR & H46HMR ?
    Please advise as soon as possible
    Regards,
    Tamer.

  43. Hi Ammar,
    Great Article even though it has been 3 years!!
    One Question though Should you call KAPUNLIBL and UTM83C to initialize the DataAreas?
    If you can send me how the code is working I’m working on the same concept but I’m using the Program.Call(APIName) to call the API.
    Thanks a lot my email is mohamad[dot]dimishkieh[at]gmail[dot]com
    Hope to hear from you soon
    Moe

    • Hii Mohamed,

      yeah you have to set the data areas before calling the main program.

      I will email you some sample classes to start your coding. 🙂

      thanks,

      Ammar

  44. Hi Ammar,

    This thread is very good info on the subject …
    I hope you can help me with the following:

    i need to call 2 programs (correct me if i am wrong)

    1- Get Customer Acct List and get from it Accts Nos and Acct Aval. Balance and other details .. I am assuming i should call H46HMR with EPGM = H70DDR
    2- Transfer between Customer accounts progam = H56HSR RPGM = H18ARRITA

    i would great-full if you can provide working sample for those and any other as well
    to

    Thanks in advance for your great help to everyone

  45. Did not finish the job yet … would highly appreciate a real world working sample at least for the functions i mentioned

  46. Hi Ammar,

    I am calling ITA option using java. I am getting the bellow error:
    Application error. RNX9001 unmonitored by H56H1R at statement *N, instruction X’0000′.

    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 H56H1R H56H1R _QRNP_PEP_H56H1R. 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.
    File Name: QCEEMSG
    Library: QSYS
    Path: /QSYS.LIB/QCEEMSG.MSGF
    Message: AS400Message (ID: CEE9901 text: Application error. RNX9001 unmonitored by H56H1R at statement *N, instruction X’0000′.):com.ibm.as400.access.AS400Message@1169fb2

    I checked the dump but can’t find more info.
    Did you experience sunch problem before?

    Do you want me to post the code?

    Thanks.

  47. Hii Bilal,
    Can you please let me know the steps that are you calling this program? are you setting the data area before calling this program? just do email or put the code here for me to refer the code what you are executing.
    thanks,
    Ammar

    • Thank you Ammar for your help.

      Find attached the jt400 (Java) code I am using to call ITA option API. Please note that I have a program that handle the data areas issues and I used many times.

      I can send you the dump file if it helps.

      Thanks.

      On Mon, Mar 16, 2015 at 10:51 AM, Ammar’s IT Blog wrote:

      > Ammar commented: “Hii Bilal, Can you please let me know the steps that > are you calling this program? are you setting the data area before calling > this program? just do email me the code what you are executing. thanks, > Ammar”

  48. Hi Ammar,
    I replied to the email I received when you put the comment and attached the code.
    thanks.

  49. Hi there, is it possible to retrieve the current equation unit date using vb.net. if so please share how to do it. I would assume its through the data areas?

  50. how can i call the H56HIR API from c#, do you have a sample

  51. How can i call the H56HIR from C#

  52. hi do you have any sample code using the prompt and validate API on Equation for example GFR71R? Please share any if you have i would like to call these. see below :

    GFR70R : P/V Customer
    Brief Description
    This module prompts and validates the customer mnemonic and customer location fields.
    If the last character in the customer mnemonic field is ‘*’ then a prompt will be forced on
    the customer location field. All customers at all locations will be displayed if F4 is pressed
    on the customer mnemonic field.
    Communications Array (CCN) (DSR70)
    PASSED

    1 9PMKEY Customer mnemonic
    7 9 PMKEY Customer location
    62 63 £GFAT1 First account type
    64 65 £GFAT2 Second account type
    118 119 £GFAT3 Third account type
    120 121 £GFAT4 Fourth account type
    127 127 £R70HG Branch/customer/account security control
    RETURNED

    H – Non transaction input function
    T – Transaction input function
    G – Enquiry

    1 6 PMKEY Customer mnemonic
    7 9 PMKEY Customer location
    10 44 £GFCUN Customer name
    45 50 £GFCPN Customer number
    51 51 £GFCUB FX/MM blocked
    52 57 £GFGRP Group
    58 61 £GFBRM Default branch
    62 63 £GFAT1 First account type
    64 65 £GFAT2 Second account type
    66 67 £GFCR1 First tax code
    68 69 £GFCR2 Second tax code
    70 71 £GFCNL Local residence
    72 86 £GFDAS Customer short name
    87 88 £GFCNP Parent country
    89 90 £GFCNR Risk country
    91 92 £GFCTP Customer type
    93 94 £GFSAC Sundry analysis code
    95 97 £GFACO Account officer
    98 99 £GFLNM Language
    100 101 £GFCA2 Analysis code
    102 103 £GFCNI Internal risk cntry
    104 109 £GFPGR Principal group
    110 112 £GFLCC Limit currency
    113 117 £GFLST Limit structure
    118 119 £GFAT3 Third account type
    120 121 £GFAT4 Fourth account type

  53. Hello Ammar

    I am starting out here from the beginning. Could you please assist with sample code for calling Equation API from windows? A simple example will be fine like Account Balance Enquiry. I just need to get a small working example to see how it all actually hangs together.

    • Hello Ammar
      I am starting out here from the beginning. Could you please assist with sample code for calling Equation API from windows? A simple example will be fine like Account Balance Enquiry. I just need to get a small working example to see how it all actually hangs together.

  54. Hi Ammar ,

    One of the most helpful post ever, i have successfully implemented H56HSR (Fund Transfer) by Studying above comments, the details of DS of H181 was really helpful,
    I need to consume more API’s of MISYS EQUATION but i dont have any detailed information of following DS

    GZH181 (Got details in this post )

    GZH151
    GZH111
    GZK421
    GZJ711

    from where can i get details of above mentioned DS regarding to length and datatypes of each fields

    Thank you

    • Thanks Mashab.Its my pleasure. please check your email.

      thanks,

      Ammar

      • Wow, you actually responded.

        All these USELESS people ask you for help but they will never share anything they know!

        How about helping now?

        Sent from my BlackBerry® wireless device

      • sharing is caring. 😀

      • Hello Ammar

        I am looking for assistance with a program that will call and Equation API from windows, VB6 preferred but .net will do also. A basic UPDATE api can be used (ANC add new customer maybe). Perhaps something that will just take 1 or 2 parameters as Input and do an Update accordingly. A hard-coded version can be used as this will allow me to fully understand how this concept hangs together. I would think that this will be sufficient for me to then further explore with more advanced API’s.

        I do have a very advanced version in VB6 but it is too cleverly parameterised for me to debug and fully understand how it works. It always crashes out for various reasons. In fact, I am not too sure if it works in the first place.

        Perhaps if you got something that you know definitely works.

        Your kind assistance will be much appreciated.

        Thank You.

        Sent from my BlackBerry® wireless device

      • Hi Ammar.

        My question is regarding “Equation Global Modules”.

        I’m having the following error: “CEE9901 – Erro de aplicação. RNX9001 não supervisionada por GWV91R na instrução *N, MI X’0000′.”

        Probably i’m calling this in wrong way from my java application.

        Can you help me on this?

        King Regards,
        Ricardo

      • Hi Ammar,

        May i ask how did you add the customer info using G01ARR using H56HSR cause i am having problem to add customer info and i dont know yet how to deal with DSAIM.

        a sample code is very much appreciated.
        invalid1923@gmail.com

        Thanks in advance. Godbless

        Mark
        Newbie in AS400

  55. Thanks!

  56. Hi I am trying to initialise the journal GZC021, i am getting a decimal data error i suspect its the field GZAM. Can you please assist.

    Thanks

  57. Hi I am trying to initialise the journal GZC021, i am getting a decimal data error i suspect its the field GZAM. Can you please assist.

    Thanks

  58. Hi I am trying to initialise the journal GZC021, i am getting a decimal data error i suspect its the field GZAM. Can you please assist.

    The journal definition specifies that the field is 1200 characters and contains 150 elements.

    Thanks

  59. Dear Ammar,
    We are implementing a project with AS400 connectivity, however Business is somehow not sharing the document with us. Need a document which will explain all the Possible Error Code and their Possible Root cause will help.
    Not able to get the document from web.

  60. Dear Ammar, How are you? please kindly send let me know your email address please.
    my email is asankakr@hotmail.com

  61. Hi Ammar,

    I really appreciate your blog and the help that you are giving to your readers. May I know if you can still entertain questions. I have seen your API code and that was great. Currently we are working on Equation API to insert records via external input. Do you have a working code on calling “UTM83C” and “H56HSR”. I have try a code similar to yours but I am getting this error –Application error. RNX9001 unmonitored by H56HSR at statement *N, instruction X’0000′ –. Can you help me to resolve this error. Thanks in advance.

  62. Dear Colleagues, I was unable to access my blog for some reason. Very sorry for that. I got the access now. Hope i can reply to your queries in coming days. thank you.

  63. Add New Customer

    We are calling G01ARRANC

    our DSAIM data format is bsed GZG011 journal

    Here’s what I have so far

    string sData = “”,”,”,”,”,”,”, ‘” + sFullName + “‘,'” + sRefCd + “‘,'” + sShortName + “‘, ‘PA’, ‘N’, ‘N’, ‘N’, ‘N’, ‘P1’, ”, ‘5412025691’, ’02’, ”, ‘PH’, ‘PH’,” + iCustOpenDt + “0, ”, ‘” + sBrCd + “‘,”, ‘TX’, ’00’, ”, ”, ”, 0, ”, ”, ‘N’, ”, ”, ”, ”, ”, ”, ”, ”, ”, ”, ”, ”, ‘PH’, ”,'” + sBrCd + “‘,’N’, ‘N’, 0, ”, ”, ”, ”, ”, ”, ”, ”, ”, 0,”, ‘N’, ‘Y’, ‘N’, ‘N’, ‘N’, ‘N’, ‘N’, ‘N’, ‘N’, ”, ”, ”, ”, 0, 0, ”, 0, 0, 0, ”, ”, ”, ”, ”, ”, ”, ””;

    try
    {

    /*
    This portion for API H56HSR Now initialize AS400 environment using cwbx dll
    */

    cwbx.AS400System sys = new cwbx.AS400System();
    cwbx.Program pgm = new cwbx.Program();

    sys.Define(“192.168.xx.xxx”);

    pgm.system = sys;
    pgm.system.UserID = “tstxxx”;
    pgm.system.Password = “passxxxxx”;

    if (sys.IsConnected(cwbx.cwbcoServiceEnum.cwbcoServiceRemoteCmd) == 0) // Remote command service is connected
    {
    // Lost connection with the AS400. Disconnect, then reconnect.

    sys.Connect(cwbx.cwbcoServiceEnum.cwbcoServiceRemoteCmd);

    if (sys.IsConnected(cwbx.cwbcoServiceEnum.cwbcoServiceRemoteCmd) == 0) //still not able to connect
    {
    //XLogger.Error(“API.Connect : Unable to connect to iSeries”, _ApplicationName);
    throw new Exception(“Unable to connect to iSeries”);
    }

    }

    StringConverter stringConverter = new cwbx.StringConverter();
    cwbx.ProgramParameters parameters = new ProgramParameters();

    pgm.LibraryName = “KLIBxxx”;
    pgm.ProgramName = “UTM83C”;
    pgm.ProgramName = “H56HSR”;

    parameters.Append(“@RPGM”, cwbrcParameterTypeEnum.cwbrcInput, 10);
    parameters[“@RPGM”].Value = stringConverter.ToBytes(“G01ARRANC “); //program name H56HSR + 3 spaces

    parameters.Append(“@BRNM”, cwbrcParameterTypeEnum.cwbrcInput, 4);
    parameters[“@BRNM”].Value = stringConverter.ToBytes(“0650”); //branch mnemonic

    parameters.Append(“@USID”, cwbrcParameterTypeEnum.cwbrcInput, 4);
    parameters[“@USID”].Value = stringConverter.ToBytes(“TSTO”); //userid

    parameters.Append(“@WSID”, cwbrcParameterTypeEnum.cwbrcInput, 4);
    parameters[“@WSID”].Value = stringConverter.ToBytes(“TSTO”); //workstation

    parameters.Append(“@JTT”, cwbrcParameterTypeEnum.cwbrcInput, 1);
    parameters[“@JTT”].Value = stringConverter.ToBytes(“A”); //transaction type ‘Add record’

    parameters.Append(“DSAIM”, cwbrcParameterTypeEnum.cwbrcInput, 9999);
    parameters[“DSAIM”].Value = stringConverter.ToBytes(sData); //DSAIM data

    parameters.Append(“@RREC”, cwbrcParameterTypeEnum.cwbrcOutput, 9999);
    parameters[“@RREC”].Value = stringConverter.ToBytes(“@RREC”); //recovery

    pgm.Call(parameters);
    }

    I am getting this error
    System.Runtime.InteropServices.COMException (0x80004005): CEE9901 – Application error. RNX9001 unmonitored by H56HSR at statement *N, instruction X’0000′.\r\n at cwbx.IcwbxProgram.Call(ProgramParameters parameters)\r\n at Connect2DB2.DataEntry.btnInsert_Click(Object sender, EventArgs e)

  64. Hi Ammar,

    Would you be so kind to identify, where could be my error was.

    Thanks in advance
    Mark Rosal

    • Hii Mark, let me check your code. Have you tried calling any of the inquiry APIs? But when passing data at the time of posting you have to follow some structural way like cwbx.PackedConverter, cwbx.ZonedConverter for decimals and cwbx.StringConverter. Let me know your email id to send you some samples. thanks, Ammar.

  65. Hi ammar

    I have read all comments which were very helpful especially to me since am new to the cbs and dealing with as400 i have tried to add new customer ANC using structure class (with its 98 field) and with correct wrapper api h56h1r and values for the structure class i extracted a valid values from existing rows in anc corresponding table so am sure the values are correct but when i run it it fails. If it is not too much can you send me a working example i appreciate it.

    Regards

  66. Hello Ammar, Your expertise in AS400 has been incredibly valuable, especially considering the scarcity of resources in this field. I’m currently facing a challenge with the “H46HMR” API and would greatly benefit from your guidance. Could you kindly provide a sample implementation of this API? Additionally, if you have any other examples related to AS400 .net, they would be immensely helpful. I look forward to your response and appreciate your assistance. You can reach me at rasool.dawood95@gmail.com. Thank you.

Trackbacks

Leave a reply to Fernando Felício Cancel reply