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: 

Delete all characters up to the first numeric value

Former Member
0 Kudos

Hi,

I have a requirement where i need to delete all the characters up to teh first numeric value.

Ex: "POBOX123A" is the requirement and it shuld retain "123A".

Please do the need ful

Thanks,

Shiva shekar

6 REPLIES 6

Former Member
0 Kudos
Data: w_char(20) value 'POBOX123A'.

DO.
if w_char+0(1) co '0123456789'.
exit.
elseif w_char+0(1) is initial.
Exit.
else.
w_char = w_char+1.
ENDIF.

ENDDO.
write : w_char.

These codes works.

regards,

gurpreet

Edited by: Gurpreet Singh on Apr 9, 2009 11:05 AM

Former Member
0 Kudos

Hi Shiva,

Here is the code for your requirement:

DATA: w_char(20) VALUE 'POBOX123A',

w_num(1) TYPE c,

count TYPE i,

len TYPE i,

w_out TYPE dd01v-datatype.

count = 0.

DO.

w_num = w_char+count(1).

CALL FUNCTION 'NUMERIC_CHECK'

EXPORTING

string_in = w_num

IMPORTING

  • STRING_OUT =

htype = w_out

.

len = STRLEN( w_char ).

IF w_out = 'NUMC'.

len = len - count.

w_char = w_char+count(len).

EXIT.

ENDIF.

count = count + 1.

ENDDO.

WRITE w_char.

Regards,

Nitin.

former_member226203
Active Contributor
0 Kudos

hi,

calculate the length of the string first.

v_val = 'POBOX123A'.

v_length = strlen(v_val).

v_next = 0.

v_last = v_next + 1.

do v_length times.

if v_val+v_next(v_last) CA 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'.

**delete it from v_val.

else.

exit.

endif.

v_next = v_next + 1.

v_last = v_last + 1.

enddo.

v_val will hve the new value now.

awin_prabhu
Active Contributor
0 Kudos

Try this code.

REPORT ztest.

DATA: s(20) TYPE c VALUE 'POBOX123A',

l TYPE i,

i TYPE i VALUE 0,

ch TYPE c,

ch1(20) TYPE c.

l = STRLEN( s ).

DO l TIMES.

ch = s+i(1).

IF ch NA '1234567890'.

i = i + 1.

IF sy-index = l.

CONCATENATE ch1 ch INTO ch1.

ELSE.

CONTINUE.

ENDIF.

ELSE.

i = i + 1.

CONCATENATE ch1 ch INTO ch1.

ENDIF.

ENDDO.

Former Member
0 Kudos

Just check these codes are tested and working.

Data: w_char(20) value 'POBOX123A'.
 
DO.
if w_char+0(1) co '0123456789'.
exit.
elseif w_char+0(1) is initial.
Exit.
else.
w_char = w_char+1.
ENDIF.
 
ENDDO.
write : w_char.

OR.

USE:

Data: w_char(20) value 'POBOX123A'.

if w_char cN sy-abcde.
write :sy-fdpos.
w_char = w_char+sy-fdpos.
ENDIF.
write : w_char.

Regards,

Gurpreet

Former Member
0 Kudos

Hey,

Please look at following code

 

data: l(20) VALUE 'POBOX123A',
      len type i.
len = strlen( l ).
do.
  if sy-index = len.
    exit.
  endif.
  if l+0(1) cn '0123456789'  .
    shift l LEFT .
  else.
    exit.
  endif.
enddo.
write: l.

-RJ