RPGIV @ Work

A unique site for RPG and System i Lovers

Welcome!

Hi, this site will provide all what you need in System i and RPG developments.

My Name is Chamara Withanachchi, System i Expert and RPG Developer. And in the field for last 11 years.

I hope you will find lot of valuable information from this site

How to call a RPG program from .NET Print E-mail
User Rating: / 0
PoorBest 
Written by Chamara Withanachchi   
{mosimage}

Some times you may want to call RPG programs from your .NET applications. We do this most of the times so we can keep our core business logic in lovely RPG and give a nice looking user interface to users.

 

Following are the steps to do this:

  • Create your RPG program in this example my sample program name is USRLOGIN and I’m going to compile it in QGPL
  • Create a Procedure; following is the steps to create a procedure
    • STRSQL
      • In SQL type following
 CREATE  PROCEDURE IDOTST1/USRLOGIN(IN iUser CHARACTER (10 ), IN
 iPassword  CHARACTER (10 ), OUT iErrCode CHARACTER (1 ), OUT   
 iErrDesc  CHARACTER (50 )) LANGUAGE RPGLE DETERMINISTIC NO SQL
 EXTERNAL NAME  IDOTST1/USRLOGIN PARAMETER STYLE GENERAL 
  • Define an ODBC connection (DSN) use iSeries Access ODBC Driver for this.
  • Code the bellow sample coding in C#

 

    OdbcCommand cmd = (OdbcCommand)ConnectionTypes.WS.GetCommand();

cmd.CommandType = CommandType.StoredProcedure;

cmd.CommandText = "{CALL QGPL.USRLOGIN(?,?,?,?)}";

OdbcParameter paramUserID = new OdbcParameter("iUser", txtUserLoginId.Text.ToUpper());

paramUserID.Direction = ParameterDirection.Input;

OdbcParameter paramPassword = new OdbcParameter("iPassword ", txtPassword.Text.ToUpper());

paramPassword.Direction = ParameterDirection.Input;

OdbcParameter paramErrFlag = new OdbcParameter("iErrCode", "");

paramErrFlag.Size = 1;

paramErrFlag.Direction = ParameterDirection.InputOutput;

OdbcParameter paramErrDesc = new OdbcParameter("iErrDesc", "");

paramErrDesc.Size = 50;

paramErrDesc.Direction = ParameterDirection.InputOutput;

cmd.Parameters.Add(paramUserID);

cmd.Parameters.Add(paramPassword);

cmd.Parameters.Add(paramErrFlag);

cmd.Parameters.Add(paramErrDesc);

cmd.ExecuteScalar();

  • Compile and run your C# coding
<Previous   Next>