‎2009 May 26 5:02 AM
Hi experts,
I created a email program,(smartform output OTF to PDF & download pdf working fine.)
now my problem is i need to send the converted pdf to mail.
but when i send mail, i see in my outbox the mail as still send in process,,,
when i open the Pdf from there it cannot be open and i got a error "There was error in opening. File damaged & could not be repaired."
please help me out what to do.
-Dunlop
‎2009 May 26 8:48 AM
Hi Dunlop,
Try this sample code below.
CALL FUNCTION 'CONVERT_OTF'
EXPORTING
FORMAT='PDF'
IMPORTING
BIN_FILESIZE = V_LEN_IN
TABLES
OTF = I_OTF
LINES = I_TLINE.
LOOP AT I_TLINE.
TRANSLATE I_TLINE USING ' ~'. " Replacing space by ~
CONCATENATE WA_BUFFER I_TLINE INTO WA_BUFFER.
ENDLOOP.
TRANSLATE WA_BUFFER USING '~ '. " Replacing space by ~
DO.
LT_OBJBIN = WA_BUFFER.
APPEND LT_OBJBIN. " Appending 255 characters as a record
SHIFT WA_BUFFER LEFT BY 255 PLACES.
IF WA_BUFFER IS INITIAL.
EXIT.
ENDIF.
ENDDO.
DESCRIBE TABLE LT_OBJBIN LINES L_TAB_LINES.
* Pack to main body as RAW.
CLEAR LT_OBJPACK-TRANSF_BIN.
LT_OBJPACK-HEAD_START = 1.
LT_OBJPACK-HEAD_NUM = 0.
LT_OBJPACK-BODY_START = 1.
LT_OBJPACK-BODY_NUM = L_LINES.
LT_OBJPACK-DOC_TYPE = TEXT-012. "RAW
APPEND LT_OBJPACK.
* Packing as PDF.
LT_OBJPACK-TRANSF_BIN = 'X'.
LT_OBJPACK-HEAD_START = 1.
LT_OBJPACK-HEAD_NUM = 1.
LT_OBJPACK-BODY_START = 1.
LT_OBJPACK-BODY_NUM = L_TAB_LINES.
LT_OBJPACK-DOC_TYPE = TEXT-010. "PDF
LT_OBJPACK-OBJ_NAME = TEXT-011. "SmartForm
LT_OBJPACK-OBJ_DESCR = PDF_NAME.
LT_OBJPACK-DOC_SIZE = L_TAB_LINES * 255.
APPEND LT_OBJPACK.
& Call the Final FM....
CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
Thanks & regards,
Dileep .C
‎2009 May 26 5:56 AM
After using the FM to convert Smartform to PDF format.. the output which you get from the FM should be transferred from 132 - long strings to 255 long strings..
Transfer the 132-long strings to 255-long strings
LOOP AT g_t_pdf_output.
TRANSLATE g_t_pdf_output USING ' ~'.
CONCATENATE g_buffer g_t_pdf_output INTO g_buffer.
ENDLOOP.
TRANSLATE g_buffer USING '~ '.
DO.
IF g_flag = 'X'.
CONCATENATE l_crlf g_buffer INTO g_t_con_bin-line.
CONDENSE g_t_con_bin-line.
ELSE.
g_t_con_bin = g_buffer.
ENDIF.
APPEND g_t_con_bin.
SHIFT g_buffer LEFT BY 255 PLACES.
IF g_buffer IS INITIAL.
EXIT.
ENDIF.
ENDDO.
Then after this you can use the FM to send email in PDF format.
Total number of lines in the mail.
DESCRIBE TABLE l_t_con_text LINES l_tablines1.
Total number of lines in the attachment.
DESCRIBE TABLE g_t_con_bin LINES l_tablines2.
Creation of the entry for the compressed document
CLEAR l_t_pack-transf_bin.
l_t_pack-head_start = 1.
l_t_pack-head_num = 0.
l_t_pack-body_start = 1.
l_t_pack-body_num = l_tablines1.
l_t_pack-doc_size = l_tablines1 * 255.
l_t_pack-doc_type = 'RAW'.
APPEND l_t_pack.
Creation of the entry for the attachment document
l_t_pack-transf_bin = 'X'.
l_t_pack-head_start = 1.
l_t_pack-head_num = 1.
l_t_pack-body_start = 1.
l_t_pack-body_num = l_tablines2.
l_t_pack-doc_type = 'PDF'.
l_t_pack-doc_size = l_tablines2 * 255.
l_t_pack-obj_descr = 'TESTPDF'.
APPEND l_t_pack.
Attached document's name
l_t_objhead-line = 'TESTPDF'.
APPEND l_t_objhead.
CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
EXPORTING
document_data = l_t_doc_data
put_in_outbox = 'X'
TABLES
packing_list = l_t_pack
object_header = l_t_objhead
contents_bin = g_t_con_bin
contents_txt = l_t_con_text
receivers = l_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.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ELSE.
COMMIT WORK.
ENDIF.
Hope this helps
‎2009 May 26 6:04 AM
Hi,
pass X to commit work parameter and check the document type parameter (eg: wa_objpack-doc_type = 'CSV')
Regards,
Ramesh.
‎2009 May 26 10:32 AM
Hi Ramesh / Madhuri
pass X to commit work parameter
works fine (but takes little time)
submit RSCONN01 with MODE = 'INT' and return.
works instantly.
I have already refered to that link madhuri, but still have some little problems, and posted in little threads,
Thanks for your valuble replies.
Hi Dileep
That solves 80 % of my problem.
-Dunlop
Edited by: Dunlop Raz on May 26, 2009 11:33 AM
‎2009 May 26 6:08 AM
solution :
If u are calling the FM :
call function 'SO_NEW_DOCUMENT_ATT_SEND_API1'
call function 'SO_DOCUMENT_SEND_API1'
make the commit_work = 'X'
and
write this statement after sending the mail with pdf as attachment-->
submit RSCONN01 with MODE = 'INT' and return.
or refer to the following link
https://www.sdn.sap.com/irj/scn/wiki?path=/display/snippets/mailsendthroughoutputcontrols
rgds,
Madhuri
Edited by: madhuri sonawane on May 26, 2009 10:38 AM
‎2009 May 26 6:11 AM
Hi,
Call the FM 'SO_NEW_DOCUMENT_ATT_SEND_API1' and pass the parameter commit_work = 'X'
Regards,
Jyothi CH.
‎2009 May 26 8:48 AM
Hi Dunlop,
Try this sample code below.
CALL FUNCTION 'CONVERT_OTF'
EXPORTING
FORMAT='PDF'
IMPORTING
BIN_FILESIZE = V_LEN_IN
TABLES
OTF = I_OTF
LINES = I_TLINE.
LOOP AT I_TLINE.
TRANSLATE I_TLINE USING ' ~'. " Replacing space by ~
CONCATENATE WA_BUFFER I_TLINE INTO WA_BUFFER.
ENDLOOP.
TRANSLATE WA_BUFFER USING '~ '. " Replacing space by ~
DO.
LT_OBJBIN = WA_BUFFER.
APPEND LT_OBJBIN. " Appending 255 characters as a record
SHIFT WA_BUFFER LEFT BY 255 PLACES.
IF WA_BUFFER IS INITIAL.
EXIT.
ENDIF.
ENDDO.
DESCRIBE TABLE LT_OBJBIN LINES L_TAB_LINES.
* Pack to main body as RAW.
CLEAR LT_OBJPACK-TRANSF_BIN.
LT_OBJPACK-HEAD_START = 1.
LT_OBJPACK-HEAD_NUM = 0.
LT_OBJPACK-BODY_START = 1.
LT_OBJPACK-BODY_NUM = L_LINES.
LT_OBJPACK-DOC_TYPE = TEXT-012. "RAW
APPEND LT_OBJPACK.
* Packing as PDF.
LT_OBJPACK-TRANSF_BIN = 'X'.
LT_OBJPACK-HEAD_START = 1.
LT_OBJPACK-HEAD_NUM = 1.
LT_OBJPACK-BODY_START = 1.
LT_OBJPACK-BODY_NUM = L_TAB_LINES.
LT_OBJPACK-DOC_TYPE = TEXT-010. "PDF
LT_OBJPACK-OBJ_NAME = TEXT-011. "SmartForm
LT_OBJPACK-OBJ_DESCR = PDF_NAME.
LT_OBJPACK-DOC_SIZE = L_TAB_LINES * 255.
APPEND LT_OBJPACK.
& Call the Final FM....
CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
Thanks & regards,
Dileep .C