Field and variable naming

In general, the rules for naming fields (data elements in a table) and variables (data elements within the working storage of an object) are the same, and we will discuss them on that basis. The Developer and IT Pro Help section in Naming Conventions describes many recommended best practices for naming within NAV. Much additional information can also be found in the recently released C/AL Coding Guidelines at https://community.dynamics.com/nav/w/designpatterns/156.cal-coding-guidelines, including a How do I video.

Variables in NAV can either be global (with a scope across the breadth of an object) or local (with a scope only within a single function). Variable names should be unique within the sphere of their scope.

Uniqueness includes not duplicating reserved words or system variables. Refer to the C/AL Reserved Words list in the Developer and IT Pro Help section.

Avoid using any word as a variable name that appears as an uppercase or capitalized word in either the Developer and IT Pro Help section or any of the published NAV technical documentation. For example, we shouldn't use the words page or image as variable names.

Variable names in NAV are not case sensitive. There is a 128-character length limit on variable names (but still a 30-character length limit on field names in tables). Variable names can contain all ASCII characters except for control characters (ASCII values 0 to 31 and 255) and the double quote (ASCII value 34), as well as some Unicode characters used in languages other than English. Characters outside the standard ASCII set (0-127) may display differently on different systems.

Note that the compiler won't tell us that an asterisk (*, ASCII value 42) or question mark (?, ASCII value 63) cannot be used in a variable name. However, because both the asterisk and the question mark can be used as wildcards in many expressions, especially filtering, neither one should be used in a variable name.

The first character of a variable name must be a letter A to Z (uppercase or lowercase), or an underscore (_, ASCII value 95) - unless the variable name is enclosed in double quotes when it is referenced in code (and such names should be avoided). Alphabets other than the 26-character English alphabet may interpret the ASCII values to characters other than A to Z, and may include more than 26 characters. A variable name's first character can be followed by any combination of the legal characters.

If we use any characters other than the A-Z alphabet, numerals, and underscores, we must surround our variable name with double quotes each time we use it in C/AL code (for example, Cust List, which contains an embedded space, or No, which contains a period).

When we create a variable with a complex data type such as Record, Report, Codeunit, Page, XMLport, Query, or Testpage, and do not supply a name, the variable name will be automatically generated according to C/AL Coding Guidelines by the Development Environment.

See Naming Conventions in the Developer and IT Pro Help section for additional C/AL variable naming guidance.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset