2008 Apr 23 3:42 PM
Hi Experts,
I am trying to send a PDF form as a mail attachment from my SAP R/3 server (version ECC 6.0)
Using the following code:
PARAMETER : p_addr TYPE adr6-smtp_addr DEFAULT 'ashish.shah xyz.com'.
*"Look up the generated function for the Book Flight Form
DATA : l_name TYPE funcname.
TRY.
CALL FUNCTION 'FP_FUNCTION_MODULE_NAME'
EXPORTING
i_name = 'Z_CUST_BOOK_FLIGHT_FORM'
IMPORTING
e_funcname = l_name
EXCEPTIONS
OTHERS = 0.
CATCH cx_fp_api_repository. "#EC NO_HANDLER
CATCH cx_fp_api_usage. "#EC NO_HANDLER
CATCH cx_fp_api_internal. "#EC NO_HANDLER
ENDTRY.
DATA : l_outputparams TYPE sfpoutputparams.
*"Start form processing
l_outputparams-getpdf = 'X'.
CALL FUNCTION 'FP_JOB_OPEN'
CHANGING
ie_outputparams = l_outputparams
EXCEPTIONS
cancel = 1
usage_error = 2
system_error = 3
internal_error = 4
OTHERS = 5.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
*" Call the generated function for the Book Flight Form
DATA : fp_docparams TYPE sfpdocparams,
reservedonly TYPE bapisbodat-reserved,
booking_data TYPE bapisbonew,
fp_result TYPE fpformoutput.
fp_docparams-fillable = 'X'.
fp_docparams-langu = sy-langu.
CALL FUNCTION l_name
EXPORTING
/1bcdwb/docparams = fp_docparams
reserved = reservedonly
booking_data = booking_data
IMPORTING
/1bcdwb/formoutput = fp_result
EXCEPTIONS
usage_error = 1
system_error = 2
internal_error = 3
OTHERS = 4.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
DATA : pdf TYPE fpformoutput-pdf.
pdf = fp_result-pdf.
*"End the form Processing session
CALL FUNCTION 'FP_JOB_CLOSE'
EXCEPTIONS
usage_error = 1
system_error = 2
internal_error = 3
OTHERS = 4.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
*"Create and send the email
DATA : bcs_exception TYPE REF TO cx_bcs.
TRY.
*"Add text to the email body
DATA : l_subject TYPE so_obj_des,
l_mailtext TYPE bcsy_text,
l_mailtext_row TYPE soli.
l_subject = 'Trip Creation Form'.
CONCATENATE 'Please fill out the form and return it to:'
'ashish.shah xyz.com'
INTO l_mailtext_row.
APPEND l_mailtext_row TO l_mailtext.
*"Create the email document
DATA : document TYPE REF TO cl_document_bcs,
num_rows TYPE i,
textlength TYPE so_obj_len.
DESCRIBE TABLE l_mailtext LINES num_rows.
num_rows = num_rows * 255.
MOVE num_rows TO textlength.
document = cl_document_bcs=>create_document(
i_type = 'RAW'
i_text = l_mailtext
i_length = textlength
i_subject = l_subject ).
*"Add ataachment
DATA : attdoctype TYPE soodk-objtp,
atttitle TYPE sood-objdes,
attsize TYPE sood-objlen,
pdftab TYPE solix_tab.
attdoctype = 'pdf'.
atttitle = 'CreateFlight'.
attsize = XSTRLEN( pdf ).
pdftab = cl_document_bcs=>xstring_to_solix(
ip_xstring = pdf ).
document->add_attachment( EXPORTING i_attachment_type = attdoctype
i_attachment_subject = atttitle
i_attachment_size = attsize
i_attachment_language = sy-langu
i_att_content_hex = pdftab ).
*"Create persistent send request
DATA : send_request TYPE REF TO cl_bcs.
send_request = cl_bcs=>create_persistent( ).
*"Add document to send request
send_request->set_document( document ).
*"Get sender object
DATA : sender TYPE REF TO cl_sapuser_bcs.
sender = cl_sapuser_bcs=>create( 'A146861' ) .
*"Add sender
CALL METHOD send_request->set_sender
EXPORTING
i_sender = sender.
*"Create recipient
DATA : recipient TYPE REF TO if_recipient_bcs.
recipient = cl_cam_address_bcs=>create_internet_address(
p_addr ).
*"Add recipient with its respective attributes to send request
send_request->add_recipient( EXPORTING i_recipient = recipient ).
*"Set send immediately
send_request->set_send_immediately( 'X' ).
*"Send document
send_request->send( ).
COMMIT WORK.
WRITE: 'Email coantaining the Interactive form was sent'.
CATCH cx_bcs INTO bcs_exception.
DATA : ex_msg TYPE string.
ex_msg = bcs_exception->get_text( ).
WRITE: 'Caught exception.', ex_msg.
ENDTRY.
I get a Mail sending failure notification in my SAP Businesss work place, with the title "Cannot be sent: Trip Creation Form " With status as :
Status for Recipient ashish.shah xyz.com:
No delivery to ashish.shah xyz.com, invalid recipient address
I have entered the correct Email IDs, but still getting this error.
Can you guys help?
Regards,
Ashish Shah
Hi Experts,
I am trying to send a PDF form as a mail attachment from my SAP R/3 server (version ECC 6.0)
Using the following code:
PARAMETER : p_addr TYPE adr6-smtp_addr DEFAULT 'ashish.shah xyz.com'.
*"Look up the generated function for the Book Flight Form
DATA : l_name TYPE funcname.
TRY.
CALL FUNCTION 'FP_FUNCTION_MODULE_NAME'
EXPORTING
i_name = 'Z_CUST_BOOK_FLIGHT_FORM'
IMPORTING
e_funcname = l_name
EXCEPTIONS
OTHERS = 0.
CATCH cx_fp_api_repository. "#EC NO_HANDLER
CATCH cx_fp_api_usage. "#EC NO_HANDLER
CATCH cx_fp_api_internal. "#EC NO_HANDLER
ENDTRY.
DATA : l_outputparams TYPE sfpoutputparams.
*"Start form processing
l_outputparams-getpdf = 'X'.
CALL FUNCTION 'FP_JOB_OPEN'
CHANGING
ie_outputparams = l_outputparams
EXCEPTIONS
cancel = 1
usage_error = 2
system_error = 3
internal_error = 4
OTHERS = 5.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
*" Call the generated function for the Book Flight Form
DATA : fp_docparams TYPE sfpdocparams,
reservedonly TYPE bapisbodat-reserved,
booking_data TYPE bapisbonew,
fp_result TYPE fpformoutput.
fp_docparams-fillable = 'X'.
fp_docparams-langu = sy-langu.
CALL FUNCTION l_name
EXPORTING
/1bcdwb/docparams = fp_docparams
reserved = reservedonly
booking_data = booking_data
IMPORTING
/1bcdwb/formoutput = fp_result
EXCEPTIONS
usage_error = 1
system_error = 2
internal_error = 3
OTHERS = 4.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
DATA : pdf TYPE fpformoutput-pdf.
pdf = fp_result-pdf.
*"End the form Processing session
CALL FUNCTION 'FP_JOB_CLOSE'
EXCEPTIONS
usage_error = 1
system_error = 2
internal_error = 3
OTHERS = 4.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
*"Create and send the email
DATA : bcs_exception TYPE REF TO cx_bcs.
TRY.
*"Add text to the email body
DATA : l_subject TYPE so_obj_des,
l_mailtext TYPE bcsy_text,
l_mailtext_row TYPE soli.
l_subject = 'Trip Creation Form'.
CONCATENATE 'Please fill out the form and return it to:'
'ashish.shah xyz.com'
INTO l_mailtext_row.
APPEND l_mailtext_row TO l_mailtext.
*"Create the email document
DATA : document TYPE REF TO cl_document_bcs,
num_rows TYPE i,
textlength TYPE so_obj_len.
DESCRIBE TABLE l_mailtext LINES num_rows.
num_rows = num_rows * 255.
MOVE num_rows TO textlength.
document = cl_document_bcs=>create_document(
i_type = 'RAW'
i_text = l_mailtext
i_length = textlength
i_subject = l_subject ).
*"Add ataachment
DATA : attdoctype TYPE soodk-objtp,
atttitle TYPE sood-objdes,
attsize TYPE sood-objlen,
pdftab TYPE solix_tab.
attdoctype = 'pdf'.
atttitle = 'CreateFlight'.
attsize = XSTRLEN( pdf ).
pdftab = cl_document_bcs=>xstring_to_solix(
ip_xstring = pdf ).
document->add_attachment( EXPORTING i_attachment_type = attdoctype
i_attachment_subject = atttitle
i_attachment_size = attsize
i_attachment_language = sy-langu
i_att_content_hex = pdftab ).
*"Create persistent send request
DATA : send_request TYPE REF TO cl_bcs.
send_request = cl_bcs=>create_persistent( ).
*"Add document to send request
send_request->set_document( document ).
*"Get sender object
DATA : sender TYPE REF TO cl_sapuser_bcs.
sender = cl_sapuser_bcs=>create( 'A146861' ) .
*"Add sender
CALL METHOD send_request->set_sender
EXPORTING
i_sender = sender.
*"Create recipient
DATA : recipient TYPE REF TO if_recipient_bcs.
recipient = cl_cam_address_bcs=>create_internet_address(
p_addr ).
*"Add recipient with its respective attributes to send request
send_request->add_recipient( EXPORTING i_recipient = recipient ).
*"Set send immediately
send_request->set_send_immediately( 'X' ).
*"Send document
send_request->send( ).
COMMIT WORK.
WRITE: 'Email coantaining the Interactive form was sent'.
CATCH cx_bcs INTO bcs_exception.
DATA : ex_msg TYPE string.
ex_msg = bcs_exception->get_text( ).
WRITE: 'Caught exception.', ex_msg.
ENDTRY.
I get a Mail sending failure notification in my SAP Businesss work place, with the title "Cannot be sent: Trip Creation Form " With status as :
Status for Recipient ashish.shah xyz.com:
No delivery to ashish.shah xyz.com, invalid recipient address
I have entered the correct Email IDs, but still getting this error.
Can you guys help?
Regards,
Ashish Shah
2008 Apr 23 4:08 PM
If you have noticed, We do not see the@ in your email id.
ARe you sure you have the @ in the mail id?
Regards,
Ravi
2008 Apr 24 9:36 AM
Hi Ravi,
I have @ in all the email IDs in my code , but i have removed it from this post.
It seems SDN has implemented some new check - where in it checks for Email IDs in the post and gives error when any email ID is encountered.
Can you now spot anything else , which could be the cause for the status as Invalid receipient?
Regards,
Ashish Shah
2008 Apr 28 10:03 AM
Can anybody help me to resolve this problem?
Regards,
Ashish Shah
2009 Aug 18 10:54 AM
Hi ashish shah,
I had your same problem.
You can use this example program BCS_EXAMPLE_6 in tr se38. It´s very easy and work well.
Regards,
Daniel Zapardiel
| User | Count |
|---|---|
| 3 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |