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

spaces in a string

Former Member
0 Likes
1,003

Hello ,

MY requirement is to find how many spaces in a string ..is there any function module plz advise.

thanks.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
957

Hi!

Use the SEARCH command for this. In higher SAP versions (ECC6) you can use the FIND as well.

Regards

Tamá

8 REPLIES 8
Read only

Former Member
0 Likes
958

Hi!

Use the SEARCH command for this. In higher SAP versions (ECC6) you can use the FIND as well.

Regards

Tamá

Read only

0 Likes
957

hello there ,

thanks for your reply. I am getting an runtime error saying endless loop..any help?

Thanks

Read only

SuhaSaha
Product and Topic Expert
Product and Topic Expert
0 Likes
957

Hello,

DATA: v_str TYPE string,
      v_len_ini TYPE i,
      v_len_fin TYPE i,
      v_spaces TYPE i.

v_str = `Welcome to SDN ABAP Forums `.
v_len_ini = STRLEN( v_str ).

WRITE / v_str.

CONDENSE v_str NO-GAPS.
v_len_fin = STRLEN( v_str ).

WRITE / v_str.

v_spaces = v_len_ini - v_len_fin.

IF v_spaces > 0.
  WRITE: / 'No of spaces:', 20 v_spaces.
ENDIF.

Does this solve your req ?

BR,

Suhas

Read only

0 Likes
957

Hey Suhas,

Thats Cool

Read only

0 Likes
957

Hi,

May be there are many ways. But one way is using split:


data: itab type table of string,
count type i.
split v_string at c_space into table itab.

describe table itab lines count.
count = count - 1.
Now count contains the number os spaces in the string.

@Keshav,

Sorry,ended up by posting same solution as I didnt checked your suggestion before posting

Regards,

Swarna Munukoti.

Edited by: Swarna Munukoti on Jan 29, 2010 12:26 PM

Read only

rameshkumar_ramasamy2
Participant
0 Likes
957

hi,

u can try this..


PARAMETER dat TYPE string.
DATA count TYPE i.

DATA: len TYPE i,
      var TYPE c.

len = strlen( dat ).


do len TIMES.
len = len - 1.
var  = dat+len(1).
if  var = ' '.
  count = count + 1.
ENDIF.
enddo.
WRITE / count.

Read only

0 Likes
957
PARAMETER dat TYPE string.

Is STRING data type allowed?

Manas M.

Read only

kesavadas_thekkillath
Active Contributor
0 Likes
957

You can check the f1 help of find and search.

But what comes to my mind now is

Split lv_string at space into table itab."make sure that the syntax is correct

describe table itab lines lv_lines.

lv_lines = lv_lines - 1.

write:'Spaces-',lv_lines.