Application Development 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: 

How to attach Microsoft 2007 files (.docx, .xlsx) using SO_DYNP_OBJECT_SEND

Former Member
0 Kudos
1,998

Hi,

Would anyone know how to attach a file with extension .docx or .xlsx to an email using function module SO_DYNP_OBJECT_SEND?

I am able to successfully attach .doc or .xls documents.

The problem stems from the fact that the packing list field 'file_ext' takes a 3-character file extension. This will not work for .xlsx or .docx since they are 4-character extension.

I found a few suggestions that said I have to add the filename to the attachment header table....like this:


data: wa_content TYPE soli.
CONCATENATE '&SO_FILENAME=' lv_filename INTO wa_content.
APPEND wa_content TO gt_att_head.

I then pass gt_att_head to fm 'SO_DYNP_OBJEC_SEND'.


   CALL FUNCTION 'SO_DYNP_OBJECT_SEND'
     EXPORTING
       object_hd_change = l_title
       object_type      = 'RAW'
       raw_editor       = abap_true
       starting_at_x    = '5'
       starting_at_y    = '1'
       ending_at_x      = '120'
       ending_at_y      = '20'
       edit_title       = 'X'
       external_commit  = abap_true
     TABLES
       packing_list     = gt_packing_list
       att_head         = gt_att_head
       att_cont         = gt_total_att_cont
       exclude_fcode    = i_exclude_fcode
     EXCEPTIONS
       object_not_sent  = 1
       owner_not_exist  = 2
       parameter_error  = 3
       OTHERS           = 4.

However, when I try to open an .xlsx file, I get the warning:

"Excel found unreadable content in 'TestFC2.xlsx'. Do you want to recover the contents of this workbook? If you trust the source of this workbook, click Yes."

Has anyone else encountered this problem and found a solution?

Thanks,

Jennifer

1 ACCEPTED SOLUTION

andrs_sarcevic
Contributor
0 Kudos
353

Hi Jennifer,

Try the following:


data: wa_content TYPE soli.

lv_filename = 'my_file.xlsx'.
CONCATENATE '&SO_FILENAME=' lv_filename INTO wa_content.
APPEND wa_content TO gt_att_head.
CONCATENATE '&SO_FORMAT=BIN'  INTO wa_content.
APPEND wa_content TO gt_att_head.

Make sure you are sending the file length somewhere. You can calculate it with the following method:


cl_bcs_utilities=>get_file_size( lv_filename ).

Another option... try using 'EXT' instead of 'RAW' for the object_type parameter. Also using 'DOC' or 'XLS' (word or excel extensions without the last 'X') might work.

Also, if you are sending an e-mail, have a look to class CL_BCS. It's newer than the FM and easy to use with plenty of examples.

Cheers,

Andres.

7 REPLIES 7

andrs_sarcevic
Contributor
0 Kudos
354

Hi Jennifer,

Try the following:


data: wa_content TYPE soli.

lv_filename = 'my_file.xlsx'.
CONCATENATE '&SO_FILENAME=' lv_filename INTO wa_content.
APPEND wa_content TO gt_att_head.
CONCATENATE '&SO_FORMAT=BIN'  INTO wa_content.
APPEND wa_content TO gt_att_head.

Make sure you are sending the file length somewhere. You can calculate it with the following method:


cl_bcs_utilities=>get_file_size( lv_filename ).

Another option... try using 'EXT' instead of 'RAW' for the object_type parameter. Also using 'DOC' or 'XLS' (word or excel extensions without the last 'X') might work.

Also, if you are sending an e-mail, have a look to class CL_BCS. It's newer than the FM and easy to use with plenty of examples.

Cheers,

Andres.

0 Kudos
353

Hi Andrés,

Thank you for the suggestions. I did as you said, but it still did not work.


   DATA: wa_content TYPE soli.
   CONCATENATE '&SO_FILENAME=' lv_filename INTO wa_content.
   APPEND wa_content TO gt_att_head.
   CLEAR:wa_content.
   wa_content = '&SO_FORMAT=BIN'.
   APPEND wa_content TO gt_att_head.

I am already sending the obtyp as 'EXT' in the packing list.


* Static data
   gs_packing_list-file_ext = lv_ext.
   gs_packing_list-transf_bin = 'X'.
   gs_packing_list-objla = sy-langu.
   gs_packing_list-objtp = 'EXT'.
   gs_packing_list-objdes = lv_filename.
   gs_packing_list-objnam = 'Attachment'.
   gs_packing_list-head_start = 1.
   gs_packing_list-head_num = 1.

I can see that the document is attached but when I open the XLSX document, I get the error about unreadable content.

Any further suggestions are appreciated.

Thank you,

Jennifer

Former Member
0 Kudos
353

HI friend,

If you face difficulties in sending the mail through that Function module use the class CL_BCS.

Here is my white paper which will guide you the steps for creating an attachment and sending a mail.

Link: [Steps for sending mail with attachement|http://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/e009f97e-ee5d-2e10-31ba-9c9509e5925c?QuickLink=index&overridelayout=true]

This class method is more flexible and more useful when compared to the old traditional method.

If you face nay issues in this please revert back to me i will help you.

Thanks,

Sri Hari

0 Kudos
353

Hi Sri Hari,

Thank you for the link. This information is very valuable. However, I didn't see an example of sending a Microsoft 2007 type file (.docx or .xlsx). Would you happen to have this information?

If using the FM 'SO_DYNP_OBJECT_SEND' doesn't work soon, I will try the CL_BCS route.

Kind regards,

Jennifer

0 Kudos
353

I think you should try CL_BCS. For an example, check program BCS_EXAMPLE_7 and this link: http://wiki.sdn.sap.com/wiki/display/Snippets/SendMailhavingMultipleFilesasAttachmentusingobjectorientedtechnique

Take a look at notes [1459896|https://service.sap.com/sap/support/notes/1459896] and [1151258|https://service.sap.com/sap/support/notes/1151258]. They might help you.

Cheers,

Andres.

former_member198837
Active Participant
0 Kudos
353

Hi Alexander,

Now I have similar issue.

Can you let me know if you got solution for this.

Regards,

Karthik.

0 Kudos
353

Hi Karthik

I had a similar problem using class cl_bcs and used note 1459896 which foxes the system by setting the filename to be &SO_FILENAME=myfile.xlsx in parameter i_attachment_header.  SOST shows the file type as XLS but the email in my inbox has an XLSX.

regards

Ian