Spool to XLS
is this possible?
what FM can i use to automatically download a spool to excel file.
like i only have to give the spool number then it will be saved into excel.
and this has to be run as a background job.
Hi,
I guess, there is no direct FM to convert spool into XLS . But there is FM to convert into PDF and send PDF as .XLS attachment to any user.
I have seen one sample program in the below link, you can look at that one and use if it is useful to ur requirement.
http://diocio.wordpress.com/2007/02/12/sap-convert-spool-request-to-pdf-and-send-as-e-mail/
Regards,
Naveen Veshala
Similar Messages
-
Convert the spool to xls format and email through attachment to the user
Hi all,
When I execute a report in background, I get spool. I need to convert the spool to xls format and email through attachment to the user.The xls file should not be saved on local system.
If I use the Spool Recepient tab in SM37 it mails the spool list as .txt file to the mail receipient. But I need to send it as an .xls file.
Can any one help me on thisDid you get the solution? i have the same problem.
-
Convert spool to xls and send the attachment through email
Hello,
I have a requirement to convert spool to xls and then send the xls as an attachment through email,how sould i go about it,which fm can i use please advice..
Thanks.Please check the links
Re: Spool to XLS
Re: converting spool data to xls file format.
Regards
Satish Boguda -
Problem when converting from spool to XLS file
Hey.
I need to get table data from the spool and send it by mail in an xls file.
so this is what i have done:
I have used the FM 'RSPO_RETURN_ABAP_SPOOLJOB' to get the data table from the spool.
then i am sending the data table in an xls file via the FM 'SO_DOCUMENT_SEND_API1'.
the problem is that the xls file that i am getting through the mail is defected.
All the contents of the spool is located in the first row, first column.
How can i fix it?
Thanks, Barak.After geting the data in a internal table.from spool......refer this report.....
data: p_email type somlreci1-receiver
value 'MAIL ID'.
data: begin of it001 occurs 0,
bukrs type t001-bukrs,
butxt type t001-butxt,
end of it001.
data: imessage type standard table of solisti1 with header line,
iattach type standard table of solisti1 with header line,
ipacking_list like sopcklsti1 occurs 0 with header line,
ireceivers like somlreci1 occurs 0 with header line,
iattachment like solisti1 occurs 0 with header line.
start-of-selection.
select bukrs butxt into table it001 from t001.
Populate table with detaisl to be entered into .xls file
perform build_xls_data .
Populate message body text
clear imessage. refresh imessage.
imessage = 'Please find attached excel file'.
append imessage.
Send file by email as .xls speadsheet
perform send_email_with_xls tables imessage
iattach
using p_email
'Example Excel Attachment'
'XLS'
'TestFileName'
'CompanyCodes'.
Form BUILD_XLS_DATA
form build_xls_data .
constants: con_cret type x value '0D', "OK for non Unicode
con_tab type x value '09'. "OK for non Unicode
*If you have Unicode check active in program attributes thnen you will
*need to declare constants as follows
*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.
concatenate 'BUKRS' 'BUTXT'
into iattach separated by con_tab.
concatenate con_cret iattach into iattach.
append iattach.
loop at it001 .
concatenate it001-bukrs it001-butxt
into iattach separated by con_tab.
concatenate con_cret iattach into iattach.
append iattach.
endloop .
endform.
Form SEND_EMAIL_WITH_XLS
form send_email_with_xls tables pit_message
pit_attach
using p_email
p_mtitle
p_format
p_filename
p_attdescription.
data: xdocdata like sodocchgi1,
xcnt type i.
Fill the document data.
xdocdata-doc_size = 1.
Populate the subject/generic message attributes
xdocdata-obj_langu = sy-langu .
xdocdata-obj_name = 'SAPRPT' .
xdocdata-obj_descr = p_mtitle .
Fill the document data and get size of attachment
clear xdocdata.
read table iattach index xcnt.
xdocdata-doc_size =
( xcnt - 1 ) * 255 + strlen( iattach ).
xdocdata-obj_langu = sy-langu.
xdocdata-obj_name = 'SAPRPT'.
xdocdata-obj_descr = p_mtitle.
clear iattachment. refresh iattachment.
iattachment[] = pit_attach[].
Describe the body of the message
clear ipacking_list. refresh ipacking_list.
ipacking_list-transf_bin = space.
ipacking_list-head_start = 1.
ipacking_list-head_num = 0.
ipacking_list-body_start = 1.
describe table imessage lines ipacking_list-body_num.
ipacking_list-doc_type = 'RAW'.
append ipacking_list.
Create attachment notification
ipacking_list-transf_bin = 'X'.
ipacking_list-head_start = 1.
ipacking_list-head_num = 1.
ipacking_list-body_start = 1.
describe table iattachment lines ipacking_list-body_num.
ipacking_list-doc_type = p_format.
ipacking_list-obj_descr = p_attdescription.
ipacking_list-obj_name = p_filename.
ipacking_list-doc_size = ipacking_list-body_num * 255.
append ipacking_list.
Add the recipients email address
clear ireceivers. refresh ireceivers.
ireceivers-receiver = p_email.
ireceivers-rec_type = 'U'.
ireceivers-com_type = 'INT'.
ireceivers-notif_del = 'X'.
ireceivers-notif_ndel = 'X'.
append ireceivers.
call function 'SO_DOCUMENT_SEND_API1'
exporting
document_data = xdocdata
put_in_outbox = 'X'
commit_work = 'X'
tables
packing_list = ipacking_list
contents_bin = iattachment
contents_txt = imessage
receivers = ireceivers
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.
endform.
Reward IF.........
Regards
Anbu -
Header Repeats When i Spool result to xls file
hey all,
I know it must be a basic thing that i must be overlooking. I am spooling the result of a query in excel using code similar to as shown below
SET MARKUP HTML ON SPOOL ON PREFORMAT OFF ;
SPOOL MY_TEST_FILE.xls;
select * from emp;
SPOOL OFF;
exit / %errorlevel%;
I get a neat xml output but with the header repeating every 15th column. (The actual query is different and has >50 records as result set.)
Any Ideas how do i ensure just one header. Any response feedback is appreciated.
Thanks,
GavyOk. i keep searching and got it. used the set pages option.
SET PAGES 50000 -
Sending an email attachment for xls file
Hi all,
I am executing the reports in background, i am getting spool after executing. Just i need to convert the spool to xls format and email through attachment and mail to the user.The xls file should not be saved on local system.
I need your help.
Regards
Vinay.see this link
to send xls as attachment.
http://www.sapdevelopment.co.uk/reporting/email/attach_xls.htm -
Hi i have script as below
SET MARKUP HTML ON ENTMAP ON SPOOL ON PREFORMAT OFF;
set linesize 125
set numwidth 20
set pagesize 50
col TEXT FOR A30
col ELAPSED_TIME_SEC for 99999999
set serveroutput off;
SET ECHO OFF;
undefine MAX_SNAP
undefine MIN_SNAP
SELECT MAX(SNAP_ID) MAX_SNAP,MIN(SNAP_ID) MIN_SNAP FROM DBA_HIST_SNAPSHOt
WHERE BEGIN_INTERVAL_TIME > (SYSDATE - 1) - 4/ 24
AND END_INTERVAL_TIME <= (SYSDATE) - 3/ 24 ORDER BY 1;
SET TERMOUT ON;
SPOOL MY_TEST_FILE.xls;
SELECT SQL_ID FROM dba_hist_sqltext
WHERE SNAP_ID > &&MIN_SNAP AND SNAP_ID<= &&MAX_SNAP;
SPOOL OFF;
but in my spool file
it appear like this .
old 1: SELECT SNAP_ID, BEGIN_INTERVAL_TIME,END_INTERVAL_TIME FROM DBA_HIST_SNAPSHOt WHERE SNAP_ID=&&MIN_SNAP
new 1: SELECT SNAP_ID, BEGIN_INTERVAL_TIME,END_INTERVAL_TIME FROM DBA_HIST_SNAPSHOt WHERE SNAP_ID= 20805
and
old 20: WHERE SNAP_ID > &&MIN_SNAP AND SNAP_ID<= &&MAX_SNAP)
new 20: WHERE SNAP_ID > 20805 AND SNAP_ID<= 20853)
what if i dont want this lines in my spool file.
is there anything which dont spool this in output.
thanks.Hi,
Add
SET VERIFY OFFto the SET commands. -
How to spool in excel sheet of table with 1561828 records
how to spool in excel sheet of table with 1561828 records
i think excel got only 65l limit?
COUNT(*)
1561828
i am using windows box...any suggestions?Raman wrote:
means excel 2007 can hold 15,61,828 records ? can i give like spool filename.xls?You can name the spool file anything you want, but surely you realize that naming it 'filename.xls' doesn't make it an xls file. A name is just a name. There are industry standards on certain names indicating certain file formats, but the name doesn't make it that format. -
Issue with 3 attachments in an email
Hi All,
Anybody can send me the program which generates 3 excel sheets as an attachment. i wrote one program which geberates .txt files as an atatchmetns.
thanks,
maheedharhi,
following is the code which uses both formats PDF and CSV OR XLS.
*& Report Z_SEND_JOB. &*
*& Title : Send spool lists with PDF / CSV attachments. &*
*& Program name : Z_SEND_JOB. &*
*& Source Code Type : Report &*
report z_send_job.
* INCLUDE *
include z_send_job_data.
include z_send_job_pai.
* AT SELECTION-SCREEN. *
at selection-screen.
if s_email1[] is initial.
message s899(mm) with 'Please Enter E-Mail id'.
stop.
endif.
if p_spool is initial and p_tcode is initial and p_pgna is initial and p_sch is initial.
message s899(mm) with 'Please enter Spool Number or Tcode or Program name or created by'.
stop.
endif.
* START-OF-SELECTION. *
start-of-selection.
perform get_job_details.
if not p_pdf is initial.
*process to send as pdf attachment
perform convert_spool_to_pdf.
perform process_email.
else.
*process to send as excel attachment
perform convert_spool_excel.
if not it_spool_xls_return[] is initial.
perform process_email.
else.
message i000(0) with 'Cannot Send this spool as an Excel File'.
endif.
endif.
*iinclude z_send_job_data.
*& Include Z_SEND_JOB_DATA
* Tables Workarea *
tables: somlreci1,
tbtcp.
* TYPE-POOLS *
type-pools: truxs.
* CONSTANTS *
constants: c_no(1) type c value ' ',
c_device(4) type c value 'LOCL'.
* GLOBAL DATA DECLARATIONS *
data : gd_recsize type i.
data : l_format(3) type c.
*Job Runtime Parameters
data : gd_eventid like tbtcm-eventid,
gd_eventparm like tbtcm-eventparm,
gd_external_program_active like tbtcm-xpgactive,
gd_jobcount like tbtcm-jobcount,
gd_jobname like tbtcm-jobname,
gd_stepcount like tbtcm-stepcount,
gd_error type sy-subrc,
gd_reciever type sy-subrc.
data : w_recsize type i.
data : gd_subject like sodocchgi1-obj_descr,
it_mess_bod like solisti1 occurs 0 with header line,
it_mess_att like solisti1 occurs 0 with header line,
gd_sender_type like soextreci1-adr_typ,
gd_attachment_desc type so_obj_nam,
gd_attachment_name type so_obj_des.
*Spool to PDF conversions
data : gd_spool_nr like tsp01-rqident ,
gd_destination like rlgrap-filename,
gd_bytecount like tst01-dsize,
gd_buffer type string.
data : gv_client type tsp01-rqclient,
gv_name type tsp01-rqo1name,
gv_type type rststype-type,
gv_objtype type rststype-type,
gv_is_otf(1) type c value ' ',
* GV_SPOOL type i,
gv_pdfspoolid type tsp01-rqident,
gv_jobname type tbtcjob-jobname,
gv_jobcount type tbtcjob-jobcount.
* Field Strings *
*Spool IDs
types: begin of t_tbtcp.
include structure tbtcp.
types: end of t_tbtcp.
*for excel
types: begin of t_spool.
include structure bapixmspoo.
types: end of t_spool.
* Internal Tables *
data: it_tbtcp type standard table of t_tbtcp initial size 0,
wa_tbtcp type t_tbtcp.
*Binary store for PDF
data: begin of it_pdf_output occurs 0.
include structure tline.
data: end of it_pdf_output.
data t_spools type standard table of t_spool with default key.
data : it_spool_xls like t_spools with header line.
data : it_spool_xls_return type truxs_t_text_data.
data: wa_spool_xls_return(255) type c.
data: it_message type standard table of solisti1 initial size 0
with header line.
data: it_attach type standard table of solisti1 initial size 0
with header line.
data : begin of gt_spool_file occurs 0,
tdline(2500) type c,
end of gt_spool_file.
* Selection Screen *
selection-screen begin of block b1 with frame title text-001.
select-options: s_email1 for somlreci1-receiver
no intervals.
parameter: p_spool like tbtcp-listident,
p_tcode like tstc-tcode,
p_pgna like tstc-pgmna,
p_sch like tbtcp-sdluname default sy-uname.
selection-screen end of block b1.
selection-screen begin of block b2 with frame title text-002.
parameter: p_pdf radiobutton group g1 default 'X',
p_excel radiobutton group g1.
selection-screen end of block b2.
*include z_send_job_pai
*& Include Z_SEND_JOB_PAI
*& Form GET_JOB_DETAILS
form get_job_details .
data : l_spool(10) type c.
if p_spool is initial.
*IF USER ENTER tcode get program name
if not p_tcode is initial.
select single pgmna into p_pgna from tstc
where tcode = p_tcode.
endif.
*get spool if for program name.
if not p_pgna is initial.
if p_sch is initial.
select listident into l_spool from tbtcp "GD_SPOOL_NR
up to 1 rows
where progname = p_pgna
order by listident descending.
endselect.
if sy-subrc eq 0.
move : l_spool to gd_spool_nr.
endif.
else.
select listident into l_spool from tbtcp
up to 1 rows
where progname = p_pgna
and sdluname = p_sch
order by listident descending.
endselect.
if sy-subrc eq 0.
move : l_spool to gd_spool_nr.
endif.
endif.
endif.
*get spool id with usr name
if not p_sch is initial and p_pgna is initial.
select listident into l_spool from tbtcp
up to 1 rows
where sdluname = p_sch
order by listident descending.
endselect.
if sy-subrc eq 0.
move : l_spool to gd_spool_nr.
endif.
endif.
else.
gd_spool_nr = p_spool.
endif.
if gd_spool_nr is initial.
message s899(mm) with 'Spool not found'.
stop.
endif.
endform. " GET_JOB_DETAILS
*& Form CONVERT_SPOOL_TO_PDF
form convert_spool_to_pdf .
call function 'RSPO_RETURN_SPOOLJOB'
exporting
rqident = gd_spool_nr
first_line = 1
last_line = 1000
desired_type = 'RAW'
tables
buffer = gt_spool_file
exceptions
no_such_job = 1
job_contains_no_data = 2
selection_empty = 3
no_permission = 4
can_not_access = 5
read_error = 6
type_no_match = 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.
select single rqclient
rqo1name
into (gv_client, gv_name)
from tsp01
where rqident = gd_spool_nr.
call function 'RSTS_GET_ATTRIBUTES'
exporting
authority = 'SP01'
client = gv_client
name = gv_name
part = 1
importing
type = gv_type
objtype = gv_objtype
exceptions
fb_error = 1
fb_rsts_other = 2
no_object = 3
no_permission = 4
others = 5.
if sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
endif.
if gv_objtype(3) = 'OTF'.
gv_is_otf = 'X'.
else.
gv_is_otf = space.
endif.
if gv_is_otf eq 'X'.
call function 'CONVERT_OTFSPOOLJOB_2_PDF'
exporting
src_spoolid = gd_spool_nr
no_dialog = ' '
importing
pdf_bytecount = gd_bytecount
pdf_spoolid = gv_pdfspoolid
btc_jobname = gv_jobname
btc_jobcount = gv_jobcount
tables
pdf = it_pdf_output.
else.
call function 'CONVERT_ABAPSPOOLJOB_2_PDF'
exporting
src_spoolid = gd_spool_nr
no_dialog = c_no
dst_device = c_device
importing
pdf_bytecount = gd_bytecount
tables
pdf = it_pdf_output
exceptions
err_no_abap_spooljob = 1
err_no_spooljob = 2
err_no_permission = 3
err_conv_not_possible = 4
err_bad_destdevice = 5
user_cancelled = 6
err_spoolerror = 7
err_temseerror = 8
err_btcjob_open_failed = 9
err_btcjob_submit_failed = 10
err_btcjob_close_failed = 11
others = 12.
endif.
if sy-subrc eq 0.
* Transfer the 132-long strings to 255-long strings
loop at it_pdf_output.
translate it_pdf_output using ' ~'.
concatenate gd_buffer it_pdf_output into gd_buffer.
endloop.
translate gd_buffer using '~ '.
do.
it_mess_att = gd_buffer.
append it_mess_att.
shift gd_buffer left by 255 places.
if gd_buffer is initial.
exit.
endif.
enddo.
endif.
endform. " CONVERT_SPOOL_TO_PDF
*& Form PROCESS_EMAIL
form process_email .
if not p_pdf is initial.
describe table it_mess_att lines gd_recsize.
else.
describe table it_spool_xls_return lines gd_recsize.
endif.
check gd_recsize > 0.
perform send_email.
endform. " PROCESS_EMAIL
*& Form SEND_FILE_AS_EMAIL_ATTACHMENT
form send_file_as_email_attachment
tables it_message
it_attach
using p_mtitle
p_format
p_filename
p_attdescription
p_sender_address
p_sender_addres_type
changing p_error
p_reciever.
data: ld_error type sy-subrc,
ld_reciever type sy-subrc,
ld_mtitle like sodocchgi1-obj_descr,
ld_email like somlreci1-receiver,
ld_format type so_obj_tp ,
ld_attdescription type so_obj_nam ,
ld_attfilename type so_obj_des ,
ld_sender_address like soextreci1-receiver,
ld_sender_address_type like soextreci1-adr_typ,
ld_receiver like sy-subrc.
data: t_packing_list like sopcklsti1 occurs 0 with header line,
t_contents like solisti1 occurs 0 with header line,
t_receivers like somlreci1 occurs 0 with header line,
t_attachment like solisti1 occurs 0 with header line,
t_object_header like solisti1 occurs 0 with header line,
w_cnt type i,
w_sent_all(1) type c,
w_doc_data like sodocchgi1.
ld_mtitle = p_mtitle.
ld_format = p_format.
ld_attdescription = p_attdescription.
ld_attfilename = p_filename.
ld_sender_address = p_sender_address.
ld_sender_address_type = p_sender_addres_type.
* 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 = '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 = 'SAPRPT'.
w_doc_data-obj_descr = ld_mtitle.
w_doc_data-sensitivty = 'F'.
clear t_attachment.
refresh t_attachment.
* do the follwoing 3 times with three different internal tables.
t_attachment[] = it_attach[].
* 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 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 = ld_attdescription.
t_packing_list-obj_name = ld_attfilename.
t_packing_list-doc_size = t_packing_list-body_num * 255.
append t_packing_list.
* Add the recipients email address
clear t_receivers.
refresh t_receivers.
loop at s_email1.
t_receivers-receiver = s_email1-low.
t_receivers-rec_type = 'U'.
t_receivers-com_type = 'INT'.
t_receivers-notif_del = 'X'.
t_receivers-notif_ndel = 'X'.
append t_receivers.
endloop.
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.
* Populate zerror return code
ld_error = sy-subrc.
if ld_error ne 0.
message s899(mm) with 'Error while sending email'.
stop.
else.
message s899(mm) with 'Email sent succesfully'.
endif.
* Populate zreceiver return code
loop at t_receivers.
ld_receiver = t_receivers-retrn_code.
endloop.
endform. " SEND_FILE_AS_EMAIL_ATTACHMENT
*& Form SEND_EMAIL &*
form send_email. " USING P_EMAIL.
data p_sender like somlreci1-receiver.
data l_sub(50) type c.
refresh it_mess_bod.
* Default subject matter
if not p_pdf is initial.
gd_subject = 'SAP Report Spool Output - .pdf File Attachment'.
gd_attachment_desc = 'spooldata'.
it_mess_bod = 'SAP Report Spool Output - .pdf File Attachment'.
append it_mess_bod.
else.
gd_subject = 'SAP Report Spool Output - .xls File Attachment'.
gd_attachment_desc = 'spooldata'.
it_mess_bod = 'SAP Report Spool Output - .xls File Attachment'.
append it_mess_bod.
endif.
* If no sender specified - default blank
if p_sender eq space.
gd_sender_type = space.
else.
gd_sender_type = 'INT'.
endif.
if not p_tcode is initial.
concatenate 'Attachment from TNS' p_tcode into l_sub separated by space.
elseif not p_pgna is initial.
concatenate 'Attachment from program' p_pgna into l_sub separated by space.
elseif not p_spool is initial.
concatenate 'Attachment from spool' p_spool into l_sub separated by space.
else.
concatenate 'Attachment from user' p_sch into l_sub separated by space.
endif.
if not p_pdf is initial.
l_format = 'PDF'.
else.
l_format = 'XLS'.
it_mess_att[] = it_spool_xls_return[].
endif.
* Send file by email according to the selection file format (.PDF,.XLS File)
perform send_file_as_email_attachment
tables it_mess_bod
it_mess_att
using l_sub
l_format
gd_attachment_name
gd_attachment_desc
p_sender
gd_sender_type
changing gd_error
gd_reciever.
endform. " SEND_EMAIL
*& Form convert_spool_excel &*
form convert_spool_excel .
data : lv_spool like tsp01-rqident,
l_count type sy-tfill,
l_tabix type sy-tabix.
lv_spool = gd_spool_nr.
call function 'RSPO_RETURN_ABAP_SPOOLJOB'
exporting
rqident = lv_spool
first_line = 1
tables
buffer = it_spool_xls
exceptions
no_such_job = 1
not_abap_list = 2
job_contains_no_data = 3
selection_empty = 4
no_permission = 5
can_not_access = 6
read_error = 7
others = 8.
if sy-subrc ne 0.
message s899(mm) with 'Error while reading spool'.
stop.
endif.
call function 'SAP_CONVERT_TO_CSV_FORMAT'
exporting
i_field_seperator = '|'
i_line_header = '-'
i_filename = 'TEST'
tables
i_tab_sap_data = it_spool_xls
changing
i_tab_converted_data = it_spool_xls_return
exceptions
conversion_failed = 1
others = 2.
if sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
endif.
data : l_length(3) type c.
*change the format to excel by using the object classes
loop at it_spool_xls_return into wa_spool_xls_return.
condense wa_spool_xls_return.
* l_length = strlen( wa_spool_xls_return ).
* l_length = l_length - 3.
**delete header lines if contains any
if wa_spool_xls_return cp '|--*--|'
or wa_spool_xls_return np '*|*|*|*'.
delete it_spool_xls_return.
clear wa_spool_xls_return.
* concatenate cl_abap_char_utilities=>newline wa_SPOOL_XLS_RETURN
* into wa_SPOOL_XLS_RETURN.
* modify it_spool_xls_return from wa_spool_xls_return.
* clear wa_spool_xls_return.
else.
*If not new line then replace '|' by tabs
if not wa_spool_xls_return eq cl_abap_char_utilities=>newline.
if wa_spool_xls_return ca '|'.
concatenate cl_abap_char_utilities=>newline wa_spool_xls_return
* cl_abap_char_utilities=>horizontal_tab
into wa_spool_xls_return.
replace all occurrences of '|' in wa_spool_xls_return
with cl_abap_char_utilities=>horizontal_tab.
*get rid of '-' symbol if contains any
* if wa_SPOOL_XLS_RETURN CA '-'. "or not wa_SPOOL_XLS_RETURN CA '|'.
* CLEAR wa_SPOOL_XLS_RETURN.
* concatenate cl_abap_char_utilities=>newline wa_SPOOL_XLS_RETURN
* cl_abap_char_utilities=>horizontal_tab
* into wa_SPOOL_XLS_RETURN.
* endif.
replace all occurrences of '.' in wa_spool_xls_return
with space.
condense wa_spool_xls_return.
modify it_spool_xls_return from wa_spool_xls_return.
* wa_SPOOL_XLS_RETURN = cl_abap_char_utilities=>newline.
* IF l_count NE 0 .
** l_tabix = l_tabix + 1.
**Insert new line for the excel data
** if sy-tabix gt 1.
** INSERT wa_SPOOL_XLS_RETURN INTO it_SPOOL_XLS_RETURN INDEX l_tabix.
** endif.
* l_count = l_count - 1.
* ENDIF.
clear wa_spool_xls_return.
else.
delete it_spool_xls_return.
clear wa_spool_xls_return .
* concatenate cl_abap_char_utilities=>newline wa_SPOOL_XLS_RETURN
** cl_abap_char_utilities=>horizontal_tab
* into wa_SPOOL_XLS_RETURN.
* modify it_SPOOL_XLS_RETURN from wa_SPOOL_XLS_RETURN.
* clear wa_SPOOL_XLS_RETURN.
endif.
endif.
endif.
endloop.
endform. " convert_spool_excel -
Build dynamic query depending upon selection of table and columns
Hi ,
I want your views on following requirement :
we r doing generic export to excel functionality .
1.User will select multiple tables and according to tables ,columns on that table will select
2.There can be multiple table
3.depending upon column and table selection , we have to build dynamic query and execute .
Please let me know is it possible .If yes then please tell me how to do above requirement.
Thanks in advanceHi,
Identifiers cannot be used as bind variables, query are parsed
before evaluate bind variables. Identifiers like table name.
For excel you can use some like this:
SET MARKUP HTML ON ENTMAP ON SPOOL ON PREFORMAT OFF
SPOOL test_xls.xls
SELECT colum1||chr(9)||columN FROM tableName;
or CSV:
SELECT colum1|| ',' ||columN FROM tableName;
SPOOL OFF
SET MARKUP HTML OFF ENTMAP OFF SPOOL OFF PREFORMAT ON
For construct the query i suggest to read "Dynamic SQL Statements":
http://www.java2s.com/Tutorial/Oracle/0440__PL-SQL-Statements/0300__Dynamic-SQL.htm
http://docs.oracle.com/cd/B28359_01/appdev.111/b28370/dynamic.htm
http://docs.oracle.com/cd/B10500_01/appdev.920/a96590/adg09dyn.htm
http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:227413938857
--sgc -
Hi how to save spool list as in xls format
hi
i run a job and a list spool is created
can anyone tell me the step to save the list generated ie the output of hte program form spool list ie hwo to save it to my maching the report output
rgarfds
AroraTransaction SP01
select your spool dataset number from the list, mark the checkbox, hit F6
System -> List -> Save -> Local file, then select 'Spreadsheet'. This will give you an XLS file, but it won't be too pretty. -
Hello all.
My requirment is to convert a spool object to an XLS file in the background (and send it via mail).
Is it possible?
If so, please help!
please attach a code sample if you have one...
Thanks allot.
Barak.hi ,
this might healp you ought
TABLES: TBTCP, T024D.
*PARAMETERS TEST(5).
DATA: TJOBNAME LIKE TBTCP-JOBNAME VALUE 'REJ_COMP_MAIL_TO_MRP',
SPOOLID LIKE TSP01-RQIDENT,
V_LGORT LIKE MSEG-LGORT,
V_DISPO LIKE T024D-DISPO,
V_REPORT TYPE RSVAR-REPORT,
V_VARIANT TYPE RSVAR-VARIANT.
DATA: BEGIN OF VVALUES OCCURS 0.
INCLUDE STRUCTURE RSPARAMS.
DATA END OF VVALUES.
DATA : BEGIN OF T_RECEIVERS OCCURS 0.
INCLUDE STRUCTURE SOMLRECI1.
DATA END OF T_RECEIVERS.
DATA: BEGIN OF T_TBTCP,
jobname like tbtcp-jobname,
jobcount like tbtcp-jobcount,
LISTIDENT LIKE TBTCP-LISTIDENT,
SDLDATE LIKE TBTCP-SDLDATE,
SDLTIME LIKE TBTCP-SDLTIME,
VARIANT LIKE TBTCP-VARIANT,
END OF T_TBTCP,
ITAB_SPOOL LIKE STANDARD TABLE OF T_TBTCP,
WA_SPOOL LIKE T_TBTCP.
DATA: PLIST LIKE SOPCKLSTI1 OCCURS 2 WITH HEADER LINE.
DATA: DOCUMENT_DATA LIKE SODOCCHGI1.
DATA: OBJTXT LIKE SOLISTI1 OCCURS 10 WITH HEADER LINE.
DATA: SO_ALI LIKE SOLI OCCURS 100 WITH HEADER LINE,
REAL_TYPE LIKE SOODK-OBJTP,
SP_LANG LIKE TST01-DLANG, LINE_SIZE TYPE I VALUE 255,
V_NAME LIKE SOEXTRECI1-RECEIVER.
DATA: GD_EVENTID LIKE TBTCM-EVENTID,
GD_EVENTPARM LIKE TBTCM-EVENTPARM,
GD_EXTERNAL_PROGRAM_ACTIVE LIKE TBTCM-XPGACTIVE,
GD_JOBCOUNT LIKE TBTCM-JOBCOUNT,
GD_JOBNAME LIKE TBTCM-JOBNAME,
GD_STEPCOUNT LIKE TBTCM-STEPCOUNT,
GD_ERROR TYPE SY-SUBRC,
GD_RECIEVER TYPE SY-SUBRC.
START-OF-SELECTION.
PERFORM GET_SPOOL_REQNUMBER USING TJOBNAME. " CHANGING SPOOLID.
PERFORM SEND_MAIL.
PERFORM REMOVE_BLANK_SPOOLS.
*& Form GET_SPOOL_REQNUMBER
text
-->P_0111 text *
<--P_UU text *
FORM GET_SPOOL_REQNUMBER USING P_0111.
SELECT ALISTIDENT BSTRTDATE BSTRTTIME AVARIANT
FROM TBTCP AS A INNER JOIN TBTCO AS B
ON AJOBNAME EQ BJOBNAME AND
AJOBCOUNT EQ BJOBCOUNT AND
ASTEPCOUNT EQ BSTEPCOUNT
INTO TABLE ITAB_SPOOL
WHERE AJOBNAME = P_0111 AND BSTRTDATE EQ SY-DATUM.
ENDFORM. " GET_SPOOL_REQNUMBER
*& Form send_mail
text
--> p1 text
<-- p2 text
FORM SEND_MAIL .
Get the spool data.
LOOP AT ITAB_SPOOL INTO WA_SPOOL.
REFRESH : SO_ALI, PLIST, T_RECEIVERS.
CLEAR : SO_ALI, PLIST, V_NAME, DOCUMENT_DATA, T_RECEIVERS, SPOOLID,
V_REPORT, V_VARIANT, V_DISPO.
IF WA_SPOOL-LISTIDENT <> '0'.
MOVE WA_SPOOL-LISTIDENT TO SPOOLID.
CALL FUNCTION 'RSPO_RETURN_SPOOLJOB'
EXPORTING
RQIDENT = SPOOLID
FIRST_LINE = 1
LAST_LINE = 0
DESIRED_TYPE = ' '
IMPORTING
REAL_TYPE = REAL_TYPE
SP_LANG = SP_LANG
TABLES
BUFFER = SO_ALI
EXCEPTIONS
NO_SUCH_JOB = 1
JOB_CONTAINS_NO_DATA = 2
SELECTION_EMPTY = 3
NO_PERMISSION = 4
CAN_NOT_ACCESS = 5
READ_ERROR = 6
TYPE_NO_MATCH = 7
OTHERS = 8.
Check the return code.
IF SY-SUBRC <> 0.
MESSAGE S208(00) WITH 'Error'.
LEAVE LIST-PROCESSING.
ENDIF.
DATA : DATE LIKE SY-DATUM,
DATE1(10) TYPE C.
Prepare the data.
CLEAR OBJTXT.
REFRESH OBJTXT.
DATE = SY-DATUM - 1.
CONCATENATE DATE6(2) '-' DATE4(2) '-' DATE+0(4) INTO DATE1.
CONCATENATE 'PLEASE CHECK THE LIST OF REJECTED MATERIALS POSTED ON :' DATE1 INTO OBJTXT.
APPEND OBJTXT.
SELECT SINGLE DSNAM FROM T024D INTO T024D-DSNAM WHERE WERKS = '1000' AND DISPO = WA_SPOOL-VARIANT.
CONCATENATE 'MRP CONTROLLER :' WA_SPOOL-VARIANT '-' T024D-DSNAM INTO OBJTXT.
APPEND OBJTXT.
OBJTXT = ''.
APPEND OBJTXT.
CLEAR PLIST.
REFRESH PLIST.
PLIST-TRANSF_BIN = SPACE.
PLIST-HEAD_START = 1.
PLIST-HEAD_NUM = 0.
PLIST-BODY_START = 1.
DESCRIBE TABLE OBJTXT LINES PLIST-BODY_NUM.
PLIST-DOC_TYPE = 'RAW'.
APPEND PLIST.
CLEAR PLIST.
PLIST-TRANSF_BIN = 'X'.
PLIST-HEAD_START = 0.
PLIST-HEAD_NUM = 0.
PLIST-BODY_START = 0.
PLIST-BODY_NUM = 0.
PLIST-DOC_TYPE = 'RAW'.
PLIST-OBJ_DESCR = WA_SPOOL-VARIANT.
APPEND PLIST.
PLIST-TRANSF_BIN = 'X'.
PLIST-HEAD_START = 0.
PLIST-HEAD_NUM = 0.
PLIST-BODY_START = 1.
DESCRIBE TABLE SO_ALI LINES PLIST-BODY_NUM.
PLIST-DOC_TYPE = REAL_TYPE.
Get the size.
READ TABLE SO_ALI INDEX PLIST-BODY_NUM.
PLIST-DOC_SIZE = ( PLIST-BODY_NUM - 1 ) * LINE_SIZE + STRLEN( SO_ALI ).
APPEND PLIST.
***get the values of the variant
MOVE : WA_SPOOL-VARIANT TO V_VARIANT.
SELECT * FROM TBTCP WHERE JOBNAME EQ TJOBNAME ORDER BY SDLDATE.
MOVE TBTCP-PROGNAME TO V_REPORT.
ENDSELECT.
CALL FUNCTION 'RS_VARIANT_VALUES_TECH_DATA'
EXPORTING
REPORT = V_REPORT
VARIANT = V_VARIANT
SEL_TEXT = ' '
MOVE_OR_WRITE = 'W'
SORTED = ' '
EXECUTE_DIRECT =
IMPORTING
TECHN_DATA =
TABLES
VARIANT_VALUES = VVALUES
EXCEPTIONS
VARIANT_NON_EXISTENT = 1
VARIANT_OBSOLETE = 2
OTHERS = 3.
LOOP AT VVALUES.
CASE VVALUES-SELNAME.
WHEN 'S_DISPO'.
MOVE VVALUES-LOW TO V_LGORT.
MOVE VVALUES-LOW TO V_DISPO.
ENDCASE.
ENDLOOP.
SELECT SINGLE USRKEY FROM T024D INTO T024D-USRKEY WHERE WERKS EQ '1000' AND DISPO EQ V_DISPO.
IF SY-SUBRC EQ 0.
T_RECEIVERS-RECEIVER = T024D-USRKEY.
T_RECEIVERS-REC_TYPE = 'U'.
APPEND T_RECEIVERS.
IF V_DISPO = '3' OR V_DISPO = '5' OR
V_DISPO = '21' OR V_DISPO = '48' OR
V_DISPO = '51' OR V_DISPO = '231' OR
V_DISPO = '512' OR V_DISPO = '921'.
T_RECEIVERS-RECEIVER =
T_RECEIVERS-REC_TYPE = 'U'.
T_RECEIVERS-COPY = 'X'.
APPEND T_RECEIVERS.
ENDIF.
IF V_DISPO = '14' OR V_DISPO = '86' OR
V_DISPO = '515' OR V_DISPO = '704' OR
V_DISPO = '711' OR V_DISPO = '712' OR
V_DISPO = '713'.
T_RECEIVERS-RECEIVER =
T_RECEIVERS-REC_TYPE = 'U'.
T_RECEIVERS-COPY = 'X'.
APPEND T_RECEIVERS.
ENDIF.
T_RECEIVERS-RECEIVER = * T_RECEIVERS-REC_TYPE = 'U'.
T_RECEIVERS-COPY = 'X'.
APPEND T_RECEIVERS.
T_RECEIVERS-RECEIVER = * T_RECEIVERS-REC_TYPE = 'U'.
T_RECEIVERS-BLIND_COPY = 'X'.
APPEND T_RECEIVERS.
ENDIF.
IF NOT SP_LANG IS INITIAL.
DOCUMENT_DATA-OBJ_LANGU = SP_LANG.
ELSE.
DOCUMENT_DATA-OBJ_LANGU = SY-LANGU.
ENDIF.
V_NAME = SY-UNAME.
Subject.
CONCATENATE 'List of Rejected Materials, MRP Controller:' WA_SPOOL-VARIANT
INTO DOCUMENT_DATA-OBJ_DESCR.
Send the email.
CALL FUNCTION 'SO_DOCUMENT_SEND_API1'
EXPORTING
DOCUMENT_DATA = DOCUMENT_DATA
SENDER_ADDRESS = V_NAME
SENDER_ADDRESS_TYPE = 'B'
TABLES
PACKING_LIST = PLIST
CONTENTS_BIN = SO_ALI
CONTENTS_TXT = OBJTXT
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.
IF SY-SUBRC <> 0.
MESSAGE E208(00) WITH 'Error in sending email'.
ENDIF.
COMMIT WORK.
Send the email immediately.
SUBMIT RSCONN01
WITH MODE = 'INT'
AND RETURN.
IF SY-SUBRC EQ 0.
WRITE 'To get the spool no'.
CALL FUNCTION 'GET_JOB_RUNTIME_INFO'
IMPORTING
EVENTID = GD_EVENTID
EVENTPARM = GD_EVENTPARM
EXTERNAL_PROGRAM_ACTIVE = GD_EXTERNAL_PROGRAM_ACTIVE
JOBCOUNT = GD_JOBCOUNT
JOBNAME = GD_JOBNAME
STEPCOUNT = GD_STEPCOUNT
EXCEPTIONS
NO_RUNTIME_INFO = 1
OTHERS = 2.
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
WRITE : / 'Spool id of the job that is sent', SPOOLID,
GD_EVENTID,
GD_EVENTPARM,
GD_EXTERNAL_PROGRAM_ACTIVE,
GD_JOBCOUNT,
GD_JOBNAME,
GD_STEPCOUNT.
ENDIF.
ENDIF.
ENDLOOP.
ENDFORM. " send_mail
*& Form remove_blank_spools
text
--> p1 text
<-- p2 text
*FORM REMOVE_BLANK_SPOOLS .
LOOP AT ITAB_SPOOL INTO WA_SPOOL.
MOVE WA_SPOOL-LISTIDENT TO SPOOLID.
CALL FUNCTION 'RSPO_ISELECT_TSP01'
EXPORTING
RFCSYSTEM = SY-SYSID
RQIDENT = SPOOLID
FORUPDATE = ' '
IMPORTING
TSP01_ELEM = W_INFO
EXCEPTIONS
ERROR = 1
OTHERS = 2.
CALL FUNCTION 'RSPO_IRETURN_RAW_DATA'
EXPORTING
RQ = W_INFO
TABLES
LINE_BUFFER = W_DATA
PAGE_INDEX = W_PAGES
LINE_BUFFER2 =
EXCEPTIONS
ERROR = 1
OTHERS = 2.
IF W_INFO-RQDOCTYPE = 'LIST'.
CALL FUNCTION 'RSPO_R_GET_TOC_SPOOLREQ'
EXPORTING
RQIDENT = SPOOLID
TABLES
TOCDESC = W_TODESC
EXCEPTIONS
ERROR = 1
OTHERS = 2.
CALL FUNCTION 'RSPO_SPOOLDATA_WRITE_INIT'.
READ TABLE W_DATA WITH KEY DATA_LINE = 'List contains no data'.
LOOP AT W_DATA.
IF W_DATA-DATA_LINE CP 'List contains no data'.
ENDIF.
ENDLOOP.
ENDIF.
ENDLOOP.
*ENDFORM. " remove_blank_spools -
Read spool data and send it through e-mail as .txt or .xls attachment
Hi All,
I have to read the spool data and send it via e-mail as .txt or .xls attachment. I have used FMs LIST_TO_ASCI, RSPO_RETURN_SPOOLJOB and SO_SOLITAB_TO_SOLIXTAB. I am using FM SO_DOCUMENT_SEND_API1 to send e-mail.
My problem is, the text file being sent is not showing entire data. It's getting truncated after 255 characters. Is this a standard? If yes, then is there any work around for it?
Alternatively, I can send the file as excel attachment. How can this be done?
Thanks,
AshwiniYou will have to convert string to Xstring and then to binary to acheive this.
Check this wiki to send a mail attachment with more than 255 characters.
[https://wiki.sdn.sap.com/wiki/display/Snippets/Tosendamailattachmentwithmorethan255charactersinaline]
Vikranth -
SQL*Plus - how to suppress the SQL in a spool file
This is my SQL*Plus script. I thought I had solved the problem, but it is back now and I don't know what I am missing. But I don't want the query at the top of the file.
SET SERVEROUTPUT ON
SET MARKUP HTML ON -SILENT
SET ECHO OFF
SET PAGESIZE 33
SET TERMOUT OFF
Spool C:\DuaneWilson.xls
SELECT *
FROM RPT_DS1_CNT_CAT_vw
WHERE ROWNUM <=100
ORDER BY CVBI_KEY;
SET MARKUP HTML OFF
SET ECHO ON
SET PAGESIZE 20
SET TERMOUT ON
SET SERVEROUTPUT OFFIt turns out when I run the script with the @ or Start with the file name, there is no SQL put out to the file. But when I just copy the text out of the file and run it at the prompt, the SQL appears in the output file. In reference to the -SILENT, I put that in after the MARKUP statement and got an error. Maybe I don't know where that goes. And I am not sure why there is a difference if it is run as a script or just pasted to the buffer. At least it should be the same in the output file, I would think.
-
URGENT ----- Problem in converting spool to pdf .
Error - File cannot be opened because of no pages ......
Hi experts,
I am passing internal table contents to spool --> then spool to pdf -
> then mail sending.
Everything is fine but only error is in the receiving mail the above error is coming.
given the code...
<b>I think the error is in converting into pdf function module</b>
<b>Help me to solve this problem as it is very urgent</b>
include data_declare. " pasted down
select * from kna1 into table itab up to 50 rows.
CALL FUNCTION 'RSPO_OPEN_SPOOLREQUEST'
EXPORTING
dest = 'LP01'
immediate_print = 'X'
IMPORTING
handle = handle
SPOOLID = spoolid.
loop at itab.
concatenate itab-kunnr itab-name1 itab-land1 into text separated by
space.
CALL FUNCTION 'RSPO_WRITE_SPOOLREQUEST'
EXPORTING
handle = handle
text = text.
endloop.
CALL FUNCTION 'RSPO_CLOSE_SPOOLREQUEST'
EXPORTING
handle = handle.
Convert Spool to PDF **********************************
<b>CALL FUNCTION 'CONVERT_ABAPSPOOLJOB_2_PDF'
EXPORTING
src_spoolid = spoolid "gd_spool_nr
no_dialog = c_no
dst_device = c_device
IMPORTING
pdf_bytecount = gd_bytecount
TABLES
pdf = it_pdf_output
EXCEPTIONS
err_no_abap_spooljob = 1
err_no_spooljob = 2
err_no_permission = 3
err_conv_not_possible = 4
err_bad_destdevice = 5
user_cancelled = 6
err_spoolerror = 7
err_temseerror = 8
err_btcjob_open_failed = 9
err_btcjob_submit_failed = 10
err_btcjob_close_failed = 11
OTHERS = 12.
CHECK sy-subrc = 0.
Transfer the 132-long strings to 255-long strings
LOOP AT it_pdf_output.
TRANSLATE it_pdf_output USING ' ~'.
CONCATENATE gd_buffer it_pdf_output INTO gd_buffer.
ENDLOOP.
TRANSLATE gd_buffer USING '~ '.
DO.
it_mess_att = gd_buffer.
APPEND it_mess_att.
SHIFT gd_buffer LEFT BY 255 PLACES.
IF gd_buffer IS INITIAL.
EXIT.
ENDIF.
ENDDO.</b>
Processing Mail Sending ************************************
DATA: p_email LIKE somlreci1-receiver,
p_sender LIKE somlreci1-receiver,
sub(40).
DESCRIBE TABLE it_mess_att LINES gd_recsize.
CHECK gd_recsize > 0.
REFRESH it_mess_bod.
Default subject matter
gd_subject = 'Subject'.
gd_attachment_desc = text-002.
it_mess_bod = text-001.
APPEND it_mess_bod.
IF p_sender EQ space.
gd_sender_type = space.
ELSE.
gd_sender_type = 'INT'.
ENDIF.
MOVE 'Orders Rejeced on' TO sub.
WRITE: sy-datum DD/MM/YYYY TO sub+27(10).
Send file by email as .xls speadsheet
PERFORM send_file_as_email_attachment
TABLES it_mess_bod
it_mess_att
USING
p_email
sub "text-009
'PDF'
gd_attachment_name
gd_attachment_desc
p_sender
gd_sender_type
CHANGING gd_error
gd_reciever.
ENDFORM. " process_email
*& Form send_file_as_email_attachment
text
-->P_IT_MESS_BOD text
-->P_IT_MESS_ATT text
-->P_TEXT_009 text
-->P_1058 text
-->P_GD_ATTACHMENT_NAME text
-->P_GD_ATTACHMENT_DESC text
<--P_GD_ERROR text
<--P_GD_RECIEVER text
FORM send_file_as_email_attachment TABLES it_message
it_attach
USING
p_email
p_mtitle
p_format
p_filename
p_attdescription
p_sender_address
p_sender_addres_type
CHANGING p_error
p_reciever.
DATA: ld_error TYPE sy-subrc,
ld_reciever TYPE sy-subrc,
ld_mtitle LIKE sodocchgi1-obj_descr,
ld_email LIKE somlreci1-receiver,
ld_format TYPE so_obj_tp ,
ld_attdescription TYPE so_obj_nam ,
ld_attfilename TYPE so_obj_des ,
ld_sender_address LIKE soextreci1-receiver,
ld_sender_address_type LIKE soextreci1-adr_typ,
ld_receiver LIKE sy-subrc.
DATA: t_packing_list LIKE sopcklsti1 OCCURS 0 WITH HEADER LINE,
t_contents LIKE solisti1 OCCURS 0 WITH HEADER LINE,
t_receivers LIKE somlreci1 OCCURS 0 WITH HEADER LINE,
t_attachment LIKE solisti1 OCCURS 0 WITH HEADER LINE,
t_object_header LIKE solisti1 OCCURS 0 WITH HEADER LINE,
w_cnt TYPE i,
w_sent_all(1) TYPE c,
w_doc_data LIKE sodocchgi1.
ld_email = p_email.
ld_mtitle = p_mtitle.
ld_format = p_format.
ld_attdescription = p_attdescription.
ld_attfilename = p_filename.
ld_sender_address = p_sender_address.
ld_sender_address_type = p_sender_addres_type.
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 = '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 = 'SAPRPT'.
w_doc_data-obj_descr = ld_mtitle.
w_doc_data-sensitivty = 'F'.
CLEAR t_attachment.
REFRESH t_attachment.
t_attachment[] = it_attach[].
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 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 = ld_attdescription.
t_packing_list-obj_name = ld_attfilename.
t_packing_list-doc_size = t_packing_list-body_num * 255.
APPEND t_packing_list.
Add the recipients email address
CLEAR t_receivers.
REFRESH t_receivers.
t_receivers-rec_type = 'U'.
t_receivers-com_type = 'INT'.
t_receivers-notif_del = 'X'.
t_receivers-notif_ndel = 'X'.
CLEAR gt_mail.
SELECT SINGLE * FROM zmail INTO gt_mail
WHERE grpnr = '1'.
IF NOT gt_mail-mail1 IS INITIAL.
t_receivers-receiver = gt_mail-mail1.
APPEND t_receivers.
ENDIF.
IF NOT gt_mail-mail2 IS INITIAL.
t_receivers-receiver = gt_mail-mail2.
APPEND t_receivers.
ENDIF.
IF NOT gt_mail-mail3 IS INITIAL.
t_receivers-receiver = gt_mail-mail3.
APPEND t_receivers.
ENDIF.
IF NOT gt_mail-mail4 IS INITIAL.
t_receivers-receiver = gt_mail-mail4.
APPEND t_receivers.
ENDIF.
LOOP AT gt_mail.
t_receivers-receiver = gt_mail-mailid..
APPEND t_receivers.
ENDLOOP.
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.
Populate zerror return code
ld_error = sy-subrc.
Populate zreceiver return code
LOOP AT t_receivers.
ld_receiver = t_receivers-retrn_code.
ENDLOOP.
ENDFORM. " send_file_as_email_attachment
Data Declaration ************************************
DATA : handle LIKE sy-tabix.
data itab like kna1 occurs 0 with header line.
data: text(50) type c.
data: spoolid type TSP01-RQIDENT.
DATA : gt_listobject LIKE abaplist OCCURS 10 .
DATA : gt_objcont LIKE soli OCCURS 10 WITH HEADER LINE.
DATA : gt_objcont1 LIKE soli OCCURS 10 WITH HEADER LINE.
DATA : gt_objhead LIKE soli OCCURS 10 WITH HEADER LINE.
DATA : gt_att_head LIKE soli OCCURS 10 WITH HEADER LINE.
DATA : gt_receivers LIKE soos1 OCCURS 10 WITH HEADER LINE.
DATA : gt_packing_list LIKE soxpl OCCURS 10 WITH HEADER LINE.
DATA : gt_so_ali LIKE soli OCCURS 100 WITH HEADER LINE.
DATA : gt_so_ali1 LIKE soli OCCURS 100 WITH HEADER LINE.
DATA : gt_document_data LIKE sood1.
DATA: lineno TYPE i , length TYPE i , size TYPE i.
DATA: gt_message LIKE soli OCCURS 10 WITH HEADER LINE,
gt_message1 LIKE soli OCCURS 10 WITH HEADER LINE.
DATA: gt_scheme LIKE ztrc_scheme OCCURS 0 WITH HEADER LINE,
gt_mail LIKE zmail_prov OCCURS 0 WITH HEADER LINE.
gt_mail LIKE zmail." occurs 0 with header line.
DATA: gd_recsize TYPE i.
Spool IDs
TYPES: BEGIN OF t_tbtcp.
INCLUDE STRUCTURE tbtcp.
TYPES: END OF t_tbtcp.
DATA: it_tbtcp TYPE STANDARD TABLE OF t_tbtcp INITIAL SIZE 0,
wa_tbtcp TYPE t_tbtcp.
Job Runtime Parameters
DATA: gd_eventid LIKE tbtcm-eventid,
gd_eventparm LIKE tbtcm-eventparm,
gd_external_program_active LIKE tbtcm-xpgactive,
gd_jobcount LIKE tbtcm-jobcount,
gd_jobname LIKE tbtcm-jobname,
gd_stepcount LIKE tbtcm-stepcount,
gd_error TYPE sy-subrc,
gd_reciever TYPE sy-subrc.
DATA: w_recsize TYPE i.
DATA: gd_subject LIKE sodocchgi1-obj_descr,
it_mess_bod LIKE solisti1 OCCURS 0 WITH HEADER LINE,
it_mess_att LIKE solisti1 OCCURS 0 WITH HEADER LINE,
gd_sender_type LIKE soextreci1-adr_typ,
gd_attachment_desc TYPE so_obj_nam,
gd_attachment_name TYPE so_obj_des.
Spool to PDF conversions
DATA: gd_spool_nr LIKE tsp01-rqident,
gd_destination LIKE rlgrap-filename,
gd_bytecount LIKE tst01-dsize,
gd_buffer TYPE string.
Binary store for PDF
DATA: BEGIN OF it_pdf_output OCCURS 0.
INCLUDE STRUCTURE tline.
DATA: END OF it_pdf_output.
CONSTANTS: c_dev LIKE sy-sysid VALUE 'DEV',
c_no(1) TYPE c VALUE ' ',
c_device(4) TYPE c VALUE 'LOCL'.
DATA: check TYPE c,
days TYPE i.
<b></b><b></b><b></b>Hi Prashant,
Thanks for your reply. Really it is very useful one.
In this, the output list is getting populated into spool and to pdf.
But my requirement sending the internal table contents to spool directly without dispalying in the output list.
I did the program like the above mentioned one already. But my requirement is not that one.
Regards
chakradhar
Maybe you are looking for
-
No users are shown for Service Desk functionality in SOLMAN 4.0
Hello! I would like to set up the business partners for Service Desk in SAP Solution Manager. If I choose the solution and execute "Edit --> Create Business partner" for the SAP R/3 4.7 then I get the warning no users are shown under the system. Fo
-
Copying from Sapscript to Smart form with d same windows
I hav created my sapsccript till now i want to copy my sapscript windows n text elements n other attributes of that sapscript to smart forms.So please help me to copy sapscript to smart form,Please help me out. Thanks & regards santhosh kumar.
-
Reinstalling Leopard without removing or changing windows partition
I am giving my mom my iMac and I would like to remove all my files and applications, I think the best way to do this is to reinstall Leopard but I need to keep the windows partition intact. The problem is that I no longer have the Windows install dis
-
My computer shows I have nearly 24,000 pics. The Events show I have only 12,000. How do I remove the duplicate that are slowing my computer?
-
Why I can't sync my iPhone with iPhoto?
My iPhone can't sync with my iPhoto, it worked before... but I don't know why, now I can't