Properties in Visual COBOL

[Migrated content. Thread originally posted on 12 December 2011]

Hello,

I want to implement a property, like this one:
        public SortOrder Order
        {
            set
            {
                OrderOfSort = value;
            }
            get
            {
                return OrderOfSort;
            }
        }

Then, I need to reference it in this manner:
        private SortOrder OrderOfSort;

            OrderOfSort = SortOrder.None;

I am not sure if it will work like expected:
       01 _orderOfSort      binary-long.

       method-id set property #orderOfSort.
       procedure division using by value val as binary-long.
           set _orderOfSort to val.
       end method.
     
       method-id get property #orderOfSort.
       procedure division returning ret as binary-long.
           set ret to _orderOfSort.
       end method.

I will appreciate some help, thank you.
  • Perhaps doing anything like this:
           class-id MngVirtualListView.SortOrder.
           
           working-storage section.
           01 _orderOfSort      binary-long.

           method-id set property #orderOfSort.
           procedure division using by value val as binary-long.
               set _orderOfSort to val.
           end method.
         
           method-id get property #orderOfSort.
           procedure division returning ret as binary-long.
               set ret to _orderOfSort.
           end method.

           end class.

    Then having defined the variable as follows:
           01 orderOfSort       type SortOrder.

    I am on it.
  • Verified Answer

    The code above should work.

    For properties where you just want to expose an underlying member, you can also just use:

    01 _orderOfSort  binary-long property as "orderOfSort".

    The compiler automatically generates the property getter and setter. This works for traditional COBOL data types and even groups.
    You also only need the # to distinguish from COBOL reserved words.
    Look out for some even neater property syntax coming in the next release.
    RBEVENTZIP.zip
  • You don't say!

    Do you mean that all will be easier in a near future? And what about my headache?

    Funny. Thanks.