Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: SQL-server-2005 C# ASP.NET .NET , +
Hi experts.
My aim is to call through ASP a CL program (in AS400) and return the result.
I have fount a nice article about this at Calling AS/400 (AS400) RPG Programs From ASP.NET[^] . But it does not elaborates anything regarding CL program.

As given in the article, I have created the class AS400Program.cs,
 
using System;
 
namespace Interfaces.Source
{
    /// <summary>
    /// Summary description for AS400Program.
    /// </summary>
    public class AS400Program
    {
        private bool as400Configured = false;
        private cwbx.AS400System as400;
        private cwbx.Program program;
 
<pre>
    // configuration format:
    // as400;userid;password;library;program
    public AS400Program(string configuration)
    {
        if(!as400Configured)
        {
            string[] settings = configuration.Split(';');
            if(settings.Length == 5)
            {
                as400 = new cwbx.AS400SystemClass();
                program = new cwbx.Program();
 
                as400.Define(settings[0]);
                program.system = as400;
                program.system.UserID = settings[1];
                program.system.Password = settings[2];
                program.LibraryName = settings[3];
                program.ProgramName = settings[4];
                as400Configured = true;
            }
            else
            {
                throw(new Exception(
                    string.Format("Invalid AS400Program configuration string : [{0}]", configuration)));
            }
        }
    }
 
    public bool Invoke(bool throwInsteadOfReturn, ref cwbx.ProgramParameters parameters)
    {
        bool success = false;
 
        try
        {
            if(as400.IsConnected(cwbx.cwbcoServiceEnum.cwbcoServiceRemoteCmd) == 0)
            {
                //  Lost connection with the AS400.  Disconnect, then reconnect.
                as400.Disconnect(cwbx.cwbcoServiceEnum.cwbcoServiceAll);
                as400.Connect(cwbx.cwbcoServiceEnum.cwbcoServiceRemoteCmd);
 
                if(as400.IsConnected(cwbx.cwbcoServiceEnum.cwbcoServiceRemoteCmd) == 0)
                {
                    //  Log something here.
                }
            }
 
            program.Call(parameters);
            success = true;
        }
        catch(Exception e)
        {
            // Capture to log the errors but then re-throw it to let caller know there was trouble.
            if(as400.Errors.Count &gt; 0)
            {
                foreach(cwbx.Error error in as400.Errors)
                {
                    //  Log something here.
                }
            }
 
            if(program.Errors.Count &gt; 0)
            {
                foreach(cwbx.Error error in program.Errors)
                {
                    //  Log something here.
                }
            }
 
            if(throwInsteadOfReturn)
            {
                throw(e);
            }
        }
 
        return(success);
    }
 
    public void Close()
    {
        as400.Disconnect(cwbx.cwbcoServiceEnum.cwbcoServiceAll);
    }
}

}
And the function similarly:
 
//  Assume the RPG program being called takes one input paramater, PartId, and returns the PartPrice.

protected enum DataLengths : int
{
    PartId     = 12,
    PartPrice  = 15,
}
 
string partId = "3001891A";  // hardcoded for this example

AS400Program program = new AS400Program(ConfigurationSettings.AppSettings["partsPricingConfig"]);
 
cwbx.StringConverter stringConverter = new cwbx.StringConverterClass();
cwbx.PackedConverter packedConverter = new cwbx.PackedConverterClass();
packedConverter.DecimalPosition = 4;
packedConverter.Digits = (int)DataLengths.PartPrice;
 
cwbx.ProgramParameters parameters = new cwbx.ProgramParametersClass();
 
parameters.Append("PartId", cwbx.cwbrcParameterTypeEnum.cwbrcInout, (int)DataLengths.PartId);
stringConverter.Length = (int)DataLengths.PartId;
parameters["PartId"].Value = stringConverter.ToBytes(partId.PadRight((int)DataLengths.PartId, ' '));
 
parameters.Append("PartPrice", cwbx.cwbrcParameterTypeEnum.cwbrcInout, (int)DataLengths.PartPrice);
parameters["PartPrice"].Value = packedConverter.ToBytes("0");
 
program.Invoke(true, ref parameters);
 
string price = packedConverter.FromBytes(parameters["PartPrice"].Value);
 
program.Close();
 
return(Double.Parse(price));

I need to know where to call the CL program, and use the price value returned from the function.
Any info regarding this will be appreciated. Smile | :)
Posted 29-Jan-13 20:28pm
ujju.15K
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

It's been far too long since I counted RPG and CL as my friends - but I found this post which shows how to call a CL program with parameters successfully...

Not sure if it will help [^]
  Permalink  
Comments
ujju.1 at 30-Jan-13 1:56am
   
Thanx Max. I am trying that now.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

Got it.
program.Invoke(true, ref parameters);
invokes the program that we declare at appsettings (read connection from
AS400Program(ConfigurationSettings.AppSettings["partsPricingConfig"]);
)
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

AS400 is very old technology and I don't have much idea about it. But after searching I came across the following articles. You can check it. This may help you.
http://www.netsplore.com/PublicPortal/Default.aspx?tabid=246[^]
AS400 Data Connection in ASP.NET[^]

--Amit
  Permalink  
Comments
francis3 at 6-Jun-13 7:36am
   
Hi,

Just want to know which is faster.
Calling RPG program or using odbc?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 490
1 Sergey Alexandrovich Kryukov 405
2 Maciej Los 285
3 ProgramFOX 265
4 Peter Leow 210
0 OriginalGriff 490
1 Sergey Alexandrovich Kryukov 405
2 Maciej Los 285
3 ProgramFOX 265
4 Peter Leow 210


Advertise | Privacy | Mobile
Web01 | 2.8.150331.1 | Last Updated 31 Jan 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100