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

Alphanumeric Field

Former Member
0 Likes
3,383

Hi Friends,

I have a field alphanumeric in an internal table I want only numeric value. Please let me know what function I can use for that.

Thanks & Regards,

Hemant Maurya

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,779

Hi

You can use CO (Contains Only) to restrict the field value.

For eg: itab-field1 CO '0123456789'.

Regards

Raj

8 REPLIES 8
Read only

Former Member
0 Likes
1,780

Hi

You can use CO (Contains Only) to restrict the field value.

For eg: itab-field1 CO '0123456789'.

Regards

Raj

Read only

0 Likes
1,779

Dear Raj,

Thanks for your quick response. Will u please let me know full syntax? I have already alphanumeric data on that field I want move only numeric value to another integer field.

Thanks & Regards,

Hemant

Read only

0 Likes
1,779

Hi Hemant

Please try the below piece of code


constants : l_c_pattern(52) type c value '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 '.
constants : l_c_pattern1(52) type c value '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 '.
data : v_alpnum type char10.

v_alpnum = '23sdsa654'.

translate v_alpnum using l_c_pattern.
translate v_alpnum using l_c_pattern1.
condense v_alpnum no-gaps.

Now v_alpnum will have only numeric part.

Regards

Ranganath

Read only

Former Member
0 Likes
1,779

hi

data: var1(10) type c value '123a2'.
data: var2(27) type c value 'abcdefghijklmnopqrstuvwxyz'.

if var1 ca var2.
write 'var1 contains aplabets'.
endif.

Regards

Sajid

Read only

awin_prabhu
Active Contributor
0 Likes
1,779

Hi Hemant,

Check below code. I copied code from FM 'TELNUMBER_REMOVE_SPECIAL_CHAR' and a modified little to ur requirement.


DATA: p_number TYPE sp_telno .
DATA: l_number_in  LIKE sph_call-no_dialed,
      l_number_out LIKE sph_call-no_dialed,
      allowed_char(10) VALUE '0123456789'.  " Only allowed characters

DATA: BEGIN OF itab OCCURS 0,
      str TYPE string,
      END OF itab,
      wa LIKE itab.
DATA: out TYPE i.  " Interger to collect only numeric values

wa-str = '134123wert543'.    " Ur internal table
APPEND wa TO itab.  clear wa.
wa-str = '7hfg566yfg'.
APPEND wa TO itab.  clear wa.

LOOP AT itab INTO wa.
  p_number = wa-str.

  MOVE p_number TO l_number_in.
  CLEAR l_number_out.
  CONDENSE l_number_in NO-GAPS.
  TRANSLATE l_number_in TO UPPER CASE.
  IF l_number_in CN allowed_char.
    DO.
      IF l_number_in(1) NE space.
        IF l_number_in(1) CO allowed_char.
          CONCATENATE l_number_out l_number_in(1) INTO l_number_out.
        ENDIF.
        SHIFT l_number_in.
      ELSE.
        EXIT.
      ENDIF.
    ENDDO.
    MOVE l_number_out TO out.
  ELSE.
    MOVE l_number_in TO out.
  ENDIF.
  WRITE:/ out.    " Display integer
ENDLOOP.

Thanks

Read only

kesavadas_thekkillath
Active Contributor
0 Likes
1,779

Loop at itab into wa.

if wa-field ca '1234567890'.

write wa-fieldsy-fdpos(*)." or wa-intfield = wa-fieldsy-fdpos(*).

skip 1.

endif.

endloop.

The above code will only work if the data is like 'aa123'.

if its like '123aa'.

Then just replace like

Loop at itab into wa.

TRANSLATE wa-field to upper case.

if wa-field ca sy-abcde.

write wa-field0(sy-fdpos)." or wa-intfield = wa-field0(sy-fdpos).

skip 1.

endif.

endloop.

Please mention how the data is in your field.

Note You cannot move a character field to type i.

Read only

venkat_o
Active Contributor
0 Likes
1,779

Hello Hemant, <li>This is very simple. you have to define one variable type N and pass the internal table field value to numeric field automatically it takes only numeric value. <li>Try this way.


 REPORT ztest_program.
 DATA:alpnum_var(12) TYPE c VALUE 'XYZ123lms456'.
 DATA:onlynum_var(12) TYPE n.
 
 onlynum_var = alpnum_var.
 WRITE onlynum_var.
Thanks Venkat.O

Read only

praveen_hannu
Contributor
0 Likes
1,779

Hi Hemanth

Declare another numeric charater variable in the program. Pass the alphanumeric field to that and it will take care of it automatically. No need of any programming effor.

Thanks

Praveen