Highlighted
Absent Member.
Absent Member.
1015 views

C# Variable compatibility with Cobol using Class Type

Jump to solution

Hi , Please help on passing value from C# to Cobol using Class Type project. I have for example a declaration :

01 tmp-rec-date.
   05 date-mm pic x(2).
   05 date-dd pic x(2).
   05 date-yy pic x(4).

 

How can I pass string / structured value from C# to Cobol using that declaration in Cobol. I'm getting "String cannot be converted to Microfocus.COBOL.Program.Reference". What will be the correct type declaration in C#? Please help.

 

 

Regards,

jhayvi

0 Likes
1 Solution

Accepted Solutions
Highlighted
Outstanding Contributor.
Outstanding Contributor.

RE: C# Variable compatibility with Cobol using Class Type

Jump to solution
Try this:

/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>

public partial class MainWindow : Window
{
private CobClass1 cobCl;

public MainWindow()
{
InitializeComponent();

cobCl = new CobClass1();
}

private void PBCall_Click(object sender, RoutedEventArgs e)
{
tdtDateOut.Text = cobCl.ConvertDateString(tdtDateIn.Text);
}
}

class-id ClassCobol.CobClass1.

working-storage section.

01 w-date.
05 date-dd pic xx.
05 date-mm pic xx.
05 date-yy pic xxxx.

method-id ConvertDateString.
local-storage section.
procedure division using by value InputString as string
returning OutputString as string.

set w-date to InputString
set OutputString to date-dd & "." & date-mm & "." & date-yy

goback.
end method.

end class.

If you send me your mail address I can send you the VS solution as ZIP file.

View solution in original post

0 Likes
2 Replies
Highlighted
New Member.

RE: C# Variable compatibility with Cobol using Class Type

Jump to solution
In native COBOL a C# string is a COBOL character array depending how you class library has been build.

So in COBOL you receive an object reference, you then examine the object reference to determine its type, ie Character array, then you can get the value.

Is it for example COM class or more of a native dll where a load library is performed?
How have you defined your COBOL linkage section?

Neil
0 Likes
Highlighted
Outstanding Contributor.
Outstanding Contributor.

RE: C# Variable compatibility with Cobol using Class Type

Jump to solution
Try this:

/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>

public partial class MainWindow : Window
{
private CobClass1 cobCl;

public MainWindow()
{
InitializeComponent();

cobCl = new CobClass1();
}

private void PBCall_Click(object sender, RoutedEventArgs e)
{
tdtDateOut.Text = cobCl.ConvertDateString(tdtDateIn.Text);
}
}

class-id ClassCobol.CobClass1.

working-storage section.

01 w-date.
05 date-dd pic xx.
05 date-mm pic xx.
05 date-yy pic xxxx.

method-id ConvertDateString.
local-storage section.
procedure division using by value InputString as string
returning OutputString as string.

set w-date to InputString
set OutputString to date-dd & "." & date-mm & "." & date-yy

goback.
end method.

end class.

If you send me your mail address I can send you the VS solution as ZIP file.

View solution in original post

0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.