2009 May 22 7:38 AM
Hi guys,
I know there is a lot of discussion already on the topic but i have searched a lot and didn't got the solution yet. I want to convert the output from an internal table to PDF and send it as an attachement. I am using the FM SO_NEW_DOCUMENT_ATT_SEND_API1. I have serached the forum but didn't got the perfect solution.
thanks.
warm regards.
Harshad.
Hi guys,
I know there is a lot of discussion already on the topic but i have searched a lot and didn't got the solution yet. I want to convert the output from an internal table to PDF and send it as an attachement. I am using the FM SO_NEW_DOCUMENT_ATT_SEND_API1. I have serached the forum but didn't got the perfect solution.
thanks.
warm regards.
Harshad.
2009 May 22 7:42 AM
May be you can try to convert the internal table to OTF and then convert to PDF.
I'm also attach a sample code for you looking forwards.
data: filesize type i.
data header like thead.
data options like itcpo.
data result like itcpp.
data otf like itcoo occurs 1000 with header line.
data lines like tline occurs 100 with header line.
parameters p_file like rlgrap-filename.
lines-tdline = 'Hello....For testing only....'.
append lines.
options-TDDEST = 'SB01'.
options-TDNEWID = 'X'.
options-tdgetotf = 'X'.
call function 'PRINT_TEXT'
exporting
device = 'PRINTER'
dialog = ' '
header = header
options = options
importing
result = result
tables
lines = lines
otfdata = otf
exceptions
canceled = 01
device = 02
form = 03
options = 04
unclosed = 05
unknown = 06
format = 07
textformat = 08
communication = 09.
* convert to PDF
call function 'CONVERT_OTF'
exporting
format = 'PDF'
importing
bin_filesize = filesize
tables
otf = otf
lines = lines
exceptions
err_conv_not_possible = 1.
2009 May 22 7:50 AM
hi
first try to covert the print text to OTF using the function module 'CONVERT_OTF'
and then with text convert to PDF ,now try to send the PDF as mail attachment with
the function module 'SO_NEW_DOCUMENT_ATT_SEND_API1'.
Regards
2009 May 22 8:04 AM
Hi,
You will have to first convert your internal table to a binary table, then convert the binary table to a binary stream and then attach it to the mail.
Use function SCMS_TEXT_TO_BINARY to convert the internal table data to binary table.
For converting from binary table to binary stream ( of type XSTRING ), you can find many examples for this on SCN.
regards,
Advait
2009 May 22 8:16 AM
Hi,
After converting it into binary format using function module Advait mentioned you can use below code to send the mail alongwith attachment.
DATA: lv_temp TYPE i,
lv_last TYPE i,
lv_toa01 TYPE toa01,
lv_lines TYPE i,
lv_offset TYPE i,
lv_buffer TYPE xstring,
lv_doc_chng TYPE sodocchgi1,
lv_bus2081 TYPE toa01-sap_object VALUE 'BUS2081',
lv_binlength TYPE sapb-length,
lv_object_id TYPE toa01-object_id,
lv_archiv_id TYPE toa01-archiv_id,
lv_ar_status TYPE toaom-ar_status VALUE 'X',
lv_arc_object TYPE toa01-ar_object VALUE 'ZMMILOGINV',
lv_doc_type_pdf TYPE toaom-doc_type VALUE 'PDF',
lwa_binarchivobject TYPE tbl1024,
lwa_reclist TYPE somlreci1,
li_objhex TYPE TABLE OF solix,
li_objcont TYPE TABLE OF solisti1,
li_objpack TYPE TABLE OF sopcklsti1,
li_binarchivobject TYPE TABLE OF tbl1024.
*---Populate the buffer string.
LOOP AT li_binarchivobject INTO lwa_binarchivobject.
CONCATENATE lv_buffer lwa_binarchivobject-line
INTO lv_buffer IN BYTE MODE .
ENDLOOP.
*---Find the number of lines buffer string.
lv_last = XSTRLEN( lv_buffer ) MOD 255.
lv_lines = XSTRLEN( lv_buffer ).
lv_lines = lv_lines / 255.
DO lv_lines TIMES.
*---Check after adding 255 to the offset if length becomes more than
*---total length then don't add 255 instead add lv_last.
lv_temp = lv_offset + 255.
IF lv_temp GE lv_binlength.
lwa_objhex-line = lv_buffer+lv_offset(lv_last).
APPEND lwa_objhex TO li_objhex.
ELSE.
lwa_objhex-line = lv_buffer+lv_offset(255).
APPEND lwa_objhex TO li_objhex.
lv_offset = lv_offset + 255.
ENDIF.
ENDDO.
*---Populate Packing internal table from relevant information required
*---to send the attachment.
lv_doc_chng-obj_name = 'SEND MAIL'.
lv_doc_chng-obj_descr = 'SEND MAIL'.
CLEAR lv_temp.
DESCRIBE TABLE li_objhex LINES lv_temp.
READ TABLE li_objcont INTO lwa_objcont INDEX lv_temp.
CLEAR lwa_objpack.
lwa_objpack-head_start = 1.
lwa_objpack-head_num = 0.
lwa_objpack-body_start = 1.
lwa_objpack-body_num = lv_temp.
lwa_objpack-doc_type = 'RAW'.
APPEND lwa_objpack TO li_objpack.
CLEAR lwa_objpack.
CLEAR lwa_objpack-transf_bin.
lwa_objpack-transf_bin = 'X'.
lwa_objpack-head_start = 1.
lwa_objpack-head_num = 1.
lwa_objpack-body_start = 1.
lwa_objpack-body_num = lv_temp.
lwa_objpack-doc_type = 'PDF'.
lwa_objpack-obj_name = 'INVOICE'.
CONCATENATE 'Invoice' wa_rbkp-belnr
INTO lwa_objpack-obj_descr
SEPARATED BY space.
lwa_objpack-doc_size = lv_temp * 255.
APPEND lwa_objpack TO li_objpack.
CLEAR: lwa_objpack.
lwa_reclist-receiver = <Populate receivers mail address>.
lwa_reclist-rec_type = lc_u.
lwa_reclist-com_type = 'INT'.
APPEND lwa_reclist TO li_reclist.
CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
EXPORTING
document_data = lv_doc_chng
commit_work = lc_x
TABLES
packing_list = li_objpack
contents_txt = li_objcont
contents_hex = li_objhex
receivers = li_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.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.KR Jaideep,
2009 May 22 8:09 AM
Hi Harshad,
Please follow check yhe link ....it may be helpfull....
2009 May 26 11:26 AM
| User | Count |
|---|---|
| 4 | |
| 2 | |
| 2 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |