static method

I am working with winforms and in the file section I have a file that needs to be accessed from a static method.  I get the following error message on fields that are associated with that file...error code COBCH0969, Cannot access object data from a static method or field.    In order to fix these compile errors I put the keyword static on the FD of the file.  When I run the program in this way I get a runtime error of NullRefernceException -- object reference not set to an instance of an object. 

Now I realize that I could make the method as public and my problems would go away, but I really don't want to have to do this.  How can I resolve this issue?  Thanks

Tags:

Parents
  • Below is the code.  I just thought of something.  I was a little misleading because this is a class was added as a new item to a project that is using winforms.  I wouldn't think that would make much of a difference though.

    The exception happens when I try and open the return-file. 

    The compile errors occur when I remove the keyword static from the FD.  Thanks for your help.

          $set sourceformat(free)

          class-id BeneScreens.beneMethods.

          Environment division.

              select return-file

                  assign       to "c:\temp\returnfilebene.wrk"

                  organization is line sequential.

          file section.

          fd  return-file static.

          01  return-rec.

              05  rr-pid-number              pic  x(06).

              05  rr-button                  pic  x(10).

          working-storage section.

          method-id InstanceMethod.

          local-storage section.

          procedure division.

              goback.

          end method.

          method-id goToPid public static.

          local-storage section.

              open input return-file. 

              read return-file

              if rr-button = "cancel"            

                  set fromPidNum                     to goToPidPidNum

              else

                  if rr-button = "ok"

                      set fromPidNum                 to rr-pid-number.

              close return-file.

          end method.

          end class. 

Reply
  • Below is the code.  I just thought of something.  I was a little misleading because this is a class was added as a new item to a project that is using winforms.  I wouldn't think that would make much of a difference though.

    The exception happens when I try and open the return-file. 

    The compile errors occur when I remove the keyword static from the FD.  Thanks for your help.

          $set sourceformat(free)

          class-id BeneScreens.beneMethods.

          Environment division.

              select return-file

                  assign       to "c:\temp\returnfilebene.wrk"

                  organization is line sequential.

          file section.

          fd  return-file static.

          01  return-rec.

              05  rr-pid-number              pic  x(06).

              05  rr-button                  pic  x(10).

          working-storage section.

          method-id InstanceMethod.

          local-storage section.

          procedure division.

              goback.

          end method.

          method-id goToPid public static.

          local-storage section.

              open input return-file. 

              read return-file

              if rr-button = "cancel"            

                  set fromPidNum                     to goToPidPidNum

              else

                  if rr-button = "ok"

                      set fromPidNum                 to rr-pid-number.

              close return-file.

          end method.

          end class. 

Children
No Data