Previous Topic Next topic Print topic


.NET COBOL Syntax Improvements

Quoteless syntax
Quotes are not needed when defining types, classes or methods, or when invoking classes and methods.
Construct improvements
The structure of class-id, method-id, enum-id, delegate-id, interface-id, valuetype-id has been improved.
Environment division, Configuration section, Repository
The Environment division, Configuration section and the Repository are no longer needed.
Static, Factory and Object blocks
The Static, Factory and Object blocks are no longer needed.
Attributes, Custom-Attribute and Class-Attributes
CUSTOM-ATTRIBUTE is now replaced by the ATTRIBUTES phrase. You no longer need to define class-attributes. Instead, specify the class custom attributes in the class definition.
Tip:
  • Visual COBOL supports the older syntax, so projects that are using it will still compile. However, it is recommended to create applications using the new syntax and adhere to the .NET COBOL Best Practices.
  • It is recommended to use the COBOL project and file templates, snippets and Intellisense as they use the new syntax. To see the new syntax in action, check the Visual COBOL samples.

The following is a more detailed overview of the changes in the syntax with examples:

Quoteless Syntax

Quotes are no longer needed when you define types, classes or methods, or when you invoke classes and methods. For example:

New Syntax Old Syntax
01 o1 type MyClass
01 o1 type "MyClass"
type MyClass::New
type "MyClass"::"New"
set o to new MyClass
set o to new "MyClass"
set class::Property to value
set "class"::"Property" to value
set return-value to class::Method(param1)
set return-value to "class"::"Method"(param1)
invoke class::Method(param1)
invoke "class"::"Method"(param1)
       method-id MyMethod public.
       
       local-storage section.
       
       procedure division.
       
           goback.
       end method.
       method-id. "MyMethod" public.
                local-storage section.
                
                procedure division.
                    goback. 
                end method "MyMethod".

Construct of class-id, method-id, enum-id, delegate-id, interface-id, valuetype-id

The construct of class-id, method-id, enum-id, delegate-id, interface-id, valuetype-id has been improved as follows:

  • You do not have to type a period after the declaration (for example, method-id MethodName).
  • Quotes are no longer required around names.
  • You do not need to use the name in the end marker.
New Syntax Old Syntax
       class-id Namespace.MyClass.
      
       object-storage section.

       method-id InstanceMethod.
       local-storage section.
       procedure division.
           goback.           
       end method.

       method-id StaticMethod public static.
       local-storage section.
       procedure division.
           goback.           
       end method.

       end class.
       class-id. MyClass as "Namespace.MyClass".
       environment division.
       configuration section.
       repository.
      
       static.
       working-storage section.
      
       end static.
      
       object.
       working-storage section.

       method-id. "InstanceMethod".
       local-storage section.
       procedure division.

           goback.           
       end method "InstanceMethod".
      
       end object.
       end class MyClass.

Environment Division, Configuration Section, Repository

You no longer need to use an Environment division, a Configuration section or a Repository paragraph. For example:

New Syntax Old Syntax
       program-id. Program1 as "MyProject.Program1".

       data division.
       working-storage section.
       procedure division.

           goback.
       end program Program1.
       program-id. Program1 as "MyProject.Program1".

       environment division.
       configuration section.
       repository.
       

       data division.
       working-storage section.
       procedure division.

           goback.
       end program Program1.

Static, Factory and Object Blocks

The Static and Object blocks are no longer used. With the new syntax you need only one working-storage section for items that were defined in a static or object block under the old syntax.

To define a static method, use the STATIC word.

The following example shows how to define static methods with the new syntax and how to avoid using an object block:

New Syntax Old Syntax
       class-id Namespace.MyClass.
      
       working-storage section.
       01 my-object-data pic x.
       01 my-static-data pic x static.

       method-id InstanceMethod.
       local-storage section.
       procedure division.
           goback.           
       end method.

       method-id StaticMethod public static.
       local-storage section.
       procedure division.
           goback.           
       end method.

       end class.
       class-id. MyClass as "Namespace.MyClass".
       environment division.
       configuration section.
       repository.
      
       static.
       working-storage section.
         01 my-static-data pic x.
       end static.
      
       object.
       working-storage section.
         01 my-object-data pic x.

       method-id. "InstanceMethod".
       local-storage section.
       procedure division.

           goback.           
       end method "InstanceMethod".
      
       end object.
       end class MyClass.

Attributes, Custom-Attribute and Class-Attributes

These are the changes for CUSTOM-ATTRIBUTE and class-attributes:

  • The CUSTOM-ATTRIBUTE phrase is replaced by the ATTRIBUTE phrase.
  • You no longer have to define class-attributes. Instead, specify the class custom-attributes in the class definition using the ATTRIBUTE phrase.
  • Quotes are no longer needed around the name of the attribute and you can omit the word "Attribute" from the name.

For example:

New Syntax Old Syntax
       class-id MyNamespace.MyClass.          
           attribute Serializable.
       
       working-storage section.
       ...

       end class.
       class-id. MyClass as "MyNamespace.MyClass".
       
       class-attributes.
       custom-attribute is type "SerializableAttribute".
       
       object.
       
       working-storage section.
	      ...
      
       end object.

       end class MyClass.
Previous Topic Next topic Print topic