Highlighted
Absent Member.
Absent Member.
10904 views

static method

Jump to solution

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 (1)
0 Likes
18 Replies
Highlighted
Micro Focus Expert
Micro Focus Expert

What was the version of your previous Visual COBOL product that was installed prior to the upgrade to 2.2?

Was it VC 2.1 or VC 2.1 update 1?

Thanks

0 Likes
Highlighted
Absent Member.
Absent Member.

Chris,

I work with BHunt.  The previous Visual COBOL version was VC 2.1 update 1.

The problem seems to occur when using an ISAM file and a text file in the same class.  See the code below, which will cause the "Object reference not set to an instance of an object" error message.  If the ISAM file was replaced with another text file, the error does NOT occur.  If the ISAM file FD is set to static and the file status is removed from the select statement, then the error still DOES occur.  What changes need to be done to the ISAM file?

      class-id BeneScreens.Class1.

      Environment division.

          select bene-file

              assign       to "\data\bene.dat"

              record key   is bene-key

              organization is Indexed

              access mode  is dynamic

              lock mode    is manual

              file status  is file-status.

          select return-file

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

              organization is line sequential.

      file section.

      fd  bene-file.

      01  bene-rec.

          05  bene-key.

              10  bene-nbr    pic x(07).

          05  bene-relship    pic x(25).

      fd  return-file static.

      01  return-rec.

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

          05  rr-button       pic x(10).

      working-storage section.

      01 file-status          pic x(02) property no set.

      method-id goPid public static.

      procedure division.

          open input return-file.

          read return-file.

          close return-file.

      end method.

      end class.

0 Likes
Highlighted
Micro Focus Expert
Micro Focus Expert

Thanks, I can now reproduce the error although I am getting different results.

I get the error whenever there are two files defined and one is static and the other is not.

If I specify them both as static or both as not static then it will work correctly.

I can reproduce with two sequential files so being an ISAM file has nothing to do with it.

I need to raise an RPI for this as it appears to be a bug.

Can you please open up a support incident for this and place my name in the description so that it will be assigned to me?

Thanks.

0 Likes
Highlighted
Absent Member.
Absent Member.

I just opened up a support incident for this as requested.  Thanks for your help.

0 Likes
Highlighted
Micro Focus Expert
Micro Focus Expert

Thanks, I created a new RPI for this and attached it to your incident.

I also find that the program will work OK if I change the order of the select statements in the program so that the static file is defined first so perhaps this could be a workaround for now?

          select return-file

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

              organization is line sequential.

          select bene-file

              assign       to "\data\bene.dat"

              record key   is bene-key

              organization is Indexed

              access mode  is dynamic

              lock mode    is manual

              file status  is file-status.

      file section.

      fd  return-file static.

      01  return-rec.

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

          05  rr-button       pic x(10).

      fd  bene-file.

      01  bene-rec.

          05  bene-key.

              10  bene-nbr    pic x(07).

          05  bene-relship    pic x(25).

0 Likes
Highlighted
Absent Member.
Absent Member.

Chris,

I changed the order on the files and received the same results as you did.  This will work for us and we will ensure all static methods/files are declared first before any non-static methods/files are.

Thanks for your help.

0 Likes
Highlighted
Micro Focus Expert
Micro Focus Expert

Adding this note for the sahe of completeness:

This has been written up as an RPI and the problem has been fixed for inclusion with Visual COBOL 2.2 update 1.

A workaround for the problem is to declare all of your static files first before the declaration of the instance files.

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.