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

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.

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

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

  • Verified Answer

    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.

    shareData.zip