Highlighted
Absent Member.
Absent Member.
1721 views

Call win forms from native cobol program with copy books

Jump to solution

Hi,

I am new to visual cobol and 3 yrs exp to Visual Studio.

We have requirement where we need to design a win forms using VS and write a cobol program which will call these win forms. We will set some values in copy book from the cobol program and pass that copy book to win forms for displaying data to user.

The Cobol Program is the entry point which will invoke win forms based on certain condition.

The cobol program should be of native project type and win forms should be of manged type.

I did some googling and was able to call win forms but when I add copy books as parameter to a method I am not able to make a call. I am getting error  saying "The parameter name is incorrect".

I have added a sample project file of my work.

0 Likes
1 Solution

Accepted Solutions
Highlighted
Micro Focus Expert
Micro Focus Expert

RE: Call win forms from native cobol program with copy books

Jump to solution

Hi,

When passing parameters from native code to managed code COBOL you cannot directly use a COBOL group item in the linkage section. You can instead define the group item as a string and then set the group item to this string.

I have fixed your two programs so that they now work.

Calling native program:

      $set ooctrl(+p) 
       identification division.
       program-id. Program1.
       class-control.
           objClass is class "$ole$WinForms.CallingClass".
       configuration section.

       data division.
       working-storage section.
        01 objInstance object reference.
           COPY "NAME.CPB".
      
       procedure division.
           invoke objClass "new" returning objInstance
           invoke objInstance "openForm1" using "Form 1 opened"
           invoke objInstance "openForm2" using "Form 2 opened"
           move "Hello" to name-test
           move "world" to details
           invoke objInstance "openForm3" using WW-TEST-RECORD
           
           goback.

       end program Program1.



Called managed class:

       class-id WinForms.CallingClass.

       working-storage section.
       01 objForm type System.Windows.Forms.Form.
       method-id InstanceMethod.
       local-storage section.
       procedure division.

           goback.
       end method.
       method-id openForm1.
       procedure division using frmTitle as string.
           set objForm to new type WinForms.Form1
           set objForm::Text to frmTitle
           invoke objForm::ShowDialog()
           goback.
       end method.
       method-id openForm2 public.       
       procedure division using frmTitle as string.
           set objForm to new type WinForms.Form2
           set objForm::Text to frmTitle
           invoke objForm::ShowDialog()
           goback.
       end method.    
       
       method-id openForm3.  
        copy "NAME.CPB".     
       procedure division using astring as string.
           set WW-TEST-RECORD to astring
           set objForm to new type WinForms.Form2
           set objForm::Text to WW-TEST-RECORD
           invoke objForm::ShowDialog()
           goback.
       end method.
         end class.

View solution in original post

0 Likes
2 Replies
Highlighted
Micro Focus Expert
Micro Focus Expert

RE: Call win forms from native cobol program with copy books

Jump to solution

Hi,

When passing parameters from native code to managed code COBOL you cannot directly use a COBOL group item in the linkage section. You can instead define the group item as a string and then set the group item to this string.

I have fixed your two programs so that they now work.

Calling native program:

      $set ooctrl(+p) 
       identification division.
       program-id. Program1.
       class-control.
           objClass is class "$ole$WinForms.CallingClass".
       configuration section.

       data division.
       working-storage section.
        01 objInstance object reference.
           COPY "NAME.CPB".
      
       procedure division.
           invoke objClass "new" returning objInstance
           invoke objInstance "openForm1" using "Form 1 opened"
           invoke objInstance "openForm2" using "Form 2 opened"
           move "Hello" to name-test
           move "world" to details
           invoke objInstance "openForm3" using WW-TEST-RECORD
           
           goback.

       end program Program1.



Called managed class:

       class-id WinForms.CallingClass.

       working-storage section.
       01 objForm type System.Windows.Forms.Form.
       method-id InstanceMethod.
       local-storage section.
       procedure division.

           goback.
       end method.
       method-id openForm1.
       procedure division using frmTitle as string.
           set objForm to new type WinForms.Form1
           set objForm::Text to frmTitle
           invoke objForm::ShowDialog()
           goback.
       end method.
       method-id openForm2 public.       
       procedure division using frmTitle as string.
           set objForm to new type WinForms.Form2
           set objForm::Text to frmTitle
           invoke objForm::ShowDialog()
           goback.
       end method.    
       
       method-id openForm3.  
        copy "NAME.CPB".     
       procedure division using astring as string.
           set WW-TEST-RECORD to astring
           set objForm to new type WinForms.Form2
           set objForm::Text to WW-TEST-RECORD
           invoke objForm::ShowDialog()
           goback.
       end method.
         end class.

View solution in original post

0 Likes
Highlighted
Absent Member.
Absent Member.

RE: Call win forms from native cobol program with copy books

Jump to solution

Thanks it helped a lot

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.