05-26-2006 7:15 PM
Hi all,
Please help me out on this problem.
I have a report that is using OO AVL and now my boss wants to receive the report's output in his Outlook. I have read a lot of posts in here and follow their instructions but none works for me. I put complete source code in here:
*&----
*& Report ZHRRPT0003
&----
*& Purpose: email HR all recent changes to designated managers
&----
*& Author: David Nguyen. *
*& Date: 05/22/2006 *
*& SAP System: R/3 Enterprise 620 *
&----
*& Modification: *
*& Date Userid Description
*&
&----
report zhrrpt0003.
tables: pa0001,"HR Master Record
t501t. "Employee Group Names
data: begin of t_list occurs 0,
pernr like pa0001-pernr,
ename like pa0001-ename,
aedtm like pa0001-aedtm,
begda like pa0001-begda,
uname like pa0001-uname,
persg like pa0001-persg,
ptext like t501t-ptext,
orgeh like pa0001-orgeh,
orgtx like t527x-orgtx,
kostl like pa0001-kostl,
ktext like cskt-ktext,
burks like pa0001-bukrs,
werks like pa0001-werks,
persk like pa0001-persk,
vdsk1 like pa0001-vdsk1,
btrtl like pa0001-btrtl,
abkrs like pa0001-abkrs,
plans like pa0001-plans,
stell like pa0001-stell,
sachz like pa0001-sachz,
sname like pa0001-sname,
otype like pa0001-otype,
sbmod like pa0001-sbmod,
kokrs like pa0001-kokrs,
end of t_list.
data: wa_list like line of t_list,
g_repid like sy-repid,
save_ok type sy-ucomm, " command field
ok_code type sy-ucomm. " command field
*-- Global data definitions for ALV
data c_save type c value 'A'.
Structure to hold Variants
data gs_variant like disvariant.
*--- ALV Grid instance reference
data gr_alvgrid type ref to cl_gui_alv_grid .
*--- Name of the custom control added on the screen
data gc_custom_control_name type scrfname value 'CC_ALV' .
*--- Custom container instance reference
data gr_ccontainer type ref to cl_gui_custom_container .
*--- Field catalog table
data gt_fieldcat type lvc_t_fcat .
*--- Layout structure
data gs_layout type lvc_s_layo.
select-options: s_aedtm for pa0001-aedtm.
parameters: p_endda like pa0001-endda NO-DISPLAY.
************************************************************************
INITIALIZATION *
************************************************************************
initialization.
s_aedtm-low = sy-datum - 1.
append s_aedtm.
p_endda = '99991231'.
start-of-selection.
perform selection.
end-of-selection.
clear gs_variant.
g_repid = sy-repid.
gs_variant-report = g_repid.
call screen 200.
Subroutines
*----
Selection
*
*----
form selection.
data temp_wa_list like line of t_list.
data temp_index type I.
select pa0001~pernr pa0001~ename pa0001~aedtm pa0001~begda
pa0001~uname pa0001~persg t501t~ptext pa0001~orgeh
t527x~orgtx pa0001~kostl cskt~ktext pa0001~bukrs
pa0001~werks pa0001~persk pa0001~vdsk1 pa0001~btrtl
pa0001~abkrs pa0001~plans pa0001~stell pa0001~sachz
pa0001~sname pa0001~otype pa0001~sbmod pa0001~kokrs
into table t_list
from pa0001 inner join t501t on pa0001~persg = t501t~persg
inner join t527x on pa0001~orgeh = t527x~orgeh
inner join cskt on pa0001~kostl = cskt~kostl
where pa0001~aedtm in s_aedtm
and pa0001~endda <= p_endda
and pa0001~kostl ne ''
order by pa0001~ename pa0001~begda.
clear temp_wa_list.
loop at t_list into wa_list.
if wa_list-pernr <> temp_wa_list-pernr.
temp_wa_list = wa_list.
if wa_list-persg = 'A'.
select * from pa0001
where pa0001~pernr = wa_list-pernr
and pa0001~aedtm < wa_list-aedtm
and pa0001~persg = 'A'
order by pa0001~aedtm.
endselect.
if pa0001-kostl = wa_list-kostl.
delete t_list index sy-tabix.
clear temp_wa_list.
endif.
endif.
else.
clear temp_index.
temp_index = sy-tabix - 1.
delete t_list index temp_index .
endif.
endloop.
endform. " END OF SELECTION
************************************************************************
Display ALV
*
************************************************************************
form display_alv.
if gr_alvgrid is initial .
*----Creating custom container instance
create object gr_ccontainer
exporting
container_name = gc_custom_control_name
exceptions
cntl_error = 1
cntl_system_error = 2
create_error = 3
lifetime_error = 4
lifetime_dynpro_dynpro_link = 5
others = 6 .
if sy-subrc <> 0.
--Exception handling
endif.
----Creating ALV Grid instance
create object gr_alvgrid
exporting
i_parent = gr_ccontainer
exceptions
error_cntl_create = 1
error_cntl_init = 2
error_cntl_link = 3
error_dp_create = 4
others = 5 .
if sy-subrc <> 0.
--Exception handling
endif.
----Preparing field catalog.
perform prepare_field_catalog changing gt_fieldcat .
----Preparing layout structure
perform prepare_layout changing gs_layout .
----Here will be additional preparations
*--e.g. initial sorting criteria, initial filtering criteria, excluding
--functions
call method gr_alvgrid->set_table_for_first_display
exporting
I_BUFFER_ACTIVE =
I_CONSISTENCY_CHECK =
I_STRUCTURE_NAME =
is_variant = gs_variant
i_save = c_save
I_DEFAULT = 'X'
is_layout = gs_layout
IS_PRINT =
IT_SPECIAL_GROUPS =
IT_TOOLBAR_EXCLUDING =
IT_HYPERLINK =
changing
it_outtab = t_list[]
it_fieldcatalog = gt_fieldcat
IT_SORT =
IT_FILTER =
exceptions
invalid_parameter_combination = 1
program_error = 2
too_many_lines = 3
others = 4 .
if sy-subrc <> 0.
--Exception handling
endif.
else .
call method gr_alvgrid->refresh_table_display
EXPORTING
IS_STABLE =
I_SOFT_REFRESH =
exceptions
finished = 1
others = 2 .
if sy-subrc <> 0.
--Exception handling
endif.
endif .
endform. "END OF DISPLAY_ALV
************************************************************************
PREPARE_FIELD_CATALOG
*
************************************************************************
form prepare_field_catalog changing gt_fieldcat type lvc_t_fcat.
data ls_fcat type lvc_s_fcat .
ls_fcat-fieldname = 'PERNR'.
ls_fcat-ref_field = 'PERNR'.
ls_fcat-ref_table = 'PA0001'.
ls_fcat-colddictxt = 'M'.
ls_fcat-selddictxt = 'L'.
append ls_fcat to gt_fieldcat.
clear ls_fcat.
ls_fcat-fieldname = 'ENAME'.
ls_fcat-ref_field = 'ENAME'.
ls_fcat-ref_table = 'PA0001'.
ls_fcat-colddictxt = 'M'.
ls_fcat-selddictxt = 'L'.
append ls_fcat to gt_fieldcat.
clear ls_fcat.
ls_fcat-fieldname = 'AEDTM'.
ls_fcat-ref_field = 'AEDTM'.
ls_fcat-ref_table = 'PA0001'.
ls_fcat-colddictxt = 'M'.
ls_fcat-selddictxt = 'L'.
append ls_fcat to gt_fieldcat.
clear ls_fcat.
ls_fcat-fieldname = 'BEGDA'.
ls_fcat-ref_field = 'BEGDA'.
ls_fcat-ref_table = 'PA0001'.
ls_fcat-colddictxt = 'M'.
ls_fcat-selddictxt = 'L'.
append ls_fcat to gt_fieldcat.
clear ls_fcat.
ls_fcat-fieldname = 'UNAME'.
ls_fcat-ref_field = 'UNAME'.
ls_fcat-ref_table = 'PA0001'.
ls_fcat-colddictxt = 'M'.
ls_fcat-selddictxt = 'L'.
append ls_fcat to gt_fieldcat.
clear ls_fcat.
ls_fcat-fieldname = 'PERSG'.
ls_fcat-ref_field = 'PERSG'.
ls_fcat-ref_table = 'PA0001'.
ls_fcat-colddictxt = 'M'.
ls_fcat-selddictxt = 'L'.
append ls_fcat to gt_fieldcat.
clear ls_fcat.
ls_fcat-fieldname = 'PTEXT'.
ls_fcat-ref_field = 'PTEXT'.
ls_fcat-ref_table = 'T501T'.
ls_fcat-colddictxt = 'M'.
ls_fcat-selddictxt = 'L'.
append ls_fcat to gt_fieldcat.
clear ls_fcat.
ls_fcat-fieldname = 'ORGEH'.
ls_fcat-ref_field = 'ORGEH'.
ls_fcat-ref_table = 'PA0001'.
ls_fcat-colddictxt = 'M'.
ls_fcat-selddictxt = 'L'.
append ls_fcat to gt_fieldcat.
clear ls_fcat.
ls_fcat-fieldname = 'ORGTX'.
ls_fcat-ref_field = 'ORGTX'.
ls_fcat-ref_table = 'T527X'.
ls_fcat-colddictxt = 'M'.
ls_fcat-selddictxt = 'L'.
append ls_fcat to gt_fieldcat.
clear ls_fcat.
ls_fcat-fieldname = 'KOSTL'.
ls_fcat-ref_field = 'KOSTL'.
ls_fcat-ref_table = 'PA0001'.
ls_fcat-colddictxt = 'M'.
ls_fcat-selddictxt = 'L'.
append ls_fcat to gt_fieldcat.
clear ls_fcat.
ls_fcat-fieldname = 'KTEXT'.
ls_fcat-ref_field = 'KTEXT'.
ls_fcat-ref_table = 'CSKT'.
ls_fcat-colddictxt = 'M'.
ls_fcat-selddictxt = 'L'.
append ls_fcat to gt_fieldcat.
Fields not display in default.
clear ls_fcat.
ls_fcat-fieldname = 'BUKRS'.
ls_fcat-ref_field = 'BURKS'.
ls_fcat-ref_table = 'PA0001'.
ls_fcat-no_out = 'X'.
ls_fcat-colddictxt = 'M'.
ls_fcat-selddictxt = 'L'.
append ls_fcat to gt_fieldcat.
clear ls_fcat.
ls_fcat-fieldname = 'WERKS'.
ls_fcat-ref_field = 'WERKS'.
ls_fcat-ref_table = 'PA0001'.
ls_fcat-no_out = 'X'.
ls_fcat-colddictxt = 'M'.
ls_fcat-selddictxt = 'L'.
append ls_fcat to gt_fieldcat.
clear ls_fcat.
ls_fcat-fieldname = 'PERSK'.
ls_fcat-ref_field = 'PERSK'.
ls_fcat-ref_table = 'PA0001'.
ls_fcat-no_out = 'X'.
ls_fcat-colddictxt = 'M'.
ls_fcat-selddictxt = 'L'.
append ls_fcat to gt_fieldcat.
clear ls_fcat.
ls_fcat-fieldname = 'VDSK1'.
ls_fcat-ref_field = 'VDSK1'.
ls_fcat-ref_table = 'PA0001'.
ls_fcat-no_out = 'X'.
ls_fcat-colddictxt = 'M'.
ls_fcat-selddictxt = 'L'.
append ls_fcat to gt_fieldcat.
clear ls_fcat.
ls_fcat-fieldname = 'BTRTL'.
ls_fcat-ref_field = 'BTRTL'.
ls_fcat-ref_table = 'PA0001'.
ls_fcat-no_out = 'X'.
ls_fcat-colddictxt = 'M'.
ls_fcat-selddictxt = 'L'.
append ls_fcat to gt_fieldcat.
clear ls_fcat.
ls_fcat-fieldname = 'ABKRS'.
ls_fcat-ref_field = 'ABKRS'.
ls_fcat-ref_table = 'PA0001'.
ls_fcat-no_out = 'X'.
ls_fcat-colddictxt = 'M'.
ls_fcat-selddictxt = 'L'.
append ls_fcat to gt_fieldcat.
clear ls_fcat.
ls_fcat-fieldname = 'PLANS'.
ls_fcat-ref_field = 'PLANS'.
ls_fcat-ref_table = 'PA0001'.
ls_fcat-no_out = 'X'.
ls_fcat-colddictxt = 'M'.
ls_fcat-selddictxt = 'L'.
append ls_fcat to gt_fieldcat.
clear ls_fcat.
ls_fcat-fieldname = 'STELL'.
ls_fcat-ref_field = 'STELL'.
ls_fcat-ref_table = 'PA0001'.
ls_fcat-no_out = 'X'.
ls_fcat-colddictxt = 'M'.
ls_fcat-selddictxt = 'L'.
append ls_fcat to gt_fieldcat.
clear ls_fcat.
ls_fcat-fieldname = 'SACHZ'.
ls_fcat-ref_field = 'SACHZ'.
ls_fcat-ref_table = 'PA0001'.
ls_fcat-no_out = 'X'.
ls_fcat-colddictxt = 'M'.
ls_fcat-selddictxt = 'L'.
append ls_fcat to gt_fieldcat.
clear ls_fcat.
ls_fcat-fieldname = 'SNAME'.
ls_fcat-ref_field = 'SNAME'.
ls_fcat-ref_table = 'PA0001'.
ls_fcat-no_out = 'X'.
ls_fcat-colddictxt = 'M'.
ls_fcat-selddictxt = 'L'.
append ls_fcat to gt_fieldcat.
clear ls_fcat.
ls_fcat-fieldname = 'OTYPE'.
ls_fcat-ref_field = 'OTYPE'.
ls_fcat-ref_table = 'PA0001'.
ls_fcat-no_out = 'X'.
ls_fcat-colddictxt = 'M'.
ls_fcat-selddictxt = 'L'.
append ls_fcat to gt_fieldcat.
clear ls_fcat.
ls_fcat-fieldname = 'SBMOD'.
ls_fcat-ref_field = 'SBMOD'.
ls_fcat-ref_table = 'PA0001'.
ls_fcat-no_out = 'X'.
ls_fcat-colddictxt = 'M'.
ls_fcat-selddictxt = 'L'.
append ls_fcat to gt_fieldcat.
clear ls_fcat.
ls_fcat-fieldname = 'KOKRS'.
ls_fcat-ref_field = 'KOKRS'.
ls_fcat-ref_table = 'PA0001'.
ls_fcat-no_out = 'X'.
ls_fcat-colddictxt = 'M'.
ls_fcat-selddictxt = 'L'.
append ls_fcat to gt_fieldcat.
endform. "END OF PREPARE_FIELD_CATALOG
************************************************************************
PREPARE_LAYOUT
*
************************************************************************
form prepare_layout changing gs_layout type lvc_s_layo.
gs_layout-cwidth_opt = 'X'.
GS_LAYOUT-stylefname = 'CELLSTYLES'. PUSHBUTTON
endform. "END OF PREPARE_LAYOUT
&----
*& Module status_0200 OUTPUT
&----
text
----
module status_0200 output.
set pf-status 'SCREEN_0200'.
set titlebar 'SCREEN_0200'.
perform display_alv.
endmodule. " status_0200 OUTPUT
&----
*& Module user_command_0200 INPUT
&----
module user_command_0200 input.
save_ok = ok_code.
clear ok_code.
case save_ok.
when 'BACK'.
call method gr_ccontainer->free.
leave to screen 0.
when 'CANCEL'.
call method gr_ccontainer->free.
leave to screen 0.
when 'EXIT'.
leave program.
endcase.
endmodule. " user_command_0200 INPUT
I will reward points and really appreciate your helps.
05-27-2006 1:11 AM
Hi,
what exactly is the problem you are facing?
Take a look at this sample code
http://www.sapdevelopment.co.uk/reporting/email/email_mbody.htm
This thread has got lot of sample code.
Regards,
Ravi
Note : Please mark all the helpful answers and close the thread if the issue is resolved.
05-27-2006 1:11 AM
Hi,
what exactly is the problem you are facing?
Take a look at this sample code
http://www.sapdevelopment.co.uk/reporting/email/email_mbody.htm
This thread has got lot of sample code.
Regards,
Ravi
Note : Please mark all the helpful answers and close the thread if the issue is resolved.
05-30-2006 4:54 PM
Thanks for all reply.
The problem I am facing is I can't export the report zhrrpt0003 to memory by using the following codes. The codes suppose to export the list to memory and read it back to table and then email it but it does display the report on the screen which it is not supposed to . Then it stops and no email is send.
However , I test the following code with another program which does not use OO ALV and it works.
Have anyone had an OO ALV report works with email?
report zemail.
data : w_name type sos04-l_adr_name.
tables: pa0001.
select-options :
Recipient address
s_name for w_name default sy-uname no intervals.
----
start-of-selection.
E-mail Abap report
perform f_send_mail.
----
Form f_send_mail
----
form f_send_mail.
Data Declaration
data:
l_datum(10),
ls_docdata type sodocchgi1,
lt_objpack type table of sopcklsti1 with header line,
lt_objhead type table of solisti1 with header line,
lt_objtxt type table of solisti1 with header line,
lt_objbin type table of solisti1 with header line,
lt_reclist type table of somlreci1 with header line,
lt_listobject type table of abaplist with header line,
l_tab_lines type i,
l_att_type like soodk-objtp.
write sy-datum to l_datum.
NOTE: Create ALI/OTF Document in Spool
SUBMIT ZHRRPT0003 WITH S_AEDTM BETWEEN '20050101' AND '20060101' SIGN
'I' EXPORTING LIST TO MEMORY AND RETURN.
Read list from memory into table
call function 'LIST_FROM_MEMORY'
tables
listobject = lt_listobject
exceptions
not_found = 1
others = 2.
if sy-subrc <> 0.
Error in function module &1
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'
tables
in = lt_listobject
out = lt_objbin
exceptions
compress_error = 1
others = 2.
if sy-subrc <> 0.
Error in function module &1
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
ls_docdata-obj_name = 'HR Changes'.
concatenate 'List of HR Changes'
into ls_docdata-obj_descr separated by space.
Main Text
lt_objtxt = ' List of HR Changes'
append lt_objtxt.
Write Packing List (Main)
describe table lt_objtxt lines l_tab_lines.
read table lt_objtxt index l_tab_lines.
ls_docdata-doc_size = ( l_tab_lines - 1 ) * 255 + strlen( lt_objtxt ).
clear lt_objpack-transf_bin.
lt_objpack-head_start = 1.
lt_objpack-head_num = 0.
lt_objpack-body_start = 1.
lt_objpack-body_num = l_tab_lines.
lt_objpack-doc_type = 'RAW'.
append lt_objpack.
Create Message Attachment
Write Packing List (Attachment)
l_att_type = 'ALI'.
describe table lt_objbin lines l_tab_lines.
read table lt_objbin index l_tab_lines.
lt_objpack-doc_size = ( l_tab_lines - 1 ) * 255 + strlen( lt_objbin ).
lt_objpack-transf_bin = 'X'.
lt_objpack-head_start = 1.
lt_objpack-head_num = 0.
lt_objpack-body_start = 1.
lt_objpack-body_num = l_tab_lines.
lt_objpack-doc_type = l_att_type.
lt_objpack-obj_name = 'ATTACHMENT'.
lt_objpack-obj_descr = 'List_of_HR_Changes'. "#EC *
append lt_objpack.
Create receiver list
loop at s_name.
lt_reclist-receiver = s_name-low.
lt_reclist-rec_type = 'U'.
append lt_reclist.
endloop.
Send Message
call function 'SO_NEW_DOCUMENT_ATT_SEND_API1'
exporting
document_data = ls_docdata
put_in_outbox = 'X'
tables
packing_list = lt_objpack
object_header = lt_objhead
contents_bin = lt_objbin
contents_txt = lt_objtxt
receivers = lt_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.
Document sent
message id 'SO' type 'S' number '022'.
else.
Document <&> could not be sent
message id 'SO' type 'S' number '023'
with ls_docdata-obj_name.
endif.
05-27-2006 5:38 AM