11-07-2007 6:15 AM
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
.
11-07-2007 6:25 AM
Hi Anil,
You will have to use the follwing 2 FM's one after the other in order to make sure that the data is converted to the correct format for sending mail.
SCMS_STRING_TO_FTEXT
SCMS_FTEXT_TO_BINARY
After using the above 2 FM, pass the itab to CONTENTS_HEX in the mail FM.
Thanks
Vijay
<b>PLZ Reward points if helpful</b>
11-07-2007 6:25 AM
Hi Anil,
You will have to use the follwing 2 FM's one after the other in order to make sure that the data is converted to the correct format for sending mail.
SCMS_STRING_TO_FTEXT
SCMS_FTEXT_TO_BINARY
After using the above 2 FM, pass the itab to CONTENTS_HEX in the mail FM.
Thanks
Vijay
<b>PLZ Reward points if helpful</b>
01-30-2008 2:09 PM
Hi Anil Kumar,
I am worndering about the status of this issue. I have a similar requirement. Can you please mail the program to venkat_175@yahoo.com?
Regards,
Venkat.
01-30-2008 6:23 PM
Hi Venkat,
I had to do away with my earlier method of writing the data to spool, instead i exported the data to memory using the FM LIST_FROM_MEMORY.
CALL FUNCTION 'LIST_FROM_MEMORY'
TABLES
listobject = t_listobject
EXCEPTIONS
not_found = 1
OTHERS = 2.
IF sy-subrc <> 0.
MESSAGE e000(su) WITH text-001.
ENDIF.
then i converted it into ASCII using LIST_TO_ASCI,
CALL FUNCTION 'LIST_TO_ASCI'
TABLES
listasci = t_xlstab
listobject = t_listobject
EXCEPTIONS
empty_list = 1
list_index_invalid = 2
OTHERS = 3.
IF sy-subrc NE 0.
MESSAGE e003(yuksdbfzs).
ENDIF.
This gives the data in ASCII format separated by '|' and the header has '-', dashes. If you use this internal table directly without any proccesing in SO_NEW_DOCUMENT_ATT_SEND_API1, then you will not get a good excel sheet attachment. To overcome this limitation, i used cl_abap_char_utilities=>newline and cl_abap_char_utilities=>horizontal_tab to add horizontal and vertical tabs to the internal table, replacing all occurences of '|' with
cl_abap_char_utilities=>horizontal_tab.
Set the doc_type as 'XLS', create the body and header using the packing_list and pass the data to be downloaded to SO_NEW_DOCUMENT_ATT_SEND_API1 as contents_bin.
This will create an excel attachment.
Sample code for formatting the data for the attachment in excel format.
Format the data for excel file download
LOOP AT t_xlstab INTO wa_xlstab .
DESCRIBE TABLE t_xlstab LINES lw_cnt.
CLEAR lw_sytabix.
lw_sytabix = sy-tabix.
If not new line then replace '|' by tabs
IF NOT wa_xlstab EQ cl_abap_char_utilities=>newline.
REPLACE ALL OCCURRENCES OF '|' IN wa_xlstab
WITH cl_abap_char_utilities=>horizontal_tab.
MODIFY t_xlstab FROM wa_xlstab .
CLEAR wa_xlstab.
wa_xlstab = cl_abap_char_utilities=>newline.
IF lw_cnt NE 0 .
lw_sytabix = lw_sytabix + 1.
Insert new line for the excel data
INSERT wa_xlstab INTO t_xlstab INDEX lw_sytabix.
lw_cnt = lw_cnt - 1.
ENDIF.
CLEAR wa_xlstab.
ENDIF.
ENDLOOP.
Sample code for creating attachment and sending mail:
FORM send_mail .
Define the attachment format
lw_doc_type = 'XLS'.
Create the document which is to be sent
lwa_doc_chng-obj_name = 'List'.
lwa_doc_chng-obj_descr = w_subject. "Subject
lwa_doc_chng-obj_langu = sy-langu.
Fill the document data and get size of message
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.
lwa_doc_chng-doc_size = ( lw_tab_lines - 1 ) * 255 + STRLEN( lt_objtxt ).
lwa_doc_chng-obj_langu = sy-langu.
lwa_doc_chng-sensitivty = 'F'.
ELSE.
lwa_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 t_xlstab LINES lw_tab_lines.
Fill the fields of the packing_list for creating the attachment:
lt_packing_list-transf_bin = 'X'.
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 = lw_doc_type.
lt_packing_list-obj_name = 'Attach'.
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.
Finally send E-Mail
CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
EXPORTING
document_data = lwa_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_bin = t_xlstab
contents_txt = lt_objtxt
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.
Hope that this give you an idea on how to do it..
03-11-2008 8:39 PM