Reputation: 2599
I am trying to call an AS400 program from C# with parameters. At the moment i am able to call programs like so
myRepository.Execute($"Call {Settings.As400ProgramLibrary}.EAPP100CL");
The execute is part of my IRepository interface
public interface IRepository<T> : IReadOnlyRepository<T> where T : class
{
void Add(T item);
void Add(IEnumerable<T> items);
void Attach(T item);
void EnrollInUnitOfWork(IUnitOfWork unitOfWork);
int Execute(string command, params object[] parameters);
IEnumerable<T> ExecWithStoreProcedure(string query, params object[] parameters);
IQueryable<T> FindBy(Func<T, bool> predicate);
IQueryable<T> FindBy(Func<T, bool> predicate, params Expression<Func<T, object>>[] includes);
void Remove(T item);
void Remove(IEnumerable<T> items);
void Update(T item);
}
How would i add parameters when telling it to execute? I looked HERE but was wondering if there is another way.
Upvotes: 1
Views: 2475
Reputation: 1324
It looks like your call string is the same as what you would type on the AS400 command line. If that is so, then you would use the PARM keyword on the CALL command.
myRepository.Execute($"CALL PGM({Settings.As400ProgramLibrary}.EAPP100CL) PARM('{Parameter1}' '{Parameter2}')");
In this snippet, I have added single quotes to pass your parameters as quoted strings, which is often the easiest, although you can also pass values as other types, like a 15,5 decimal. I have also explicitly added the PGM keyword, although it often works without it (like your call string had).
For further reference see the CL manual: CALL command
Upvotes: 1