GetLength

The GetLength built-in variable method determines the length of a variable. This length includes leading and embedded spaces, but not trailing spaces. The result is also returned in the Glb.Length and Glb.FullLength built-in segment attributes.

In MCP platform, for a String variable and National String (single-byte) variable, Glb.Length and Glb.FullLength are set to the length of the variable data in bytes. For a National String (multi-byte) variable, Glb.Length is set to the length of the variable data in characters. In both cases, Glb.FullLength holds the same value as Glb.Length.

In Windows platform, for a String variable, Glb.Length and Glb.FullLength are set to the length of the variable data in bytes. For a National String variable, Glb.Length is set to the length of the variable data in characters and Glb.FullLength is set to the length of the variable data in bytes.

If the variable data is spaces, both Glb.Length and Glb.FullLength are set to zero.

For external binary files the GetLength method returns the size in bytes of the External Blob physical file. If the External Blob file cannot be located or is not accessible then a zero value is returned.

In MCP platform, GetLength can return a maximum length of 2000 characters. If the truncated data exceeds this length, Glb.Length is set to 2000 . However, this 2000 characters restriction does not apply for GetLength on the Windows platforms.

Syntax

<<string variable>>::GetLength(void) : numericLiteral

Owner

Any string-primitive variable.

Return type

A numeric literal.

Examples

Example 1

This example sets Glb.Length to 9, the length of "ABCDE FGH", when the AttachAndSpace logic statement is executed. This value is truncated to "ABCDE" and assigned to SD_Data1 (which is of length 6). The difference in values between SD_Length and Glb.Length indicates truncation has occurred. The final GetLength invocation ignores the trailing space in SD_Data1 and sets Glb.Length to 5.

SD_Data1 := "ABC"
SD_Data1.GetLength()          : Glb.Length is 3
Attach "DE" SD_Data1          : SD_Data1 is "ABCDE"
SD_Data1.GetLength()          : Glb.Length is 5
Attach&Space "FGH" SD_Data1   : "ABCDE FGH" truncated to "ABCDE ",
                              : since SD_Data1 is of length 6
SD_Length := Glb.Length       : SD_Length is 9 
SD_Data1.GetLength()          : Glb.Length is 5 (truncated length
                              : minus the trailing space)        

Example 2

This example gets the length of external binary object MyBlob.

MyBlobLength = MyBlob.GetLength()