‎2008 Feb 25 3:35 AM
Dear all,
I need to perform the check on a string where it contains email address.
For eg:
abc@yahoo.com - this is a valid email add
@yaho.com - this is invalid email add
qwertyuyu.com - this is invalid email add
Do you think is there any standard FM can perform such check?
Please comment.
Thanks in advance.
‎2008 Feb 25 3:46 AM
Hi,
Please try this code. I hope it will meet most of your requirements.
FORM check_email_val .
DATA: lv_len type i,
lv_len1 type i,
lv_len2 type i,
lv_char1,
lv_char2(2) type c,
lv_char3,
lv_last_3 type i,
lv_email(40) type c,
lv_email_str(40) type c,
lv_temp1(40) type c,
lv_temp2(40) type c,
lv_temp3(40) type c,
lv_temp4(40) type c,
lv_temp5(10) type c,
lv_temp6(10) type c,
lv_rev_str(20) type c,
lv_last_4(4) type c,
lv_flag1 type c,
lv_flag2 type c,
lv_flag3 type c,
lv_str(6) type c.
lv_email = zuserpass-email.
lv_len = strlen( lv_email ).
IF ok_code EQ 'PRO'.
*check whether @ symbol is there, depending on flag validate any further
IF lv_email CA '@'.
lv_flag1 = 'X'.
ELSE.
lv_flag1 = ' '.
Message S013(zusermsg). "Email ID must have a '@'
Endif.
IF lv_flag1 = 'X'.
*split and check whether the split halves have any '@' or special characters leaving out '_' and '.'
SPLIT lv_email at '@' INTO lv_temp3 lv_temp4.
IF ( lv_temp3 CA '@~!#$%^&*()-={}}[]'',/?<>:"|\`' ) OR ( lv_temp4 CA '@~!#$%^&*()''-={}}[],/?<>:"|\`' ).
Message S016(zusermsg). "Special characters except '_' , '.' , '@' are not allowed
EXIT.
ENDIF.
*checking whether there is an '_' of '.' in immediate precedence to '@'
*reversing lv_temp3 and taking its first character
CALL FUNCTION 'STRING_REVERSE'
EXPORTING
STRING = lv_temp3
LANG = sy-langu
IMPORTING
RSTRING = lv_rev_str
.
IF SY-SUBRC <> 0.
ENDIF.
*fetching the character just before '@'
lv_char1 = lv_rev_str+0(1).
IF ( lv_char1 EQ '_' ) or ( lv_char1 EQ '.' ).
MESSAGE S021(zusermsg). "Cannot have '_' or '.' just before or just after '@'
EXIT.
ENDIF.
*fetching the character just after '@'
lv_char3 = lv_temp4+0(1).
IF ( lv_char3 EQ '_' ) or ( lv_char3 EQ '.' ).
MESSAGE S021(zusermsg).
EXIT.
ENDIF.
*checking whether a '.' is present in lv_temp4
IF lv_temp4 CA '.'.
lv_flag2 = 'X'.
ELSE.
lv_flag2 = ' '.
MESSAGE S020(zusermsg). "Email ID should have a '.'
ENDIF.
*further checking whether there is a '.' separating email id into two halves
IF lv_flag2 EQ 'X'.
SPLIT lv_temp4 at '.' INTO lv_temp1 lv_temp2.
IF lv_temp1 EQ ' '.
MESSAGE S018(zusermsg). "Enter a valid portal name
ENDIF.
IF lv_temp2 EQ ' '.
MESSAGE S019(zusermsg). "Domain name cannot be blank
ELSE.
lv_flag3 = 'X'.
ENDIF.
ENDIF. "end of flag2 IF
*check for a valid domain
IF lv_flag3 EQ 'X'.
IF ( lv_temp2 CP 'com' ) OR ( lv_temp2 CP 'edu' ) OR ( lv_temp2 CP 'net' ) OR ( lv_temp2 CP 'org' ).
LEAVE TO SCREEN 1003.
ELSE.
*if email ID is of type co.in
IF lv_temp2 CA '.'.
SPLIT lv_temp2 at '.' INTO lv_temp5 lv_temp6.
IF lv_temp5 CP 'co'.
lv_len1 = strlen( lv_temp6 ).
the email ID should be of the form co.xx
IF lv_len1 GT 2.
MESSAGE S022(zusermsg). "Email Id will be of the form .com, .org, .net or .co.in or .co.uk etc.
EXIT.
ENDIF.
checking whether the penultimate and the final character are alphabets
lv_char2 = lv_temp6+0(2).
IF ( lv_char2 NA 'aAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyYzZ' ).
MESSAGE S023(zusermsg). "Invalid domain name
ENDIF.
LEAVE TO SCREEN 1003.
ELSE. "to the 'co' IF
MESSAGE S022(zusermsg). "Email Id will be of the form .com, .org, .net or .co.in or .co.uk etc.
ENDIF. " end of 'co' IF
ENDIF. "end of first IF
ENDIF. "end of lv_temp CA '.'
ENDIF. "end of flag3 IF
ENDIF. "end of flag1
ENDIF. "end of ok_code IF
ENDFORM. " check_email_val
Reward if Helpful.
‎2008 Feb 25 3:46 AM
Hi,
Please try this code. I hope it will meet most of your requirements.
FORM check_email_val .
DATA: lv_len type i,
lv_len1 type i,
lv_len2 type i,
lv_char1,
lv_char2(2) type c,
lv_char3,
lv_last_3 type i,
lv_email(40) type c,
lv_email_str(40) type c,
lv_temp1(40) type c,
lv_temp2(40) type c,
lv_temp3(40) type c,
lv_temp4(40) type c,
lv_temp5(10) type c,
lv_temp6(10) type c,
lv_rev_str(20) type c,
lv_last_4(4) type c,
lv_flag1 type c,
lv_flag2 type c,
lv_flag3 type c,
lv_str(6) type c.
lv_email = zuserpass-email.
lv_len = strlen( lv_email ).
IF ok_code EQ 'PRO'.
*check whether @ symbol is there, depending on flag validate any further
IF lv_email CA '@'.
lv_flag1 = 'X'.
ELSE.
lv_flag1 = ' '.
Message S013(zusermsg). "Email ID must have a '@'
Endif.
IF lv_flag1 = 'X'.
*split and check whether the split halves have any '@' or special characters leaving out '_' and '.'
SPLIT lv_email at '@' INTO lv_temp3 lv_temp4.
IF ( lv_temp3 CA '@~!#$%^&*()-={}}[]'',/?<>:"|\`' ) OR ( lv_temp4 CA '@~!#$%^&*()''-={}}[],/?<>:"|\`' ).
Message S016(zusermsg). "Special characters except '_' , '.' , '@' are not allowed
EXIT.
ENDIF.
*checking whether there is an '_' of '.' in immediate precedence to '@'
*reversing lv_temp3 and taking its first character
CALL FUNCTION 'STRING_REVERSE'
EXPORTING
STRING = lv_temp3
LANG = sy-langu
IMPORTING
RSTRING = lv_rev_str
.
IF SY-SUBRC <> 0.
ENDIF.
*fetching the character just before '@'
lv_char1 = lv_rev_str+0(1).
IF ( lv_char1 EQ '_' ) or ( lv_char1 EQ '.' ).
MESSAGE S021(zusermsg). "Cannot have '_' or '.' just before or just after '@'
EXIT.
ENDIF.
*fetching the character just after '@'
lv_char3 = lv_temp4+0(1).
IF ( lv_char3 EQ '_' ) or ( lv_char3 EQ '.' ).
MESSAGE S021(zusermsg).
EXIT.
ENDIF.
*checking whether a '.' is present in lv_temp4
IF lv_temp4 CA '.'.
lv_flag2 = 'X'.
ELSE.
lv_flag2 = ' '.
MESSAGE S020(zusermsg). "Email ID should have a '.'
ENDIF.
*further checking whether there is a '.' separating email id into two halves
IF lv_flag2 EQ 'X'.
SPLIT lv_temp4 at '.' INTO lv_temp1 lv_temp2.
IF lv_temp1 EQ ' '.
MESSAGE S018(zusermsg). "Enter a valid portal name
ENDIF.
IF lv_temp2 EQ ' '.
MESSAGE S019(zusermsg). "Domain name cannot be blank
ELSE.
lv_flag3 = 'X'.
ENDIF.
ENDIF. "end of flag2 IF
*check for a valid domain
IF lv_flag3 EQ 'X'.
IF ( lv_temp2 CP 'com' ) OR ( lv_temp2 CP 'edu' ) OR ( lv_temp2 CP 'net' ) OR ( lv_temp2 CP 'org' ).
LEAVE TO SCREEN 1003.
ELSE.
*if email ID is of type co.in
IF lv_temp2 CA '.'.
SPLIT lv_temp2 at '.' INTO lv_temp5 lv_temp6.
IF lv_temp5 CP 'co'.
lv_len1 = strlen( lv_temp6 ).
the email ID should be of the form co.xx
IF lv_len1 GT 2.
MESSAGE S022(zusermsg). "Email Id will be of the form .com, .org, .net or .co.in or .co.uk etc.
EXIT.
ENDIF.
checking whether the penultimate and the final character are alphabets
lv_char2 = lv_temp6+0(2).
IF ( lv_char2 NA 'aAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyYzZ' ).
MESSAGE S023(zusermsg). "Invalid domain name
ENDIF.
LEAVE TO SCREEN 1003.
ELSE. "to the 'co' IF
MESSAGE S022(zusermsg). "Email Id will be of the form .com, .org, .net or .co.in or .co.uk etc.
ENDIF. " end of 'co' IF
ENDIF. "end of first IF
ENDIF. "end of lv_temp CA '.'
ENDIF. "end of flag3 IF
ENDIF. "end of flag1
ENDIF. "end of ok_code IF
ENDFORM. " check_email_val
Reward if Helpful.
‎2008 Feb 25 3:49 AM
FSCHU,
use cl_http_client class and send a dummy http request to the site to see whether its available or not.
check out the following program for sample code
RSWF_TEST_HTTP
NOTE: if you are connecting to internet via proxy and the url you are trying to reach is on internet.
SICF GOTO->HTTP client proxy settings
in global settings tab
check the check box "proxy setting is active"
and in the "HTTP log" tab
enter proxy host name e.g proxy.sap.com....
enter the proxy server port (generally 80)
if required you need to enter
proxy server authentication (uid/pwd)