Passing data between C# and COBOL

[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
  • .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.


  • 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.
  • Verified Answer

    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.