Page 1 of 1

Usage of LenDP function

Posted: Fri Jun 24, 2005 10:11 am
by vinodlakshmanan
Hi,
I need to use the LenDP function on one of my input fields.
1. What is the meaning of "length in display positions"
2. The function accepts only integer values for mapname. How do I get to know which integer value maps to which NLS Map?

Thanks,
Vinod

Posted: Fri Jun 24, 2005 11:22 am
by ArndW
Hello Vinod,

let's say that you have a UTF-16 NLS enabled and you have a string with a single Japanese Kanji (let's just assume that it's the symbol for Chikara [which is my favorite Kanji]), if you were to do a LEN(KanjiString) you would get 2 (because it is 2 bytes long), if you were to do a LENDP(KanjiString) you would get 1, because it is only one character and occupies only 1 display position.

The LENDP() is the NLS equivalent of the LEN() function, it ignores the number of bytes used to store a character string and just computes the number of distinct characters used - in single-byte non-nls these two values are always identical, i.e. a string of 12 bytes will have exactly 12 characters. In variable-length encodings you will never know how many characters are in a string until you parse them.

The [Mapname] is optional and should only be used if the string you are looking at is in another NLS encoding than the process is using.

Posted: Fri Jun 24, 2005 6:04 pm
by vinodlakshmanan
Now if I want to specify the mapname as UTF8, what would be the value out there.
Basically, DataStage is expecting an integer value in mapname and is giving a compilation error if I do not supply this field or give a character value; only numeric values are being compiled correctly. DS version is 7.0.0.

Posted: Sat Jun 25, 2005 8:18 am
by ArndW
Vinod,

the 2nd argument is optional as documented. At V7.5 I wrote a dummy routine which consisted of 1 line - Ans = LENDP(Arg1) and it compiles correctly also displays a length of 2 when I enter (through cut-and-paste) the 4 bytes/2 Characters that make up the name "Tokyo".

Posted: Mon Jun 27, 2005 6:36 pm
by ray.wurlod
A small clarification to Arnd's first post.

LEN(TheString) returns the number of characters in TheString.
BYTELEN(TheString) returns the number of bytes in TheString.
LENDP(TheString) returns the number of display postions required for TheString.

For example, consider a string comprising two single-width characters and one double-width character.
  • LEN(TheString) returns 3.

    BYTELEN(TheString) returns however many bytes are needed to store these characters, which theoretically can be as many as four per character under UV-UTF8 encoding. If two bytes per character, this function would return 6.

    LENDP(TheString) returns 4.