Having problems with your account or logging in?
A lot of changes are happening in the community right now. Some may affect you. READ MORE HERE
Highlighted
Ahmed1 Absent Member.
Absent Member.
4850 views

Calling Managed OO COBOL from C#

Jump to solution

Hi,

In a nutshell, how can I call managed COBOL from C#. Is there any references I need to add or something ??

 

Best Regards

Tags (2)
0 Likes
2 Solutions

Accepted Solutions
Micro Focus Expert
Micro Focus Expert

RE: Calling Managed OO COBOL from C#

Jump to solution

If you are calling a method in a COBOL class from C# then all you need to add is a reference to the COBOL project for the Class library to the C# project.

If you are trying to call a COBOL procedural program from C# then you need to add a reference to the MicroFocus.COBOL.Runtime assembly to the C# project.

Open up the Samples browser in Start-->All Programs-->Micro Focus Visual COBOL-->Samples and look at the program called C# Winbook as this is a good example of how to call a managed COBOL procedural program directly from C# which also uses the ilsmartlinkage directive to expose the COBOL linkage section to C#.

Thanks..

0 Likes
Micro Focus Expert
Micro Focus Expert

RE: Calling Managed OO COBOL from C#

Jump to solution

A hyphen is not a supported character in C# so you cannot have data-names with hyphens.

You can use the ilsmartlinkage directive if this is a procedural COBOL program and it will remove the hyphens from linkage section data items.

From docs:

"Hyphens are removed from data item names and the letter following a removed hyphen is folded to upper case. For example a data item author-name is renamed to AuthorName".

0 Likes
8 Replies
Micro Focus Expert
Micro Focus Expert

RE: Calling Managed OO COBOL from C#

Jump to solution

If you are calling a method in a COBOL class from C# then all you need to add is a reference to the COBOL project for the Class library to the C# project.

If you are trying to call a COBOL procedural program from C# then you need to add a reference to the MicroFocus.COBOL.Runtime assembly to the C# project.

Open up the Samples browser in Start-->All Programs-->Micro Focus Visual COBOL-->Samples and look at the program called C# Winbook as this is a good example of how to call a managed COBOL procedural program directly from C# which also uses the ilsmartlinkage directive to expose the COBOL linkage section to C#.

Thanks..

0 Likes
Ahmed1 Absent Member.
Absent Member.

RE: Calling Managed OO COBOL from C#

Jump to solution

It worked well for me but I have noticed that any hyphened variables or method names are not portable to C# i.e they are not accessible from the auto-complete or manually! Generally it's awesome :)

Thanks

0 Likes
Micro Focus Expert
Micro Focus Expert

RE: Calling Managed OO COBOL from C#

Jump to solution

A hyphen is not a supported character in C# so you cannot have data-names with hyphens.

You can use the ilsmartlinkage directive if this is a procedural COBOL program and it will remove the hyphens from linkage section data items.

From docs:

"Hyphens are removed from data item names and the letter following a removed hyphen is folded to upper case. For example a data item author-name is renamed to AuthorName".

0 Likes
Charan2 Absent Member.
Absent Member.

RE: Calling Managed OO COBOL from C#

Jump to solution

Hi Chris,

ILSMARTLINKAGE does remove hyphen from the Linkage variables. Also it creates the Class for the program (as Program Class), with all the methods/entry points as Methods of the class. It converts all 01 level Linkage data items as Classes too.

For example :  After using the ILSMARTLINKAGE Compiler directive.

1. A new class is created as Program(Same as program name).

2. Convert all procedures to methods in the class fro each entry point( for ex Addition ) is a method now in the Program class.

2. It remove hyphen from the linkage variables and convert it in Upper case. (add-number1 as AddNumber1)

3. It also create 01 level Linkage items as Class Addnumber1 is a class now , we need to create an object of the Addnumber1 class and assign values to it. then use it in invoking the method. (So all the 01 Level Linkgae variables are converted to class variables)

But if in a linkage section there is one variable (at 01 level) which is defined using redefine clause than it won't  be converted into the class as mentioned in step 3.

For ex. 01 Sum  Pic xx redefine add-number1.

Then Sum wont be converted as a class variable, So to use it we have to use AddNumber1 class variable as part of Program class.

So how we can solve this problem.

Hope you are able to understand the problem here.

Thanks

Charan

0 Likes
Micro Focus Expert
Micro Focus Expert

RE: Calling Managed OO COBOL from C#

Jump to solution

Try adding the directive NOILSMARTRESTRICT to the class. The default is set to ILSMARTRESTRICT which suppresses the generation of redefined elementary items.

Thanks.

0 Likes
Micro Focus Expert
Micro Focus Expert

RE: Calling Managed OO COBOL from C#

Jump to solution

Actually, I just tested the NOILSMARTRESTRICT directive and it does not solve the problem as there appears to be a bug. I am creating an RPI for this and Development is currently researching the problem.

Thanks.

0 Likes
Samir1 Absent Member.
Absent Member.

RE: Calling Managed OO COBOL from C#

Jump to solution
Hello, I am looking for winbook example, it is not in my trial version, is this available to download from this site? Regards Samir
0 Likes
Micro Focus Expert
Micro Focus Expert

RE: Calling Managed OO COBOL from C#

Jump to solution
Start a new discussion for a new topic. Don't hijack an existing thread.

When you post your question in a new discussion, tell us what product and version you have installed, and where you looked for the sample.
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.