Highlighted
Absent Member.
Absent Member.
2125 views

Passing data between C# and COBOL

Jump to solution

[Migrated content. Thread originally posted on 25 November 2011]

Hello,

I have found information about how to pass data between C and COBOL, but nothing about C#.

Have you got any file regarding the conversion with C# (like cbltypes.h for C)?

Thanks
0 Likes
1 Solution

Accepted Solutions
Highlighted
Micro Focus Expert
Micro Focus Expert

RE: Passing data between C# and COBOL

Jump to solution
Sorry but the SmartLinkage directive is only available for managed programs.

In the case where you would like C# to call a native COBOL program you would need to use Platform Invoke from the C# in order to call the native program directly.

An alternative approach (and the recommended way) is to have C# call a managed COBOL wrapper program that will call the native COBOL program. When the native program returns to the COBOL wrapper it can convert the parameters back to .NET format and return them to C#.

You could then use SmartLinkage on the managed COBOL wrapper so that C# could access the parameters as .NET types.

View solution in original post

0 Likes
3 Replies
Highlighted
Micro Focus Expert
Micro Focus Expert

RE: Passing data between C# and COBOL

Jump to solution
.NET types can be shared between C# and COBOL.

See the following for a comparison of native types and COBOL data types:

COBOL/.NET Type Compatibility Chart

Also in Visual COBOL R4 the SmartLinkage option was introduced that lets you exposed COBOL group types to C# as native .NET types.

There is a sample program which demonstrates how this works.

On the start menu under Visual COBOL is an entry called Visual COBOL Samples. One of these samples shows you how to use the SmartLinkage feature. It is called C# WinBook.

Take a look at this sample as it will show you how parameters can be passed between the two languages.


0 Likes
Highlighted
Absent Member.
Absent Member.

RE: Passing data between C# and COBOL

Jump to solution
Hi,

I am trying to follow your example. But I am not able to create a reference to my native project (see image).

Maybe this linkage does not work with native COBOL, does this?

Based on this supposition, I am building a "bridge" between the C# program and the native COBOL program. That's it: a managed program that does nothing but provides the parameters to the native COBOL app.
0 Likes
Highlighted
Micro Focus Expert
Micro Focus Expert

RE: Passing data between C# and COBOL

Jump to solution
Sorry but the SmartLinkage directive is only available for managed programs.

In the case where you would like C# to call a native COBOL program you would need to use Platform Invoke from the C# in order to call the native program directly.

An alternative approach (and the recommended way) is to have C# call a managed COBOL wrapper program that will call the native COBOL program. When the native program returns to the COBOL wrapper it can convert the parameters back to .NET format and return them to C#.

You could then use SmartLinkage on the managed COBOL wrapper so that C# could access the parameters as .NET types.

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.