Actually I have a problem when I tried to send an email to user from program. This is urgent one. Can I have any suggestions or solutions for this problem from you guys? plz . I welcome to get it as soon as possible. Also I tried to explain as better as I am. If you have any questions or I am not clear , I will explain you for your questions.
Let me explain the problem fully.
1) I need to create a selection screen field for user to enter the email id. - This is done
2)If the user enter the email id and execute the report then I have to email the current output of the report to entered( from selection screen) email id as a text. - This is done
3) Now the user needs the some choice to see the output in email. So he wants to add a check box in selection screen just below the "Email id" field in selection screen. So If the user enter the email id and execute the report without choosing the check box then he would able to see the report's output in the email as text. otherwise the user tick the check box and enter the email id and execute the report then we need to send the report's output as a attachment in the email. So when the person( selection screen email id's owner) opens his email he would like to see the attachemnt then If he opens the attachement he would see the report's output now.
This is the purpose the user needs the check box. - This is done
4) I use FM 'SO_NEW_DOCUMENT_ ATT_SEND_ API1' to send the email as a text to selection screen's email id. - This is done
5) Also I use FM 'SO_NEW_DOCUMENT_ ATT_SEND_ API1' to send the email as a attachment to selection screen's email id. - This is done
6) If the user wants to run this in background and send the email to selection screen's email id(without attachment), then I have to send the report's output to email id as a text. - This is done
7) If the user wants to run this in background and send the email to selection screen's email id(with attachment), then I have to send the report's output to email id as a attachment. - This is not done still. This is partially done. I can able to see the attachment . But If I open the attachment I am seeing only last page of the report's output. I didn't see any other previous pages. If it only one page report then it is ok. But my requirement is more than one page. So I need to send all pages to email as a attachment. I tried it many way. But I could not able to find the solution yet. But If I execute the report in foreground for attachment then I would able to see all the pages in attachment. But I have only problem in BACKGROUND.
I added 2 attachments here. 1) the codes which send the email to email id as a text. 2) the codes which send the email to email id as a attachment.
After look at the below attachment codes plz read this following line.
Also when I used to send the email as a attachment, I used the "SAVE_LIST" FM to catch the current list from memory and compress it through the FM "COMPRESSED_ LIST" and send these internal table records to the EMAIL FM "'SO_NEW_DOCUMENT_ ATT_SEND_ API1". I have read the "SAVE_LIST" FMs documentation too. I have seen that this is not suitable for background emailing. So I think I need any other FMs used here instead of this particular FM or else I would expect any other solutions for this problem.
1) *
DATA: DOC_DATA LIKE SODOCCHGI1,
RECEIVERS LIKE SOMLRECI1 OCCURS 0 WITH HEADER LINE,
PACK LIKE SOPCKLSTI1 OCCURS 0 WITH HEADER LINE,
TXT LIKE SOLISTI1 OCCURS 0 WITH HEADER LINE,
CNT TYPE I,
TEXT LIKE SOLISTI1 OCCURS 0 WITH HEADER LINE,
TAB_LINES LIKE SY-TABIX.
Add all email id's from selection screen in the mailing list one by
one
LOOP AT M_EMAIL.
RECEIVERS-RECEIVER = M_EMAIL-LOW.
RECEIVERS-REC_TYPE = 'U'.
APPEND RECEIVERS.
CLEAR RECEIVERS.
ENDLOOP.
there is no entry in the input then don't call the FM
CHECK NOT RECEIVERS[] IS INITIAL.
*
DO.
CNT = SY-INDEX.
READ LINE SY-INDEX.
IF SY-SUBRC <> 0. EXIT. ENDIF.
TEXT-LINE = SY-LISEL.
APPEND TEXT.
IF CNT > 5500.
REFRESH TEXT.
CLEAR TEXT.
TEXT-LINE = 'Report too large for SAP.'.
APPEND TEXT.
EXIT.
ENDIF.
ENDDO.
*
DOC_DATA-OBJ_DESCR = 'Report as a text'.
DESCRIBE TABLE TEXT LINES TAB_LINES.
DOC_DATA-DOC_SIZE = TAB_LINES * 255.
Creation of the entry for the compressed document
CLEAR PACK-TRANSF_BIN.
PACK-HEAD_START = 1.
PACK-HEAD_NUM = 0.
PACK-BODY_START = 1.
PACK-BODY_NUM = TAB_LINES.
PACK-DOC_TYPE = 'RAW'.
APPEND OBJPACK.
CLEAR OBJPACK.
*
object for showing the report's text
OBJTXT = ' Report as a text'.
APPEND TXT.
CLEAR TXT.
*
New FM to mail the user & directly to email id
CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
EXPORTING
DOCUMENT_DATA = DOC_DATA
PUT_IN_OUTBOX = 'X'
COMMIT_WORK = 'X'
TABLES
PACKING_LIST = PACK
OBJECT_HEADER = TXT
CONTENTS_TXT = TEXT
RECEIVERS = RECEIVERS.
COMMIT WORK.
*
***********************************************************************************************
2)
Structures for recipient addresses
Structures and internal tables for the send data
DATA: pack LIKE sopcklsti1 OCCURS 2 WITH HEADER LINE.
DATA: head LIKE solisti1 OCCURS 1 WITH HEADER LINE.
DATA: bin LIKE solisti1 OCCURS 0 WITH HEADER LINE.
DATA: txt LIKE solisti1 OCCURS 10 WITH HEADER LINE.
DATA: reclist LIKE somlreci1 OCCURS 5 WITH HEADER LINE.
DATA: doc_chng LIKE sodocchgi1.
DATA: tab_lines LIKE sy-tabix.
*
DATA: user_address LIKE sousradri1 OCCURS 1 WITH HEADER LINE.
DATA: sent_to_all LIKE sonv-flag.
clear listobject[].
clear compress_list[].
.
CALL FUNCTION 'SAVE_LIST'
EXPORTING
list_index = sy-lsind
TABLES
listobject = listobject
EXCEPTIONS
list_index_invalid = 1.
*
IF sy-subrc = 1.
WRITE: 'Error in save_list.'.
ENDIF.
It's always necessary to compress the list
CALL FUNCTION 'TABLE_COMPRESS'
TABLES
in = listobject
out = compress_list
EXCEPTIONS
compress_error = 1
OTHERS = 2.
IF sy-subrc <> 0.
WRITE: 'Error in table_compress.'.
ENDIF.
*move list to office table objbin
MOVE compress_list[] TO bin[].
Create the document which is to be sent
doc_chng-obj_name = 'List'.
doc_chng-obj_descr = 'Report list'.
*
DESCRIBE TABLE txt LINES tab_lines.
READ TABLE txt INDEX tab_lines.
doc_chng-doc_size = ( tab_lines - 1 ) * 255 + STRLEN( txt ).
Fill the fields of the packing_list for the main document:
CLEAR pack-transf_bin.
pack-head_start = 1.
pack-head_num = 0.
pack-body_start = 1.
pack-body_num = tab_lines.
pack-doc_type = 'TXT'.
APPEND pack.
Create the attachment (the list itself)
DESCRIBE TABLE bin LINES tab_lines.
It is binary document
MOVE compressed_list[] to bin[].
pack-transf_bin = 'X'.
pack-head_start = 1.
pack-head_num = 0.
pack-body_start = 1.
pack-body_num = tab_lines.
pack-doc_type = 'ALI'
pack-obj_name = 'Attachment'.
pack-obj_descr = 'Report for email attachment'.
pack-doc_size = tab_lines * 255.
APPEND pack.
Add all email id's in the mailing list one by one
LOOP AT M_EMAIL.
RECLIST-RECEIVER = M_EMAIL-LOW.
RECLIST-REC_TYPE = 'U'.
APPEND RECLIST.
CLEAR RECLIST.
ENDLOOP.
CHECK sy-subrc = 0.
****
CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
EXPORTING
document_data = doc_chng
put_in_outbox = 'X'
commit_work = 'X'
IMPORTING
sent_to_all = sent_to_all
TABLES
packing_list = pack
object_header = head
contents_bin = bin
contents_txt = txt
receivers = reclist
EXCEPTIONS
too_many_receivers = 1
document_not_sent = 2
operation_no_authorization = 4
OTHERS = 99.