on 05-18-2010 6:48 PM
Hello Everybody,
i stuck in a little issue: My webdynpro has a field to allow users to input phone-numbers.
Finally (bevore writing the input into my db-table) i like to validate if the made input contains only numbers.
regarding to i trief the following.
DATA lv_tst_string(15) TYPE c.
* Check if the entered value is numeric
lv_tst_string = '0123456789'.
IF ls_customer_mod-telefone CO lv_tst_string.
" Then raise a message
* get message manager
DATA lo_message_manager TYPE REF TO if_wd_message_manager.
lo_api_controller ?= wd_this->wd_get_api( ).
CALL METHOD lo_api_controller->get_message_manager
RECEIVING
message_manager = lo_message_manager.
* report message
CALL METHOD lo_message_manager->report_error_message
EXPORTING
message_text = 'möp'.
ENDIF.
But, no matter what i enter as phone number, the message is never thrown and the insert ever performed.
What did i miss?
Best regards
Philipp
Thanks for your suggestions!
Actually not the ouput is overwritten, but the if condition doesnt work.
IF ls_customer_mod-telefone CO '0123456789'.
...
ELSE.
...
ENDIF.
This always jumps into the else-block, no matter what i typed in. I feel bit confused
Regarding the second idea: I chose type characters because i thought num / i does not allow leading "0" like 0172938478. Or am i wrong?
Best regards
Philipp
Edited by: Philipp.Heinemann on May 19, 2010 11:57 AM
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
IF ls_customer_mod-telefone CO '0123456789'.
...
ELSE.
...
ENDIF.
Try to use the statement as below
IF ls_customer_mod-telefone CN '0123456789'. " change CO to CN.
As,
CO -> Contains Only: True, if operand1 only contains characters from operand2. Upper/lower case and trailing blanks are taken into account for both operands. If operand2 is of type string and is initial, then the logical expression is false, unless operand1 is also of type string and is initial, in which case the logical expression is always true. If the result of the comparison is negative, sy-fdpos contains the offset of the first character in operand1, that is not contained in operand2. If the result of the comparison is positive, sy-fdpos contains the length of operand1.
CN -> Contains Not Only; True if a logical expression with CO is false, that is, if operand1 contains not only characters from operand2. sy-fdpos is set in the same way as for CO. If the comparison is true, sy-fdpos contains the offset of the first character in operand1 that is not contained in operand2. If the comparison is false, sy-fdpos contains the length of operand1.
Hope it helps you.
Surprisingly adding a space in the condition works.
IF ls_customer_mod-telefone CN '0123456789 '.
Unfortunatelly, "928 938 8" are now valid inputs, which is okay in this stage of the the program.
But is there any way to kind of "trim" inputs. For example to avoid leading spaces in a name-field?
Surprisingly adding a space in the condition works.
IF ls_customer_mod-telefone CN '0123456789 '.
Unfortunatelly, "928 938 8" are now valid inputs, which is okay in this stage of the the program.
But is there any way to kind of "trim" inputs. For example to avoid leading spaces in a name-field?
Hi Phillipp,
You could try and use the regular expression. I have used this and it works. You could try a pattern as:
^[1-9]\d{2}-[1-9]\d{2}-\d{4}$
Let me know if you need more clarity.
Regards,
Preethi.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
The condense did work, but i didn't set the attributes back into the context node - bad mistake
Now the condese absolutely solves my problem.
Thank you for the regex-hint as well. For more complex checks this is defenitely the tool of choice, but for my purpose the condense fits best.
Thank you guys!
Hi,
Either change the type of Telefone to Num or I, then automatically it will whether all digits entered are numbers or you can check via code like this :
if lv_ca_no CN '0123456789 ' . < Add one space also after 9 >
<Throw error message>
Endif.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Reporting a message to the message manager is not like doing a
message e016(rp) with 'blah'.
in the PAI of a screen - it doesn't stop the processing.
With this in mind you might want to re-write the code above so that it is an if - else - endif construct rather than just an if -message - endif type construct.
Be aware also of the lifetime of the message you generate - if you are navigating away from the current component and the message was raised against the current component, you won't see that message on the screen. You can deal with this by using a "umbrella" component - or rather than having to do that yourself - use the FPM framework which provides such functionality itself!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello,
Instead of using method report_error_message, call method "raise_t100_error" and store your error message in a message class using SE91 transaction. pass msgid = message class name, msgno = message no and msgty = 'E'. It should work.
it seems that in your case, the code is reaching to the error message point and it is moving forward and your error message is over written with success message and process is completed. if it does not work, use statement "exit" just after the method report_error_message in your code.
Thanks
Vishal Kapoor
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
93 | |
10 | |
10 | |
9 | |
9 | |
7 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.