cancel
Showing results for 
Search instead for 
Did you mean: 

how to create error messages & validate input fields

Former Member
0 Kudos

Hello All,

in my WD application, i have few input fields , now on click of button i want to validate input fields so that no blank value can be passed.

1) Postal code : this should be 5 digit ( if someone enter more or less then 5 digit

it will not take )

2) Time Zone : (no blank value can be passed ).

3) Valid to & Valid from date : Valid to date greater then equal to Valid from date .

Could anyone plz let me know how to create error message for this ?

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

I assume the postcode was type char ?

But you wan to check for Integer.

A simple check in ABAP

if postcode co '0123456789'.

"all INT as expected

else.

" message please enter a valid post code

endif.

regards

Phil

Former Member
0 Kudos

hi,

Do the Comparsion in his way

A simple check in ABAP

if postcode CO sy-abcde.

sucess

else.

error

endif.

cheers

Former Member
0 Kudos

Hi All ,

Thanks for your help ...!

Answers (2)

Answers (2)

Former Member
0 Kudos

Hi,

You can do all your validation in the wddobeforeaction method. To report messages, you need to first get the instance of the message manager. You can do that as follows:

data: lr_view type ref to if_wd_view_controller,

msg type ref to if_wd_message_manager.

lr_view = wd_this->wd_get_api( ).

msg = lr_view->get_message_manager( ).

When the user presses 'Save' or something, if you want the validations to happen, check if the current action is the action you want. You can do that as below:

data: lr_action type ref to if_wd_action.

lr_action = lr_view->get_current_action ( ).

Now, read the context attributes of the respective fields, and pass them to your validation APIs. If there is a error, report it using the report_attribute_error_message of the message manager. Check out if_wd_message_manager for various messages that are possible. If you report it on an attribute, the actual event handler for the action will not be called.

Hope this helps. Revert for any clarification.

Regards

Nithya

Former Member
0 Kudos

HiNithya ,

For length its working , but I want to check for integer or character type.

I cants change item_postal(user input field) to type INT as its already declared.

could you please send me the code , how to check whether given field is integer or charcter type ).

item_postal LIKE stru_maintain_address-postal. .

elem_maintain_address->get_attribute(

EXPORTING

name = `POSTAL`

IMPORTING

value = item_postal ).

IF strlen( item_postal ) < 5.

l_current_controller ?= wd_this->wd_get_api( ).

CALL METHOD l_current_controller->get_message_manager

RECEIVING

message_manager = l_message_manager.

  • report message

CALL METHOD l_message_manager->report_error_message

EXPORTING

message_text = 'POSTAL CODE INVALID '

Thanks for your time .

rahul

Former Member
0 Kudos

Create a field symbol of integer type and try assigning the entered value to it. It will result in a conversion error if you are trying to do this with a string. You can check the type that way.

Regards

Nithya

Sharadha1
Active Contributor
0 Kudos

Hi,

You have to use the interface 'IF_WD_MESSAGE_MANAGER' to raise messages .

Check for the condition (in your case, if length of postal code > 5 digits),then call one of the methods form message manager interface. There are number of waus in which you can display messages to the user using this message manager interface.

For more details,

see this link

http://help.sap.com/saphelp_nw70/helpdata/en/6c/7aae42cd7fb611e10000000a155106/frameset.htm

Regards,

Sharadha