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 replace a number from string?

former_member220941
Participant
0 Likes
3,112

Dear All,

I have below requirement can any one plz help me.

In this below string i want to remove GB it is country key and this key is dynamic .how to remove it ?

DATA : L_var1 TYPE string .

l_var1 =  '                  Ledger 0L                        VAT reg.no.: GB602372281                       RFASLM00/SAPUSER    Page           1'.

Thanks,

Raj.

12 REPLIES 12
Read only

Former Member
0 Likes
2,330

would you always have "VAT reg.no.:" preceding it?

Read only

former_member188724
Contributor
0 Likes
2,330

Hi Raj,

How you populate the vat reg in the string. You may move the value from databse selection and move it to string by concatenation.

If so then while concatenating VAT REgNO & the value you can remove the Country key by checking if the VAT no CA 'ABCD.....Z' then do not concatenate that part to the string.

Hope it helps.

Regards,

K.S

Read only

0 Likes
2,330

Except GB everything is remains same.

BR,

Raj.

Read only

0 Likes
2,330

check for VAT reg.no. using CS and then pick up offset using Sy-fdpos then sy-fdpos+lengthof (VAT reg.no.) and this would be teh position where your country key starts, you can now remove it.

Read only

0 Likes
2,330

Hi Raj,

As you say all are no's except GB or can be any other country.

Declare a variable of type numeric,

move the contents of the vat which contains GB123456.

then it will contai only nos without country, provided all nos will come after GB, i.e.,GB doesn't come in between no's.if the format is different please send the possible formats.

Hope this helps.

Regards,

K.S

Read only

Former Member
0 Likes
2,330

1. Use SPLIT statement to split your string at ':'

    Like SPLIT lv_var1 into l_split_1 l_split_2 at ':'.

2. In your second temporary variable you will have l_split_2 = GB1234567

3. l_var3 = l_split_2+2(10). " this will pass your digits of VAT no.

4. Concatenate l_split_1 l_var3 into l_final.

This is just an idea how you can achieve it.

Read only

GirieshM
Active Contributor
0 Likes
2,330

Hi Raj,

Try this,

REPORT  ztezt.

DATA text TYPE string VALUE 'I know you know GB602372281 RFA'.

DATA: text1 TYPE string,

       text2 TYPE c LENGTH 48,

       off TYPE i,

       lv_len TYPE i,

       len TYPE i.

lv_len = strlen( text ).

FIND 'GB' IN text MATCH OFFSET off

                      MATCH LENGTH len.

REPLACE SECTION OFFSET off LENGTH len OF:

                 text WITH '  '.

lv_len = lv_len - off.

lv_len = lv_len - 2.

SPLIT text+off(lv_len) at space into text1 text2.

WRITE: text.

Read only

0 Likes
2,330

GB is not constant it is dynamic...it may be IN or US or DE like that..

Read only

GirieshM
Active Contributor
0 Likes
2,330

Hi Raj,

Try any of the 3 steps:

1. The offset of the Country code is it constant?. i.e., it always comes at 16th position for example. If so try to hard code offset directly.

2. check you might find his country code in local or global variables. Based on that you can change your Find syntax.

3. You have to find the company code from respective table based on key and write the syntax based on that.

With Regards,

Giriesh M

Read only

former_member156446
Active Contributor
0 Likes
2,330

data: lv_vat type string value 'GB602372281'.

replace all occurance of sy-abcd in lv_vat by space.

condence lv_vat.

Read only

Former Member
0 Likes
2,330

You need to first define how to recognize country key before trying to remove it.

I am assuming that it would be first 2 alphabets that appear right after string ' VAT reg.no.: ' and I am replacing only the first occurrence.

Have a look at this snippet.

  1. DATA str TYPE string
  2.   VALUE 'Ledger 0L  VAT reg.no.: GB602372281  RFASLM00/SAPUSER'.
  3. REPLACE REGEX '(?:VAT reg.no.: )[a-zA-Z]{2}' IN str WITH ''.
  4. WRITE str.

/.

Read only

0 Likes
2,330

Thanks a lot Manish it is working fine..... .

Regards,

Raj.