‎2007 Apr 23 6:04 AM
i am trying 2 send a email with a attachment using the function module 'SO_NEW_DOCUMENT_ATT_SEND_API1' . if i send an attachment should i use the packing option in that function module ? wat is that for ?? can anybody tel me the mandatory parameters for this function modules
‎2007 Apr 23 6:07 AM
Hi
See the sample code using this Fun module and use accordingly:
----
INCLUDE ZINCUSMAIL *
----
include <symbol>.
data : i_doc_data like sodocchgi1.
data : begin of i_pack_list occurs 0.
include structure sopcklsti1.
data : end of i_pack_list.
data : begin of i_receivers occurs 0.
include structure somlreci1.
data : end of i_receivers.
data : begin of i_contents occurs 0.
include structure solisti1.
data : end of i_contents.
data : begin of i_header occurs 0.
include structure solisti1.
data : end of i_header.
data : begin of i_att occurs 0.
include structure solisti1.
data : end of i_att.
Internal Table for Internet address.
data: begin of it_inad occurs 0,
kunnr like kna1-kunnr, " Customer Code
name1 like kna1-name1, " Customer Name
ssobl like knkk-ssobl, " Security Deposit
klimk like knkk-klimk, " Credit Limit
opbal like bsid-wrbtr, " Opening Balance
clbal like bsid-wrbtr, " Closing Balance
smtp like adr6-smtp_addr, " Internet mail (SMTP) address
end of it_inad.
data : pdf_line(134),
asdf like pdf_line occurs 0 with header line.
data : pdf_table like tline occurs 0 with header line,
pdf_fsize type i.
data : stuff(65000),
len type i,
pos type i,
tab_lines like sy-tabix.
data: spoolid type tsp01-rqident,
spdel type tsp01sys.
data: v_gjahrt like bsid-gjahr,
fmondest(10),
tmondest(10),
kunnr1 like kna1-kunnr,
gjah(4),
fmon(10).
&----
*& Form hide_write
&----
form hide_write.
new-page print on
line-size 160
line-count 58
no-title
no-heading
destination 'LOCL'
immediately ' '
new list identification 'X'
no dialog.
set blank lines on.
endform. " hide_write
&----
*& Form end_write
&----
form end_write using kunnr1.
set blank lines off.
new-page print off.
***Using Spoolid we are getting PDF formated file
spoolid = spdel-rqident = sy-spono.
spdel-sys = sy-sysid.
call function 'CONVERT_ABAPSPOOLJOB_2_PDF'
exporting
src_spoolid = spoolid
no_dialog = 'X'
importing
pdf_bytecount = pdf_fsize
tables
pdf = pdf_table
exceptions
others = 0.
***Delleting Spool request
call function 'RSPO_IDELETE_SPOOLREQ'
exporting
spoolreq = spdel
exceptions
others = 2.
***Converting PDF table line size 134 into standard list size 255
loop at pdf_table into pdf_line.
if pos = 34170.
perform attach.
endif.
stuff+pos(134) = pdf_line.
add 134 to pos.
endloop.
if not ( stuff is initial ).
perform attach.
endif.
clear pdf_line.
clear pdf_table[].
describe table i_att lines tab_lines.
i_pack_list-transf_bin = 'X'.
i_pack_list-head_start = '1'.
i_pack_list-head_num = '1'.
i_pack_list-body_start = '1'.
i_pack_list-body_num = tab_lines.
i_pack_list-doc_type = 'PDF'.
i_pack_list-obj_name = 'LedgerMail'.
concatenate fmon '-' gjah into i_pack_list-obj_descr.
*i_pack_list-obj_descr = '2092-Oct03'.
i_pack_list-obj_langu = 'E'.
i_pack_list-doc_size = tab_lines * 255.
append i_pack_list.
***Data for receivers list
loop at it_inad where kunnr eq kunnr1.
i_receivers-receiver = it_inad-smtp.
i_receivers-rec_type = 'U'.
i_receivers-rec_date = sy-datum.
i_receivers-express = 'X'.
i_receivers-com_type = 'INT'.
i_receivers-notif_del = 'X'.
append i_receivers.
endloop.
call function 'SO_NEW_DOCUMENT_ATT_SEND_API1'
exporting
document_data = i_doc_data
PUT_IN_OUTBOX = ' '
IMPORTING
SENT_TO_ALL =
NEW_OBJECT_ID =
tables
packing_list = i_pack_list
object_header = i_header
contents_bin = i_att
contents_txt = i_contents
receivers = i_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
.
refresh i_att. clear i_att.
refresh i_receivers. clear i_receivers.
delete i_pack_list where doc_type = 'PDF'.
*refresh i_header.
*refresh i_contents.
*clear i_doc_data.
endform. " end_write
&----
*& Form doc_data
&----
form doc_data using fmondest v_gjahrt.
gjah = v_gjahrt.
fmon = fmondest.
***Data for Document Data
i_doc_data-obj_name = 'LedgerMail'.
concatenate 'Customer Ledger for : ' fmondest gjah
into i_doc_data-obj_descr separated by space.
i_doc_data-obj_langu = 'E'.
i_doc_data-obj_prio = '1'.
i_doc_data-no_change = 'X'.
i_doc_data-doc_size = '5101'.
***Data for Packing list
i_pack_list-head_start = '1'.
i_pack_list-head_num = '1'.
i_pack_list-body_start = '1'.
i_pack_list-body_num = '20'.
i_pack_list-doc_type = 'RAW'.
i_pack_list-obj_langu = 'E'.
append i_pack_list.
***Data for Header
i_header-line = 'Header'. append i_header.
***Data for contents
i_contents-line = 'Dear Customer,'. append i_contents.
i_contents-line = ' '. append i_contents.
concatenate 'Please find your enclosed Ledger for the month of : '
fmondest gjah into i_contents-line separated by space.
append i_contents.
i_contents-line = ' '. append i_contents.
i_contents-line = 'This is a computer generated document and does not
require a signature.'. append i_contents.
i_contents-line = ' '. append i_contents.
i_contents-line = 'Note : If you do not have Acrobat Reader please click
on the below link.'. append i_contents.
i_contents-line = ' '. append i_contents.
i_contents-line = 'http://www.adobe.com/products/acrobat/readstep2.html'
. append i_contents.
i_contents-line = ' '. append i_contents.
i_contents-line = ' '. append i_contents.
i_contents-line = ' '. append i_contents.
i_contents-line = ' '. append i_contents.
i_contents-line = ' '. append i_contents.
i_contents-line = ' '. append i_contents.
i_contents-line = ' '. append i_contents.
i_contents-line = ' '. append i_contents.
i_contents-line = ' '. append i_contents.
endform. " doc_data
&----
*& Form attach
&----
form attach.
clear pos.
len = strlen( stuff ).
while len > 0.
subtract 255 from len.
i_att = stuff+pos(255).
append i_att.
add 255 to pos.
endwhile.
clear pos.
clear stuff.
endform. " attach
reward if useful
regards,
Anji
‎2007 Apr 23 6:20 AM
Hi
This is the coding part related to : SO_NEW_DOCUMENT_ATT_SEND_API1
TABLES : soli.
TABLES : zpsdsalrep.
DATA: v_email TYPE soli-line.
DATA: v_email1 TYPE soli-line.
DATA: l_adrnr LIKE kna1-adrnr.
DATA: l_objky TYPE nast-objky.
DATA: l_zzterrmg TYPE zpsdsalrep-zzterrmg.
DATA: l_zsupervisor TYPE zpsdsalrep-zsupervisor.
DATA: l_kunnr TYPE kna1-kunnr.
DATA: l_kunnr1 TYPE vbak-kunnr.
SELECT SINGLE kunnr FROM vbak INTO l_kunnr1
WHERE vbeln = nast-objky.
SELECT SINGLE adrnr FROM kna1 INTO l_adrnr
WHERE kunnr = l_kunnr1.
CHECK sy-subrc IS INITIAL.
SELECT SINGLE smtp_addr FROM adr6 INTO v_email
WHERE addrnumber = l_adrnr.
SELECT SINGLE zzterrmg FROM zpsdsalrep INTO l_zzterrmg
WHERE zzsalesrep = l_kunnr1.
SELECT SINGLE zsupervisor FROM zpsdsalrep INTO l_zsupervisor
WHERE zzterrmg = l_zzterrmg.
SELECT SINGLE kunnr FROM kna1 INTO l_kunnr
WHERE sortl = l_zsupervisor.
SELECT SINGLE adrnr FROM kna1 INTO l_adrnr
WHERE kunnr = l_kunnr.
CHECK sy-subrc IS INITIAL.
SELECT SINGLE smtp_addr FROM adr6 INTO v_email1
WHERE addrnumber = l_adrnr.
DATA: l_reclist LIKE somlreci1 OCCURS 0 WITH HEADER LINE.
DATA: l_objtxt LIKE solisti1 OCCURS 0 WITH HEADER LINE.
DATA: l_objpack LIKE sopcklsti1 OCCURS 0 WITH HEADER LINE.
DATA: l_doc_chng LIKE sodocchgi1.
DATA: l_objhead LIKE solisti1 OCCURS 0 WITH HEADER LINE.
DATA: l_tab_lines LIKE sy-tabix.
CONSTANTS: k_true TYPE boolean_flg VALUE 'X'.
DATA: l_mail TYPE somlreci1-receiver.
DATA: l_mail1 TYPE somlreci1-receiver.
DATA: k_mail2 TYPE somlreci1-receiver.
DATA: k_mail TYPE somlreci1-receiver.
l_mail = v_email.
l_mail1 = v_email1.
k_mail2 = text-006.
k_mail = text-007.
Creation of the document to be sent
File Name
l_doc_chng-obj_name = 'SENDFILE'.
Mail Subject
l_doc_chng-obj_descr = text-001.
Completing the recipient list
l_reclist-receiver = l_mail.
l_reclist-rec_type = 'U'.
APPEND l_reclist.
l_reclist-receiver = l_mail1.
l_reclist-rec_type = 'U'.
APPEND l_reclist.
l_reclist-receiver = k_mail.
l_reclist-rec_type = 'U'.
APPEND l_reclist.
l_reclist-receiver = k_mail2.
l_reclist-rec_type = 'U'.
APPEND l_reclist.
Mail Contents
l_objtxt = text-002.
APPEND l_objtxt.
CLEAR l_objtxt. " put in a blank line
APPEND l_objtxt.
l_objtxt = text-003.
APPEND l_objtxt.
l_objtxt = text-004 .
APPEND l_objtxt.
Calculate email size in bytes
DESCRIBE TABLE l_objtxt LINES l_tab_lines.
READ TABLE l_objtxt INDEX l_tab_lines.
l_doc_chng-doc_size = ( l_tab_lines - 1 ) * 255 + STRLEN( l_objtxt ).
Creation of the entry for the compressed document
for the email text
CLEAR l_objpack-transf_bin.
l_objpack-head_start = 1.
l_objpack-head_num = 0.
l_objpack-body_start = 1.
l_objpack-body_num = l_tab_lines.
l_objpack-doc_type = 'RAW'.
APPEND l_objpack.
Creation of the document attachment
(Assume that the data in OBJBIN is in BMP format)
DESCRIBE TABLE l_objbin LINES l_tab_lines.
l_objhead = text-001 .
APPEND l_objhead.
CLEAR l_objpack.
**/ Creation of the entry for the compressed/attached document
l_objpack-transf_bin = k_true.
l_objpack-head_start = 1.
l_objpack-head_num = 1.
l_objpack-body_start = 1.
l_objpack-body_num = l_tab_lines.
l_objpack-doc_type = 'PDF'.
l_objpack-obj_name = text-005.
l_objpack-obj_descr = text-001.
l_objpack-doc_size = l_tab_lines * 255.
APPEND l_objpack. "/ .
Sending the document
CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1' "/ .
EXPORTING
document_data = l_doc_chng
put_in_outbox = 'X'
TABLES
packing_list = l_objpack
object_header = l_objhead
contents_bin = l_objbin
contents_txt = l_objtxt
receivers = l_reclist
EXCEPTIONS
too_many_receivers = 1
document_not_sent = 2
operation_no_authorization = 4
OTHERS = 99.
IF sy-subrc <> 0.
WRITE: / 'unsuccessful', sy-subrc.
ELSE.
WRITE: / 'successful'.
ENDIF.
**/Take_note it is a requirement to do a commit work for the
email to go into transaction SOST.
COMMIT WORK. "/Take_note .
Regards,
Sreeram
‎2007 Apr 23 6:24 AM
Hi,
This ids the totla documetation of this FM
FU SO_NEW_DOCUMENT_ATT_SEND_API1
____________________________________________________
Short text
SAPoffice: Send new document with attachments via RFC
Functionality
This function module enables you to send a new document including any existing attachments. The document and the attachments are transferred in the same table. They are created when sent and can also be placed in the sender's outbox.
It is necessary to distinguish between the document and its folder entries. The document itself only exists in the database once. It is a template for the folder entries and can be addressed via its object ID. Any number of folder entries can belong to the document. The folder entries have the content and the attributes of the document as well as some additional attributes relating to the folder entry itself. (Send priority and expiry date of the entry, for example.) Folder entries are created when a document is resubmitted, referenced, or sent, as well as when a new document is created.
Import Parameters
PUT_IN_OUTBOX
Default = ' '.
If this flag is activated ('X'), the newly created document is also placed in the outbox of the active user when it is sent.
DOCUMENT_DATA
This structure must contain the attributes of the document to be sent.
OBJ_NAME
Name of document.
OBJ_DESCR
Title (short description) of document.
OBJ_LANGU
Language of document.
OBJ_SORT
Sort field of document. You can search for this term using attribute search.
OBJ_EXPDAT
Expiration date of document. The document itself cannot expire, but each time the document is entered in a folder, this date is used as the default for the expiration date of the entry (field EXPIRY_DAT).
SENSITIVTY
Document sensitivity.
A personal document can have the following levels of sensitivity:
'O' : Standard, normal sensitivity
'F' : Functional, can be forwarded functionally
'P' : Confidential, not visible to substitutes
For documents in shared folders, only sensitivity level 'O' is permitted.
OBJ_PRIO
Recipient priority. The document itself does not have a priority level, but each time the document is entered in a folder, this value is used as the default for recipient priority for the entry (field PRIORITY).
NO_CHANGE
If this flag is activated ('X'), documents in shared folders can only be changed by the author. The author can change documents in private folders after they have been sent.
PRIORITY
Recipient priority for the folder entry. This value gives the priority, which was assigned to the document by the owner, after receipt.
EXPIRY_DAT
Expiration date of the folder entry. When the expiration date has been reached or passed, the entry is placed in private trash and can be retrieved from there if needed, up until the next time the trash is emptied. A new folder entry is initially given the expiration date of the document from field OBJ_EXPDT.
PROC_TYPE
If this field does not contain the default value (default is ' '), the document can be processed.
The following entries are permitted:
'D' : Dialog module
'F' : Function module
'R' : Report
'S' : Report with transfer of values to global memory
'T' : Transaction
'U' : Transaction with transfer of values to global memory
PROC_NAME
Processing element. You must enter the name of the dialog module, function module, report or transaction in accordance with the entry in the field PROC_TYPE.
PROC_SYST
Name of system in which the document is to be processed. If no system is specified or '*' is entered, processing is possible in all systems.
PROC_CLINT
Client in which the document is to be processed. If no client is specified or '*' is entered, processing is possible in all clients.
SKIP_SCREN
If this flag is activated ('X'), the first screen is skipped during processing.
TO_DO_OUT
If this flag is activated ('X'), the document cannot be processed from the SAPoffice interface. You must use the API function module SO_DOCUMENT_SET_STATUS_API1.
FREE_DEL
If this flag is activated ('X'), the document can be deleted by using the API, even in foreign folders.
DOC_SIZE
Size of the document in bytes. For PC documents, the size of the relevant file should be entered, for RAW and SCR documents the size is the "length of the last line" + "number of other lines multiplied by 255".
Export Parameters
NEW_OBJECT_ID
Object ID of the document created during the send process.
SENT_TO_ALL
If this flag is activated ('X'), the document was sent to all specified recipients or, in the case of external forwarding, the corresponding send requests were delivered to a subsystem. If sending or delivery failed in one or more cases, the flag is not activated.
Table Parameters
PACKING_LIST
This table requires information about how the data in the tables OBJECT_HEADER, CONTENTS_BIN, and CONTENTS_TXT is to be distributed to the documents and its attachments. The first row is for the document, the following rows are each for one attachment.
TRANSF_BIN
If this flag is activated ('X'), the table entry describes an object stored in binary format. The content of the object is in the table CONTENTS_BIN. If the flag is not activated, the object content is in the table CONTENTS_TXT in ASCII format.
HEAD_START
Requires the start row of the table OBJECT_HEADER, as of which the specific header data of the object is stored.
HEAD_NUM
Requires the number of rows in the table OBJECT_HEADER that contain specific header data for the object. The relevant rows are arranged in a block and defined uniquely together with the entry in HEAD_START.
BODY_START
Requires the start row of the table dependent on the TRANSF_BIN flag as of which the object content is stored.
BODY_NUM
Requires the number of rows of the table dependent on the flag TRANSFER_BIN, which contain the object content. The relevant rows are arranged in a block and defined uniquely together with the entry in HEAD_START.
DOC_TYPE
Attachment type. In the first row of the table, this field is not used.
OBJ_NAME
Attachment name. In the first row of the table, this field is not used.
OBJ_DESCR
Attachment title (short description). In the first row of the table, this field is not used.
OBJ_LANGU
Attachment language. In the first row of the table, this field is not used.
DOC_SIZE
Attachment size in bytes. For PC objects, enter the size of the relevant file here. For RAW and SCR objects, the size is the "length of the last page" + "number of other rows multiplied by 255". In the first row of the table, this field is not used.
MESS_TYPE
This field is not used.
OBJECT_HEADER
This table must contain the summarized data dependent on each object type. SAPscript objects store information here about forms and styles, for example. Excel list viewer objects store the number of rows and columns amongst other things, and PC objects store their original file name.
LINE
Requires the type-specific data of the object line by line. The fields HEAD_START and HEAD_NUM in the table PACKING_LIST define which section belongs to which object.
CONTENTS_BIN
This table must contain the summarized content of the objects identified as binary objects.
LINE
Requires the object content line by line. The fields BODY_START and BODY_NUM in the table PACKING_LIST define which section belongs to which object.
CONTENTS_TXT
This table must contain the summarized content of the objects identified as ASCII objects.
LINE
Requires the object content line by line. The fields BODY_START and BODY_NUM in the table PACKING_LIST define which section belongs to which object.
OBJECT_PARA
The table is only needed if the document to be sent is to be processed. The table must contain SET/GET parameters that are transferred to the processing element during processing.
It is not possible to transfer processing parameters to the document attachment.
NAME
Name of SET/GET parameter. Only the first three characters are used.
OPTION
This field is not used.
LOW
Contains the value of the parameter in NAME.
HIGH
This field is not used.
OBJECT_PARB
This table is used only if a particular processing type is assigned to the document to be sent. The meaning of the table depends on the processing type. If the processing element is a report, or transaction with transfer of values to the global memory, the table content is interpreted as the quantity of parameters with the relevant values and exported to the memory ID taken from the first row. If the processing element is a function module or a dialog module, the table is transferred to this as table parameter MSGDIAL.
It is not possible to transfer processing parameters to the document attachments.
NAME
If the processing element is a report or a transaction with transfer of values to the global memory, the field of the first row of the table must contain the name of the memory ID used for the export. The fields of the other rows accommodate the parameter names. If the processing element is a function module or a dialog module, the fields must contain values corresponding to the use of the module.
VALUE
If the processing element is a report or a transaction with transfer of values to the global memory, the field for the first row of the table must remain empty. The fields for the other rows accommodate the values belonging to the parameters in NAME. If the processing element is a function or dialog module, the fields must contain values corresponding to the use of the modules.
RECEIVERS
This table must contain the document recipients.
RECEIVER
Name of recipient.
The following entry types are possible:
SAP user name of the recipient
SAPoffice name of the recipient
Shared distribution list
Fax number in the form of structure SADRFD
Internet address in the form of structure SADRUD
Remote SAP name in the form of structure SADR7D
X.400 address in the form of structure SADR8D
ADR_TYPE
Type of RECEIVER entry.
The following values are permitted:
'B' : SAP user name
' ' : SAPoffice name
'C' : Shared distribution list
'F' : Fax number
'U' : Internet address
'R ' : Remote SAP name
'X' : X.400 address
REC_ID
If the recipient is a SAPoffice user, you can enter the user ID in this field instead of entering the recipient name in RECEIVER.
REPLY_DOC
If there is a value in this field, the document is a reply to the folder entry identified by the specified ID. A correspondence history is automatically created/continued.
REC_DATE
The date on which the document is to reach the recipient. This date cannot be guaranteed for external recipients, as it depends on connected products.
PROXY_ID
If automatic forwarding is active in the recipient's system, this field contains the SAP user ID or the address ID of the external address, to which the document was ultimately sent.
RETRN_CODE
When the recipient has received the document, the function module enters the value '0' in this field. If the document is not successfully received, a value other than '0' is entered in the field.
EXPRESS
If this flag is activated ('X'), the document is sent with the attribute 'express'. If the recipient is a logged-on SAPoffice user, he or she receives a message immediately, saying that he or she has received an express mail.
COPY
If this flag is activated ('X'), the document is sent with the attribute 'copy'.
BLIND_COPY
If this flag is activated ('X'), the document is sent with the attribute 'secret copy'. If the recipient is a SAPoffice user, he or she can neither print nor forward the document.
NO_FORWARD
If this flag is activated ('X') and the recipient is a SAPoffice user, he or she cannot forward the document.
NO_PRINT
If this flag is activated ('X') and the recipient is a SAPoffice user, he or she cannot print the document.
TO_ANSWER
If this flag is activated ('X') and the recipient is a SAPoffice user, the user must reply to the document before he or she can delete it from his or her inbox.
TO_DO_EXPL
If this flag is activated ('X') and the recipient is a SAPoffice user, the user must process the document before he or she can delete it from his or her inbox.
TO_DO_GRP
If this field contains a value between '1' and '9', a SAPoffice user in the recipient group indicated by this number must process the document, before the recipients can delete it from their inboxes. If the value '0' is entered, the document does not need to be processed.
COM_TYPE
Communication type used to send the document. This field is only relevant if the recipient is an address number, that is, if the document is sent externally via address management. If the field is empty, the standard communication type specified in address management is used.
The following values are permitted:
'INT' : Send by using the Internet
'FAX' : Send as a fax
'X40' : Send by using X.400
'RML' : Send to another SAP system
LFDNR
Current number from address management. This field is only relevant if the recipient is an address number, that is, if the document is sent via address management. If the field is empty, the default current number in address management is used.
FAX
This field is not used.
COUNTRY
This field is not used.
SPOOL_ID
This field is not used.
NOTIF_DEL
If this flag is activated ('X'), the sender receives confirmation when the recipient receives the document. He or she also receives a message if the document could not be delivered. This flag should only be activated for external sending, since internal sending is synchronous. Confirmation is only supported by a small number of mail systems, however. For example: X.400 and SAP SAP.
NOTIF_READ
If this flag is activated ('X'), the sender is notified as soon as the recipient has read the document. This flag should only be activated for external sending, since internal sending is synchronous. Read notification is only supported by a small number of mail systems, however. For example: X.400 and SAP SAP.
NOTIF_NDEL
If this flag is activated ('X'), the recipient receives a message if the document could not be delivered to the recipient. This flag should only be activated for external sending, since internal sending is synchronous. The message is only supported by a small number of mail systems, however. For example: X.400 and SAP SAP.
SAP_BODY
If this flag is activated ('X'), SAP-specific data is transferred to the document in an external body part if the document is sent by means of X.400. This flag should only be activated if the target system is an SAP system.
Exceptions
TOO_MANY_RECEIVERS
Too many recipients were specified. The active user does not have authorization to send to this number of recipients.
DOCUMENT_NOT_SENT
The document could not be sent. It was not delivered to any of the specified recipients.
DOCUMENT_TYPE_NOT_EXIST
A document class assigned to the document or an attachment does not exist.
OPERATION_NO_AUTHORIZATION
The document was not allowed to be sent, because one of the required authorizations did not exist.
PARAMETER_ERROR
The combination of parameter values transferred to the function module was not a permitted combination.
X_ERROR
An internal error or a database inconsistency has occurred.
ENQUEUE_ERROR
A lock required for the send process could not be set. It is probable that another user is currently processing the document.
Example
Sending a new RAW document with an ALI attachment to an Internet address and an internal recipient.
&----
*& Report ZSSO_DOCUMENT_SEND_API1
*&
&----
*& Send document with OTF/ALI attachment from spool to external reci-
*& pient. OTF/ALI document is converted to PDF/HTML format during the
*& SAPconnect send process.
*&
*& This report serves as example documentation for the function
*& modules SO_NEW_DOCUMENT_ATT_SEND_API1 and SO_DOCUMENT_SEND_API1.
*& Following this example you should be able to develop your own
*& report to send documents with all kinds of attachments.
*&
&----
REPORT ZSSO_DOCUMENT_SEND_API1.
Data Declaration
Data: docdata like sodocchgi1,
objpack like sopcklsti1 occurs 1 with header line,
objhead like solisti1 occurs 1 with header line,
objtxt like solisti1 occurs 10 with header line,
objbin like solisti1 occurs 10 with header line,
reclist like somlreci1 occurs 1 with header line.
Data: listobject like abaplist occurs 1 with header line.
Data: tab_lines type i,
doc_size type i,
att_type like SOODK-OBJTP.
NOTE: Create ALI/OTF Document in Spool
ALI Document can be created by displaying a list and selecting
menue System -> List -> Print (only put to Spool).
OTF Document can be created running report SF_EXAMPLE_01 in system.
*
Example used here:
create list in memory
submit SHOWCOLO exporting list to memory and return.
and read list from memory into table
CALL FUNCTION 'LIST_FROM_MEMORY'
TABLES
listobject = listobject
EXCEPTIONS
OTHERS = 1
.
IF sy-subrc <> 0.
message ID '61' TYPE 'E' NUMBER '731'
with 'LIST_FROM_MEMORY'.
ENDIF.
Because listobject is of size RAW(1000)
and objbin is of size CHAR(255) we make this table copy
CALL FUNCTION 'TABLE_COMPRESS'
IMPORTING
COMPRESSED_SIZE =
TABLES
IN = listobject
OUT = objbin
EXCEPTIONS
OTHERS = 1
.
if sy-subrc <> 0.
message ID '61' TYPE 'E' NUMBER '731'
with 'TABLE_COMPRESS'.
endif.
NOTE: Creation of attachment is finished yet.
For your report, the attachment should be placed into table
objtxt for plain text or
objbin for binary content.
Now create the message and send the document.
Create Message Body
Title and Description
docdata-obj_name = 'TEST_ALI'.
docdata-obj_descr = 'Test including ALI/HTML Attachment'.
Main Text
objtxt = 'Test Document.'.
append objtxt.
objtxt = 'You will find an ALI/HTML attachment in this
message.'.
append objtxt.
objtxt = 'Have a nice day.'.
append objtxt.
Write Packing List (Main)
describe table objtxt lines tab_lines.
read table objtxt index tab_lines.
docdata-doc_size = ( tab_lines - 1 ) * 255 + strlen( objtxt ).
clear objpack-transf_bin.
objpack-head_start = 1.
objpack-head_num = 0.
objpack-body_start = 1.
objpack-body_num = tab_lines.
objpack-doc_type = 'RAW'.
append objpack.
Create Message Attachment
Write Packing List (Attachment)
att_type = 'ALI'.
describe table objbin lines tab_lines.
read table objbin index tab_lines.
objpack-doc_size = ( tab_lines - 1 ) * 255 + strlen( objbin ).
objpack-transf_bin = 'X'.
objpack-head_start = 1.
objpack-head_num = 0.
objpack-body_start = 1.
objpack-body_num = tab_lines.
objpack-doc_type = att_type.
objpack-obj_name = 'ATTACHMENT'.
objpack-obj_descr = 'Attached Document'.
append objpack.
Create receiver list
reclist-receiver = 'testuser@ COMPANY.COM'. "<-- change address
reclist-rec_type = 'U'.
append reclist.
reclist-receiver = sy-uname. "<-- change internal user
reclist-rec_type = 'B'.
append reclist.
Send Message
CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
EXPORTING
document_data = docdata
PUT_IN_OUTBOX = 'X'
IMPORTING
SENT_TO_ALL =
NEW_OBJECT_ID =
tables
packing_list = objpack
OBJECT_HEADER = objhead
CONTENTS_BIN = objbin
CONTENTS_TXT = objtxt
OBJECT_PARA =
OBJECT_PARB =
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'.
Parameter
DOCUMENT_DATA
PUT_IN_OUTBOX
SENT_TO_ALL
NEW_OBJECT_ID
PACKING_LIST
OBJECT_HEADER
CONTENTS_BIN
CONTENTS_TXT
CONTENTS_HEX
OBJECT_PARA
OBJECT_PARB
RECEIVERS
Exceptions
TOO_MANY_RECEIVERS
DOCUMENT_NOT_SENT
DOCUMENT_TYPE_NOT_EXIST
OPERATION_NO_AUTHORIZATION
PARAMETER_ERROR
X_ERROR
ENQUEUE_ERROR
Function group
SOI1
Don't forget to reward if useful...