cancel
Showing results for 
Search instead for 
Did you mean: 

regarding the attachment of XLS file containing smartform data through mail

Former Member
0 Kudos
104

HI ,

I am facing problem in the attachment of XLS file with the Smartform data through mail.

We are receiving the mail but the XLS file is not opening properly and the data is not

in proper format.

We are using ECC6 system.

This thing works in SAP 4.6 C

Can anyone please help me regarding this.

We are using function module SX_OBJECT_CONVERT_OTF_RAW' and 'SO_NEW_DOCUMENT_ATT_SEND_API1'.

CALL FUNCTION 'SX_OBJECT_CONVERT_OTF_RAW'

EXPORTING

format_src = 'OTF'

format_dst = 'RAW'

devtype = 'ASCIIPRI'

len_in = w_len_in

  • IMPORTING

LEN_OUT =

TABLES

content_in = t_spool

content_out = objbin

  • EXCEPTIONS

  • ERR_CONV_FAILED = 1

  • OTHERS = 2

CALL FUNCTION 'SO_DOCUMENT_SEND_API1'

EXPORTING

document_data = doc_chng

  • PUT_IN_OUTBOX = ' '

  • sender_address = p$_send

sender_address = p$_sendt

sender_address_type = 'INT'

*{ INSERT RE2K900945 2

COMMIT_WORK = 'X'

*} INSERT

IMPORTING

sent_to_all = sent_to_all

  • NEW_OBJECT_ID =

  • SENDER_ID =

TABLES

packing_list = objpack

object_header = objhead

contents_bin = objbin

contents_txt = objtxt

  • CONTENTS_HEX =

  • OBJECT_PARA =

  • OBJECT_PARB =

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

MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno

WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

ELSE.

WRITE: / 'Excel file was send'(m05).

ENDIF.

Also somewhere I have read that contents_bin has become obsolete and been replaced by contents_hex like :

Filled the OBJPACK like this:

clear objpack-transf_bin.

  • The document needs no header (head_num = 0)

objpack-head_start = 1.

objpack-head_num = 0.

  • but it has a body

objpack-body_start = 1.

objpack-body_num = tab_lines.

  • of type RAW

objpack-doc_type = 'RAW'.

append objpack.

clear tab_lines.

  • create the attachment (the list itself)

describe table objbin lines tab_lines.

objpack-transf_bin = 'X'.

  • The document needs no header (head_num = 0)

objpack-head_start = 1.

objpack-head_num = 0.

  • but it has a body

objpack-body_start = 1.

objpack-body_num = tab_lines.

  • of type RAW

*{ REPLACE RE2K901725 2

*\ objpack-doc_type = 'ZXL'.

    • Begin of Changes - 46C To ECC6 - IN9GUPTA

objpack-doc_type = 'XLS'.

    • End of Changes - 46C To ECC6 - IN9GUPTA

*} REPLACE

objpack-obj_name = 'Payment data'(019).

objpack-obj_descr = 'Payment data'(019).

objpack-doc_size = tab_lines * 255.

append objpack.

*

DATA :

l_hex LIKE solix,

lt_contents_hex LIKE STANDARD TABLE OF solix ,

conv TYPE REF TO cl_abap_conv_out_ce,

l_buffer TYPE xstring,

l_hexa(510) TYPE x,

l_line TYPE string.

LOOP AT objbin INTO l_line.

conv = cl_abap_conv_out_ce=>create( encoding = 'UTF-8' endian = 'B').

CALL METHOD conv->write( data = l_line ).

l_buffer = conv->get_buffer( ).

MOVE l_buffer TO l_hexa.

MOVE l_hexa TO l_hex-line.

APPEND l_hex TO lt_contents_hex.

ENDLOOP.

call function 'SO_NEW_DOCUMENT_ATT_SEND_API1'

exporting

document_data = doc_chng

put_in_outbox = 'X'

*{ INSERT RE2K901149

    • Begin of Changes - 46C To ECC6 - IN9PAVITHRAM

COMMIT_WORK = 'X'

    • End of Changes - 46C To ECC6 - IN9PAVITHRAM

*} INSERT

importing

sent_to_all = sent_to_all

tables

packing_list = objpack

object_header = objhead

*{ REPLACE RE2K901725

*\ contents_bin = objbin

    • Begin of Changes - 46C To ECC6 - IN9GUPTA

contents_hex = lt_contents_hex

    • End of Changes - 46C To ECC6 - IN9GUPTA

*} REPLACE

contents_txt = objtxt

receivers = reclist

exceptions

too_many_receivers = 1

document_not_sent = 2

operation_no_authorization = 4

others = 99.

Can anyone help me in this regarding and guide me where I am going wrong.....

I am not getting the proper data in XLS file .

Regards,

Amit Gupta

Accepted Solutions (0)

Answers (1)

Answers (1)

Former Member
0 Kudos

Hi Everyone,

I am able to fill the exact data in XLS form in OBJBIN table as I have downloaded the contents of OBJBIN

in Debugging mode as XLS file and the file is opening properly.

The real problem comes when I try to pass the contents of OBJBIN to Function module

SO_DOCUMENT_SEND_API1.

Then mail attachment wont open properly.

So can anyone please help me regarding this.

We are using ECC6 system.

Former Member
0 Kudos

Hi,

Below is the code i already devloped it may useful to you.

*--Start of changes

  • Populate message body text

perform populate_email_message_body.

*--Populate table with details to be entered in .XLS file

perform build_attachment.

*--Send file by email as .xls spread sheet.

perform send_file_as_email_attachment tables it_message

it_attach

using

'List of New Products Information'

'XLS'

'filename'

' '

' '

' '

changing gd_error

gd_reciever.

&----


*& Form populate_email_message_body

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


form populate_email_message_body .

refresh it_message.

it_message = 'List of products Information'.

append it_message.

endform. " populate_email_message_body

&----


*& Form BUILD_ATTACHMENT

&----


form build_attachment .

class cl_abap_char_utilities definition load.

constants:

con_tab type c value cl_abap_char_utilities=>horizontal_tab,

con_cret type c value cl_abap_char_utilities=>cr_lf.

concatenate 'Material'(007)

'Description'(008)

'Plant'(009)

'Manufactured in'(010)

'Vendor'(011)

'Product Hierarchy'(012)

'Material Status'(013)

'X-chain material status'(014)

'Procurement Type'(015)

'Special procurement type'(016)

'MRP Type'(017)

  • 'MRP Controller'(018)

'Material Group'(019)

into it_attach separated by con_tab.

*---End of changes by vpattaparla.

concatenate con_cret it_attach into it_attach.

append it_attach.

loop at tab_out_mail into wa_out.

concatenate wa_out-matnr wa_out-maktx wa_out-werks

wa_out-manfc wa_out-lifnr wa_out-prdha

wa_out-mstae wa_out-mstav wa_out-beskz

  • wa_out-sobsl wa_out-dismm wa_out-dispo" vpattaparla.

wa_out-sobsl wa_out-dismm

wa_out-matkl

into it_attach separated by con_tab.

concatenate con_cret it_attach into it_attach.

append it_attach.

clear wa_out.

endloop.

endform. " BUILD_ATTACHMENT

form send_file_as_email_attachment

tables pit_message

pit_attach

using

p_mtitle

p_format

p_filename

p_attdescription

p_sender_address

p_sender_addres_type

changing p_error

p_reciever.

data: ld_error type sy-subrc,

ld_reciever type sy-subrc,

ld_mtitle like sodocchgi1-obj_descr,

ld_email like somlreci1-receiver,

ld_format type so_obj_tp ,

ld_attdescription type so_obj_nam ,

ld_attfilename type so_obj_des ,

ld_sender_address like soextreci1-receiver,

ld_sender_address_type like soextreci1-adr_typ,

ld_receiver like sy-subrc.

  • ld_email = p_email.

ld_mtitle = p_mtitle.

ld_format = p_format.

ld_attdescription = p_attdescription.

  • ld_attfilename = p_filename.

ld_attfilename = 'List of New Products Information'.

ld_sender_address = p_sender_address.

ld_sender_address_type = p_sender_addres_type.

  • Fill the document data.

w_doc_data-doc_size = 1.

  • Populate the subject/generic message attributes

w_doc_data-obj_langu = sy-langu.

w_doc_data-obj_name = 'SAPRPT'.

w_doc_data-obj_descr = 'List of New Products Information'.

w_doc_data-sensitivty = 'F'.

  • Fill the document data and get size of attachment

clear w_doc_data.

describe table it_attach lines w_cnt.

w_doc_data-doc_size =

( w_cnt - 1 ) * 255 + strlen( it_attach ).

w_doc_data-obj_langu = sy-langu.

w_doc_data-obj_name = 'SAPRPT'.

w_doc_data-obj_descr = 'List of New Products Information'.

w_doc_data-sensitivty = 'F'.

clear t_attachment.

refresh t_attachment.

t_attachment[] = pit_attach[].

  • Describe the body of the message

clear t_packing_list.

refresh t_packing_list.

t_packing_list-transf_bin = space.

t_packing_list-head_start = 1.

t_packing_list-head_num = 0.

t_packing_list-body_start = 1.

describe table it_message lines t_packing_list-body_num.

t_packing_list-doc_type = 'RAW'.

append t_packing_list.

  • Create attachment notification

t_packing_list-transf_bin = 'X'.

t_packing_list-head_start = 1.

t_packing_list-head_num = 1.

t_packing_list-body_start = 1.

describe table t_attachment lines t_packing_list-body_num.

t_packing_list-doc_type = ld_format.

  • t_packing_list-obj_descr = ld_attdescription.

t_packing_list-obj_descr = 'List of New Products Information'.

t_packing_list-obj_name = 'List of New Products Information'.

t_packing_list-doc_size = t_packing_list-body_num * 255.

append t_packing_list.

  • Add the recipients email address

clear t_receivers.

refresh t_receivers.

t_receivers-receiver = wa_dri-email.

t_receivers-rec_type = 'U'.

t_receivers-com_type = 'INT'.

t_receivers-notif_del = 'X'.

t_receivers-notif_ndel = 'X'.

append t_receivers.

call function 'SO_DOCUMENT_SEND_API1'

EXPORTING

document_data = w_doc_data

put_in_outbox = 'X'

sender_address = ld_sender_address

sender_address_type = ld_sender_address_type

commit_work = 'X'

TABLES

packing_list = t_packing_list

contents_bin = t_attachment

contents_txt = it_message

receivers = t_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.

  • Populate zerror return code

ld_error = sy-subrc.

  • Populate zreceiver return code

loop at t_receivers.

ld_receiver = t_receivers-retrn_code.

endloop.

refresh: t_attachment,it_message,t_receivers,it_attach.

refresh: tab_out_mail.

clear: w_doc_data.

endform. " send_file_as_email_attachment

Edited by: phani kumar on Sep 4, 2009 9:45 PM

Former Member
0 Kudos

hi Thanks for your reply,

But I guess i am not building excel using horizontal tab and cr_lf , but my excel will be created from my

smartorm data.

If u could help me in that case.....

My real problem is that when I open the file from my mailbox , even in SOST the data inside the excel is in

XML tags....

Bu to my surprise when I download the contents of OBJBIN in debugging mode ,

proper excel file is created with data...

Please help me in this case...

Amit

Sandra_Rossi
Active Contributor
0 Kudos

I guess the problem is related to unicode (2 bytes per character instead of 1 byte in 4.6c, the storage of bytes is maybe different in this parameter, or something like that).

Whatever... Could you try by using CONTENTS_HEX parameter instead of CONTENTS_BIN?