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 with xstring attachment for SO_NEW_DOCUMENT_SEND_API1

Former Member
0 Likes
1,594

Hi folks,

I'm facing a problem with an attached xtring object. The scenario: Web Dynpro application takes file upload as xstring parameter. The parameter is being transfered to backend RFC which should send out an email with the file attached.

unfortunately its not being converted into the right format

I tried to upload a pdf file. Therefore I cut the xtring into 255 pieces and creatae an attachment table.

the doc_type is 'PDF'.

the email gets sent out without errors, I receive the mail, it contains the pdf but when I open it it is corrupted.

see some code:

DATA lv_uploaddata TYPE xstring.

lv_uploaddata = iv_uploaddata.

WHILE NOT lv_uploaddata IS INITIAL.

wa_objtxt = lv_uploaddata.

SHIFT lv_uploaddata BY 255 PLACES.

APPEND wa_objtxt TO lt_attachment.

CLEAR wa_objtxt.

ENDWHILE.

  • attachment

wa_objpack-transf_bin = 'X' .

wa_objpack-head_start = 1.

wa_objpack-head_num = 1.

wa_objpack-body_start = 1.

DESCRIBE TABLE lt_attachment LINES wa_objpack-body_num.

READ TABLE lt_attachment INTO wa_objtxt INDEX lv_table_lines .

wa_objpack-doc_type = 'PDF'.

wa_objpack-obj_descr = 'update_request'.

wa_objpack-obj_name = 'update_request'.

wa_objpack-doc_size =

wa_objpack-body_num * 255 + STRLEN( wa_objtxt ).

APPEND wa_objpack TO it_objpack.

CLEAR wa_objpack.

*-- Sending the EMail document in given format

CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'

EXPORTING

document_data = lv_doc_data

put_in_outbox = c_false

  • commit_work = konst_x

TABLES

packing_list = it_objpack

contents_txt = it_objtxt

contents_bin = lt_attachment

receivers = it_reclist

.

am I doing something wrong?

kind regards

Stefan

5 REPLIES 5
Read only

Former Member
0 Likes
933

use this f.m to convert the otf to pdf...

CALL FUNCTION 'CONVERT_OTF'

EXPORTING

format = 'PDF'

max_linewidth = 132

IMPORTING

bin_filesize = v_len_in

TABLES

otf = i_otf

lines = i_tline.

use below f.m to convert it to 255 char

CALL FUNCTION 'QCE1_CONVERT'

TABLES

t_source_tab = i_tline

t_target_tab = so_ali[]

EXCEPTIONS

convert_not_possible = 1

then pass it to f.m SO_NEW_DOCUMENT_SEND_API1

OTHERS = 2.

Read only

0 Likes
933

what is the use of the function 'CONVERT_OTF'

and what do i need to proide to it what is the otf? is it the table consisting of char255 ?

what if I have different attachments like an xls sheet or word doc I suppose i need dfferent converters I can't find much ressources here.

regards

Stefan

Read only

Former Member
0 Likes
933

lv_uploaddata = iv_uploaddata.

translate lv_uploaddata using '~ '.

WHILE NOT lv_uploaddata IS INITIAL.

I am not sure if this helps but you might want to add the above code and see if it works.

Read only

0 Likes
933

adding translate lv_uploaddata using '~ '. makes the attachment more than twice as big as the original file and I still can't open it

without it the attachment is perfectly sized

Read only

Former Member
0 Likes
933

check this

REPORT zsendemail .

PARAMETERS: psubject(40) type c default 'Hello',

p_email(40) type c default 'write email id' .

data: it_packing_list like sopcklsti1 occurs 0 with header line,

it_contents like solisti1 occurs 0 with header line,

it_receivers like somlreci1 occurs 0 with header line,

it_attachment like solisti1 occurs 0 with header line,

gd_cnt type i,

gd_sent_all(1) type c,

gd_doc_data like sodocchgi1,

gd_error type sy-subrc.

data: it_message type standard table of SOLISTI1 initial size 0

with header line.

***********************************************************************

*START-OF-SELECTION.

START-OF-SELECTION.

Perform populate_message_table.

*Send email message, although is not sent from SAP until mail send

*program has been executed(rsconn01)

PERFORM send_email_message.

*Instructs mail send program for SAPCONNECT to send email(rsconn01)

perform initiate_mail_execute_program.

&----


*& Form POPULATE_MESSAGE_TABLE

&----


  • Adds text to email text table

----


form populate_message_table.

Append 'Email line 1' to it_message.

Append 'Email line 2' to it_message.

Append 'Email line 3' to it_message.

Append 'Email line 4' to it_message.

endform. " POPULATE_MESSAGE_TABLE

&----


*& Form SEND_EMAIL_MESSAGE

&----


  • Send email message

----


form send_email_message.

  • Fill the document data.

gd_doc_data-doc_size = 1.

  • Populate the subject/generic message attributes

gd_doc_data-obj_langu = sy-langu.

gd_doc_data-obj_name = 'SAPRPT'.

gd_doc_data-obj_descr = psubject.

gd_doc_data-sensitivty = 'F'.

  • Describe the body of the message

clear it_packing_list.

refresh it_packing_list.

it_packing_list-transf_bin = space.

it_packing_list-head_start = 1.

it_packing_list-head_num = 0.

it_packing_list-body_start = 1.

describe table it_message lines it_packing_list-body_num.

it_packing_list-doc_type = 'RAW'.

append it_packing_list.

  • Add the recipients email address

clear it_receivers.

refresh it_receivers.

it_receivers-receiver = p_email.

it_receivers-rec_type = 'U'.

it_receivers-com_type = 'INT'.

it_receivers-notif_del = 'X'.

it_receivers-notif_ndel = 'X'.

append it_receivers.

  • Call the FM to post the message to SAPMAIL

call function 'SO_NEW_DOCUMENT_ATT_SEND_API1'

exporting

document_data = gd_doc_data

put_in_outbox = 'X'

importing

sent_to_all = gd_sent_all

tables

packing_list = it_packing_list

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.

  • Store function module return code

gd_error = sy-subrc.

  • Get it_receivers return code

loop at it_receivers.

endloop.

endform. " SEND_EMAIL_MESSAGE

&----


*& Form INITIATE_MAIL_EXECUTE_PROGRAM

&----


  • Instructs mail send program for SAPCONNECT to send email.

----


form initiate_mail_execute_program.

wait up to 2 seconds.

if gd_error eq 0.

submit rsconn01 with mode = 'INT'

with output = 'X'

and return.

endif.

endform. " INITIATE_MAIL_EXECUTE_PROGRAM