{"title":"Code data type","url":"https://jonas-paprotka.de/docs/dev-itpro/developer/methods-auto/code/code-data-type/","by":"JOP-AL","license":"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.","credit":"Microsoft Corporation, CC BY 4.0","origin":"https://learn.microsoft.com/en-us/dynamics365/business-central/dev-itpro/developer/methods-auto/code/code-data-type","source":{"name":"Business Central developer and IT pro docs","repo":"https://github.com/MicrosoftDocs/dynamics365smb-devitpro-pb","commit":"828b6ee72fcd75755627cd6011f3d20899217ab2","date":"2026-11-19"},"checked":"2026-11-19","description":"Denotes a special type of string that is converted to uppercase and removes any trailing or leading spaces.","date":"2026-10-01","meta":{"topic":"reference"},"outline":[{"level":2,"title":"Remarks","slug":"remarks","at":168,"chars":827},{"level":2,"title":"Example","slug":"example","at":995,"chars":563},{"level":2,"title":"Related information","slug":"related-information","at":1558,"chars":117}],"text":"> Version: _Available or changed with runtime version 1.0._\nDenotes a special type of string that is converted to uppercase and removes any trailing or leading spaces.\n## Remarks\nThe length of a Code variable equals the number of characters in the text without leading or trailing spaces.\nYou 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.\nYou 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.\nFields 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.\n## Example\nThis 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.\n```al\nc := 'ABC';\n// Results in variable c, which contains 'ABC'\n// and is 3 characters in length.\nc := '1';\n// Results in variable c, which contains '1'\n// and is 1 character in length.\nc := '';\n// Results in variable c, which contains '' (empty string)\n// and is zero (0) characters in length.\nc := ' 2 ';\n// Results in variable c, which contains '2'\n// and is 1 character in length.\n```\n## Related information\nGet Started with AL<../../devenv-get-started>\nDeveloping Extensions<../../devenv-dev-overview>"}