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 fetch intiger values from string.

Former Member
0 Likes
962

Hi Friends,

I need one help.

I want to fetch the particular integer values from one string...

Exp: I am having the field value like "ABCD123456" or "ABC 123456" or "ABCDE 123456".

Now i want to get the integer values. Here I need only "123456"

Thanks.

Sridhar.

7 REPLIES 7
Read only

former_member673464
Active Contributor
0 Likes
908

hi,

Only digits in the string are copied when conversion from string to numc takes place. The field is right-justified and filled with trailing zeros. If the target field is too short, it is truncated from the left.

regards,

veeresh

Message was edited by:

veereshbabu ponnada

Read only

Former Member
0 Likes
908

if v_string ca '0123456789 '.

v_number = v_string+sy-fdpos.

endif.

Regards,

Ravi

Read only

Former Member
0 Likes
908

THIS may be useful to ur issue.

CP (Contains Pattern):

The complete string c1 matches the pattern c2 (c1 "matches" c2).

The pattern c2 can contain ordinary characters and wildcards.

'*' stands for any character string and '+' denotes any character.

If the result of the comparison is positive, the system field SY-FDPOS contains the offset of the first character of c2 in c1. The wildcard character '*' at the beginning of the pattern c2 is ignored when determining the value of SY-FDPOS.

If the result of the comparison is negative, the system field SY-FDPOS contains the length of c1.

Examples:

'ABCDE' CP 'CD' is true; SY-FDPOS = 2.

'ABCDE' CP '*CD' is false; SY-FDPOS = 5.

'ABCDE' CP '+CD' is true; SY-FDPOS = 0.

'ABCDE' CP '+CD*' is false; SY-FDPOS = 5.

'ABCDE' CP 'BD*' is true; SY-FDPOS = 1.

Read only

Former Member
0 Likes
908

Hi Sridhar,

Here is a simple solution...

data:str type string value 'ABCD123456',

val(10) type n.

val = str.

write: val NO-ZERO .

output : 123456

Regards,

Kiran B

Read only

0 Likes
908

Thanks man, its really usefull..and i resolved my problem..

thanks to all who replied to my query....

Thanks,

Sridhar

Read only

Former Member
0 Likes
908

sridhar,

Use this code...

REPORT YCHATEST1.

DATA : v_str type String,

V_len type i,

v_num type i.

start-of-selection.

v_str = 'ABCD123456'.

v_len = strlen( v_str ).

do .

v_num = v_num + 1.

if v_len eq v_num.

exit.

else.

if v_str+0(v_num) ca sy-abcde.

REPLACE v_str+0(v_num) WITH space INTO v_str.

v_num = v_num - 1 .

v_len = v_len - 1.

endif.

endif.

enddo.

Don't forget to reward if useful

Read only

Former Member
0 Likes
908

Execute the code .

parameters : val(30)  type c.
data : final(30) type c,
       cnt type i,
       v type c,
       n type i.


cnt = strlen( val ).
do cnt times.
move val+n(1) to v.
if v ca '0123456789'.
move v to final+n(1).
endif.
n = n + 1.
enddo.

condense final no-gaps.

write:/ final .

-


Never mind but you could have given a 10 pointer to kiran for his time and idea .. its just a request ..

Regards,

Vijay