Application Development 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: 

replace charachters

Former Member
0 Kudos

I have abcc345. i need to replace all the charachters by spaces.

incase i have asdfghj00001 again all charachters by spaces.

but number remains the same.

in all cases i just need to replace the charachters numbere remaining the same

1 ACCEPTED SOLUTION

Former Member
0 Kudos

HI,

See if one variable has value like abc456.

simply declare one variable with type N.

example ..


data:  
  w_var1(20) type c value 'ABC1101',
  w_var2(20) type N.

w_var2 = w_var1.

write : / w_var2. 
Then simply it writes ....  1101.

hope u got it..

this is the concept of type conversion...................

Regards

Sunil Kumar Mutyala.

6 REPLIES 6

Former Member
0 Kudos

Hi use the keywords REPLACE and CONDENSE.

cheers!!

former_member329859
Participant
0 Kudos

hi,

str = abcc3345.

str1 = str+4(1).

str2 = str+4(4) = 3345. then take it in anather variable

same for below one with some modification

Former Member
0 Kudos

Hi,

Use this....


DATA : lv_field type char20 value 'asdfghj00001',
       moff type i,
       lv_strlen type i,
       lv_length type i.


find first occurrence of regex '\d' in lv_field match offset moff.

lv_strlen = strlen( lv_field ).

lv_length = lv_strlen - moff.

write : / lv_field+moff(lv_length).

Hope it will helps

Former Member
0 Kudos

HI,

See if one variable has value like abc456.

simply declare one variable with type N.

example ..


data:  
  w_var1(20) type c value 'ABC1101',
  w_var2(20) type N.

w_var2 = w_var1.

write : / w_var2. 
Then simply it writes ....  1101.

hope u got it..

this is the concept of type conversion...................

Regards

Sunil Kumar Mutyala.

Former Member
0 Kudos

Hi,

Use Replace as follows;

DATA lv_text TYPE string VALUE 'ab000cdeSDFf34534gh1ASDF234ijk5abc0'.
WRITE : /,'Before Replace :',lv_text.
REPLACE ALL OCCURRENCES OF REGEX '[A-Za-z]' IN lv_text WITH ''.
WRITE : /,'After Replace :',lv_text.

Output:

Before Replace : ab000cdeSDFf34534gh1ASDF234ijk5abc0

After Replace : 00034534123450

Remember that there is no space between the single quotes in the WITH clause of the REPLACE statement.

Regards

KArthik D

Former Member
0 Kudos

Hi,

You can also use;

REPLACE ALL OCCURRENCES OF REGEX '[[:alpha:]]' IN lv_text WITH ''.

Regards

Karthik D