on 07-20-2011 3:08 AM
Hi Experts,
I know this topic is very easy & can found solution by a search, But still I am struck at one point need experts advice on the error I am getting below.
I have written a code to convert Smartform as PDF & send Email with some custom "Body" text.
I am getting a strange problem/error.
When I comment the "Message Body" part, my attachment is working very fine. & when I Add message to the Program, my PDF Attachment is getting corrupted.
The code as follow's
Please help me to figure it out where I am committing mistake.
* Create Message Body Title and Description
l_wa_message = 'Dear Finance & Accounts Manager,'.
APPEND l_wa_message TO l_it_message. CLEAR l_wa_message.
APPEND INITIAL LINE TO l_it_message.
l_wa_message = 'Attached please find your latest Order'.
APPEND l_wa_message TO l_it_message. CLEAR l_wa_message.
*****************************************************************
* Message Body Text
DESCRIBE TABLE l_it_message LINES v_lines_txt.
READ TABLE l_it_message INTO l_wa_message INDEX v_lines_txt.
CLEAR l_wa_objpack-transf_bin.
l_wa_objpack-head_start = 1.
l_wa_objpack-head_num = 0.
l_wa_objpack-body_start = 1.
l_wa_objpack-body_num = v_lines_txt.
l_wa_objpack-doc_type = 'RAW'.
APPEND l_wa_objpack TO l_it_objpack.
* PDF Attachment
DESCRIBE TABLE l_it_objbin LINES l_tab_lines.
CLEAR l_wa_objbin.
READ TABLE l_it_objbin INTO l_wa_objbin INDEX l_tab_lines.
l_wa_objpack-doc_size = ( l_tab_lines - 1 ) * 255 + STRLEN( l_wa_objbin ).
l_wa_objpack-transf_bin = 'X'.
l_wa_objpack-head_start = 1.
l_wa_objpack-head_num = 1.
l_wa_objpack-body_start = 1.
l_wa_objpack-body_num = l_tab_lines.
l_wa_objpack-doc_type = 'PDF'.
l_wa_objpack-obj_name = 'Attachment'.
l_wa_objpack-obj_descr = 'ORDER'.
APPEND l_wa_objpack TO l_it_objpack.
l_wa_docdata-obj_name = 'SAPRT'.
l_wa_docdata-expiry_dat = sy-datum + 10.
l_wa_docdata-obj_descr = 'ORDER STATEMENT'.
l_wa_docdata-sensitivty = 'F'.
**********************************************************************************
l_wa_docdata-doc_size = ( v_lines_txt - 1 ) * 255 + STRLEN( l_wa_message ).
" Also tried to replace with the following
l_wa_docdata-doc_size = l_tab_lines * 255 .
" Also tried to replace with the following
l_wa_objpack-doc_size = ( l_tab_lines - 1 ) * 255 + STRLEN( l_wa_objbin ).
**********************************************************************************
* Assigning the email id to Structure of the API Recipient List table
* To External Client EMail ID.
l_wa_reclist-receiver = 'abc at xyz dot com'.
l_wa_reclist-rec_type = 'U'.
APPEND l_wa_reclist TO l_it_reclist.
CLEAR: l_wa_reclist.
* Sending the Form Output in the PDF format to email
CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
EXPORTING
document_data = l_wa_docdata
put_in_outbox = 'X'
commit_work = 'X'
TABLES
packing_list = l_it_objpack
contents_bin = l_it_objbin
contents_txt = l_it_message
receivers = l_it_reclist .
The Error I get in PDF attachment when Message Body is included is "There was an error opening this document. The file is damaged and could not be repaired"
When I comment message Body, The PDF attachment works very fine.
Please suggest me how to rectify the Error.
Links used as reference to build the program.
[Smartform as a PDF to Mail id|http://wiki.sdn.sap.com/wiki/display/Snippets/SmartformasaPDFtoMailid]
[Smartform to Mail as PDF attachment|http://wiki.sdn.sap.com/wiki/display/Snippets/Smartform%20to%20Mail%20as%20PDF%20attachment?bc=true]
Thanks & Regards,
Dileep .C
Same program worked without any changes when system upgraded to EHP5. Really F*ing Strange.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Dileep,
Below is the sample code thru which able to pass the body text successfully.
Please observe this and do the necessary changes in ur code accordingly.Hope it will work out.
Main Text
CLEAR I_OBJPACK-TRANSF_BIN.
I_OBJPACK-HEAD_START = 1.
I_OBJPACK-HEAD_NUM = 0.
I_OBJPACK-BODY_START = 1.
I_OBJPACK-BODY_NUM = V_LINES_TXT.
I_OBJPACK-DOC_TYPE = 'RAW'.
APPEND I_OBJPACK.
Attachment (pdf-Attachment)
I_OBJPACK-TRANSF_BIN = 'X'.
I_OBJPACK-HEAD_START = 1.
I_OBJPACK-HEAD_NUM = 0.
I_OBJPACK-BODY_START = 1.
DESCRIBE TABLE I_OBJBIN LINES V_LINES_BIN.
READ TABLE I_OBJBIN INDEX V_LINES_BIN.
I_OBJPACK-DOC_SIZE = V_LINES_BIN * 255 .
I_OBJPACK-BODY_NUM = V_LINES_BIN.
I_OBJPACK-DOC_TYPE = 'PDF'.
I_OBJPACK-OBJ_NAME = 'smart'.
I_OBJPACK-OBJ_DESCR = 'test'.
APPEND I_OBJPACK.
CLEAR I_RECLIST.
I_RECLIST-RECEIVER =
I_RECLIST-REC_TYPE = 'U'.
APPEND I_RECLIST.
CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
EXPORTING
DOCUMENT_DATA = WA_DOC_CHNG
PUT_IN_OUTBOX = 'X'
COMMIT_WORK = 'X'
TABLES
PACKING_LIST = I_OBJPACK
OBJECT_HEADER = WA_OBJHEAD
CONTENTS_BIN = I_OBJBIN
CONTENTS_TXT = I_OBJTXT
RECEIVERS = I_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.
WRITE:/ 'Error When Sending the File', SY-SUBRC.
ELSE.
WRITE:/ 'Mail sent'.
ENDIF.
Regards,
Sreeram
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
85 | |
10 | |
10 | |
9 | |
7 | |
6 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.