Skip to Content
0
Oct 25, 2012 at 08:43 PM

Problems creating a PDF attachment using FM SO_DYNP_OBJECT_SEND

854 Views

Hi,

I have a requirement to create a new QM action to allow users send shop papers to users as well as other documents. The requirement is to pre-attach a shop paper, SAPscript, as an attachment to the SO_DYNP_OBJECT_SEND function module , and to allow the user to enter the title, message note, as well as adding any other attachments as needed.

FM SO_DYNP_OBJECT_SEND works well for this purpose as I am able to add the shop paper to the FM in a preliminary step, and allow the user to update the title, message texts, and add additional attachments. My problem is that the SAPscript attachment is not readable when received by the receiver. I get an Adobe Reader error saying that it could not open the file because the file had been damaged, or it wasn’t correctly decoded. My guess is that I have done something wrong with the packing list, but I am not entirely sure what the problem is.

Below is the test code I am using for this project.. Any help with this issue is greatly appreciated, as I am running out of ideas as to what the problem is.

Thanks,

Roy

<abap> that creates the SAPscript form

CALL FUNCTION 'CLOSE_FORM'

IMPORTING

RESULT = itcpp

TABLES

otfdata = otfdata

EXCEPTIONS

unopened = 1

bad_pageformat_for_print = 2

OTHERS = 3.

IF sy-subrc = 0.

CALL FUNCTION 'CONVERT_OTF'

EXPORTING

format = c_format_pdf

IMPORTING

bin_filesize = g_filesize

TABLES

otf = otfdata

lines = g_pdf_tab

EXCEPTIONS

err_max_linewidth = 1

err_format = 2

err_conv_not_possible = 3

OTHERS = 4.

CALL FUNCTION 'QCE1_CONVERT'

TABLES

t_source_tab = g_pdf_tab

t_target_tab = objbin.

* Make each line 255 characters

CALL FUNCTION 'SX_TABLE_LINE_WIDTH_CHANGE'

TABLES

content_in = objbin

content_out = objbin2.

LOOP AT objbin2.

MOVE-CORRESPONDING objbin2 TO attach_content.

APPEND attach_content.

ENDLOOP.

* Mail body

APPEND 'Message content' TO message_content.

objhead = 'PDFattch.pdf'.

APPEND objhead.

* Packing List

attach_list-transf_bin = 'X'.

attach_list-head_start = 1.

attach_list-head_num = 0.

attach_list-body_start = 1.

attach_list-objtp = 'RAW'. " 'BIN' 'EXT' 'PDF' 'RAW' 'SCR' 'RAW'...

attach_list-objdes = 'PDFattachment'.

attach_list-objla = sy-langu.

DESCRIBE TABLE g_pdf_tab LINES sy-tfill.

attach_list-body_num = sy-tfill.

attach_list-objnam = 'PDFattachment'. "Attachment

attach_list-objlen = attach_list-body_num * 255.

attach_list-file_ext = 'PDF'.

APPEND attach_list.

* Receivers

CLEAR receiver_list.

receiver_list-recextnam = 'testuser@sfc.com'.

receiver_list-adr_name = 'testuser@sfc.com'.

* EMAIL ADDRESS

receiver_list-recesc = 'E'. "<-

receiver_list-sndart = 'INT'."<-

receiver_list-sndpri = '1'."

APPEND receiver_list.

CALL FUNCTION 'SO_DYNP_OBJECT_SEND'

EXPORTING

outbox_flag = 'S'

raw_editor = 'X'

IMPORTING

return_code = lv_rc

TABLES

** objcont = message_content

** objhead = objhead

rec_tab = receiver_list

packing_list = attach_list

att_cont = attach_content

*** att_head = attach_header

EXCEPTIONS

object_not_sent = 1

owner_not_exist = 2

parameter_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.

ENDIF.

ENDFORM. " SEND_SAPSCRIPT