Highlighted
Absent Member.
Absent Member.
1439 views

record layouts

Jump to solution

I would like to be able to use an FD record layout in a derived class.  I don't want any instance of the class to be able to use the fields in the record layout so I have them marked as private.  I would rather use protected.  Can this be done?

below is the code that I am working with.  If I make the private field protected I get the following compile error

Error 2 COBCH0885 : Visibility attributes can only be used with native managed types at 01

select test-file

assign       to "\temp\test.dat"

organization is indexed

access       is dynamic

record key   is test-key

lock mode    is manual

file status  is fileStatus.

      

fd  test-file.

       01 test-rec                           private.

           05  test-key    pic  x(07)          private.

Tags (1)
0 Likes
1 Solution

Accepted Solutions
Highlighted
Micro Focus Expert
Micro Focus Expert

RE: record layouts

Jump to solution

You can't directly mark groups, or members of groups as anything other than private.  Only fields mapping directly onto managed types (binary-long, string object references) are allowed to have more than private visibility.  However, you can mark fields in the record definition as properties, something like:

     $set sourceformat(free)

class-id a.

select test-file

assign       to "\temp\test.dat"

organization is indexed

access       is dynamic

record key   is test-key

lock mode    is manual.

fd  test-file.

      01 test-rec property protected.

          05  test-key    pic  x(07)        property protected.

end class.

class-id b inherits type a.

method-id m.

  set test-key to "ABCDEFG"

end method.

end class.

In this case, both test-rec and test-key are exposed as string properties, and access to the properties works by expanding the pic x field (or group) to a Unicode string for the get property and vice versa for the set property.  In this example, setting the test-rec property and setting the test-key property will in fact update the same data area in the inherited program.

View solution in original post

0 Likes
4 Replies
Highlighted
Micro Focus Expert
Micro Focus Expert

RE: record layouts

Jump to solution

You can't directly mark groups, or members of groups as anything other than private.  Only fields mapping directly onto managed types (binary-long, string object references) are allowed to have more than private visibility.  However, you can mark fields in the record definition as properties, something like:

     $set sourceformat(free)

class-id a.

select test-file

assign       to "\temp\test.dat"

organization is indexed

access       is dynamic

record key   is test-key

lock mode    is manual.

fd  test-file.

      01 test-rec property protected.

          05  test-key    pic  x(07)        property protected.

end class.

class-id b inherits type a.

method-id m.

  set test-key to "ABCDEFG"

end method.

end class.

In this case, both test-rec and test-key are exposed as string properties, and access to the properties works by expanding the pic x field (or group) to a Unicode string for the get property and vice versa for the set property.  In this example, setting the test-rec property and setting the test-key property will in fact update the same data area in the inherited program.

View solution in original post

0 Likes
Highlighted
Absent Member.
Absent Member.

RE: record layouts

Jump to solution

This seems to be working for me.  Thanks a bunch.

0 Likes
Highlighted
Absent Member.
Absent Member.

RE: record layouts

Jump to solution

Do you know if there is a way to access the test-file in the derived class?

0 Likes
Highlighted
Micro Focus Expert
Micro Focus Expert

RE: record layouts

Jump to solution

I'm afraid we don't have any way of doing this at the moment.

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.