alternately, you can use cwbx.dll, an activex automation object from client access
you can call the program directly using cwbx.Programs and not required to create stored procedure
Main Topics
Browse All TopicsIs there a simple way to call an AS400 (RPG or CL) program from a C# program? I would simply like to call program, pass parameters, get return values. I am using OLEDB to access the AS400 database via SQL calls, but I would like to use many of the existing AS400 programs that are already there.
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
definitely not.
you need at least V4R4
http://www-1.ibm.com/suppo
I have 2 ideas for you that have worked for me in the past. I'm normally a VB guy, so I can't give you precise C# code, but I can tell you exactly what you need to do and it's really simple.
First off, if you're using ODBC and using SQL you can simply do a SQL CALL( ). SQL in the iSeries allows you do a call statement. The Call statement can call any RPG, CL, Cobol, CLLE, RPGLE, etc. that's on the 400. You have the option to wait for an answer or to just do the call and exit. The SQL Call statement can also call a stored procedure. In fact you could even get really sophisticated and use the call statement to create a source file, then pass in some code and then compile a program and run it. Basically you could do almost anything.
The syntax is simple. Just setup your connection like any normal SQL connection and instead of doing a select statement just do somthing like this: 'Call MyCLPgm (PARM1)' or Just 'Call MyRPGPgm' and then execute it. Simple and elegant.
The other way is to do a REXEC procedure if you're running from windows. This opens a shell that executes a remote procedure call on the 400. The only thing here is that you have to have the RPC service running on the 400. This can be turned on by opening up Operations Navigator and going to the Networking section and then to TCP/IP Servers. Just start it up and leave it running. If it's running the the windows REXEC can execute remote procedure calls to the 400.
The shell program requires some SendKeys operations to it because you have log in, etc. So it's a little more cumbersome that the SQL Call Statement, but here's some VB code that I've used successfully to do the REXEC which will call any program on the 400 also.
---------
Dim strCommand1 As String = "SBMJOB CMD(CALL PGM(LAWMOD7/IFCEXCEDGL) PARM("
Dim strCommand2 As String 'LawUser and LawJobName
Dim strCommand3 As String = "))"
Dim strCommand As String
Dim ReturnCode
Dim strPassword As String = ""
Dim strUser As String = ""
strUser = InputBox("Enter Lawson User ID", "Login to Lawson", "", , )
strPassword = InputBox("Enter Lawson Password", "Login to Lawson", "", , ) & "~"
strCommand2 = "'" & strUser & "'" & " '" & InputBox("Enter Lawson GL165 Job Name", "Job to Execute", "", , ) & "'"
strCommand = strCommand1 & strCommand2 & strCommand3
'Open the command shell with a handle to reactivate using sendkeys
ReturnCode = Shell(Environ$("WINDIR") & "\system32\rexec.exe iseries -l " & strUser & " " & strCommand, AppWinStyle.NormalFocus)
'Wait a second for the shell command to execute and prompt for the password.
For x As Integer = 1 To 10000
Next x
'Activate the shell window
AppActivate(ReturnCode)
'Send the password to the shell runas program
SendKeys.SendWait(strPassw
---------
This is some code that we use to send some data to the AS/400 and to Lawson Financials in particular and then call a Lawson job to process the journal entries we pass in from another system.
The advantage of the SQL Call is that you can wait for results or you can use the submit the job to batch. You have more control and it's actually a lot simpler.
Let me know if you need more help. Like I said, my C# skills aren't much beyond reading it and understanding it, but conceptually, I can probably explain what you need to do.
Good luck.
Bryant
that's possible if you're using cwbx.program cause parameter can be defined as in/out/InOut
in fact i was recently put lots of interest on usage of cwbx to call as/400 API directly from VB, however, my VB is very poor. If you like to look around, please look at www.dd400.com
after some more researches, i found that performance wise, C/C++ API is better compared to activeX automation object.
please see http://publib.boulder.ibm.
I have tried to create a stored procedure but it does not work. Here is the code:
private void button1_Click(object sender, EventArgs e)
{
string ConnString = "Provider=IBMDA400.DataSou
"Data Source=172.30.28.36;" +
"USER ID=DOTNET;" +
"PASSWORD=DOTNET;" +
"DEFAULT COLLECTION =MYLIB;";
OleDbConnection myConnection = new OleDbConnection(ConnString
OleDbCommand myCommand = new OleDbCommand("CALL MYLIB.ACXTEST(?,?)", myConnection);
myCommand.CommandType = CommandType.Text;
//setup the parameters
OleDbParameter myParameter = new OleDbParameter("INPARM", OleDbType.Char, 5);
myParameter.Value = this.txtInput.Text;
myParameter.Direction = ParameterDirection.InputOu
myCommand.Parameters.Add(m
OleDbParameter myParameter2 = new OleDbParameter("OUTPARM", OleDbType.Char, 7);
myParameter2.Value = "String2";
myParameter2.Direction = ParameterDirection.InputOu
myCommand.Parameters.Add(m
try
{
myConnection.Open();
myCommand.ExecuteNonQuery(
this.lblReturn.Text = Convert.ToString(myParamet
myConnection.Close();
}
catch (Exception excv)
{
string ErrorMsg = excv.Message.ToString();
this.lblReturn.Text = "FAILED " + ErrorMsg;
}
}
==========================
HERE IS AS400 CODE:
CREATE PROCEDURE mylib/ACXTEST(INOUT inparm CHAR ( 5), INOUT
outparm CHAR ( 7)) DETERMINISTIC NO SQL EXTERNAL NAME
mylib/ACCTEST PARAMETER STYLE GENERAL
CREATE PROCEDURE statement complete.
==========================
Here is error message
$exception {"SQL0440: Routine ACCTEST in MYLIB not found with specified parameters.\r\nCause . . . . . : A function or procedure with the specified name and compatible arguments was not found. Recovery . . . : Specify the correct number and type of parameters on the CALL statement or function invocation. Try the request again."} System.Exception {System.Data.OleDb.OleDbEx
You can do it the way you did, but parameters can be a hassle. i would recommend you look at using the cwbx.dll that someone else here recommended. Here are some links to articles I wrote discussing how to do this:
http://www.netsplore.com/P
http://www.netsplore.com/P
Business Accounts
Answer for Membership
by: _b_hPosted on 2006-02-10 at 21:55:45ID: 15929385
There is a sample for Host Integration Server on the Microsoft Website that will work for you as well. ownloads/d etails.asp x? FamilyID =145B7A37- 4F44-4093- 9C54-36FAB 9389AC0&di splaylang= en
Essentially, you create a stored procedure on the AS/400 that points to a program and describes its parms.
Then you call the stored procedure in your C# program.
This link contains CL and RPGLE examples, as well as C# code:
http://www.microsoft.com/d
This should get you started
Barry