ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

How to Call a RPG program from .Net

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to Call a RPG program from .Net

    Hi All,
    How to call a RPG program from .Net. Can anyone help me out

    Regards,

    Sajan Gopinath

  • #2
    Re: How to Call a RPG program from .Net

    http://www.aranrock.com/C_sharp_for_...-with-net.html
    Hunting down the future ms. Ex DeadManWalks. *certain restrictions apply

    Comment


    • #3
      Re: How to Call a RPG program from .Net

      Hello

      I have another solution:

      1 - Create a physical file, with a 1000 long one-field record.
      2 - Put a trigger on the file (ADDPFTRG), for Trigger Time *AFTER Trigger Event *INSERT.
      3 - In your trigger program interrogate the 1000 long string for commands and parameters and call whatever programs you want, then delete the record.
      4 - In C#, insert the command into the file using ODBC.

      I like this method, because it saves C# coding; It limits the functions that can be executed; It doesn't need a password as long as ODBC is running. Also I really hate Visual Studio.

      Comment


      • #4
        Re: How to Call a RPG program from .Net

        I think the easiest way to call an RPG-program from whatever environment is to register the RPG program as external stored procedure and call it through the SQL-Command CALL.

        Birgitta

        Comment


        • #5
          Re: How to Call a RPG program from .Net

          That depends. What kinds of interface does the program have? what are it's parms? Are you expecting anything in return from the program? All of these effect the solution you should use.
          "Time passes, but sometimes it beats the <crap> out of you as it goes."

          Comment


          • #6
            How to Call a RPG program from .Net

            Hi,
            here you have the C# Source(1) and the RGP Source(2)
            Best regrads
            Axel Arnold Bangert - Herzogenrath 2011
            __________________________________________________ _____________
            (1)
            using System;
            using System.Collections.Generic;
            using System.Text;
            using cwbx;

            namespace ConsoleApplication1
            {
            class Program
            {
            static void Main(string[] args)
            {
            string result = string.Empty;
            StringConverter stringConverter = new StringConverter();
            AS400System system = new AS400System();
            system.Define("AS400");
            system.UserID = "XXXXXX";
            system.Password = "yyyyyyyyyyy";
            system.IPAddress = "62.176.136.104";
            system.Connect(cwbcoServiceEnum.cwbcoServiceRemote Cmd);
            if (system.IsConnected(cwbcoServiceEnum.cwbcoServiceR emoteCmd) == 1)
            {
            cwbx.Program program = new cwbx.Program();
            program.LibraryName = "XXXXXXX";
            program.ProgramName = "BA2_TE_RPG";
            program.system = system;
            string param = "Beispiel";
            int paramLength = 15;
            ProgramParameters parameters = new ProgramParameters();
            parameters.Append("in", cwbrcParameterTypeEnum.cwbrcInout, paramLength);
            parameters.Append("out", cwbrcParameterTypeEnum.cwbrcInout, paramLength);
            parameters["in"].Value = stringConverter.ToBytes(param.PadRight(paramLength , ' '));
            try
            {
            program.Call(parameters);
            }
            catch (Exception ex)
            {
            if (system.Errors.Count > 0)
            {
            foreach (cwbx.Error error in system.Errors)
            {
            Console.WriteLine("System= " + error.Text);
            Console.WriteLine(ex);
            }
            }
            if (program.Errors.Count > 0)
            {
            foreach (cwbx.Error error in program.Errors)
            {
            Console.WriteLine("Program= " + error.Text);
            }
            }
            }
            result = stringConverter.FromBytes(parameters["in"].Value) + " = " + stringConverter.FromBytes(parameters["out"].Value);
            }
            system.Disconnect(cwbcoServiceEnum.cwbcoServiceAll );
            Console.WriteLine(result);
            Console.ReadKey();
            }
            }
            }
            __________________________________________________ ___________________
            (2)

            Comment


            • #7
              Re: How to Call a RPG program from .Net

              I agree with Birgitta, you probably have the business logic in RPG anyway so try to reuse that with ext stored procs.
              the smoking gnu

              Comment


              • #8
                Re: How to Call a RPG program from .Net

                3 1/2 years on and this site still gives out solutions, you gotta say the community here is committed ...
                ... or maybe it just should be
                Greg Craill: "Life's hard - Get a helmet !!"

                Comment

                Working...
                X