The AL developer preview is still evolving with frequent updates. Follow us on the Dynamics NAV Team Blog for the announcements.

LENGTH Method (FieldRef)

Gets the maximum size of the field (the size specified in the DataLength property of the field). This method is usually used for finding the defined length of code and text fields.


Length := FieldRef.LENGTH  


Type: FieldRef

Refers to the current field.

Return Value

Type: Integer

The defined length of the field.


For Text and Code fields this method returns the defined length. For other types of fields, it returns the fixed byte size, for example, Integer fields returns 4.


The following example opens the Customer table as a RecordRef variable. The FIELD Method (RecordRef) creates a FieldRef for any specified field and stores the reference in the MyFieldRef variable. The LENGTH method retrieves the maximum size of the field and stores the value in the varLength variable. The value that is stored in the varLength is displayed in a message box. This example requires that you create the following global variables and text constant.

Variable name DataType
CustomerRecref RecordRef
MyFieldRef FieldRef
varLength Integer
varFieldNo Integer
Text constant ENU value
Text000 The maximum size of the field is %1.

varFieldNo := 1;  
MyFieldRef := CustomerRecref.FIELD(varFieldNo);  
varLength := MyFieldRef.LENGTH;  
MESSAGE(Text000, varLength);  

See Also

FieldRef Data Type