Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

Unable to convert spool into excel format for sending mail

Hi, i have a requirement in which i have to submit a program to spool and read the spool data and send it as an excel attachment via mail. i am using RSPO_RETURN_SPOOLJOB to read the spool data and am passing the internal table to the FM SO_NEW_DOCUMENT_ATT_SEND_API1 to create the attachment. however the problem i am facing is that, the spool internal table has data in wierd format and my excel attachment is not coming in ascii readable format, its in the same format as in the spool itab. Even if am coverting the spool into hexadecimal using FM SO_SOLITAB_TO_SOLIXTAB and passing it to the send mail FM still i get the same excel data. The attachment is getting created and mail is also being sent but the excel contains data in unrecognizable format.I don't know how to convert this spool data into readable format. plz help me figure it out..

*****

FORM read_spool .

IF NOT w_spoolno IS INITIAL.

CALL FUNCTION 'RSPO_RETURN_SPOOLJOB'

EXPORTING

rqident = w_spoolno "spool number

IMPORTING

real_type = w_doc_type

TABLES

buffer = t_compressed_list

EXCEPTIONS

no_such_job = 1

job_contains_no_data = 2

selection_empty = 3

no_permission = 4

can_not_access = 5

read_error = 6

type_no_match = 7

OTHERS = 8.

ENDIF.

CALL FUNCTION 'SO_SOLITAB_TO_SOLIXTAB'

EXPORTING

ip_solitab = t_compressed_list

IMPORTING

ep_solixtab = t_spool_hex.

ENDFORM. " read_spool

*

*

      • Send mail

DATA: lt_packing_list TYPE STANDARD TABLE OF

sopcklsti1 WITH HEADER LINE,

lt_objhead TYPE STANDARD TABLE OF solisti1 WITH HEADER LINE,

lt_objbin TYPE STANDARD TABLE OF solisti1 WITH HEADER LINE,

lt_objtxt TYPE STANDARD TABLE OF solisti1 WITH HEADER LINE,

lt_reclist TYPE STANDARD TABLE OF somlreci1 WITH HEADER LINE.

DATA: doc_chng LIKE sodocchgi1 ,

lw_tab_lines LIKE sy-tabix,

lw_doc_type LIKE soodk-objtp.

  • Data for the status output after sending

DATA: lt_user_address TYPE STANDARD TABLE OF sousradri1

WITH HEADER LINE.

DATA: lw_sent_to_all LIKE sonv-flag.

&----


*& Form send_mail

&----


FORM send_mail .

lw_doc_type = 'XLS'.

  • Create the document which is to be sent

doc_chng-obj_name = 'List'.

doc_chng-obj_descr = w_subject. "Subject

doc_chng-obj_langu = sy-langu.

  • Fill the document data and get size of attachment

LOOP AT t_message.

lt_objtxt = t_message-line.

APPEND lt_objtxt.

ENDLOOP.

DESCRIBE TABLE lt_objtxt LINES lw_tab_lines.

IF lw_tab_lines GT 0.

READ TABLE lt_objtxt INDEX lw_tab_lines.

doc_chng-doc_size = ( lw_tab_lines - 1 ) * 255 + STRLEN( lt_objtxt )

.

doc_chng-obj_langu = sy-langu.

doc_chng-sensitivty = 'F'.

ELSE.

doc_chng-doc_size = 0.

ENDIF.

  • Fill Packing List For the body of e-mail

lt_packing_list-head_start = 1.

lt_packing_list-head_num = 0.

lt_packing_list-body_start = 1.

lt_packing_list-body_num = lw_tab_lines.

lt_packing_list-doc_type = 'RAW'.

APPEND lt_packing_list.

  • Create the attachment (the list itself)

DESCRIBE TABLE lt_objbin LINES lw_tab_lines.

CLEAR lw_tab_lines.

  • DESCRIBE TABLE t_spool_hex LINES lw_tab_lines.

  • Fill the fields of the packing_list for creating the attachment:

  • It is binary document

lt_packing_list-transf_bin = 'X'.

lt_packing_list-head_start = 1.

lt_packing_list-head_num = 1.

  • But a body

lt_packing_list-body_start = 1.

lt_packing_list-body_num = lw_tab_lines.

  • of type DOC_TYPE

lt_packing_list-doc_type = lw_doc_type.

lt_packing_list-obj_name = 'Attachment'.

lt_packing_list-obj_descr = w_docdesc.

  • lt_packing_list-doc_size = lw_tab_lines * 255.

APPEND lt_packing_list.

  • Fill the mail recipient list

lt_reclist-rec_type = 'U'.

LOOP AT t_recipient_list.

lt_reclist-receiver = t_recipient_list-address.

APPEND lt_reclist.

ENDLOOP.

CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'

EXPORTING

document_data = doc_chng

put_in_outbox = 'X'

commit_work = 'X'

IMPORTING

sent_to_all = lw_sent_to_all

TABLES

packing_list = lt_packing_list

object_header = lt_objhead

contents_txt = lt_objtxt

contents_hex = t_spool_hex

receivers = lt_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

.

Tags:
Former Member

Helpful Answer

by
Not what you were looking for? View more on this topic or Ask a question