2006 Jan 03 8:42 AM
Hi,
we are generating purchase orders via bapi (bapi_po_create). Once created, they are
automatically sent to vendor and we want to attach a document to the email but we don't
know how.
If anyone could help us..
Thanks.
2006 Jan 03 10:20 AM
Hi,
This question was discussed couple of days back. Here was a solution for it:
REPORT zramki_send_mail_bor .
&----
*& Report ZRAMKI_SEND_MAIL_BOR
*&
&----
*& Send document with BOR Object as attachment
&----
DATA: docdata LIKE sodocchgi1,
objpack LIKE sopcklsti1 OCCURS 10 WITH HEADER LINE,
objhead LIKE solisti1 OCCURS 10 WITH HEADER LINE,
objtxt LIKE solisti1 OCCURS 10 WITH HEADER LINE,
objbin LIKE solisti1 OCCURS 10 WITH HEADER LINE,
objhex LIKE solix OCCURS 10 WITH HEADER LINE,
reclist LIKE somlreci1 OCCURS 1 WITH HEADER LINE.
DATA: tab_lines TYPE i,
doc_size TYPE i,
objdes(100).
For the BOR attachment
CONSTANTS:
c_object_describe LIKE swotobjid-describe VALUE '<OBJECT>'.
DATA:
l_object TYPE swotobjid,
l_objheader LIKE soxobj.
PARAMETERS:
p_objtyp TYPE swo_objtyp OBLIGATORY,
p_objkey TYPE swo_typeid OBLIGATORY.
Create Message Body
Main Text
objtxt = 'Test Document.'.
APPEND objtxt.
objtxt = 'You will find a BOR object attachment in message.'.
APPEND objtxt.
objtxt = 'Have a nice day.'.
APPEND objtxt.
Title and Description
DESCRIBE TABLE objtxt LINES tab_lines.
READ TABLE objtxt INDEX tab_lines.
docdata-doc_size = ( tab_lines - 1 ) * 255 + STRLEN( objtxt ).
docdata-obj_name = 'BOR Object'.
Concatenate p_objtyp '-' p_objkey into objdes.
Concatenate 'BOR Object' objdes 'as Attachment'
into docdata-obj_descr separated by space.
condense docdata-obj_descr.
Write Packing List (Main)
CLEAR objpack-transf_bin.
objpack-head_start = 0.
objpack-head_num = 0.
objpack-body_start = 1.
objpack-body_num = tab_lines.
objpack-doc_type = 'RAW'.
APPEND objpack.
Create OBJ attachment
l_object-describe = c_object_describe.
l_object-objtype = p_objtyp.
l_object-objkey = p_objkey.
CALL FUNCTION 'OWN_LOGICAL_SYSTEM_GET'
IMPORTING
own_logical_system = l_object-logsys
EXCEPTIONS
own_logical_system_not_defined = 1
OTHERS = 2.
IF sy-subrc <> 0.
MESSAGE e398(00) WITH 'No Log Sys Found'.
ENDIF.
MOVE-CORRESPONDING l_object TO l_objheader.
APPEND l_objheader TO objhead.
Write Packing List (Attachment)
CLEAR objpack.
objpack-head_start = 1.
objpack-head_num = 1.
objpack-body_start = 0.
objpack-body_num = 0.
objpack-doc_type = 'OBJ'.
objpack-obj_name = p_objtyp.
objpack-obj_descr = Objdes.
APPEND objpack.
Create receiver list
reclist-receiver = sy-uname.
reclist-rec_type = 'B'.
APPEND reclist.
Send Message
CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
EXPORTING
document_data = docdata
put_in_outbox = 'X'
commit_work = 'X'
TABLES
packing_list = objpack
object_header = objhead
contents_bin = objbin
contents_txt = objtxt
receivers = 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 'SO' TYPE 'S' NUMBER '023'
WITH docdata-obj_name.
ENDIF.
WRITE: / 'End of Program'.
2006 Jan 03 12:47 PM
Thanks,
but the problem is that we don't create the email, it is created automatically at bapi commit. We need to recuperate it before it is send...
2006 Jan 03 7:15 PM
Hi,
May be you can use a workflow to solve your problem. You may try calling the BAPI in a workflow task and send your document by attaching it to the workitem or another simpler way would be to create a subsequent step for sending the attachment.
Cheers!