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

Extract numeric string in string

Former Member
0 Likes
1,066

I want to extract numeric string from astring.

it should stop reading if it hits an alphabet that is requirement.it is not that numeric string is of fixed lenght but it will be in begining.

example:78965rocksalt

result:78965.

4 REPLIES 4
Read only

hymavathi_oruganti
Active Contributor
0 Likes
780

REPORT ZTESTH .

DATA: P(5) TYPE N,

T TYPE I.

P = '123AD'.

T = P.

WRITE T.

execute above report and check. it will solve ur doubt

Read only

Former Member
0 Likes
780

you can use the below logic.

lstr = '121354ad'.

if lstr ca sy-abcde.

write lstr+0(sy-fdpos) to lnum.

endif.

Regards

Anurag

Please note you might need to translate to upper case as CA is case-sensitive.

Message was edited by: Anurag Bankley

Read only

Former Member
0 Likes
780

Hi,

Declare the variable as type N.

data: a1(20) type c value '78945asdfaf',

a2(5) type n.

a2 = a1.

write:/ a1,

/ a2.

regards

Subbu

Read only

andreas_mann3
Active Contributor
0 Likes
780

Hi,

use fm PREPARE_STRING

DATA zahl(11) VALUE ' 0123456789'.

    CALL FUNCTION 'PREPARE_STRING'
         EXPORTING
              i_valid_chars  = zahl
              i_xvalid_check = 'X'
              i_xchar_repl   = 'X'
              i_xtoupper     = 'X'
         CHANGING
              c_string       = example.

    CONDENSE example NO-GAPS.
    result = example.

Andreas

pls reward useful answers

thank you