‎2006 Jun 28 8:08 PM
Hello,
I am wondering what is the code to obtain the length of a string of characters, is there such a thing like sy-length? Thanks a lot!
Regards,
Anyi
‎2006 Jun 28 8:10 PM
Hi
DATA: STRING(20).
DATA: LEN TYPE I.
STRING = 'ABDCE'.
LEN = STRLEN( STRING ).
In this case LEN = 5.
Or you can use DESCRIBE FIELD statament to know the length of variable (in this case 20):
DESCRIBE FIELD STRING LENGTH LEN.
Max
‎2006 Jun 28 8:10 PM
Hi
DATA: STRING(20).
DATA: LEN TYPE I.
STRING = 'ABDCE'.
LEN = STRLEN( STRING ).
In this case LEN = 5.
Or you can use DESCRIBE FIELD statament to know the length of variable (in this case 20):
DESCRIBE FIELD STRING LENGTH LEN.
Max
‎2006 Jun 28 8:14 PM
If you just need the <u>defined</u> length(as opposed to occupied length which STRLEN tells you) of a field then you can use the code below.
DESCRIBE FIELD myfield LENGTH field_length.
‎2006 Jun 28 8:14 PM
‎2006 Jun 28 8:18 PM
Hi,
There is no System variable to find the length of the string.
We have to go with Strlen( ) as other have used.
Thanks,
Pramod
‎2006 Jun 28 8:19 PM
H anyi,
The ABAP function STRLEN returns the length of a string up to the last character that is not a space.
[COMPUTE] <n> = STRLEN( <c> ).
STRLEN processes any operand <c> as a character data type, regardless of its real type. There is no type conversion.
As with mathematical functions, the keyword COMPUTE is optional.
DATA: INT TYPE I,
WORD1(20) VALUE '12345'.
WORD2(20).
WORD3(20) VALUE ' 4 '.
INT = STRLEN( WORD1 ). WRITE INT.
INT = STRLEN( WORD2 ). WRITE / INT.
INT = STRLEN( WORD3 ). WRITE / INT.
The results are 5 , 0, and 4 respectively.
reward helpful answers.
regards,
keerthi.
‎2006 Jun 28 8:19 PM
hi anyi,
data: Str type string,
LEN type i.
len = strlen( str ).