Highlighted
Absent Member.
Absent Member.
2291 views

Allowing 'sub forms' to see Working Storage of 'Main form'?

Jump to solution

I have a VisCobol solution (SOL1) containing a main program (MP1) (+form) and another 'sub' program (+form) (SP1) which is contained within the SOL1 structure.

MP1 opens various files etc and has the majority of the working-storage contained therein.

On a 'call out' to SP1 I want SP1 to be able to 'see' file data and working storage variables already populated by MP1. Is there a way of doing this or must I continually pass linkage around between MP1 and SP1?

SP1 would be a form which contains a list box showing employee data but the file is already open as part of MP1 code.

0 Likes
1 Solution

Accepted Solutions
Highlighted
Micro Focus Expert
Micro Focus Expert

RE: Allowing 'sub forms' to see Working Storage of 'Main form'?

Jump to solution

I am attaching an example of how external data may be used to share data between programs.

Form1 and Form2 both have defined in working-storage a data record defined as:

  01 company-record   external.
         05 contact       pic x(30).
         05 company    pic x(30).
         05 phone         pic x(20).

Because it is defined as external in both programs it actually refers to the same data item so changes made to the data in one program are automatically reflected in the other.

There are other ways of sharing data between programs such as creating a class containing properties defined with the static attribute. Then all programs can access this property data by using the class-name::property-name syntax.

This example shows how to use external.

Form1:

      class-id shareData.Form1 is partial
                inherits type System.Windows.Forms.Form.
      working-storage section.
      01 company-record   external.
         05 contact       pic x(30).
         05 company     pic x(30).
         05 phone         pic x(20).
      01 subform  type shareData.Form2.
      method-id NEW.
      procedure division.
          invoke self::InitializeComponent
          goback.
      end method.
      method-id button1_Click final private.
      procedure division using by value sender as object e as type System.EventArgs.
          set contact to txtContact::Text
          set company to txtCompany::Text
          set phone to txtPhone::Text
          set subform to new shareData.Form2
          invoke subform::ShowDialog
       *> To redisplay any changes made to data.  
          set txtContact::Text to contact
          set txtCompany::Text to company
          set txtPhone::Text to phone
      end method.
      end class.

Form2:

      class-id shareData.Form2 is partial
                inherits type System.Windows.Forms.Form.
      working-storage section.
      01 company-record   external.
         05 contact       pic x(30).
         05 company    pic x(30).
         05 phone         pic x(20).
      method-id NEW.
      procedure division.
          invoke self::InitializeComponent()
          set txtContact::Text to contact
          set txtCompany::Text to company
          set txtPhone::Text to phone
          goback.
      end method.
      method-id button1_Click final private.
      procedure division using by value sender as object e as type System.EventArgs.
          set contact to txtContact::Text
          set company to txtCompany::Text
          set phone to txtPhone::Text
          invoke self::Close
      end method.
      end class.

View solution in original post

0 Likes
3 Replies
Highlighted
Knowledge Partner
Knowledge Partner

RE: Allowing 'sub forms' to see Working Storage of 'Main form'?

Jump to solution

Have you considered using EXTERNAL?


Tom Morrison
Consultant

0 Likes
Highlighted
Absent Member.
Absent Member.

RE: Allowing 'sub forms' to see Working Storage of 'Main form'?

Jump to solution

Apologies...been on hols...could you give me a coding example please?

0 Likes
Highlighted
Micro Focus Expert
Micro Focus Expert

RE: Allowing 'sub forms' to see Working Storage of 'Main form'?

Jump to solution

I am attaching an example of how external data may be used to share data between programs.

Form1 and Form2 both have defined in working-storage a data record defined as:

  01 company-record   external.
         05 contact       pic x(30).
         05 company    pic x(30).
         05 phone         pic x(20).

Because it is defined as external in both programs it actually refers to the same data item so changes made to the data in one program are automatically reflected in the other.

There are other ways of sharing data between programs such as creating a class containing properties defined with the static attribute. Then all programs can access this property data by using the class-name::property-name syntax.

This example shows how to use external.

Form1:

      class-id shareData.Form1 is partial
                inherits type System.Windows.Forms.Form.
      working-storage section.
      01 company-record   external.
         05 contact       pic x(30).
         05 company     pic x(30).
         05 phone         pic x(20).
      01 subform  type shareData.Form2.
      method-id NEW.
      procedure division.
          invoke self::InitializeComponent
          goback.
      end method.
      method-id button1_Click final private.
      procedure division using by value sender as object e as type System.EventArgs.
          set contact to txtContact::Text
          set company to txtCompany::Text
          set phone to txtPhone::Text
          set subform to new shareData.Form2
          invoke subform::ShowDialog
       *> To redisplay any changes made to data.  
          set txtContact::Text to contact
          set txtCompany::Text to company
          set txtPhone::Text to phone
      end method.
      end class.

Form2:

      class-id shareData.Form2 is partial
                inherits type System.Windows.Forms.Form.
      working-storage section.
      01 company-record   external.
         05 contact       pic x(30).
         05 company    pic x(30).
         05 phone         pic x(20).
      method-id NEW.
      procedure division.
          invoke self::InitializeComponent()
          set txtContact::Text to contact
          set txtCompany::Text to company
          set txtPhone::Text to phone
          goback.
      end method.
      method-id button1_Click final private.
      procedure division using by value sender as object e as type System.EventArgs.
          set contact to txtContact::Text
          set company to txtCompany::Text
          set phone to txtPhone::Text
          invoke self::Close
      end method.
      end class.

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.