Using ilsmartlinkage in a project with multiple cbl files.

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.

 

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

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

  • Verified Answer

    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);

           }

       }

    }