Highlighted
New Member.
2026 views

Using ilsmartlinkage in a project with multiple cbl files.

Jump to solution

I am able to access COBOL copybook variables from C# using the ilsmartlinkage compiler directive as long as there is only one cbl in the referenced project. However, if I add an additional cbl to the referenced project I get a compiler error and have to add an additional compiler directive of ilsmartnest to get it to compile without error. Once I do that I cannot get access to the copybook variables from C#. What am I doing wrong or what do I need to do additionally?

Below is my sample code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SandboxClassC
{
    class Sandbox
    {
        static void Main(string[] args)
        {
            CobolModule01 clientRecLinkage = new CobolModule01();
            ClientRecord clientRec = new ClientRecord();
            clientRec.ClientId = "123456789";
            clientRecLinkage.CobolModule01(clientRec);
        }
    }
}

Assume that I have a Visual COBOL solution with two modules, CobolModule01 and CobolModule02. Also that my copybook contains a 01 level ClientRecord definition with a 05 level ClientId data item.

 

0 Likes
1 Solution

Accepted Solutions
Highlighted
Micro Focus Expert
Micro Focus Expert

RE: Using ilsmartlinkage in a project with multiple cbl files.

Jump to solution

I just tested this again and it works fine when using both ilsmartlinkage and ilsmartnest directives in the project.

When you add ilsmartnest you will have to qualify the client record with the program name as a namespace.

So instead of using:

   ClientRecord clientRec = new ClientRecord();

try

   CobolModule01.ClientRecord clientRec = new CobolModule01.ClientRecord();

My sample looked like:

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using testsmartlink;

namespace ConsoleApplication1

{

   class Program

   {

       static void Main(string[] args)

       {

           Program1 myprogram = new Program1();

           Program1.Clientrecord cr = new Program1.Clientrecord();

           cr.Clientid = "1234";

           cr.Clientname = "fred";

           myprogram.Program1(cr);

           Program2 myprogram2 = new Program2();

           Program2.Clientrecord cr2 = new Program2.Clientrecord();

           cr2.Clientid = "9876";

           cr2.Clientname = "Chris";

           myprogram2.Program2(cr2);

       }

   }

}

View solution in original post

0 Likes
3 Replies
Highlighted
Micro Focus Expert
Micro Focus Expert

RE: Using ilsmartlinkage in a project with multiple cbl files.

Jump to solution

I have been able to reproduce this here.

Do you wish for both of these programs to be called from C# or just the main entry point of module01?

Try moving the smartlinkage directive to the top of Module01 source as:

$set ilsmartlinkage

and removing it from the project properties.

There seems to be a limitation here in that the same linkage section item names can only be referenced by one outer program within a project using the ilsmatylinkage directive.

When you place the directive in the project properties it applies to all of the programs within that project.

0 Likes
Highlighted
New Member.

RE: Using ilsmartlinkage in a project with multiple cbl files.

Jump to solution

Ideally I would like to be able to access and call all programs within the dll even if they have common copybooks in the linkage sections without altering the source code. I know that's asking for a lot and that's why I thought the ilsmartnest might work. Any further suggestions?

0 Likes
Highlighted
Micro Focus Expert
Micro Focus Expert

RE: Using ilsmartlinkage in a project with multiple cbl files.

Jump to solution

I just tested this again and it works fine when using both ilsmartlinkage and ilsmartnest directives in the project.

When you add ilsmartnest you will have to qualify the client record with the program name as a namespace.

So instead of using:

   ClientRecord clientRec = new ClientRecord();

try

   CobolModule01.ClientRecord clientRec = new CobolModule01.ClientRecord();

My sample looked like:

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using testsmartlink;

namespace ConsoleApplication1

{

   class Program

   {

       static void Main(string[] args)

       {

           Program1 myprogram = new Program1();

           Program1.Clientrecord cr = new Program1.Clientrecord();

           cr.Clientid = "1234";

           cr.Clientname = "fred";

           myprogram.Program1(cr);

           Program2 myprogram2 = new Program2();

           Program2.Clientrecord cr2 = new Program2.Clientrecord();

           cr2.Clientid = "9876";

           cr2.Clientname = "Chris";

           myprogram2.Program2(cr2);

       }

   }

}

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.