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

Split letter

david_escofettrenado
Participant
0 Likes
896

We have a field that have a letter in the first character or at last. F.e: A23234343 or 2233667F.

We want to extract the number values from left or from right but we don't know were the letter is.

Any suggestion?

Best Regards.

1 ACCEPTED SOLUTION
Read only

matt
Active Contributor
0 Likes
875
TRANSLATE l_char_field TO UPPER CASE.
TRANSLATE l_char_field 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 l_char_field.
l_val_field = l_char_field.

matt

7 REPLIES 7
Read only

Former Member
0 Likes
875

hi,

Check this code.

data:

w_num(10) type n.

w_num = 'A23234343'.

write:

w_num.

w_num = '2233667F'.

write: w_num.

adjust the length of the numeric variable as per your requirement.

Hope this is helpful..

Thanks

Sharath

Edited by: Sharath Panuganti on Feb 5, 2009 2:43 PM

Read only

Former Member
0 Likes
875

Hi David,

Please read help on CO (contains only) and CA (contains any).

I think you have to use contains any for the alphabet and then delete it from the string.

Thanx.

Read only

Former Member
0 Likes
875

Hi,

DATA : w_num(8) TYPE n.

w_num = 'A23234343'.

WRITE w_num.

Read only

Former Member
0 Likes
875

v_text = 'A123456'.

v_length = STRLEN( v_text ).

v_next = 0.

v_last = v_length - 1.

if 1st charecter in v_text CO 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'.

delete it.

endif.

if lastcharecter CO 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'.

delete the last char.

endif.

Read only

Former Member
0 Likes
875

Hi David



strlen = STRLEN( lv_field ).

IF lv_field(1) = 'A'.
lv_number = lv_field+1.

ELSEIF lv_field(strlen)  = 'F'.

strlen1 = strlen - 1.
lv_number = lv_field(strlen1).

ENDIF.

*take care of data types

Pushpraj

Read only

matt
Active Contributor
0 Likes
876
TRANSLATE l_char_field TO UPPER CASE.
TRANSLATE l_char_field 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 l_char_field.
l_val_field = l_char_field.

matt

Read only

Former Member
0 Likes
875

Hi,

Try this...

DATA : LEN TYPE I,

CHR.

DATA : STR1 TYPE STRING VALUE '23234343F'.

LEN = STRLEN( STR1 ).

CHR = STR1+0(1).

IF CHR CO '1234567890'.

STR1 = STR1+0(8).

ELSE.

STR1 = STR1+1(8).

ENDIF.

WRITE : STR1.

regards.