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 avoid alphabets while calculation

Former Member
0 Likes
1,517

Hi,

I m doing some calculation using two fields which contain values in numbers and alphabets and also alpha numberic. Requirement is i should skip the alphabet values and pick only number values and do the caluculation. What is the condition should i give to achive this? And also for alphanumeric values like 9DTI10000789, i should pick only the number part. How to do this?

Ezhil

13 REPLIES 13
Read only

matt
Active Contributor
0 Likes
1,472

For 9DTI10000789 what result do you expect. 910000789?

If so, you can use:

TRANSLATE value TO UPPER CASE.
TRANSLATE value USING 'A B C D E F G H I J K L M N O P Q R S T U V W X Y Z '.
CONDENSE value NO-GAPS

An alternative is to consider each character of the string at a time using value+offset(length).

Is the alpha part fixed? Then you could just use value(1) to get '9' and value+4(8) to get '10000789'.

matt

Read only

SuhaSaha
Product and Topic Expert
Product and Topic Expert
0 Likes
1,472

Hello Ezhil,

Can you please explain if you have "9DTI10000789" do you want "910000789" or "10000789"?

BR,

Suhas

Read only

andreas_mann3
Active Contributor
0 Likes
1,472

use fm PREPARE_STRING

A.

Read only

0 Likes
1,472

Hi

1 2 3

Field A: 900000000 AAAAAAA 9DTI10000000

Field B: 999999999 ZZZZZZZZ 9DTI10000099

Like this, the values are there, Here column 1 is no problem. Column 2 contains only alphabets, so i should totally skip this. And column 3 contains alphanumberic values so i should consider only number part (10000000 and 10000099).

Ezhil

Read only

0 Likes
1,472

Hi,

If the positions of the number to be use are fixed you can use off sets like below:

1 2 3

Field A: 900000000 AAAAAAA 9DTI10000000

Field B: 999999999 ZZZZZZZZ 9DTI10000099


data: lv_field(10).

move itab-col3+4(8) to lv_field.

result = lv_field + itab-col1.

.

if it is not fixed and would only appear on the left hand side you can do like below:


do.
 if itab-col3 ca sy-abdce.
 shift itab-col3 left by 1 places.
else.
exit.
endif
enddo.

Regards,

Himanshu

Read only

0 Likes
1,472

Hi,

Check this...

Use this for your third column



data : lv_a TYPE String VALUE '9DTI10000789'.
data : lv_b TYPE string,
       lv_c TYPE string.

REPLACE REGEX '([[:alpha:]])(\d)' IN lv_a WITH '$1#$2'.
SPLIT lv_a AT '#' INTO lv_b lv_c.
WRITE:/ lv_b.
WRITE:/ lv_c.

To check if there a string contains any alphabets


data : lv_a TYPE String VALUE 'DTI'.
if lv_a CO sy-abcde.
  WRITE: 'YES'.
ENDIF.

Use this for your second column.

Read only

0 Likes
1,472

Hi

The positions are not fixed.

Ezhil

Read only

0 Likes
1,472

Hi,

try this....This is working fine.

data:

w_value(30) type c value '9DT108657',

w_len type i,

w_i type i.

w_len = strlen( w_value ).

do w_len times.

if w_value+w_i(1) CA sy-abcde.

w_value+w_i(1) = ' '.

endif.

add 1 to w_i.

subtract 1 from w_len.

enddo.

condense w_value no-gaps.

write 😕 w_value.

Read only

former_member156446
Active Contributor
0 Likes
1,472

>

> Requirement is i should skip the alphabet values and pick only number values and do the caluculation.

> Ezhil

if not a CA sy-abcde or not b CA Sy-abcde.
c = a + b.
endif.

Read only

Former Member
0 Likes
1,472

hi

var = fieldA-col3+4(8).

it will give you '10000000'

same for fieldB-col3

try this code

DATA: ch(15) VALUE '9DTI10000000',

var(8).

var = ch+4(8).

WRITE / var.

Edited by: mayank jain on Aug 12, 2009 10:06 AM

Edited by: mayank jain on Aug 12, 2009 10:07 AM

Read only

Former Member
0 Likes
1,472

in such case you have to use offset

find the length of col3.

now set the offset to string length.

now check the char. if it is number or char at offset.

if number(0-9) subtract offset by 1 and repeate the procedure untill you fine the first char. in the string.

once you find the char. take the value from offset+1 to string length to another variable.

this will be the numeric part of col3.

Edited by: mayank jain on Aug 12, 2009 10:28 AM

Read only

Former Member
0 Likes
1,472

try this code

DATA: ch(15) VALUE '9DTI10000000123',

var(15),

len TYPE i,

ia type i.

len = STRLEN( ch ).

ia = len - 1.

DO len TIMES.

IF chia(1) ne '0' and chia(1) ne '1' and chia(1) ne '2' and chia(1) ne '3' and

chia(1) ne '4' and chia(1) ne '5' and chia(1) ne '6' and chia(1) ne '7' and chia(1) ne '8' and chia(1) ne '9'.

add 1 to ia.

len = len - ia.

var = ch+ia(len).

exit.

else.

ia = ia - 1.

ENDIF.

enddo.

IF var IS INITIAL.

var = ch.

ENDIF.

WRITE / var.

Edited by: mayank jain on Aug 12, 2009 11:02 AM

Read only

Former Member
0 Likes
1,472

Thanks everybody. I solved the problem using sy-abcde.