Calling Managed OO COBOL from C#

Hi,

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

 

Best Regards

  • Verified Answer

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

  • 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

  • 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

  • Verified Answer

    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".

  • 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

  • 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

  • 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

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

    Thanks.

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

  • Hello, I am looking for winbook example, it is not in my trial version, is this available to download from this site? Regards Samir