cancel
Showing results for 
Search instead for 
Did you mean: 

Input Field - Only Numbers

Former Member
0 Kudos

Hi,

How to make a input field accept only numbers instead of character and numbers?

Can anyone help me out with this?

Regards,

Kanakaraj V A

Accepted Solutions (0)

Answers (3)

Answers (3)

former_member402443
Contributor
0 Kudos

Hi Kankaraj ,

Check this code.

METHOD check_employee_no .

  • Variable declaration

DATA : lv_mand TYPE zbu_000mz9jo,

lv_emplen TYPE zbu_00pqz9jo,

lv_emptyp TYPE zbu_00hzz9jo,

lv_empno TYPE zempno,

lv_empstr TYPE string,

lv_message TYPE string,

lv_bup TYPE bu_partner,

lv_string TYPE string,

h_type TYPE dd01v-datatype,

lv_check TYPE wdy_boolean VALUE abap_false.

  • Constants Declaration

CONSTANTS : c_numc(10) TYPE c VALUE '1234567890'.

CLEAR : lv_empno, lv_mand, lv_emplen, lv_emptyp,

lv_empstr, lv_string, lv_bup.

  • Function module for Checking the numeric value

CALL FUNCTION 'NUMERIC_CHECK'

EXPORTING

string_in = lv_empno

IMPORTING

string_out = lv_empno

htype = h_type.

IF h_type = 'CHAR'.

MESSAGE e020(/dmpui/ip) INTO lv_message.

    • report message*

CALL METHOD lo_message_manager->report_error_message

EXPORTING

message_text = lv_message.

lv_check = abap_true.

ELSEIF lv_emptyp EQ 'A' OR lv_emptyp EQ 'a'.

IF lv_empno CA sy-abcde OR lv_empno CA c_numc.

lv_check = abap_false.

ELSE.

MESSAGE e021(/dmpui/ip) INTO lv_message.

  • report message

CALL METHOD lo_message_manager->report_error_message

EXPORTING

message_text = lv_message.

ENDIF.

endif.

  • Set the flag

ex_check = lv_check.

ENDMETHOD.

Hopes this will helps you.

Regard

Manoj Kumar

Former Member
0 Kudos

Hi,

Read The attribute and then check for numbers like this.

 IF ur_attribute CO '0123456789'. 

then ur_attribute is a number.

if ur_attribute CO SYABCDE.

Then its alphabate.

else it is alphanumeric.

I hope it helps.

Regards,

Rohit.

arjun_thakur
Active Contributor
0 Kudos

Hi Kanakraj,

Create an attribute of type i and bind it with the input field. It'll accept numbers only.

This will bring a 0 in the input field automatically, if you want to remove it then plz refer the code below:


  DATA lo_el_context TYPE REF TO if_wd_context_element.
  DATA ls_context TYPE wd_this->element_context.
  DATA lv_abc TYPE wd_this->element_context-abc.

* get element via lead selection
  lo_el_context = wd_context->get_element( ).
* @TODO handle not set lead selection
  IF lo_el_context IS INITIAL.
  ENDIF.

** get single attribute
  lo_el_context->set_attribute_null(
    EXPORTING
      name =  `ABC` "ABC is the name of attribute of 'i' type
).

Regards

Arjun

Edited by: Arjun on Mar 6, 2009 2:22 PM