Skip to Content
0
Former Member
Jun 11, 2013 at 08:10 AM

email address validation

142 Views

Hi every one ......see my code

* ----------------------------------------------------------------------*

* & Start of selection *

* ----------------------------------------------------------------------*

START-OF-SELECTION.

SELECT LIFNR

LAND1

NAME1

NAME2

NAME3

NAME4

ORT01

ORT02

PFACH

PSTL2

PSTLZ

REGIO

SORTL

STRAS

FROM LFA1

INTO TABLE IT_LFA1

WHERE LIFNR IN S_LIFNR.

* AND SPRAS = SY-LANGU. "Message language

END-OF-SELECTION.

DATA: unstruct TYPE sx_address.

unstruct-type = 'INT'.

unstruct-address = p_email.

CALL FUNCTION 'SX_INTERNET_ADDRESS_TO_NORMAL'

EXPORTING

ADDRESS_UNSTRUCT = unstruct

* COMPLETE_ADDRESS = 'X'

* IMPORTING

* ADDRESS_NORMAL =

* LOCAL =

* DOMAIN =

* COMMENT =

* ADDR_NORMAL_NO_UPPER =

EXCEPTIONS

ERROR_ADDRESS_TYPE = 1

ERROR_ADDRESS = 2

ERROR_GROUP_ADDRESS = 3

OTHERS = 4

.

IF SY-SUBRC <> 0.

message 'Please enter valid email address' TYPE 'I'.

else.

message 'Email address is valid' TYPE 'I'.

ENDIF.

PERFORM TRAITEMENT.

PERFORM CONVERSION.

* &---------------------------------------------------------------------*

* & Form TRAITEMENT

* &---------------------------------------------------------------------*

* text

* ----------------------------------------------------------------------*

* --> p1 text

* <-- p2 text

* ----------------------------------------------------------------------*

FORM TRAITEMENT .

PERFORM OPEN_FORM.

* LOOP AT it_lfa1 INTO wa_lfa1.

PERFORM WRITE_FORM.

* ENDLOOP.

PERFORM CLOSE_FORM.

ENDFORM. " TRAITEMENT

* &---------------------------------------------------------------------*

* & Form OPEN_FORM

* &---------------------------------------------------------------------*

* text

* ----------------------------------------------------------------------*

* --> p1 text

* <-- p2 text

* ----------------------------------------------------------------------*

FORM OPEN_FORM .

ITCPO-TDGETOTF = 'X'. "Return of OTF table. No printing, display, or faxing

STRUCT-TDDEST = 'LP01'. "Spool: Output device

STRUCT-TDNOPREV = 'X'. "No print preview

*To access the SAP Script output in OTF format

STRUCT-TDGETOTF = 'X'.

CALL FUNCTION 'OPEN_FORM'

EXPORTING

* APPLICATION = 'TX'

* ARCHIVE_INDEX =

* ARCHIVE_PARAMS =

DEVICE = 'PRINTER'

DIALOG = SPACE

FORM = 'ZPHF_VMS1'

LANGUAGE = sy-langu "Message language

OPTIONS = STRUCT

* MAIL_SENDER =

* MAIL_RECIPIENT =

* MAIL_APPL_OBJECT =

* RAW_DATA_INTERFACE = '*'

* SPONUMIV =

* IMPORTING

* LANGUAGE = sy-langu

* NEW_ARCHIVE_PARAMS =

* RESULT =

* EXCEPTIONS

* CANCELED = 1

* DEVICE = 2

* FORM = 3

* OPTIONS = 4

* UNCLOSED = 5

* MAIL_OPTIONS = 6

* ARCHIVE_ERROR = 7

* INVALID_FAX_NUMBER = 8

* MORE_PARAMS_NEEDED_IN_BATCH = 9

* SPOOL_ERROR = 10

* CODEPAGE = 11

* OTHERS = 12

.

IF SY-SUBRC <> 0.

* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

ENDFORM. " OPEN_FORM

* &---------------------------------------------------------------------*

* & Form WRITE_FORM

* &---------------------------------------------------------------------*

* text

* ----------------------------------------------------------------------*

* --> p1 text

* <-- p2 text

* ----------------------------------------------------------------------*

FORM WRITE_FORM .

CALL FUNCTION 'WRITE_FORM'

EXPORTING

ELEMENT = 'HEADER1'

* FUNCTION = 'SET'

* TYPE = 'BODY'

WINDOW = 'HEADER'.

CALL FUNCTION 'WRITE_FORM'

EXPORTING

ELEMENT = 'LINE'

* FUNCTION = 'SET'

* TYPE = 'BODY'

WINDOW = 'LINE_HD'.

LOOP AT IT_LFA1 INTO WA_LFA1.

CALL FUNCTION 'WRITE_FORM'

EXPORTING

ELEMENT = 'NEW-PAGE'

* FUNCTION = 'SET'

* TYPE = 'BODY'

WINDOW = 'MAIN'.

ENDLOOP.

ENDFORM. " WRITE_FORM.

* &---------------------------------------------------------------------*

* & Form CLOSE_FORM

* &---------------------------------------------------------------------*

* text

* ----------------------------------------------------------------------*

* --> p1 text

* <-- p2 text

* ----------------------------------------------------------------------*

FORM CLOSE_FORM .

CALL FUNCTION 'CLOSE_FORM'

IMPORTING

RESULT = I_ITCPP "SAPscript output parameters

* RDI_RESULT =

TABLES

OTFDATA = T_OTF

EXCEPTIONS

UNOPENED = 1

BAD_PAGEFORMAT_FOR_PRINT = 2

SEND_ERROR = 3

SPOOL_ERROR = 4

CODEPAGE = 5

OTHERS = 6

.

IF SY-SUBRC <> 0.

W_ERREUR = W_ERREUR + 1.

ENDIF.

ENDFORM. "CLOSE_FORM

* ENDLOOP. " CLOSE_FORM

* &---------------------------------------------------------------------*

* & Form CONVERSION spool to pdf format

* &---------------------------------------------------------------------*

* text

* ----------------------------------------------------------------------*

* --> p1 text

* <-- p2 text

* ----------------------------------------------------------------------*

FORM CONVERSION .

DATA: l_xstring TYPE xstring.

CALL FUNCTION 'CONVERT_OTF'

EXPORTING

FORMAT = 'PDF'

MAX_LINEWIDTH = 132

* ARCHIVE_INDEX = ' '

* COPYNUMBER = 0

* ASCII_BIDI_VIS2LOG = ' '

* PDF_DELETE_OTFTAB = ' '

* PDF_USERNAME = ' '

IMPORTING

BIN_FILESIZE = BINFILESIZE

BIN_FILE = l_xstring

TABLES

OTF = T_OTF

LINES = PDFTAB[] "SAPscript: Text LINES

* EXCEPTIONS

* ERR_MAX_LINEWIDTH = 1

* ERR_FORMAT = 2

* ERR_CONV_NOT_POSSIBLE = 3

* ERR_BAD_OTF = 4

* OTHERS = 5

.

IF sy-subrc = 0.

DATA send_request TYPE REF TO cl_bcs. "CLASS INTERFACE - Business Communication Service

DATA document TYPE REF TO cl_document_bcs. "CLASS INTERFACE - Wrapper Class for Office Documents

DATA recipient TYPE REF TO if_recipient_bcs. "INTERFACE - Interface of Recipient Object in BCS

DATA bcs_exception TYPE REF TO cx_bcs. "CLASS INTERFACE - CX_STATIC_CHECK.

DATA pdf_size TYPE so_obj_len. "Size of Document Contents

DATA pdf_content TYPE solix_tab. "GBT: SOLIX as Table Type

DATA pdf_xstring TYPE xstring.

DATA sent_to_all TYPE os_boolean.

DATA: l_document TYPE REF TO cl_document_bcs. " Mail body

TRY.

*-------- create persistent send request ------------------------

send_request = cl_bcs=>create_persistent( ).

*-------- create and set document -------------------------------

pdf_content = cl_bcs_convert=>xstring_to_solix( l_xstring ).

pdf_size = BINFILESIZE . "v_len_in.

DATA:l_text TYPE bcsy_text. " Mail body

APPEND 'Hi,' TO l_text.

APPEND 'The vendor master details are attached for further reference.' to l_text.

Append 'Regards,' to l_text.

APPEND 'Meenakshi.' to l_text.

* append 'Hello world!' to text.

document = cl_document_bcs=>create_document(

i_type = 'RAW'

i_text = l_text

i_length = '12'

i_subject = 'Vendor Master details') .

CALL METHOD document->add_attachment

EXPORTING

i_attachment_type = 'PDF'

i_attachment_subject = 'Vendor Master Details'

i_att_content_hex = pdf_content.

* add document object to send request

send_request->set_document( document ).

* --------- add recipient (e-mail address) -----------------------

* create recipient object

recipient = cl_cam_address_bcs=>create_internet_address( p_email ).

* add recipient object to send request

send_request->add_recipient( recipient ).

SEND_REQUEST->SET_SEND_IMMEDIATELY( 'X' ).

* ---------- send document ---------------------------------------

sent_to_all = send_request->send( i_with_error_screen = 'X' ).

COMMIT WORK.

IF sent_to_all IS INITIAL.

MESSAGE i500(sbcoms) WITH p_email.

ELSE.

MESSAGE s022(so).

ENDIF.

* ------------ exception handling ----------------------------------

* replace this rudimentary exception handling with your own one !!!

CATCH cx_bcs INTO bcs_exception.

MESSAGE i865(so) WITH bcs_exception->error_type.

ENDTRY.

ENDIF.

ENDFORM.

Here the problem iam facing is for incorrect email also the input showing the message that 'document was send'....pls reply me