Email attachment or internal table
Hi
I would like to email a txt file with multiple records( length of 512 characters).
What functions are available?
record1 field1(512characters)
record2 field1(512characters)
Check below code...
DATA : l_email_title TYPE sood1-objdes.
DATA : l_file_name TYPE soobjchgi1-obj_descr.
DATA : lit_email_receiver TYPE zphr1_email_tab.
DATA : lit_email_msg LIKE soli.
DATA : lit_attachment LIKE soli.
DATA: l_lines LIKE sy-tabix,
l_msg_lines LIKE sy-tabix.
Creation of the document to be sent
CLEAR: l_email_title,
l_file_name,
lit_email_receiver,
lit_email_msg,
lit_attachment,
gf_doc_chng,
it_objtxt,
it_objbody,
it_objpack,
it_objhead,
it_reclist.
REFRESH: it_objtxt,
it_objbody,
it_objpack,
it_objhead,
it_reclist.
*Passing mail subject
gf_doc_chng-obj_name = text-035.
gf_doc_chng-obj_descr = text-036.
Fill the document data.
gf_doc_chng-doc_size = 1.
Populate the subject/generic message attributes
gf_doc_chng-obj_langu = sy-langu.
gf_doc_chng-obj_name = c_saprpt.
gf_doc_chng-sensitivty = c_value_f.
Fill the document data and get size of attachment
DESCRIBE TABLE it_output_soli LINES l_lines.
gf_doc_chng-doc_size =
( l_lines - 1 ) * 255 + STRLEN( it_output_soli ).
gf_doc_chng-obj_langu = sy-langu.
gf_doc_chng-obj_name = c_saprpt.
gf_doc_chng-sensitivty = c_value_f.
*Passing text for mail body
it_objbody = space.
APPEND it_objbody.
CLEAR it_objbody.
it_objbody = c_hi.
APPEND it_objbody.
CLEAR it_objbody.
it_objbody = space.
APPEND it_objbody.
CLEAR it_objbody.
it_objbody = text-036.
APPEND it_objbody.
CLEAR it_objbody.
it_objbody = space.
APPEND it_objbody.
CLEAR it_objbody.
it_objbody = c_thanks.
APPEND it_objbody.
CLEAR it_objbody.
it_objbody = space.
APPEND it_objbody.
CLEAR it_objbody.
DESCRIBE TABLE it_objbody LINES l_msg_lines.
READ TABLE it_objbody INDEX l_msg_lines.
gf_doc_chng-doc_size = ( l_msg_lines - 1 ) * 255 + STRLEN( it_objbody
Creation of the entry for the compressed document
it_objpack-transf_bin = ' '.
it_objpack-head_start = 1.
it_objpack-head_num = 0.
it_objpack-body_start = 1.
it_objpack-body_num = l_msg_lines.
it_objpack-doc_type = c_doc_type.
APPEND it_objpack.
CLEAR it_objpack.
LOOP AT it_output_soli.
it_objtxt = it_output_soli.
APPEND it_objtxt.
CLEAR it_objtxt.
ENDLOOP.
Passing the heading of the report
it_objhead = text-037.
APPEND it_objhead.
CLEAR it_objhead.
*To compress the table to size of 255 characters
CALL FUNCTION 'TABLE_COMPRESS'
TABLES
in = it_objtxt
out = it_comprsd.
IF sy-subrc <> 0.
ENDIF.
To decompress the compressed table
CALL FUNCTION 'TABLE_DECOMPRESS'
TABLES
in = it_comprsd
out = it_decomprsd.
IF sy-subrc <> 0.
ENDIF.
Creation of the document attachment
CLEAR : l_msg_lines,l_lines.
DESCRIBE TABLE it_decomprsd LINES l_lines.
IF l_lines <> 0. "Don't create attachment if no data is present
Creation of the entry for the compressed attachment
it_objpack-transf_bin = c_value_x.
it_objpack-head_start = 1.
it_objpack-head_num = 1.
it_objpack-body_start = 1.
it_objpack-body_num = l_lines.
it_objpack-doc_type = c_excel.
it_objpack-obj_name = sy-repid.
it_objpack-obj_descr = text-036.
it_objpack-doc_size = l_lines * 255.
APPEND it_objpack.
CLEAR it_objpack.
ENDIF.
LOOP AT s_email.
it_reclist-receiver = s_email-low.
it_reclist-rec_type = c_rec_type.
it_reclist-express = c_value_x.
APPEND it_reclist.
ENDLOOP.
*Passing maild of the user(who runs the report)
with extension @eur.appliedbiosystems.com
CLEAR it_reclist.
CONCATENATE sy-uname text-031 INTO it_reclist-receiver.
it_reclist-rec_type = c_rec_type.
it_reclist-express = c_value_x.
APPEND it_reclist.
with extension @applera.com
CLEAR it_reclist.
CONCATENATE sy-uname text-032 INTO it_reclist-receiver.
it_reclist-rec_type = c_rec_type.
it_reclist-express = c_value_x.
APPEND it_reclist.
*Sending mail with attachment
CALL FUNCTION 'SO_DOCUMENT_SEND_API1'
EXPORTING
document_data = gf_doc_chng
put_in_outbox = c_val
commit_work = c_val
TABLES
packing_list = it_objpack
contents_bin = it_decomprsd
contents_txt = it_objbody
receivers = it_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 IS NOT INITIAL.
WRITE: / text-034.
ELSE.
WRITE: / text-033.
ENDIF.
ENDFORM. " send_email
Similar Messages
-
How to attach an internal table as excel file in wf container.
Hi all, I have a task that is attaching an xml file in wf container, but I need to attach as excel file, how can I convert this xml to excel ?
my currento code is like this:
* Call Transformation to generate XSTRING of the generated data *
TRY .
CALL TRANSFORMATION ztr_wf_excel
SOURCE appl_stat = li_data2
RESULT XML pi_attach.
CATCH cx_st_error INTO lo_exception.
lv_text = lo_exception->get_text( ).
ENDTRY.
IF lv_text IS INITIAL.
pi_header-file_type = 'B'.
pi_header-file_name = 'Data'.
pi_header-file_extension = 'XLS'.
pi_header-language = 'E'.
CALL FUNCTION 'SAP_WAPI_ATTACHMENT_ADD'
EXPORTING
workitem_id = lw_worklist-wi_id
att_header = pi_header
att_bin = pi_attach
do_commit = 'X'
IMPORTING
att_id = lw_att_id.
this code is working fine, but I need to attach an excel file instead an xml file
How can I do that?
Regardshi ,
Follow this approach :
You can use following funcntions. First one to create internal table to string and second FM SCMS_STRING_TO_XSTRING to convert String to XSTRING. Then this XSTRING value you can pass to CL_WD_RUNTIME_SERVICES=>ATTACH_FILE_TO_RESPONSE.
data: tab_str type string.
data: begin of it_tab1,
name(20),
age(10) ,
end of it_tab1.
data : lv_name type xstring.
data it_tab like STANDARD TABLE OF it_tab1.
data: wa like line of it_tab.
wa-name = 'naresh'.
wa-age = '30'.
append wa to it_tab.
wa-name = 'naresh1'.
wa-age = '31'.
append wa to it_tab.
CALL FUNCTION 'SOTR_SERV_TABLE_TO_STRING'
IMPORTING
TEXT = tab_str
TABLES
TEXT_TAB = it_tab
CALL FUNCTION 'SCMS_STRING_TO_XSTRING'
EXPORTING
TEXT = tab_str
IMPORTING
BUFFER = lv_name
CALL METHOD CL_WD_RUNTIME_SERVICES=>ATTACH_FILE_TO_RESPONSE
EXPORTING
I_FILENAME = 'c:\test.txt'
I_CONTENT = lv_name
I_MIME_TYPE = 'TXT'
Refer below links. This has been discussed many times :
Re: download a file -
ABAP transformation to XML for sap chart engine with internal table
Hello.
I am new to the SAP chart engine, XML and transformations so please be patient with me from an ABAP-program I am trying to call a Z-transformation and attach an internal table with two columns. In the ST program I want to loop through the table and for each row insert the two values from the table in the XML.
In an ABAP-program I have an internal table containing datacoordinates for a scattered chart.
The table looks like this:
DATA: BEGIN OF coordinate,
x_value TYPE f,
y_value TYPE f,
END OF coordinate,
polygon_data LIKE STANDARD TABLE OF coordinate with header line.
As a prototype I just add a few coordinates like this:
polygon_data-x_value = '700'.
polygon_data-y_value = '8'.
APPEND polygon_data.
polygon_data-x_value = '1400'.
polygon_data-y_value = '3'.
APPEND polygon_data.
polygon_data-x_value = '1400'.
polygon_data-y_value = '10'.
APPEND polygon_data.
polygon_data-x_value = '700'.
polygon_data-y_value = '10'.
APPEND polygon_data.
polygon_data-x_value = '700'.
polygon_data-y_value = '3'.
APPEND polygon_data.
I have created a Z-transformation and I call it like this (I also have a separate transformation for all the customizing generated with SAP chart designer but that one works fine):
DATA: data_xml TYPE xstring.
CALL TRANSFORMATION ztest_ce_tables2xml
SOURCE polygon_data = polygon_data
RESULT XML data_xml.
Since I am trying to create a scattered chart I need to insert an X and Y value for each coordinate.In the manual SAP Chart engine - XML format description it looks like this:
<ChartData>
<Series>
<Point>
<Value type="x">1</Value>
<Value type="y">1</Value>
</Point>
<Point>
<Value type="x">2</Value>
<Value type="y">2</Value>
</Point>
My ST-program that I cannot get to work looks like below. How can I loop through my internal table and get the X and thy Y value for each row in my internal table?
BR Tommy (Sweden)
<?sap.transform simple?>
<tt:transform xmlns:tt="http://www.sap.com/transformation-templates">
<tt:root name="POLYGON_DATA"/>
<tt:template>
<ChartData>
<Series>
<tt:loop ref=".POLYGON_DATA">
<Point>
<Value type="x"><tt:copy ref=".POLYGON_DATA.X_VALUE"/></Value>
<Value type="y"><tt:copy ref=".POLYGON_DATA.Y_VALUE"/></Value>
</Point>
</tt:loop>
</Series>
</ChartData>
</tt:template>
</tt:transform>Hello again.
I found the solution and would like to share it with the forum, maybe it could help someone.
My first error was in the call transformation statement:
CALL TRANSFORMATION ztest_ce_tables2xml
SOURCE polygon_data = polygon_data [] <----
Do not forget these
RESULT XML data_xml.
I also had an error in the ST program, it should look like this:
<?sap.transform simple?>
<tt:transform xmlns:tt="http://www.sap.com/transformation-templates">
<tt:root name="POLYGON_DATA"/>
<tt:template>
<ChartData>
<Series>
<tt:loop ref=".POLYGON_DATA">
<Point>
<Value type="x"><tt:value ref="$ref.X_VALUE"/></Value>
<Value type="y"><tt:value ref="$ref.Y_VALUE"/></Value>
</Point>
</tt:loop>
</Series>
</ChartData>
</tt:template>
</tt:transform> -
Internal Table attached as Excel file to an eMail - BCS_EXAMPLE_7 for UC
Hi forums,
SAP provided an example report to send out internal tables attached as an Excel file to a recipients eMail address. I attached the coding of the BCS_EXAMPLE_7 programm to this thread.
report bcs_example_7.
This report provides an example for sending an Excel
attachment in Unicode Systems
constants:
gc_tab type c value cl_bcs_convert=>gc_tab,
gc_crlf type c value cl_bcs_convert=>gc_crlf.
parameters:
mailto type ad_smtpadr
default 'john.doe(a)crazy-company.com'. "#EC *
data send_request type ref to cl_bcs.
data document type ref to cl_document_bcs.
data recipient type ref to if_recipient_bcs.
data bcs_exception type ref to cx_bcs.
data main_text type bcsy_text.
data binary_content type solix_tab.
data size type so_obj_len.
data sent_to_all type os_boolean.
start-of-selection.
perform create_content.
perform send.
*& Form send
form send.
try.
-------- create persistent send request ------------------------
send_request = cl_bcs=>create_persistent( ).
-------- create and set document with attachment ---------------
create document object from internal table with text
append 'Hello world!' to main_text. "#EC NOTEXT
document = cl_document_bcs=>create_document(
i_type = 'RAW'
i_text = main_text
i_subject = 'Test Created By BCS_EXAMPLE_7' ). "#EC NOTEXT
add the spread sheet as attachment to document object
document->add_attachment(
i_attachment_type = 'xls' "#EC NOTEXT
i_attachment_subject = 'ExampleSpreadSheet' "#EC NOTEXT
i_attachment_size = size
i_att_content_hex = binary_content ).
add document object to send request
send_request->set_document( document ).
--------- add recipient (e-mail address) -----------------------
create recipient object
recipient = cl_cam_address_bcs=>create_internet_address( mailto ).
add recipient object to send request
send_request->add_recipient( recipient ).
---------- send document ---------------------------------------
sent_to_all = send_request->send( i_with_error_screen = 'X' ).
commit work.
if sent_to_all is initial.
message i500(sbcoms) with mailto.
else.
message s022(so).
endif.
------------ exception handling ----------------------------------
replace this rudimentary exception handling with your own one !!!
catch cx_bcs into bcs_exception.
message i865(so) with bcs_exception->error_type.
endtry.
endform. "send
*& Form create_content
Create Example Content
1) Write example text into a string
2) convert this string to solix_tab
form create_content.
data lv_string type string.
data ls_t100 type t100.
as example content we use some system messages out of t100
get them for all installed languages from db
and write one line for each language into the spread sheet
columns are separated by TAB and each line ends with CRLF
concatenate 'This Is Just Example Text!' "#EC NOTEXT
gc_crlf gc_crlf
into lv_string.
header line
concatenate lv_string
'MSGID' gc_tab
'MSGNO' gc_tab
'Language' gc_tab "#EC NOTEXT
'Text' gc_crlf "#EC NOTEXT
into lv_string.
data lines
select * from t100 into ls_t100
where arbgb = 'SO' and msgnr = '182'.
concatenate lv_string
ls_t100-arbgb gc_tab
ls_t100-msgnr gc_tab
ls_t100-sprsl gc_tab
ls_t100-text gc_crlf
into lv_string.
endselect.
select * from t100 into ls_t100
where arbgb = 'SO' and msgnr = '316'.
concatenate lv_string
ls_t100-arbgb gc_tab
ls_t100-msgnr gc_tab
ls_t100-sprsl gc_tab
ls_t100-text gc_crlf
into lv_string.
endselect.
convert the text string into UTF-16LE binary data including
byte-order-mark. Mircosoft Excel prefers these settings
all this is done by new class cl_bcs_convert (see note 1151257)
try.
cl_bcs_convert=>string_to_solix(
exporting
iv_string = lv_string
iv_codepage = '4103' "suitable for MS Excel, leave empty
iv_add_bom = 'X' "for other doc types
importing
et_solix = binary_content
ev_size = size ).
catch cx_bcs.
message e445(so).
endtry.
endform. "create_content
NOTES:
UTF-16LE including the BOM (Byte order mark)
is preferred by Microsoft Excel. If you want to create
other binary content you may choose another codepage (e.g.
'4110' (UTF-8) which is standard for e-mails).
Find SAP codepage names in the drop down list
for the codepage setting of node SMTP in transaction SCOT.
Or: leave iv_codepage and iv_add_bom empty. Then the target
codepage is set according to SAPconnect settings
Important:
SAP neither guarantees that the attachment created
by this report can be opened by all Excel Versions nor
that it can be opened by any 3rd party software at all
Best regards to you
Thorsten Hüser
SAP CRM Senior consultant
arvato / BertelsmannHi forums,
SAP provided an example report to send out internal tables attached as an Excel file to a recipients eMail address. I attached the coding of the BCS_EXAMPLE_7 programm to this thread.
report bcs_example_7.
This report provides an example for sending an Excel
attachment in Unicode Systems
constants:
gc_tab type c value cl_bcs_convert=>gc_tab,
gc_crlf type c value cl_bcs_convert=>gc_crlf.
parameters:
mailto type ad_smtpadr
default 'john.doe(a)crazy-company.com'. "#EC *
data send_request type ref to cl_bcs.
data document type ref to cl_document_bcs.
data recipient type ref to if_recipient_bcs.
data bcs_exception type ref to cx_bcs.
data main_text type bcsy_text.
data binary_content type solix_tab.
data size type so_obj_len.
data sent_to_all type os_boolean.
start-of-selection.
perform create_content.
perform send.
*& Form send
form send.
try.
-------- create persistent send request ------------------------
send_request = cl_bcs=>create_persistent( ).
-------- create and set document with attachment ---------------
create document object from internal table with text
append 'Hello world!' to main_text. "#EC NOTEXT
document = cl_document_bcs=>create_document(
i_type = 'RAW'
i_text = main_text
i_subject = 'Test Created By BCS_EXAMPLE_7' ). "#EC NOTEXT
add the spread sheet as attachment to document object
document->add_attachment(
i_attachment_type = 'xls' "#EC NOTEXT
i_attachment_subject = 'ExampleSpreadSheet' "#EC NOTEXT
i_attachment_size = size
i_att_content_hex = binary_content ).
add document object to send request
send_request->set_document( document ).
--------- add recipient (e-mail address) -----------------------
create recipient object
recipient = cl_cam_address_bcs=>create_internet_address( mailto ).
add recipient object to send request
send_request->add_recipient( recipient ).
---------- send document ---------------------------------------
sent_to_all = send_request->send( i_with_error_screen = 'X' ).
commit work.
if sent_to_all is initial.
message i500(sbcoms) with mailto.
else.
message s022(so).
endif.
------------ exception handling ----------------------------------
replace this rudimentary exception handling with your own one !!!
catch cx_bcs into bcs_exception.
message i865(so) with bcs_exception->error_type.
endtry.
endform. "send
*& Form create_content
Create Example Content
1) Write example text into a string
2) convert this string to solix_tab
form create_content.
data lv_string type string.
data ls_t100 type t100.
as example content we use some system messages out of t100
get them for all installed languages from db
and write one line for each language into the spread sheet
columns are separated by TAB and each line ends with CRLF
concatenate 'This Is Just Example Text!' "#EC NOTEXT
gc_crlf gc_crlf
into lv_string.
header line
concatenate lv_string
'MSGID' gc_tab
'MSGNO' gc_tab
'Language' gc_tab "#EC NOTEXT
'Text' gc_crlf "#EC NOTEXT
into lv_string.
data lines
select * from t100 into ls_t100
where arbgb = 'SO' and msgnr = '182'.
concatenate lv_string
ls_t100-arbgb gc_tab
ls_t100-msgnr gc_tab
ls_t100-sprsl gc_tab
ls_t100-text gc_crlf
into lv_string.
endselect.
select * from t100 into ls_t100
where arbgb = 'SO' and msgnr = '316'.
concatenate lv_string
ls_t100-arbgb gc_tab
ls_t100-msgnr gc_tab
ls_t100-sprsl gc_tab
ls_t100-text gc_crlf
into lv_string.
endselect.
convert the text string into UTF-16LE binary data including
byte-order-mark. Mircosoft Excel prefers these settings
all this is done by new class cl_bcs_convert (see note 1151257)
try.
cl_bcs_convert=>string_to_solix(
exporting
iv_string = lv_string
iv_codepage = '4103' "suitable for MS Excel, leave empty
iv_add_bom = 'X' "for other doc types
importing
et_solix = binary_content
ev_size = size ).
catch cx_bcs.
message e445(so).
endtry.
endform. "create_content
NOTES:
UTF-16LE including the BOM (Byte order mark)
is preferred by Microsoft Excel. If you want to create
other binary content you may choose another codepage (e.g.
'4110' (UTF-8) which is standard for e-mails).
Find SAP codepage names in the drop down list
for the codepage setting of node SMTP in transaction SCOT.
Or: leave iv_codepage and iv_add_bom empty. Then the target
codepage is set according to SAPconnect settings
Important:
SAP neither guarantees that the attachment created
by this report can be opened by all Excel Versions nor
that it can be opened by any 3rd party software at all
Best regards to you
Thorsten Hüser
SAP CRM Senior consultant
arvato / Bertelsmann -
Problem In Integrating 3 Internal Tables to make data for email attachment
Hi All,
I am facing a problem. I am having some data in 3 internal tables. Consider it Header Data, Details Data, Tail Data in 3 different Internal tables with different Fields.
Now I want to send this data as an attachment in email. Now the problem is I am integrating the data in 3 internal tables into 1 single internal table with the help of following code :
loop at it1.
concatenate it1-field1
it1-field2
into itab.
append itab.
endloop.
loop at it2.
concatenate it2-field1
it2-field2
into itab.
append itab.
endloop.
similarly for 3rd internal table. But here it goes wrong.
For each and every field in each record, some specific number of characters are fixed. If any field doesn't uses those characters to complete, it has to leave the remaining characters blank and should start next field from there.
E.g.
Like record is :
AAA reserved chars : 10
XXX " " : 15
YYY " " : 8
so it should print like :
AAA XXX YYY .
But in attachment it is printing like :
AAAXXXYYY.
This is because I am using concatenate function. Please suggest me a way to integrate the data of 3 internal tables into a single internal table including the spaces reserved for each field.
Thanks.Hi Ravi,
Did u try to use de addicion 'Separated by space' in the concatenate function?
If it doesn't work, try this...
You have to do as if you want to create a text file, using de offset function.
Creating an internal table with one field and put all the records of your tables into this internal table.
data: wa_line(400).
data: begin of itab_line occurs 0,
line(400),
endif itab_line.
Loop at itab1.
clear wa_line.
write: itab1-field1 to wa_line+0(10).
write: itab1-field2 to wa_line+10(8).
write: itab1-fieldN to wa_line+nn(mm).
append wa_line to itab_line.
clear itab_line.
endloop.
Do the same with itab2 and itab3.
Cheers,
FC. -
Problem with Emailing the Internal table data as an excel attachment
Hi Friends,
I am facing problem with Emailing an internal table data as an excel file. I am using standard function module "SO_NEW_DOCUMENT_ATT_SEND_API1" which is using SOLI structure can have record with 255 character length. But my Internal table having each record means after concatenating all the fields it is going to be morethan 450 characters. so i t is not displaying all the data in excel file.
Can somebody help me if there is any other function module or any other way that i need to follow.
thanks for help
venkat.You must use the the :
CL_ABAP_CHAR_UTILITIES=>HORIZONTAL_TAB as a field seperator and
CL_ABAP_CHAR_UTILITIES=>CR_LF as a record seperator.
Check this example:
http://www.sapdevelopment.co.uk/reporting/email/attach_xls.htm
Regards,
Naimesh Patel -
Excel attachment contains only 1st row of Internal Table.
Hello,
I have designed a Vendor Ledger report and want to send the same as an excel attachment. I have made use of function module SO_NEW_DOCUMENT_ATT_SEND_API1 wherein I pass the parameters.
The program works perfectly fine as I am receiving email along with the excel attachment. Also, the excel attachment opens without any errors. Also, the alignment of columns and data is perfect.
But the problem is if my internal table is having 10 rows, I get only the first row of the internal table in the excel sheet.
I also put a break point just before calling the function module to send email, I could see that the internal table which contains the attachment is having all 10 rows.
I really don't know what's going wrong in this.
Request you to please help.
Regards,
Danish.Hi,
Hi this is my code. Also, one thing I found that if i remove the Report Name i.e. "Vendor Ledger" , I get more than 1 row in my excel sheet. I feel there is some problem with the document size attributes.
* Header for exception report
CONCATENATE 'CC' 'Vendor' 'Stat' 'Name' 'Doc.No' 'FY' 'DDate' 'PDate'
'AssNo.' 'Doc.Tp' 'G/L' 'LAmt' 'LCurr' 'DAmt'
'D/C' 'Cl.Doc' 'TaxCd' 'TaxAmt'
INTO it_attachment SEPARATED BY
cl_abap_char_utilities=>horizontal_tab.
CONCATENATE cl_abap_char_utilities=>cr_lf it_attachment INTO it_attachment.
APPEND it_attachment.
* Split Internal table data using horizontal tab.
CLEAR it_main.
LOOP AT it_main.
CLEAR: lc_amt, dc_amt, tax_amt.
lc_amt = it_main-lc_amount.
dc_amt = it_main-amt_doccur.
tax_amt = it_main-w_tax_base.
CONCATENATE it_main-comp_code
it_main-vendor
it_main-status
it_main-name1
it_main-doc_no
it_main-fisc_year
it_main-doc_date
it_main-pstng_date
it_main-alloc_nmbr
it_main-doc_type
it_main-sp_gl_ind
lc_amt
it_main-loc_currcy
dc_amt
it_main-db_cr_ind
it_main-clr_doc_no
it_main-w_tax_code
tax_amt
INTO it_attachment SEPARATED BY
cl_abap_char_utilities=>horizontal_tab.
CONCATENATE cl_abap_char_utilities=>cr_lf it_attachment INTO it_attachment.
APPEND it_attachment.
ENDLOOP.
* Create Mail Body and Attachment.
psubject = 'Vendor Ledger'.
lv_message = 'Dear Sir/Madam,'.
APPEND lv_message TO it_message.
lv_message = ' '.
APPEND lv_message TO it_message.
lv_message = 'Attachment contain Vendor Ledger for Testing.'.
APPEND lv_message TO it_message.
lv_message = ' '.
APPEND lv_message TO it_message.
lv_message = ' '.
APPEND lv_message TO it_message.
lv_message = 'This is a System Generated Mail. Please do not reply.'.
APPEND lv_message TO it_message.
**Perform for populating mail characteristic info
CLEAR gd_doc_data.
* Populate the subject/generic message attributes
gd_doc_data-obj_langu = sy-langu.
READ TABLE it_attachment INDEX w_cnt.
gd_doc_data-doc_size = 1.
gd_doc_data-obj_name = 'Danish'. "'SAPRPT'.
gd_doc_data-obj_descr = psubject.
gd_doc_data-sensitivty = 'F'.
* Describe the body of the message
CLEAR it_packing_list.
REFRESH it_packing_list.
it_packing_list-transf_bin = space.
it_packing_list-head_start = 1.
it_packing_list-head_num = 0.
it_packing_list-body_start = 1.
DESCRIBE TABLE it_message LINES it_packing_list-body_num.
it_packing_list-doc_size = it_packing_list-body_num * 255.
it_packing_list-doc_type = 'RAW'.
APPEND it_packing_list.
**Describe the attachment info
CLEAR it_packing_list.
it_packing_list-transf_bin = 'X'.
it_packing_list-head_start = 1.
it_packing_list-head_num = 1.
it_packing_list-body_start = 1.
DESCRIBE TABLE it_attachment LINES it_packing_list-body_num.
it_packing_list-doc_type = 'XLS'.
it_packing_list-obj_name = 'File'.
it_packing_list-obj_descr = 'File'.
it_packing_list-doc_size = it_packing_list-body_num * 255.
APPEND it_packing_list.
REFRESH it_receivers.
CLEAR it_receivers.
it_receivers-receiver = 'Email Address'.
it_receivers-rec_type = 'U'.
it_receivers-com_type = 'INT'.
APPEND it_receivers.
**Function Module to send mail
CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
EXPORTING
document_data = gd_doc_data
put_in_outbox = 'X'
commit_work = 'X'
TABLES
packing_list = it_packing_list
contents_bin = it_attachment
contents_txt = it_message
receivers = it_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.
Regards,
Danish. -
How Internal table data send to sap mail as a attachment?
Hi,
Can any one please let me know , how we will send internal table data to sap mail.
In my internal table my data output length is more than 255 characters.
Thanks in advance.Hi
Try out the below code:
DATA: ld_mtitle LIKE sodocchgi1-obj_descr,
ld_format TYPE so_obj_tp ,
ld_attdescription TYPE so_obj_nam ,
ld_attfilename TYPE so_obj_des .
* ld_receiver LIKE sy-subrc.
DATA: it_packing_list LIKE sopcklsti1 OCCURS 0 WITH HEADER LINE,
it_attachment LIKE solisti1 OCCURS 0 WITH HEADER LINE,
it_receivers LIKE somlreci1 OCCURS 0 WITH HEADER LINE,
w_cnt TYPE i,
w_sent_all(1) TYPE c, "#EC NEEDED
w_doc_data LIKE sodocchgi1.
REFRESH it_receivers . CLEAR it_receivers .
IF v_trip_send = 'X'.
it_receivers-receiver = it_trip_dload-approver_email .
ELSE .
it_receivers-receiver = it_adv_dload-approver_email .
ENDIF.
it_receivers-rec_type = c_u .
APPEND it_receivers. CLEAR it_receivers.
* it_receivers-receiver = ' <Email ID> ' "Email address.
IF v_trip_send = 'X' .
it_receivers-receiver = it_trip_dload-requester_email .
ELSE .
it_receivers-receiver = it_adv_dload-requester_email .
ENDIF .
it_receivers-rec_type = c_u .
it_receivers-copy = 'X' .
APPEND it_receivers. CLEAR it_receivers.
ld_mtitle = p_mtitle.
ld_format = p_format.
ld_attdescription = p_attdescription.
ld_attfilename = p_filename.
* Fill the document data.
w_doc_data-doc_size = 1.
* Populate the subject/generic message attributes
w_doc_data-obj_langu = sy-langu.
w_doc_data-obj_name = c_saprpt.
w_doc_data-obj_descr = ld_mtitle .
w_doc_data-sensitivty = 'F'.
* Fill the document data and get size of attachment
CLEAR w_doc_data.
READ TABLE it_attach INDEX w_cnt.
w_doc_data-doc_size =
( w_cnt - 1 ) * 255 + STRLEN( it_attach ).
w_doc_data-obj_langu = sy-langu.
w_doc_data-obj_name = c_saprpt.
w_doc_data-obj_descr = ld_mtitle.
w_doc_data-sensitivty = c_f.
CLEAR it_attachment.
REFRESH it_attachment.
it_attachment[] = it_attach[].
* Describe the body of the message
CLEAR it_packing_list.
REFRESH it_packing_list.
it_packing_list-transf_bin = space.
it_packing_list-head_start = 1.
it_packing_list-head_num = 0.
it_packing_list-body_start = 1.
DESCRIBE TABLE it_message LINES it_packing_list-body_num.
it_packing_list-doc_type = c_raw.
APPEND it_packing_list.
* Create attachment notification
it_packing_list-transf_bin = c_x.
it_packing_list-head_start = 1.
it_packing_list-head_num = 1.
it_packing_list-body_start = 1.
DESCRIBE TABLE it_attachment LINES it_packing_list-body_num.
it_packing_list-doc_type = ld_format.
it_packing_list-obj_descr = ld_attdescription.
it_packing_list-obj_name = ld_attfilename.
it_packing_list-doc_size = it_packing_list-body_num * 255.
APPEND it_packing_list.
CALL FUNCTION 'SO_DOCUMENT_SEND_API1'
EXPORTING
document_data = w_doc_data
put_in_outbox = c_x
commit_work = c_x
IMPORTING
sent_to_all = w_sent_all
TABLES
packing_list = it_packing_list
contents_bin = it_attachment
contents_txt = it_message
receivers = it_receivers.
&*********<removed_by_moderator_together_with_6_unmentionables>************&
Edited by: Julius Bussche on Jun 23, 2008 11:04 PM -
Send An Internal Table Via Excel File As An Attachment of E-mail
Hi,
I've sent my internal table via Excel file as an attachment of email but all records of internal table are in a row of sended excel file.
How can i send an internal table via excel file , records of internal table for each rows of excel file,as an attachment of email correctly?
CALL FUNCTION 'SO_DOCUMENT_SEND_API1'
EXPORTING
document_data = w_doc_data
put_in_outbox = 'X'
sender_address = ld_sender_address
sender_address_type = ld_sender_address_type
commit_work = 'X'
IMPORTING
sent_to_all = w_sent_all
TABLES
packing_list = t_packing_list " t_packing_list-doc_type = 'XLS'.
contents_bin = pit_attach " this is a normal internal table.
contents_txt = pit_message
receivers = 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.Hi,
CLASS CL_ABAP_CHAR_UTILITIES DEFINITION LOAD.
CONSTANTS:
CON_TAB TYPE C VALUE CL_ABAP_CHAR_UTILITIES=>HORIZONTAL_TAB,
CON_CRET TYPE C VALUE CL_ABAP_CHAR_UTILITIES=>CR_LF.
LOOP AT T_FINAL INTO WA_T_FINAL.
CONCATENATE WA_T_FINAL-PERNR
WA_T_FINAL-NAME
WA_T_FINAL-LEVEL
WA_T_FINAL-POS
WA_T_FINAL-JOB
WA_T_FINAL-SECTION
WA_T_FINAL-DEPT
WA_T_FINAL-GROUP
WA_T_FINAL-EX_HEAD
WA_T_FINAL-SUPID
WA_T_FINAL-SUPNM
WA_T_FINAL-FHRNM
WA_T_FINAL-VACID
WA_T_FINAL-VAC_SECTION
WA_T_FINAL-VAC_DEPT
WA_T_FINAL-VAC_GROUP
WA_T_FINAL-VAC_EX_HEAD
WA_T_FINAL-VAC_FHRNM
INTO T_FINAL3 SEPARATED BY CON_TAB.
CONCATENATE CON_CRET T_FINAL3 INTO T_FINAL3.
APPEND T_FINAL3.
ENDLOOP.
*Fill the document data.
W_DOC_DATA-DOC_SIZE = 1.
*Populate the subject/generic message attributes
W_DOC_DATA-OBJ_LANGU = SY-LANGU.
W_DOC_DATA-OBJ_NAME = 'REPORT'.
W_DOC_DATA-OBJ_DESCR = LD_MTITLE . "mail description
W_DOC_DATA-SENSITIVTY = 'F'.
*Fill the document data and get size of attachment
CLEAR W_DOC_DATA.
READ TABLE T_FINAL1 INDEX W_CNT.
W_DOC_DATA-DOC_SIZE =
( W_CNT - 1 ) * 255 + STRLEN( T_FINAL1 ).
W_DOC_DATA-OBJ_LANGU = SY-LANGU.
W_DOC_DATA-OBJ_NAME = 'SAPRPT'.
W_DOC_DATA-OBJ_DESCR = LD_MTITLE.
W_DOC_DATA-SENSITIVTY = 'F'.
CLEAR T_ATTACHMENT.
REFRESH T_ATTACHMENT.
T_ATTACHMENT[] = PT_FINAL1[].
*Describe the body of the message
CLEAR T_PACKING_LIST.
REFRESH T_PACKING_LIST.
T_PACKING_LIST-TRANSF_BIN = SPACE.
T_PACKING_LIST-HEAD_START = 1.
T_PACKING_LIST-HEAD_NUM = 0.
T_PACKING_LIST-BODY_START = 1.
DESCRIBE TABLE IT_MESSAGE LINES T_PACKING_LIST-BODY_NUM.
T_PACKING_LIST-DOC_TYPE = 'RAW'.
APPEND T_PACKING_LIST.
*Create 1st attachment notification
T_PACKING_LIST-TRANSF_BIN = 'X'.
T_PACKING_LIST-HEAD_START = 1.
T_PACKING_LIST-HEAD_NUM = 1.
T_PACKING_LIST-BODY_START = 1.
DESCRIBE TABLE T_ATTACHMENT LINES T_PACKING_LIST-BODY_NUM.
T_PACKING_LIST-DOC_TYPE = LD_FORMAT.
T_PACKING_LIST-OBJ_DESCR = 'Application 1'.
T_PACKING_LIST-OBJ_NAME = 'Application 1'.
T_PACKING_LIST-DOC_SIZE = T_PACKING_LIST-BODY_NUM * 255.
APPEND T_PACKING_LIST.
CLEAR T_PACKING_LIST.
*Add the recipients email address
CLEAR T_RECEIVERS.
REFRESH T_RECEIVERS.
T_RECEIVERS-RECEIVER = LD_EMAIL.
T_RECEIVERS-REC_TYPE = 'U'.
T_RECEIVERS-COM_TYPE = 'INT'.
T_RECEIVERS-NOTIF_DEL = 'X'.
T_RECEIVERS-NOTIF_NDEL = 'X'.
APPEND T_RECEIVERS.
CALL FUNCTION 'SO_DOCUMENT_SEND_API1'
EXPORTING
DOCUMENT_DATA = W_DOC_DATA
PUT_IN_OUTBOX = 'X'
SENDER_ADDRESS = LD_SENDER_ADDRESS
SENDER_ADDRESS_TYPE = LD_SENDER_ADDRESS_TYPE
COMMIT_WORK = 'X'
IMPORTING
SENT_TO_ALL = W_SENT_ALL
TABLES
PACKING_LIST = T_PACKING_LIST
CONTENTS_BIN = T_ATTACHMENT
CONTENTS_TXT = IT_MESSAGE
RECEIVERS = 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.
Edited by: Rahul Ghosh on Apr 6, 2009 6:42 AM -
Internal table to XLS to email
Hi,
A lot of postings here and on other SAP communities are talking about email and attachment issues. But a proper answer to my problem i haven't found yet.
Problem : i'm having an internal table (with text, amount, currencies, dates, so different formats) and i want to send it as a 'real' excel file (not as tab delimited or csv file, but as real excel with the correct formats) to an email receiver. The columns with amount and currencies should work correctly after opening the file in Excel.
The main problem is to convert the internal table to an binary internal table (max record length 255) of type excel. By the way, i also need it in background.
I don't know if the MIME format is binary, but a convert from internal table to MIME (corresponding to the excel attachment) is also possible ?
regards,
Hans
[email protected]Sorry for the late answer.
You don't need a WAS java stack to run a java programm on your server.
Follow these steps:
1) Install a java runtime environment (jre) on the filesystem of your server (take care of rights for executing)
2) Write a java programm on your pc, that uses an excel library mentioned before. It should get a source filename as parameter. Deploy it to your server. Write a batch command to execute the program like this "java your_program your_parameter"
3) Extract your tabulary data from within abap and write it to a csv - file (comma separated value) on your server
4) Send an event from within abap (uh oh)
5) On event, call a batch command from within your server OS and run the java program with the filename you created before (uh oh).
As you can see, it's is not easy to do that, but it should work. In my opinion, it is a very ugly way to solve the problem.
I don't know, if abap supports a SPAWN routine like C or C++. This could be an easier way to call a program on your server from within abap.
On a WAS 640 there is a java stack if you to install it. There you can implement a java based utility service (servlet) that converts your data to excel.
Another opinion: Use another j2ee servlet server (i.e. apache tomcat, works fine, no license fee). You can install it on your sap server or on another maschine.
Good luck and kind regards,
Andreas -
Email internal table as zip file
Hello everyone
I spent several days to have a full example on how to convert an internal table has ZIP file than send it by email.
I found several example to upload file from the OS and than convert it to ZIP to save it after. But nothing from the current internal email.
So, for the benefit of everybody who that can interrest, here is the code I did. Feel free to optimize it and post the new version here.
===========================================
Moderator message - Please respect the 2,500 character maximum when posting. Post only the relevant portions of code
==========================================
Regards
dstj
Edited by: Rob Burbank on Feb 12, 2010 2:09 PMHello Daniel,
Thank you very much for this post, it is quite helpful. However, I have followed your template very closely and my file will not send. I am not an advaned ABAP programmer, but have a good knowledge of programming in general...here's a bit of my code related to this...
*-Create table body
LOOP AT (internal table) INTO (structure)
(Fill lv_line with one line of string based on structure)
CALL FUNCTION 'SCMS_STRING_TO_XSTRING'
EXPORTING
text = lv_line
IMPORTING
buffer = lv_xline
CONCATENATE lv_xcontent lv_xline INTO lv_xcontent IN BYTE MODE.
ENDLOOP.
*-Create zip xstring
CREATE OBJECT lo_zipper.
CALL METHOD lo_zipper->add
EXPORTING
name = 'AHReport.zip'
content = lv_xcontent.
CALL METHOD lo_zipper->save
RECEIVING
zip = lv_xzipcontent.
*-Convert zip xstring to binary
CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'
EXPORTING
buffer = lv_xzipcontent
TABLES
binary_tab = lt_data.
*- Add attachment
TRY.
CALL METHOD l_document->add_attachment
EXPORTING
i_attachment_type = 'ZIP'
i_attachment_subject = 'Report'
i_att_content_hex = lt_data.
CATCH cx_document_bcs.
ENDTRY.
Any help would be very much appreciated, ty. -
Displaying the contents of internal table- in email Step of workflows
Hello Folks,
I wanted to display the contents of an internal table ( would contain a list of opportunites ), in an email sent throught the workflow:
My idea was to LOOP AT <ITAB> into <WA> from an external program and then call the workflow for each content of the <WA>. This will be a problem as, if there are like 1000 records in the internal table, then workflows will be called 1000 times...sending 1000 emails..
My requirement is that we need to send a single email to the single person, displaying the content of the internal table in the email body......
My question
1) Is this scenario possible through worflows ?
2) If not, please provide an alternative ..
Thanks
AnandDo you mean to say that just by inserting the multiline element
within the body of the 'Send email' step type, the contents
of the multiline element is displayed automatically without
we having to loop at it somehow ?
Follow the below apporach,
1. First create a multiline container element in the workflow conatiner.
2. Populate the internla table , by using the bor methods and pass back the populated ITAB to the WF by using the binding concept.
3. Now create a mail step in the workflow, you have the option of inserting the workflow container elements into the mail conten, so insert the multiline container element , then it prompts to select the option like a) Do you liek to display only first line b) Display the ITAB line by line c) Display ITAB lines continuously with out line break.
4. based upon the requirement select any one of the options.
Note: Make sure the line length of the ITAB won't excced 132 charecters, because the send mail step will consider only 132 characters. -
Send internal table to pdf and then email.
hi experts.
i want to send my alv data or any other data like internal table in pdf through email.
anybody help me out plz.Hi Harris,
You got to use two FMs to achieve this.
First one to get the contents in to an internal table
Second one to send an e-mail with the content selected already.
So, better search SDN to get more info... -
Send excel attachment with more than 255 characters in the internal table
Hi,
I need to send an attachment in the form of spreadsheet.
But the internal table that is being used for sending attachment in mails can have only 255 characters in one row.
Whereas my spreadsheet requires a greater width than 255 characters .Hi,
I need to send an attachment in the form of spreadsheet.
But the internal table that is being used for sending attachment in mails can have only 255 characters in one row.
Whereas my spreadsheet requires a greater width than 255 characters . -
Every time my lg g pad 8.3 lte tablet is turned off it reverts the saving email attachment back to internal storage. Every time I turn on, I change it back to save to SD card. It stays that way until it is turned off for more than a minute. If I do a restart, it holds the setting, but loses it when it is shut down for any period of time. Does anyone else have this issue? The setting holds for photos taken with camera storing to SD card. Only the email attachment setting does not hold.
I believe that system has a hall sensor on it to detect when the lid is closed so it can put the system to sleep and/or disable the monitor so it can be used with an external monitor only. If the sensor is marginal or has a bad cable, it may intermittently cut the monitor on and off, and may likewise put the system to sleep. One way to check would be to plug in an external monitor and if the laptop's screen cuts off or doesn't show up, start using the trackpad and press on a non-typing key like the shift key. If the external display suddenly pops and becomes active while the laptop display remains black, it's probably a problem with the sensor or the cable/connection. You might be able to fool the sensor into kicking on and off by moving a magnet over it. It's located on the left had side of the base with the unit opened up, and right over the audio output plug.
I know of some people that put a small magnet right over the hall sensor's location so the laptop display turns off and they use the system with an external monitor, keyboard, and mouse. If fooling with magnets, make sure they're small and don't get them close to the hard drive because a strong magnet can wipe them out.
I don't know if this will help you much, but it might.
Maybe you are looking for
-
HI All I want to display Entry Date while displaying line items. How can i do that. Thanks Gautam Anand
-
Build 7600 This Copy of Windows is not genuine
Diagnostic Report (1.9.0027.0): Windows Validation Data--> Validation Code: 50 Cached Online Validation Code: N/A, hr = 0xc0000034 Windows Product Key: *****-*****-QXY7X-TG33Q-9TDMY Windows Product Key Hash: mfe+izvSb6PsVJ/TfAP4kLVWtF0= Windows Produ
-
WHEN TO USE LOGGER IN CREATE INDEX?
HI ALL, WHEN TO USE LOGGER IN CREATE INDEX STATEMENT? AND WHEN TO USE NOLOGGING? HOW IS INDEX PHYSICALLY STORED IN DATABASE? THANKS IN ADVANCE. SANDESH
-
Restoring computer monitor's native resolution
Hi all, In the middle of downloading and installing Windows updates, updating drivers, and restarting the computer, my computer monitor's resolution somehow changed. I believe that the native resolution is 1400x1050, but I can't seem to find that un
-
Accruals in Purchasing....can they be recognized the Projects
Hello All, I have a questions about accruals in Projects, our Apps. version is 11.0.2, we have set our Accrue Inventory Items set to On Reciept. We would like to set the Accrue Expense Items to On Receipt also. I have read that there is no intergrati