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
{
public class AS400Program
{
private bool as400Configured = false;
private cwbx.AS400System as400;
private cwbx.Program 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)
{
as400.Disconnect(cwbx.cwbcoServiceEnum.cwbcoServiceAll);
as400.Connect(cwbx.cwbcoServiceEnum.cwbcoServiceRemoteCmd);
if(as400.IsConnected(cwbx.cwbcoServiceEnum.cwbcoServiceRemoteCmd) == 0)
{
}
}
program.Call(parameters);
success = true;
}
catch(Exception e)
{
if(as400.Errors.Count > 0)
{
foreach(cwbx.Error error in as400.Errors)
{
}
}
if(program.Errors.Count > 0)
{
foreach(cwbx.Error error in program.Errors)
{
}
}
if(throwInsteadOfReturn)
{
throw(e);
}
}
return(success);
}
public void Close()
{
as400.Disconnect(cwbx.cwbcoServiceEnum.cwbcoServiceAll);
}
}
}
And the function similarly:
protected enum DataLengths : int
{
PartId = 12,
PartPrice = 15,
}
string partId = "3001891A";
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. :)