# Code data type
> Version: _Available or changed with runtime version 1.0._
Denotes a special type of string that is converted to uppercase and removes any trailing or leading spaces.
## Remarks
The length of a Code variable equals the number of characters in the text without leading or trailing spaces.
You must specify the length of a Code variable or field. The maximum length of a Code variable is 1024 characters. The maximum length of a Code field in a table is 2048 characters. A Code variable cannot be null. The Code data type supports Unicode.
You can index any character position in a string, such as A[65]. The resulting value will be a ../char/char-data-type. You cannot assign a char to a position in the code variable greater than the current length of the variable +1.
Fields that contain a date formula must not have data type Code. Instead, use the ../dateformula/dateformula-data-type. All fields that contain a date formula with data type Code must be converted into data type DateFormula.
## Example
This example shows some typical examples of code string assignments. In these examples, assume that the variable c is a code variable with a maximum length of 4.
```al
c := 'ABC';
// Results in variable c, which contains 'ABC'
// and is 3 characters in length.
c := '1';
// Results in variable c, which contains '1'
// and is 1 character in length.
c := '';
// Results in variable c, which contains '' (empty string)
// and is zero (0) characters in length.
c := ' 2 ';
// Results in variable c, which contains '2'
// and is 1 character in length.
```
## Related information
Get Started with AL<../../devenv-get-started>
Developing Extensions<../../devenv-dev-overview>

Copyright (c) Microsoft Corporation. CC BY 4.0, https://creativecommons.org/licenses/by/4.0/; code samples MIT. From https://learn.microsoft.com/en-us/dynamics365/business-central/dev-itpro/developer/methods-auto/code/code-data-type, MicrosoftDocs/dynamics365smb-devitpro-pb at 828b6ee (2026-11-19). Changed: includes filled in, links to this site, and for agents shortened without dropping a fact. https://jonas-paprotka.de/docs/dev-itpro/developer/methods-auto/code/code-data-type/
