Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Problem in Email Sending

Former Member
0 Likes
757

Hi All,

i am trying to send smartform output as email. i am getting the email as attachment, but when i try to open that it saying

There was an error opening this document . The file is damaged and could not be repaired.

i am using FM CONVERT_OTF to convert the data into PDF and then converting this to 255.

wa_message-line = 'This is for sending the E-mail to every vendor'.

APPEND wa_message TO it_message.

wa_message-line = 'Regards,'.

APPEND wa_message-line TO it_message.

wa_message-line = 'Sarath.'.

APPEND wa_message-line TO it_message.

gd_doc_data-obj_langu = sy-langu.

DESCRIBE TABLE it_message LINES w_cnt.

READ TABLE it_message INDEX w_cnt.

gd_doc_data-doc_size = ( w_cnt - 1 ) * 255 + STRLEN( it_message ).

gd_doc_data-obj_name = 'SAPRPT'.

gd_doc_data-obj_descr = 'Volume Incentive'.

gd_doc_data-sensitivty = 'F'.

  • Describe the body of the message

CLEAR wa_packing_list.

REFRESH it_packing_list.

CLEAR:wa_packing_list-transf_bin. " = space.

wa_packing_list-head_start = 1.

wa_packing_list-head_num = 0.

wa_packing_list-body_start = 1.

  • DESCRIBE TABLE it_message LINES wa_packing_list-body_num.

wa_packing_list-body_num = w_cnt.

  • DESCRIBE TABLE it_tline2 LINES wa_packing_list-body_num.

wa_packing_list-doc_type = 'RAW'.

APPEND wa_packing_list TO it_packing_list.

  • Describe the attachment info

wa_packing_list-transf_bin = 'X'.

wa_packing_list-head_start = 1.

wa_packing_list-head_num = 1.

wa_packing_list-body_start = 1.

DESCRIBE TABLE it_tline2 LINES wa_packing_list-body_num.

  • DESCRIBE TABLE it_message LINES wa_packing_list-body_num.

wa_packing_list-doc_type = 'PDF'.

wa_packing_list-obj_name = 'Volume Incentive'.

wa_packing_list-obj_descr = 'Volume Incentive'.

READ TABLE it_tline2 INTO wa_tline2 INDEX wa_packing_list-body_num.

wa_packing_list-doc_size = ( wa_packing_list-body_num - 1 ) * 255 + STRLEN( wa_tline2 ) .

APPEND wa_packing_list TO it_packing_list.

*Populating Mail Recepients

wa_receivers-receiver = i am giving the email address.

wa_receivers-rec_type = 'U'.

  • wa_receivers-express = 'X'.

APPEND wa_receivers TO it_receivers.

CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'

EXPORTING

document_data = gd_doc_data

put_in_outbox = 'X'

commit_work = 'X'

TABLES

packing_list = it_packing_list

contents_bin = it_tline2

contents_txt = it_message

receivers = it_receivers

EXCEPTIONS

too_many_receivers = 1

document_not_sent = 2

document_type_not_exist = 3

operation_no_authorization = 4

parameter_error = 5

x_error = 6

enqueue_error = 7

OTHERS = 8.

IF sy-subrc = 0.

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

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

ENDIF.

please let me know on this.

Thanks.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
653

Attach PDF mail in ABAP Program by Mohammed Rasul.S

CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'

EXPORTING

formname = sf_name

IMPORTING

fm_name = fm_name

EXCEPTIONS

no_form = 1

no_function_module = 2

OTHERS = 3.

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 FUNCTION 'SSF_GET_DEVICE_TYPE'

EXPORTING

i_language = sy-langu

i_application = 'SAPDEFAULT'

IMPORTING

e_devtype = g_rspoptype.

Gs_ssfcompop-tdprinter = g_rspoptype.

Gs_ssfctrlop-no_dialog = 'X'.

Gs_ssfctrlop-getotf = 'X'.

CALL FUNCTION fm_name

EXPORTING

control_parameters = gs_ssfctrlop

output_options = gs_ssfcompop

p_bukrs = p_bukrs

p_belnr = p_belnr

p_budat = p_budat

p_lifnr = p_lifnr

g_text = g_text

g_qsatz = g_qsatz

g_qscod = g_qscod

IMPORTING

document_output_info = gs_ssfcrespd

job_output_info = gs_ssfcrescl

job_output_options = gs_ssfcresop

TABLES

t_pay = t_pay

t_bseg = t_bseg

t_mseg = t_mseg

t_t052u = t_t052u

EXCEPTIONS

formatting_error = 1

internal_error = 2

send_error = 3

user_canceled = 4

OTHERS = 5.

CALL FUNCTION 'CONVERT_OTF'

EXPORTING

format = 'PDF'

max_linewidth = 132

IMPORTING

bin_filesize = g_bin_filesize

TABLES

otf = gs_ssfcrescl-otfdata

lines = t_lines

EXCEPTIONS

err_max_linewidth = 1

err_format = 2

err_conv_not_possible = 3

OTHERS = 4.

IF sy-subrc NE 0.

ENDIF.

DATA: lt_mailrecipients TYPE STANDARD TABLE OF somlrec90 WITH HEADER LINE,

lt_mailtxt TYPE STANDARD TABLE OF soli WITH HEADER LINE,

lt_attachment TYPE STANDARD TABLE OF solisti1 WITH HEADER LINE,

lt_mailsubject TYPE sodocchgi1,

lt_packing_list TYPE STANDARD TABLE OF sopcklsti1 WITH HEADER LINE,

reclist TYPE STANDARD TABLE OF somlreci1 WITH HEADER LINE,

gv_cnt TYPE i.

REFRESH: lt_mailrecipients,lt_mailtxt,lt_attachment,lt_packing_list,reclist.

CLEAR: lt_mailsubject, gv_cnt.

*Convert into 255 line

CALL FUNCTION 'SX_TABLE_LINE_WIDTH_CHANGE'

EXPORTING

line_width_dst = 255

TABLES

content_in = t_lines

content_out = lt_attachment.

*Put in the Mail Contents

lt_mailtxt = 'Following Payment Document Detail is Attached with this mail'.

APPEND lt_mailtxt.

CLEAR lt_mailtxt.

CONCATENATE 'Vendor Number : ' p_lifnr INTO lt_mailtxt RESPECTING BLANKS.

APPEND lt_mailtxt.

CLEAR lt_mailtxt.

CONCATENATE 'Company Code : ' p_bukrs INTO lt_mailtxt RESPECTING BLANKS.

APPEND lt_mailtxt.

CLEAR lt_mailtxt.

CONCATENATE 'Payment Doc No : ' p_belnr INTO lt_mailtxt RESPECTING BLANKS.

APPEND lt_mailtxt.

CLEAR lt_mailtxt.

CONCATENATE 'Fiscal Year : ' p_gjahr INTO lt_mailtxt RESPECTING BLANKS.

APPEND lt_mailtxt.

CLEAR lt_mailtxt.

DATA: g_tprdate(10) TYPE c.

CONCATENATE p_budat6(2) p_budat4(2) p_budat+0(4) INTO g_tprdate SEPARATED BY '.'.

CONCATENATE 'Posting Date : ' g_tprdate INTO lt_mailtxt RESPECTING BLANKS.

APPEND lt_mailtxt.

CLEAR lt_mailtxt.

*Pack the mail contents and attachment

lt_packing_list-transf_bin = space.

Lt_packing_list-head_start = 1.

Lt_packing_list-head_num = 0.

Lt_packing_list-body_start = 1.

Lt_packing_list-body_num = LINES ( lt_mailtxt ).

Lt_packing_list-doc_type = 'RAW'.

APPEND lt_packing_list. CLEAR lt_packing_list.

*

Lt_packing_list-transf_bin = 'X'.

Lt_packing_list-head_start = 1.

Lt_packing_list-head_num = 1.

Lt_packing_list-body_start = 1.

Lt_packing_list-body_num = STRLEN( lt_attachment ).

Lt_packing_list-doc_type = 'PDF'.

  • You can give RAW incase if you want just a txt file.

Lt_packing_list-obj_name = 'ZIVDOC.PDF'.

Lt_packing_list-obj_descr = 'ZIVDOC.PDF'.

Lt_packing_list-doc_size = lt_packing_list-body_num * 255.

APPEND lt_packing_list. CLEAR lt_packing_list.

*

Lt_mailsubject-obj_name = 'MAILATTCH'.

Lt_mailsubject-obj_langu = sy-langu.

Lt_mailsubject-obj_expdat = sy-datum + 20.

Lt_mailsubject-obj_descr = 'You have got mail'.

Lt_mailsubject-sensitivty = 'F'.

gv_cnt = LINES( lt_attachment ).

Lt_mailsubject-doc_size = ( gv_cnt - 1 ) * 255 + STRLEN(

lt_attachment ).

CLEAR reclist.

Reclist-receiver = sy-uname.

Reclist-rec_type = ' '."If my sap inbox

APPEND reclist.

CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'

EXPORTING

document_data = lt_mailsubject

  • put_in_outbox = 'X'

commit_work = 'X'

TABLES

packing_list = lt_packing_list

contents_bin = lt_attachment

contents_txt = lt_mailtxt

receivers = reclist

EXCEPTIONS

too_many_receivers = 1

document_not_sent = 2

document_type_not_exist = 3

operation_no_authorization = 4

parameter_error = 5

x_error = 6

enqueue_error = 7

OTHERS = 8.

IF sy-subrc NE 0.

MESSAGE 'Mail Sending Failed' TYPE 'I'.

ELSE.

MESSAGE 'Mail Sent Successfully' TYPE 'I'.

ENDIF.

Regards,

Mohammed Rasul.S

5 REPLIES 5
Read only

Former Member
0 Likes
653

Hi;

Do one thing, after conversion, please download the PDF locally and then try to open it.

else sample code can be found http://www.sap-img.com/smartforms/conversion-of-smartform-output-to-pdf.htm

Regards

Shashi

Read only

0 Likes
653

hi Sashi,

i have done that. when i download it is getting opened.

any how i have solved the issue by using the standard program BCS_EXAMPLE_6 (Send PDF Form by E-Mail).

Thanks for the Answer.

Read only

Former Member
0 Likes
654

Attach PDF mail in ABAP Program by Mohammed Rasul.S

CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'

EXPORTING

formname = sf_name

IMPORTING

fm_name = fm_name

EXCEPTIONS

no_form = 1

no_function_module = 2

OTHERS = 3.

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 FUNCTION 'SSF_GET_DEVICE_TYPE'

EXPORTING

i_language = sy-langu

i_application = 'SAPDEFAULT'

IMPORTING

e_devtype = g_rspoptype.

Gs_ssfcompop-tdprinter = g_rspoptype.

Gs_ssfctrlop-no_dialog = 'X'.

Gs_ssfctrlop-getotf = 'X'.

CALL FUNCTION fm_name

EXPORTING

control_parameters = gs_ssfctrlop

output_options = gs_ssfcompop

p_bukrs = p_bukrs

p_belnr = p_belnr

p_budat = p_budat

p_lifnr = p_lifnr

g_text = g_text

g_qsatz = g_qsatz

g_qscod = g_qscod

IMPORTING

document_output_info = gs_ssfcrespd

job_output_info = gs_ssfcrescl

job_output_options = gs_ssfcresop

TABLES

t_pay = t_pay

t_bseg = t_bseg

t_mseg = t_mseg

t_t052u = t_t052u

EXCEPTIONS

formatting_error = 1

internal_error = 2

send_error = 3

user_canceled = 4

OTHERS = 5.

CALL FUNCTION 'CONVERT_OTF'

EXPORTING

format = 'PDF'

max_linewidth = 132

IMPORTING

bin_filesize = g_bin_filesize

TABLES

otf = gs_ssfcrescl-otfdata

lines = t_lines

EXCEPTIONS

err_max_linewidth = 1

err_format = 2

err_conv_not_possible = 3

OTHERS = 4.

IF sy-subrc NE 0.

ENDIF.

DATA: lt_mailrecipients TYPE STANDARD TABLE OF somlrec90 WITH HEADER LINE,

lt_mailtxt TYPE STANDARD TABLE OF soli WITH HEADER LINE,

lt_attachment TYPE STANDARD TABLE OF solisti1 WITH HEADER LINE,

lt_mailsubject TYPE sodocchgi1,

lt_packing_list TYPE STANDARD TABLE OF sopcklsti1 WITH HEADER LINE,

reclist TYPE STANDARD TABLE OF somlreci1 WITH HEADER LINE,

gv_cnt TYPE i.

REFRESH: lt_mailrecipients,lt_mailtxt,lt_attachment,lt_packing_list,reclist.

CLEAR: lt_mailsubject, gv_cnt.

*Convert into 255 line

CALL FUNCTION 'SX_TABLE_LINE_WIDTH_CHANGE'

EXPORTING

line_width_dst = 255

TABLES

content_in = t_lines

content_out = lt_attachment.

*Put in the Mail Contents

lt_mailtxt = 'Following Payment Document Detail is Attached with this mail'.

APPEND lt_mailtxt.

CLEAR lt_mailtxt.

CONCATENATE 'Vendor Number : ' p_lifnr INTO lt_mailtxt RESPECTING BLANKS.

APPEND lt_mailtxt.

CLEAR lt_mailtxt.

CONCATENATE 'Company Code : ' p_bukrs INTO lt_mailtxt RESPECTING BLANKS.

APPEND lt_mailtxt.

CLEAR lt_mailtxt.

CONCATENATE 'Payment Doc No : ' p_belnr INTO lt_mailtxt RESPECTING BLANKS.

APPEND lt_mailtxt.

CLEAR lt_mailtxt.

CONCATENATE 'Fiscal Year : ' p_gjahr INTO lt_mailtxt RESPECTING BLANKS.

APPEND lt_mailtxt.

CLEAR lt_mailtxt.

DATA: g_tprdate(10) TYPE c.

CONCATENATE p_budat6(2) p_budat4(2) p_budat+0(4) INTO g_tprdate SEPARATED BY '.'.

CONCATENATE 'Posting Date : ' g_tprdate INTO lt_mailtxt RESPECTING BLANKS.

APPEND lt_mailtxt.

CLEAR lt_mailtxt.

*Pack the mail contents and attachment

lt_packing_list-transf_bin = space.

Lt_packing_list-head_start = 1.

Lt_packing_list-head_num = 0.

Lt_packing_list-body_start = 1.

Lt_packing_list-body_num = LINES ( lt_mailtxt ).

Lt_packing_list-doc_type = 'RAW'.

APPEND lt_packing_list. CLEAR lt_packing_list.

*

Lt_packing_list-transf_bin = 'X'.

Lt_packing_list-head_start = 1.

Lt_packing_list-head_num = 1.

Lt_packing_list-body_start = 1.

Lt_packing_list-body_num = STRLEN( lt_attachment ).

Lt_packing_list-doc_type = 'PDF'.

  • You can give RAW incase if you want just a txt file.

Lt_packing_list-obj_name = 'ZIVDOC.PDF'.

Lt_packing_list-obj_descr = 'ZIVDOC.PDF'.

Lt_packing_list-doc_size = lt_packing_list-body_num * 255.

APPEND lt_packing_list. CLEAR lt_packing_list.

*

Lt_mailsubject-obj_name = 'MAILATTCH'.

Lt_mailsubject-obj_langu = sy-langu.

Lt_mailsubject-obj_expdat = sy-datum + 20.

Lt_mailsubject-obj_descr = 'You have got mail'.

Lt_mailsubject-sensitivty = 'F'.

gv_cnt = LINES( lt_attachment ).

Lt_mailsubject-doc_size = ( gv_cnt - 1 ) * 255 + STRLEN(

lt_attachment ).

CLEAR reclist.

Reclist-receiver = sy-uname.

Reclist-rec_type = ' '."If my sap inbox

APPEND reclist.

CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'

EXPORTING

document_data = lt_mailsubject

  • put_in_outbox = 'X'

commit_work = 'X'

TABLES

packing_list = lt_packing_list

contents_bin = lt_attachment

contents_txt = lt_mailtxt

receivers = reclist

EXCEPTIONS

too_many_receivers = 1

document_not_sent = 2

document_type_not_exist = 3

operation_no_authorization = 4

parameter_error = 5

x_error = 6

enqueue_error = 7

OTHERS = 8.

IF sy-subrc NE 0.

MESSAGE 'Mail Sending Failed' TYPE 'I'.

ELSE.

MESSAGE 'Mail Sent Successfully' TYPE 'I'.

ENDIF.

Regards,

Mohammed Rasul.S

Read only

0 Likes
653

hi,

i have done it in the same way as you have given me. but still it is the same.

solved the issue by using the standard program BCS_EXAMPLE_6 (Send PDF Form by E-Mail).

Thanks for the Answer.

Read only

Former Member
0 Likes
653

the proble has been solved using by using the standard program BCS_EXAMPLE_6 (Send PDF Form by E-Mail).