Error: A static file cannot reference instance items occurs on file defined in an ASP.NET application

0 Likes
over 7 years ago

Problem:

Customer is trying to define an ISAM file within a class program within an ASP.NET Web Application.
The compiler is flagging an error that points to the file status data-item that is defined in the select clause.

The error is as follows:

COBCH1268 : A static file cannot reference instance items …\Default.aspx.cbl

The program is shown below:

       class-id mywebsite_Default is partial   
              inherits type System.Web.UI.Page public.
       input-output section.
       file-control.
            select test-file assign to "C:\TEST.DAT"
                                   organization is indexed
                                    access is dynamic
                                    record key is test-refno
                                    file status is FS.
       data division.
       file section.
       fd test-file is external.
       01 test-record.
          03 test-refno            pic 9(8).
          03 test-name            pic x(20).
       working-storage section.
       77 FS                         pic x(2).   
       method-id Page_Load protected.
       local-storage section.
       procedure division using by value sender as object by value e as type EventArgs.

          goback.         

       end method.
       end class.

Resolution:

This error occurs because you have your file defined as EXTERNAL in your FD.

When you define a file as external then the compiler will automatically generate the file as being static so that it is accessible to all instances of the class.

This means that the file status data item defined for the file needs to also be defined as static.

You can do this as follows:

77 FS   PIC X(2) STATIC.

The alternative would be to remove the external clause from the file description and then the file would belong to the instance and not to the class and you would not have to define the file status as static.

Comment List
Anonymous
Related Discussions
Recommended