Pages

Thursday, 4 October 2012

C/AL Data types



C/AL Data Types






Fundamental Data Types

Fundamental data types are designed to store Boolean values, numbers, text, time, and dates.



BigInteger Data Type

The BigInteger data type stores very large whole numbers.

Char Data Type

The char data type stores a single character as a value in the range 0 to 255. This data type can be freely converted between a number and a character. This means that you can use the same mathematical operators as you can with a variable of a numerical data type.
For example, you can assign a constant string of length 1 to a char variable.


C := "A";
You can also assign a single char in a text, code, or binary data type variable to a char variable.


C := S[2]; 

Decimal Data Type

The decimal data type denotes decimal numbers ranging from -10+E63 to +10+E63. The exponent ranges from -63 to +63. Decimal numbers are held in memory with 18 significant digits.

Duration Data Type

The duration data type represents the difference between two datetimes, in milliseconds.

Integer Data Type

The integer data type stores integers between -2,147,483,647 and 2,147,483,647.

Option Data Type

The option data type denotes an option value. Option values can be converted to numeric values. The values range from -2,147,483,647 to 2,147,483,647.
For example, assume that Number is a numeric variable and that Type denotes a field of type Option in the Purchase Header table. In the following statement, the option value is converted to a number.

Number := "Purchase Header".Type;
In another example, the following code shows how the possible values of an option field can be used as constants.

"Purchase Header".Type := "Purchase Header".Type::Invoice;

Code Data Type

The code data type denotes a special type of text string. When a given text is assigned to a variable of data type code, the text is changed to uppercase, and any leading and trailing spaces are removed. You can index any character position in a string, for example, A[65]. The resulting values will be of the char data type. The maximum length of a variable of data type code ranges from 1 to 250 characters. The length of a variable of data type code always corresponds to the number of characters in the text without leading and trailing spaces.
The following table shows some typical examples of code string assignments. In the following examples, it is assumed that the variable c is of data type code, and has a maximum length of 4.
Assignment Variable c contains Length
c := 'AbC'; 'ABC' 3
c := '1'; '1' 1
c := ''; '' (empty string) 0 (zero)
c := '2'; '2' 1
c := '1 2'; '1 2' 3

Text Data Type

The text data type denotes a text string. The length of the string ranges from 1 to 1024 characters. You can index any character position in a string, for example A[65] refers to the 65th character in the variable called A. The resulting values will be of data type char. The length of a variable of data type text corresponds to the number of characters in the text. For example, an empty text string has length 0.
The following table shows some typical examples of text strings. In these examples, it is assumed that the variable t is of data type text and has a maximum length of 6.
Assignment Result
t := 'AbC' The variable t now contains "AbC"
t := '123456abx'; Gives a runtime error because the length (9) exceeds the maximum length (6)
Note
When you use the text and code data types, it is important to distinguish between the maximum length of the string and the actual length of the string. The maximum length is the upper limit for the number of characters in the string. The actual length describes the number of characters used in the string.

Boolean Data Type

The possible values of Boolean data types are TRUE or FALSE.

Date Data Type

The date data type denotes dates ranging from January 3, 0001 to December 31, 9999. An undefined date is expressed as 0D. All dates have a corresponding closing date. The closing date for a given date is regarded as a period following the given date but before the next normal date. A closing date is therefore sorted immediately after the corresponding normal date but before the next normal date.

DateTime Data Type

The datetime data type denotes a date and the time of day. The datetime is stored in the database as Coordinated Universal Time (UTC). UTC is the international time standard (formerly Greenwich Mean Time, or GMT). Zero hours UTC is midnight at 0 degrees longitude. The datetime is always displayed as local time in Microsoft Dynamics NAV. Local time is determined by the time zone regional settings used by your computer. You must always enter datetimes as local time. When you enter a datetime as local time, it is converted to UTC using the current settings for the time zone and daylight saving time.
There is only one constant available when you use this data type: undefined datetime, which is expressed as 0DT.
The range of a datetime depends on whether you are using the Microsoft Dynamics NAV Classic Database Server, or SQL Server.
  • Classic Database Server
    The earliest permitted datetime is January 3, 0001, 00:00:00.000.
    The latest permitted datetime is December 31, 9999, 23:59:59.999.
  • SQL Server
    The earliest permitted datetime is January 1, 1754, 00:00:00.000.
    The latest permitted datetime is December 31, 9999, 23:59:59.999.
    Any datetimes that are not within this range and that you try to enter or construct by, for example, adding a datetime to a duration, are regarded as undefined datetimes and give an error message.
    Undefined dates are stored as January 1, 1753, 00:00:00.000.

 

Time Data Type

The time data type denotes a time ranging from 00:00:00 to 23:59:59.999. An undefined time is expressed as 0T.

Descriptive Data Types

The following tables shows the relationship between the descriptive data types and the simple C/AL data types.
Descriptive data type Included system data types
Numeric
  • Char
  • Integer
  • BigInteger
  • Duration
  • Option
  • Decimal
String
  • Text
  • Code

Complex Data Types

Complex data types are used when you need to work with, for example, records in tables, pictures (bitmaps), or disk files. C/AL is object oriented so each complex data type can include both member variables and member functions.

Automation Data Type

Use the Automation data type to reference an automation server. In order to use an automation server in C/SIDE, define a variable of type Automation and give it a name. Next, click the AssistButton in the Subtype field. In the Automation Object List form that opens, use the AssistButton in the Automation Server field to get a list of available automation servers. Select a server and then click OK. When the lookup form closes, the table part of the Automation Object List form is filled in with the interfaces of the selected automation server. Select an interface and then click OK.
This procedure has selected the GUID of the automation server, the version number, and the GUID of the interface. It is immediately evaluated into a name such as <name of server>.<name of interface>, as in the following:

'Microsoft Excel X.0 Object Library'.Application

BigText Data Type

The BigText data type contains large text documents. Data of the BigText data type cannot be displayed in the debugger or in a message window. However, you can use the BigText functions to extract part of a big text and place it in a normal text string that can be displayed.
The maximum length of a BigText variable is 2147483647 characters. This is the equivalent of 2 gigabytes (GB).

BLOB Data Type

A BLOB is a Binary Large Object. Variables of this data type differ from normal numeric and string data type variables in that they have a variable length. BLOBs are used to store memos (text), bitmaps (pictures), or user-defined types. The maximum size of a BLOB is often determined by your system’s disk storage capacity. The upper limit is 2GB.

Codeunit Data Type

The codeunit data type stores codeunits. A codeunit can contain a number of user-defined functions.

DateFormula Data Type

The DateFormula data type contains a date formula that has the same capabilities as an ordinary input string for the CALCDATE function. The DateFormula data type is used to provide multilanguage capabilities to the CALCDATE function.

Dialog Data Type

The dialog data type stores dialog windows. A number of functions are available for manipulating dialogs.

File Data Type

The file data type provides access to operating system files.

FieldRef Data Type

The fieldref data type identifies a field in a table and gives you access to this field. The fieldref object can refer to any field in any table in the database.

Form Data Type

The form data type stores forms. This data type can contain a number of simpler elements called controls. Controls are used to display information to the user or to receive user input.

GUID Data Type

The GUID data type gives a unique identifying number to any database object.
The GUID data type is a 16-byte binary data type. This data type is used for the global identification of objects, programs, records, and so on. The most important property of a GUID is that each value is globally unique. The value is generated by an algorithm, developed by Microsoft, which assures this uniqueness.
The GUID is a 16-byte binary data type and can be logically grouped into the following subgroups: 4byte-2byte-2byte-2byte-6byte. The standard text representation is {12345678-1234-1234-1234-1234567890AB}.

InStream and OutStream Data Types

The InStream and OutStream data types enable you to read from or write to files and BLOBs. In addition, you can use InStream and OutStream to read from and write to objects of the Automation and OCX data types.

KeyRef Data Type

The keyref data type identifies a key in a table and the fields in this key. This gives you access to the key and the fields it contains. The keyref object can refer to any key in any table in the database.

OCX Data Type

Used to reference a custom control (OCX, ActiveX Control).

Record Data Type

The record data type consists of a number of simpler elements called fields. A record corresponds to a row in a table. Each field in the record is used to store values of a certain data type. The fields are accessed using the variable name of the record (often the same as the name of the corresponding table), a dot (a period), and the field name. A record is typically used to hold information about a fixed number of properties.

RecordID Data Type

The RecordID data type contains the table number and the primary key of a table. You can store a RecordID in the database but you cannot set filters on a RecordID.

RecordRef Data Type

The RecordRef data type identifies a row in a table. Each record consists of fields, which form the columns of the table. A record is typically used to hold information about a fixed number of properties.
The RecordRef object can refer to any table in the database. Use the RecordRef.OPEN function to select the table you want to access. When you use the RecordRef.OPEN function, a new object is created. This object contains references to the open table, filters, the record itself, and all the fields it contains.
If one RecordRef variable is assigned to another RecordRef variable, they both refer to the same table instance.

Report Data Type

The report data type stores reports. It can contain a number of simpler elements called controls. Controls are used to display information to the user.

TableFilter Data Type

The TableFilter data type applies a filter to another table. This data type can only be used when you are setting security filters from the Permission table.

Variant Data Type

The variant data type can contain the following C/AL data types:
  • Record
  • File
  • Action
  • Codeunit
  • Automation
  • Boolean
  • Option
  • Integer
  • Decimal
  • Char
  • Text
  • Code
  • Date
  • Time
  • Binary
  • DateFormula
  • TransactionType
  • InStream
  • OutStream.






                                                                                                                                                                                  

2 comments: