We are converting microfocus dialog screens into C# screens. we are facing problem like in sub-programs we have function for call dialog screens now we are unable to find the way to call C# screen or code from managed Cobol.
we are accessing the data from C# to Cobol and Cobol to C# by using data blocks but with this approach we are unbale to maintain the state(table variable are getting empty, validations are getting fails) because we are exiting the from the Cobol and transferring the control to C#.
is any way to call C# code from the Cobol. So that we can trigger the screen where ever we required in Cobol.
Calling C# code from managed COBOL is not difficult at all. They are both .NET languages so they can easily call each other by calling their methods.
A very simple example would be: (Add a reference to the COBOL project in the C# project.
$set ilusing"csClass"
program-id. Program1 as "cobmain.cobmain".
data division.
working-storage section.
01 mystring string value "from COBOL".
01 myint binary-long value 1.
01 ret-value binary-long value 0.
procedure division.
display "in cobmain"
declare csClass1 as type Class1 = new Class1
set ret-value = csClass1::csMethod(by reference mystring, myint)
display "ret value = ", ret-value
display mystring
display myint
goback.
end program Program1.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace csClass
{
public class Class1
{
public int csMethod(ref string mystring, ref int myint)
{
Console.WriteLine("in Class1");
Console.WriteLine(mystring);
Console.WriteLine(myint);
mystring = "from C#";
myint = 99;
return (0);
}
}
}