Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

How to get string length?

Former Member
0 Likes
70,536

Hello

I m making sapscript n one of tht field is 50 char long.

i wnt to use strlen func for getting length of that field .

hw cn i do this ?

if ne othr method is thr pls tell me...

Thanks in Advance.

5 REPLIES 5
Read only

Former Member
0 Likes
31,262

Use the Key word STRLEN to find teh string length in the print program. And pass same value to SAP Script.

Thanks,

Read only

Former Member
31,262

Hello,

Check this code:



DATA: STR(50) VALUE 'How to get string length? '.

DATA: LEN TYPE I.

LEN = STRLEN( STR ).

WRITE: LEN.

Cheers,

Vasanth

Read only

0 Likes
31,262

Adding:

It can be used also in conditional expressions

      IF ( strlen( lv_all_mails ) + strlen( another_email ) ) LE 130.
CONCATENATE lv_all_mails another_email INTO lv_all_mails SEPARATED BY space.
ENDIF.
Read only

Former Member
0 Likes
31,262

Hi,

Data : V_string(50) VALUE 'ABCDEFGH',

v_cnt TYPE I.

v_cnt = strlen( v_string ).

write : v_cnt.

Pls. reward if useful..

Read only

Former Member
0 Likes
31,262

Hi ,

Use STRLEN .

For example

DATA: int TYPE i,

word1(20) TYPE c VALUE '12345',

word2(20) TYPE c ,

word3(20) TYPE c VALUE ' 4 '.

int = strlen( word1 ). WRITE int.

int = strlen( word2 ). WRITE / int.

int = strlen( word3 ). WRITE / int.

Hope this helps .

Regards,

Chandru