The following is a more detailed overview of the changes in the syntax with examples:
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". |
The construct of class-id, method-id, enum-id, delegate-id, interface-id, valuetype-id has been improved as follows:
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. |
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. |
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. |
These are the changes for CUSTOM-ATTRIBUTE and class-attributes: