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

counting string length

Former Member
0 Likes
2,341

i want the count of the number of integers used in the string '1,2,10,22,3,5' leaving commas.

plz help.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,130

Hi,

If the string has only integers and commas you can use:

FIND ALL OCCURRENCES OF ',' IN string MATCH COUNT mcnt.

The number of integers is mcnt + 1.

Regards.

Sandra Marques

6 REPLIES 6
Read only

Former Member
0 Likes
1,130

Hi



data:p_string.  "Your string

data :w_num(10) value '0123456789',
        count type i.

w_len = strlen(p_string)


do w_len times.



if p_string+count(count + 1) CA sy-abcde.      "if character add character to output

chara = charct + 1.

elseif p_string+count(count + 1) CA w_num.          "if chara cter is number adding to number

nunber = number + 1.
endif.

count = count + 1.
enddo.


write : charat.

write : number.


Regards,

Prabhudas

Edited by: Prabhu Das on Apr 17, 2009 4:58 PM

Edited by: Prabhu Das on Apr 17, 2009 4:59 PM

Read only

Former Member
0 Likes
1,131

Hi,

If the string has only integers and commas you can use:

FIND ALL OCCURRENCES OF ',' IN string MATCH COUNT mcnt.

The number of integers is mcnt + 1.

Regards.

Sandra Marques

Read only

Former Member
0 Likes
1,130

Hi,



p_string "input string.

data : w_num(10) type '0123456789'.

data : begin of itab occurs 0,
            num type char10.
         end of itab.

split p_string at ',' into itab.

loop at itab.
if itab-num CA w_num.
count = count + 1.
endif.
endloop.

Read only

Former Member
0 Likes
1,130

if its only commas and integers then you can do this way.

replace all occurence of ',' in p_string with space.
condense p_string.
len = strlen( p_string ).

Regards,

Lalit Mohan Gupta.

Read only

Former Member
0 Likes
1,130

hi sonu,

chk this code snippet.

REPORT  znitesh1.
DATA: a TYPE string VALUE '1,2,3,,4,5,6'.
DATA: b TYPE i VALUE 0.
REPLACE ALL OCCURRENCES OF ',' IN a WITH ' '.
b = STRLEN( a ).
WRITE b.

thanks

Read only

Former Member
0 Likes
1,130

if it is more than , and integers then you can do this way.

data: wa_num(10) value '0123456789',
count type i,
len type i.
len = strlen( p_string ).
do len times.
if p_string+0(1) ca wa_num.
count = count + 1.
endif.
shift p_string circular.
enddo.

Regards,

Lalit Mohan Gupta.