Email-ID of PA0001-PERNR
Hi friends,
How to get email id of pa0001-pernr.
Pls reply.
Thanks in advance.
Hi,
See the below sample program.
parameters p_pernr type PRELP-PERNR.
data : v_date type sy-datum,
wa_data type p0105,
it_data type standard table of p0105.
v_date = sy-datum.
CALL FUNCTION 'HR_READ_INFOTYPE'
EXPORTING
pernr = p_pernr
infty = '0105'
BEGDA = v_date
tables
infty_tab = it_data
EXCEPTIONS
INFTY_NOT_FOUND = 1
OTHERS = 2
IF sy-subrc = 0.
loop at it_data into wa_data.
write: wa_data-usrid_long.
endloop.
ENDIF.
Regards
Vinod
Similar Messages
-
Reg:Email id of the PERNR ABAP-HR
Hi Team,
I have a requirement here that needs to send a mail to the Email address of the PERNR.
So here the question is How can i get the email id of the PERNR??
email address are stored in USR21 table i only have PERNR ?? So how can i relate it?
in the infotype PA0105 we have the field USRID_LONG where we can get the email id some times but not sure.
If i can get either the BNAME or the ADDRNUMBER and PERSNUMBER also fine ..
Please help me to pull the logic for this.
Thanks!
Karthik.SSometimes you can have a nemail address in PA0105, just check type of Communication, PA0105-USRTY (T591A)
Else use FM HR_GET_USER_FROM_EMPLOYEE (sister of R_GET_EMPLOYEES_FROM_USER) to get user id, then use BAPI_USER_GET_DETAIL or SUSR_USER_READ + ADDR_PERS_COMP_GET_COMPLETE .
(I often saw PA0105 for personal mail, reserved to HR, and office mail in user id)
Regards,
Raymond -
Hi ,
how can we send a form output as email and fax ? How to do the config for this? Can you explain the process to be done?
Rama.Hi,
See following code :
REPORT zmail_att NO STANDARD PAGE HEADING LINE-SIZE 200.
DATA : BEGIN OF ITAB OCCURS 0,
PERNR LIKE PA0001-PERNR,
ENAME LIKE PA0001-ENAME,
END OF ITAB.
DATA: message_content LIKE soli OCCURS 10 WITH HEADER LINE,
receiver_list LIKE soos1 OCCURS 5 WITH HEADER LINE,
packing_list LIKE soxpl OCCURS 2 WITH HEADER LINE,
listobject LIKE abaplist OCCURS 10,
compressed_attachment LIKE soli OCCURS 100 WITH HEADER LINE,
w_object_hd_change LIKE sood1,
compressed_size LIKE sy-index.
START-OF-SELECTION.
SELECT PERNR ENAME
INTO CORRESPONDING FIELDS OF TABLE ITAB
FROM PA0001
WHERE PERNR < 50.
LOOP AT ITAB.
WRITE :/02 SY-VLINE , ITAB-PERNR, 15 SY-VLINE , ITAB-ENAME, 50
SY-VLINE.
ENDLOOP.
Receivers
receiver_list-recextnam = 'XXXXX@X...'. --> EMAIL ADDRESS
RECEIVER_list-RECESC = 'E'. "<-
RECEIVER_list-SNDART = 'INT'."<-
RECEIVER_list-SNDPRI = '1'."<-
APPEND receiver_list.
General data
w_object_hd_change-objla = sy-langu.
w_object_hd_change-objnam = 'Object name'.
w_object_hd_change-objsns = 'P'.
Mail subject
w_object_hd_change-objdes = 'Message subject'.
Mail body
APPEND 'Message content' TO message_content.
Attachment
CALL FUNCTION 'SAVE_LIST'
EXPORTING
list_index = '0'
TABLES
listobject = listobject.
CALL FUNCTION 'TABLE_COMPRESS'
IMPORTING
compressed_size = compressed_size
TABLES
in = listobject
out = compressed_attachment.
DESCRIBE TABLE compressed_attachment.
CLEAR packing_list.
packing_list-transf_bin = 'X'.
packing_list-head_start = 0.
packing_list-head_num = 0.
packing_list-body_start = 1.
packing_list-body_num = sy-tfill.
packing_list-objtp = 'ALI'.
packing_list-objnam = 'Object name'.
packing_list-objdes = 'Attachment description'.
packing_list-objlen = compressed_size.
APPEND packing_list.
CALL FUNCTION 'SO_OBJECT_SEND'
EXPORTING
object_hd_change = w_object_hd_change
object_type = 'RAW'
owner = sy-uname
TABLES
objcont = message_content
receivers = receiver_list
packing_list = packing_list
att_cont = compressed_attachment.
Reward points if helpful.
Regards.
Srikanta Gope -
Smartform output to be send via Email
Hi Guys,
I have a custom report and output generated by Smartform, currently it is printing on printer.
My requirement is to sent this output to customer via Email.(email and perferred communication details are available from customer master)
We have a output management server which will receive this output and convert into PDF format and distribute this output to customer.
I would like to know what are the possible changes require on driver program.
Appriciate your help.
Regards
Pravin
Edited by: Pravin on Apr 16, 2008 9:23 PM
Edited by: Pravin on Apr 16, 2008 9:25 PMHi Pravin,
Check the following sample program. Smartform driver program. It helps you how to convert smartform output as PDF using function module CONVERT_OTF. Once it is converted mail can be sent through function module SO_NEW_DOCUMENT_ATT_SEND_API1.
Wherever u find MAI that should be mail.
REPORT zvenkat_smartform_via_mai.
*& Structures and Infotype Internal tables.
TABLES pernr.
INFOTYPES:
0000,
0001,
0002,
0006,
0022,
0023.
INCLUDE dbpnpmac.
*& Declaration part
* Types
TYPES:
BEGIN OF t_emp_info,
pernr TYPE pa0001-pernr,
ename TYPE pa0001-ename,
bukrs TYPE pa0001-bukrs,
persk TYPE pa0001-persk,
stell TYPE pa0001-stell,
gblnd TYPE pa0002-gblnd,
END OF t_emp_info,
BEGIN OF t_mard,
matnr TYPE mard-matnr,
werks TYPE mard-werks,
labst TYPE mard-labst,
meins TYPE mara-meins,
END OF t_mard.
* Work areas
DATA:
w_emp_info TYPE t_emp_info.
* Internal tables
DATA:
i_emp_info TYPE STANDARD TABLE OF t_emp_info,
i_mard TYPE STANDARD TABLE OF t_mard.
" Mai related declarations
"Variables
DATA :
g_sent_to_all TYPE sonv-flag,
g_tab_lines TYPE i.
"Types
TYPES:
t_document_data TYPE sodocchgi1,
t_packing_list TYPE sopcklsti1,
t_attachment TYPE solisti1,
t_body_msg TYPE solisti1,
t_receivers TYPE somlreci1,
t_pdf TYPE tline.
"Workareas
DATA :
w_document_data TYPE t_document_data,
w_packing_list TYPE t_packing_list,
w_attachment TYPE t_attachment,
w_body_msg TYPE t_body_msg,
w_receivers TYPE t_receivers,
w_pdf TYPE t_pdf.
"Internal Tables
DATA :
i_document_data TYPE STANDARD TABLE OF t_document_data,
i_packing_list TYPE STANDARD TABLE OF t_packing_list,
i_attachment TYPE STANDARD TABLE OF t_attachment,
i_body_msg TYPE STANDARD TABLE OF t_body_msg,
i_receivers TYPE STANDARD TABLE OF t_receivers,
i_pdf TYPE STANDARD TABLE OF t_pdf.
PARAMETERS:
p_mai_id(99) TYPE c.
*& Start-of-selection.
START-OF-SELECTION.
GET pernr.
PERFORM get_data.
PERFORM show_smartform.
*& End-of-selection.
END-OF-SELECTION.
*& Form get_data
FORM get_data .
rp-provide-from-last p0000 space pn-begda pn-endda.
rp-provide-from-last p0001 space pn-begda pn-endda.
rp-provide-from-last p0002 space pn-begda pn-endda.
MOVE-CORRESPONDING: p0000 TO w_emp_info,
p0001 TO w_emp_info,
p0002 TO w_emp_info.
SELECT matnr werks labst
FROM mard
INTO CORRESPONDING FIELDS OF TABLE i_mard.
ENDFORM. " get_data
*& Form show_smartform
FORM show_smartform .
DATA :
l_sform_name TYPE tdsfname,
l_fm_name TYPE rs38l_fnam.
DATA :
l_sf_control TYPE ssfctrlop,
l_sf_options TYPE ssfcompop.
DATA: i_otf LIKE itcoo OCCURS 100 WITH HEADER LINE.
* i_pdf LIKE tline OCCURS 100 WITH HEADER LINE.
DATA: op_option TYPE ssfctrlop,
job_output TYPE ssfcrescl.
* op_option-getotf = 'X'.
l_sform_name = 'ZVENKAT_SMARTFORM'.
CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'
EXPORTING
formname = l_sform_name
IMPORTING
fm_name = l_fm_name
EXCEPTIONS
no_form = 1
no_function_module = 2
OTHERS = 3.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ELSE.
CALL FUNCTION l_fm_name
EXPORTING
control_parameters = op_option
output_options = l_sf_options
w_emp_info = w_emp_info
IMPORTING
* DOCUMENT_OUTPUT_INFO =
job_output_info = job_output
TABLES
p0006 = p0006
p0022 = p0022
p0023 = p0023
i_mard = i_mard.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
CALL FUNCTION 'CONVERT_OTF'
EXPORTING
format = 'PDF'
TABLES
otf = job_output-otfdata
lines = i_pdf.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
PERFORM send_mai.
ENDIF.
ENDFORM. " show_smartform
*& Form send_mai
FORM send_mail .
"Subject of the mai.
w_document_data-obj_name = 'MAI_TO_HEAD'.
w_document_data-obj_descr = 'Regarding Mai Program by SAP ABAP'.
"Body of the mai
PERFORM build_body_of_mai
USING:space,
'Hi,',
'I am fine. How are you? How are you doing ? ',
'This program has been created to send simple mai',
'with Subject,Body with Address of the sender. ',
'Regards,',
'Venkat.O,',
'SAP HR Technical Consultant.'.
"Write Packing List for Body
DESCRIBE TABLE i_body_msg LINES g_tab_lines.
w_packing_list-head_start = 1.
w_packing_list-head_num = 0.
w_packing_list-body_start = 1.
w_packing_list-body_num = g_tab_lines.
w_packing_list-doc_type = 'RAW'.
APPEND w_packing_list TO i_packing_list.
CLEAR w_packing_list.
"Write Packing List for Attachment
w_packing_list-transf_bin = 'X'.
w_packing_list-head_start = 1.
w_packing_list-head_num = 1.
w_packing_list-body_start = 1.
DESCRIBE TABLE i_attachment LINES w_packing_list-body_num.
w_packing_list-doc_type = 'PDF'.
w_packing_list-obj_descr = 'PDF Attachment'.
w_packing_list-obj_name = 'PDF_ATTACHMENT'.
w_packing_list-doc_size = w_packing_list-body_num * 255.
APPEND w_packing_list TO i_packing_list.
CLEAR w_packing_list.
"Fill the document data and get size of attachment
w_document_data-obj_langu = sy-langu.
READ TABLE i_attachment INTO w_attachment INDEX g_tab_lines.
w_document_data-doc_size = ( g_tab_lines - 1 ) * 255 + STRLEN( w_attachment ).
"Receivers List.
w_receivers-rec_type = 'U'. "Internet address
w_receivers-receiver = p_mai_id. "here mai Id should be given
w_receivers-com_type = 'INT'.
w_receivers-notif_del = 'X'.
w_receivers-notif_ndel = 'X'.
APPEND w_receivers TO i_receivers .
CLEAR:w_receivers.
"Function module to send mai to Recipients
CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
EXPORTING
document_data = w_document_data
put_in_outbox = 'X'
commit_work = 'X'
IMPORTING
sent_to_all = g_sent_to_all
TABLES
packing_list = i_packing_list
contents_bin = i_attachment
contents_txt = i_body_msg
receivers = i_receivers
EXCEPTIONS
too_many_receivers = 1
document_not_sent = 2
document_type_not_exist = 3
operation_no_authorization = 4
parameter_error = 5
x_error = 6
enqueue_error = 7
OTHERS = 8.
IF sy-subrc = 0 .
MESSAGE i303(me) WITH 'Mai has been Successfully Sent.'.
ELSE.
WAIT UP TO 2 SECONDS.
"This program starts the SAPconnect send process.
SUBMIT rsconn01 WITH mode = 'INT'
WITH output = 'X'
AND RETURN.
ENDIF.
ENDFORM. " send_mai
*& Form build_body_of_mai
* text
* -->L_MESSAGE text
FORM build_body_of_mai USING l_message.
w_body_msg = l_message.
APPEND w_body_msg TO i_body_msg.
CLEAR w_body_msg.
ENDFORM. " build_body_of_mai
I hope that it helps u .
Regards,
Venkat.O -
Hi champs,
i am devloping a report in which i have to mail the
report to the conser vendor, email id.
can any one give me the code and steps for developing this
report.
<removed_by_moderator>
<removed_by_moderator>
vivek
Edited by: Julius Bussche on Aug 26, 2008 12:18 PMHi Vivek,
Check out the following program which creates report output as pdf format and sends to mentioned mail id. Change according to ur requirment .
REPORT zvenkat_mai_pdf_attach.
" Data retrieval related declarations
"Variables
DATA:
g_spool_no TYPE TSP01-RQIDENT.
"Types
TYPES:
BEGIN OF t_emp_dat,
pernr TYPE pa0001-pernr,
persg TYPE pa0001-persg,
persk TYPE pa0001-persk,
plans TYPE pa0001-plans,
stell TYPE pa0001-stell,
END OF t_emp_dat.
"Work area
DATA:
w_emp_data TYPE t_emp_dat.
"Internal tables
DATA:
i_emp_data TYPE STANDARD TABLE OF t_emp_dat.
" Mai related declarations
"Variables
DATA :
g_sent_to_all TYPE sonv-flag,
g_tab_lines TYPE i.
"Types
TYPES:
t_document_data TYPE sodocchgi1,
t_packing_list TYPE sopcklsti1,
t_attachment TYPE solisti1,
t_body_msg TYPE solisti1,
t_receivers TYPE somlreci1,
t_pdf TYPE tline.
"Workareas
DATA :
w_document_data TYPE t_document_data,
w_packing_list TYPE t_packing_list,
w_attachment TYPE t_attachment,
w_body_msg TYPE t_body_msg,
w_receivers TYPE t_receivers,
w_pdf TYPE t_pdf.
"Internal Tables
DATA :
i_document_data TYPE STANDARD TABLE OF t_document_data,
i_packing_list TYPE STANDARD TABLE OF t_packing_list,
i_attachment TYPE STANDARD TABLE OF t_attachment,
i_body_msg TYPE STANDARD TABLE OF t_body_msg,
i_receivers TYPE STANDARD TABLE OF t_receivers,
i_pdf TYPE STANDARD TABLE OF t_pdf.
parameters:p_mai_id(99) type c.
"Top-of-page.
TOP-OF-PAGE.
PERFORM top_of_page.
"Start-of-selection.
START-OF-SELECTION.
PERFORM get_data.
IF i_emp_data[] IS INITIAL.
PERFORM test_data.
ENDIF.
PERFORM do_print_n_get_spoolno.
"End-of-selection.
END-OF-SELECTION.
PERFORM send_mai.
*& Form top_of_page
FORM top_of_page.
DATA: inc_colnum TYPE i.
ULINE.
inc_colnum = sy-linsz - 60.
WRITE: / 'Report: ', sy-repid(18).
WRITE AT 30(inc_colnum) sy-title CENTERED.
inc_colnum = sy-linsz - 20.
WRITE: AT inc_colnum 'Page: ', (11) sy-pagno RIGHT-JUSTIFIED.
WRITE: / 'Client: ', sy-mandt.
inc_colnum = sy-linsz - 20.
WRITE: AT inc_colnum 'Date: ', sy-datum.
WRITE: / 'User : ', sy-uname.
inc_colnum = sy-linsz - 60.
WRITE AT 30(inc_colnum) 'Company Confidential' CENTERED.
inc_colnum = sy-linsz - 20.
WRITE: AT inc_colnum 'Time: ', (10) sy-uzeit RIGHT-JUSTIFIED.
ULINE .
SKIP.
ULINE AT /(127).
WRITE:/ sy-vline,'pernr' COLOR COL_HEADING,13
sy-vline,'persg' COLOR COL_HEADING,20
sy-vline,'persk' COLOR COL_HEADING,26
sy-vline,'plans' COLOR COL_HEADING,35
sy-vline,'stell' COLOR COL_HEADING,46
sy-vline.
ULINE AT /(46).
ENDFORM. "top_of_page
"Form get_data from PA0001
FORM get_data.
SELECT pernr
persg
persk
plans
stell
FROM pa0001
INTO CORRESPONDING FIELDS OF TABLE i_emp_data
UP TO 4 ROWS.
ENDFORM. " get_data
"Form do_print_n_get_spoolno
FORM do_print_n_get_spoolno.
"Display Output
LOOP AT i_emp_data INTO w_emp_data .
AT FIRST.
PERFORM get_print_parameters.
ENDAT.
WRITE:/ sy-vline,w_emp_data-pernr,13
sy-vline,w_emp_data-persg,20
sy-vline,w_emp_data-persk,26
sy-vline,w_emp_data-plans,35
sy-vline,w_emp_data-stell,46
sy-vline.
ULINE AT /(46).
AT LAST.
g_spool_no = sy-spono.
NEW-PAGE PRINT OFF.
CALL FUNCTION 'ABAP4_COMMIT_WORK'.
ENDAT.
ENDLOOP.
ENDFORM. "do_print_n_get_spoolno
"Form send_mai
"PACKING LIST
"This table requires information about how the data in the
"tables OBJECT_HEADER, CONTENTS_BIN and CONTENTS_TXT are to
"be distributed to the documents and its attachments.The first
"row is for the document, the following rows are each for one
"attachment.
FORM send_mai .
"Subject of the mai.
w_document_data-obj_name = 'MAI_TO_HEAD'.
w_document_data-obj_descr = 'Regarding Mai Program by SAP ABAP'.
"Body of the mai
PERFORM build_body_of_mai
USING:space,
'Hi,',
'I am fine. How are you? How are you doing ? ',
'This program has been created to send simple mai',
'with Subject,Body with Address of the sender. ',
'Regards,',
'Venkat.O,',
'SAP HR Technical Consultant.'.
"Convert ABAP Spool job to PDF
PERFORM convert_spool_2_pdf TABLES i_attachment.
"Write Packing List for Body
DESCRIBE TABLE i_body_msg LINES g_tab_lines.
w_packing_list-head_start = 1.
w_packing_list-head_num = 0.
w_packing_list-body_start = 1.
w_packing_list-body_num = g_tab_lines.
w_packing_list-doc_type = 'RAW'.
APPEND w_packing_list TO i_packing_list.
CLEAR w_packing_list.
"Write Packing List for Attachment
w_packing_list-transf_bin = 'X'.
w_packing_list-head_start = 1.
w_packing_list-head_num = 1.
w_packing_list-body_start = 1.
DESCRIBE TABLE i_attachment LINES w_packing_list-body_num.
w_packing_list-doc_type = 'PDF'.
w_packing_list-obj_descr = 'PDF Attachment'.
w_packing_list-obj_name = 'PDF_ATTACHMENT'.
w_packing_list-doc_size = w_packing_list-body_num * 255.
APPEND w_packing_list TO i_packing_list.
CLEAR w_packing_list.
"Fill the document data and get size of attachment
w_document_data-obj_langu = sy-langu.
READ TABLE i_attachment INTO w_attachment INDEX g_tab_lines.
w_document_data-doc_size = ( g_tab_lines - 1 ) * 255 + STRLEN( w_attachment ).
"Receivers List.
w_receivers-rec_type = 'U'. "Internet address
w_receivers-receiver = p_mai_id. "specify ur mai id here
w_receivers-com_type = 'INT'.
w_receivers-notif_del = 'X'.
w_receivers-notif_ndel = 'X'.
APPEND w_receivers TO i_receivers .
CLEAR:w_receivers.
"Function module to send mai to Recipients
CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
EXPORTING
document_data = w_document_data
put_in_outbox = 'X'
commit_work = 'X'
IMPORTING
sent_to_all = g_sent_to_all
TABLES
packing_list = i_packing_list
contents_bin = i_attachment
contents_txt = i_body_msg
receivers = i_receivers
EXCEPTIONS
too_many_receivers = 1
document_not_sent = 2
document_type_not_exist = 3
operation_no_authorization = 4
parameter_error = 5
x_error = 6
enqueue_error = 7
OTHERS = 8.
IF sy-subrc = 0 .
MESSAGE i303(me) WITH 'Mai has been Successfully Sent.'.
ELSE.
WAIT UP TO 2 SECONDS.
"This program starts the SAPconnect send process.
SUBMIT rsconn01 WITH mode = 'INT'
WITH output = 'X'
AND RETURN.
ENDIF.
ENDFORM. " send_mai
" Form build_body_of_mai
FORM build_body_of_mai USING l_message.
w_body_msg = l_message.
APPEND w_body_msg TO i_body_msg.
CLEAR w_body_msg.
ENDFORM. " build_body_of_mai
*& Form get_print_parameters
FORM get_print_parameters .
"Variables
DATA:
l_lay TYPE pri_params-paart,
l_lines TYPE pri_params-linct,
l_cols TYPE pri_params-linsz,
l_val TYPE c.
*Types
TYPES:
t_pripar TYPE pri_params,
t_arcpar TYPE arc_params.
"Work areas
DATA:
lw_pripar TYPE t_pripar,
lw_arcpar TYPE t_arcpar.
l_lay = 'X_65_132'.
l_lines = 65.
l_cols = 132.
"Read, determine, change spool print parameters and archive parameters
CALL FUNCTION 'GET_PRINT_PARAMETERS'
EXPORTING
in_archive_parameters = lw_arcpar
in_parameters = lw_pripar
layout = l_lay
line_count = l_lines
line_size = l_cols
no_dialog = 'X'
IMPORTING
out_archive_parameters = lw_arcpar
out_parameters = lw_pripar
valid = l_val
EXCEPTIONS
archive_info_not_found = 1
invalid_print_params = 2
invalid_archive_params = 3
OTHERS = 4.
IF l_val <> space AND sy-subrc = 0.
lw_pripar-prrel = space.
lw_pripar-primm = space.
NEW-PAGE PRINT ON
NEW-SECTION
PARAMETERS lw_pripar
ARCHIVE PARAMETERS lw_arcpar
NO DIALOG.
ENDIF.
ENDFORM. " get_print_parameters
*& Form convert_spool_2_pdf
FORM convert_spool_2_pdf TABLES l_attachment .
"Variables
DATA:
l_no_of_bytes TYPE i,
l_pdf_spoolid LIKE tsp01-rqident,
l_jobname LIKE tbtcjob-jobname,
l_jobcount LIKE tbtcjob-jobcount.
CALL FUNCTION 'CONVERT_ABAPSPOOLJOB_2_PDF'
EXPORTING
src_spoolid = g_spool_no
no_dialog = ' '
IMPORTING
pdf_bytecount = l_no_of_bytes
pdf_spoolid = l_pdf_spoolid
btc_jobname = l_jobname
btc_jobcount = l_jobcount
TABLES
pdf = i_pdf
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.
CASE sy-subrc.
WHEN 0.
WHEN 1.
MESSAGE s000(0k) WITH 'No ABAP Spool Job'.
EXIT.
WHEN 2.
MESSAGE s000(0k) WITH 'Spool Number does not exist'.
EXIT.
WHEN 3.
MESSAGE s000(0k) WITH 'No permission for spool'.
EXIT.
WHEN OTHERS.
MESSAGE s000(0k)
WITH 'Error in Function CONVERT_ABAPSPOOLJOB_2_PDF'.
EXIT.
ENDCASE.
CALL FUNCTION 'SX_TABLE_LINE_WIDTH_CHANGE'
EXPORTING
line_width_src = 134
line_width_dst = 255
TABLES
content_in = i_pdf
content_out = l_attachment
EXCEPTIONS
err_line_width_src_too_long = 1
err_line_width_dst_too_long = 2
err_conv_failed = 3
OTHERS = 4.
IF sy-subrc <> 0.
MESSAGE s000(0k) WITH 'Conversion Failed'.
EXIT.
ENDIF.
ENDFORM. " convert_spool_2_pdf
*& Form test_data
FORM test_data .
DO 10 TIMES.
w_emp_data-pernr = sy-index.
w_emp_data-persg = '2'.
w_emp_data-persk = '93'.
w_emp_data-plans = '99999999'.
w_emp_data-stell = '31414144'.
APPEND w_emp_data TO i_emp_data.
CLEAR w_emp_data.
ENDDO.
ENDFORM. " test_data
I hope that it helps u .
Regards,
Venkat.O -
How to convert sap script to pdf and send it as email attachment
hi,
my requirement is to convert a standard sales order form to pdf and send it as email attachment. get me some sample code for the same
thanks in advanceHi
See this sample code and after that use the fun module to send the mail
SO_NEW_DOCUMENT_ATT_SEND_API1
REPORT zzz_jaytest .
Types Declaration
TYPES : BEGIN OF ty_pa0001,
pernr TYPE pa0001-pernr,
bukrs TYPE pa0001-bukrs,
werks TYPE pa0001-werks,
END OF ty_pa0001.
Internal Table Declaration
DATA : i_pa0001 TYPE STANDARD TABLE OF ty_pa0001, "For pa0001 Details
i_otf TYPE STANDARD TABLE OF itcoo, "For OTF data
i_content_txt TYPE soli_tab, "Content
i_content_bin TYPE solix_tab, "Content
i_objhead TYPE soli_tab,
Work Area Declaration
w_pa0001 TYPE ty_pa0001, "For pa0001 Details
w_res TYPE itcpp, "SAPscript output
"parameters
w_otf TYPE itcoo, "For OTF
w_pdf TYPE solisti1, "For PDF
w_transfer_bin TYPE sx_boolean, "Content
w_options TYPE itcpo, "SAPscript output
"interface
Variable Declaration
v_len_in TYPE so_obj_len,
v_size TYPE i.
Constants Declaration
CONSTANTS : c_x TYPE c VALUE 'X', "X
c_locl(4) TYPE c VALUE 'LOCL', "Local Printer
c_otf TYPE sx_format VALUE 'OTF', "OTF
c_pdf TYPE sx_format VALUE 'PDF', "PDF
c_printer TYPE sx_devtype VALUE 'PRINTER', "PRINTER
c_bin TYPE char10 VALUE 'BIN', "BIN
c_name TYPE string VALUE 'C:\ZZZ_JAYTEST.PDF',"Downloading
"File Name
c_form(11) TYPE c VALUE 'ZZZ_JAYTEST'. "Form Name
START-OF-SELECTION.
Selecting the records from pa0001
SELECT pernr bukrs werks FROM pa0001
INTO TABLE i_pa0001 UP TO 10 ROWS.
Setting the options
w_options-tdcopies = 1 ."Number of copies
w_options-tdnoprev = c_x."No print preview
w_options-tdgetotf = c_x."Return of OTF table
w_options-tddest = c_locl."Spool: Output device
Opening the form
CALL FUNCTION 'OPEN_FORM'
EXPORTING
form = c_form
device = c_printer
language = sy-langu
OPTIONS = w_options
IMPORTING
RESULT = w_res.
LOOP AT i_pa0001 INTO w_pa0001.
Writting into the form
CALL FUNCTION 'WRITE_FORM'
EXPORTING
element = 'MAIN'
window = 'MAIN'.
ENDLOOP.
Closing the form
CALL FUNCTION 'CLOSE_FORM'
IMPORTING
RESULT = w_res
TABLES
otfdata = i_otf
EXCEPTIONS
unopened = 1
bad_pageformat_for_print = 2
send_error = 3
spool_error = 4
codepage = 5
OTHERS = 6.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
Converting OTF data to single line
LOOP AT i_otf INTO w_otf.
CONCATENATE w_otf-tdprintcom w_otf-tdprintpar
INTO w_pdf.
APPEND w_pdf TO i_content_txt.
ENDLOOP.
Converting to PDF Format
CALL FUNCTION 'SX_OBJECT_CONVERT_OTF_PDF'
EXPORTING
format_src = c_otf
format_dst = c_pdf
devtype = c_printer
CHANGING
transfer_bin = w_transfer_bin
content_txt = i_content_txt
content_bin = i_content_bin
objhead = i_objhead
len = v_len_in
EXCEPTIONS
err_conv_failed = 1
OTHERS = 2.
v_size = v_len_in.
Downloading the PDF File
CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
bin_filesize = v_size
filename = c_name
filetype = c_bin
TABLES
data_tab = i_content_bin.
If you r using this function module check it once....
call function 'CONVERT_OTF'
EXPORTING
format = 'PDF'
max_linewidth = 132
IMPORTING
bin_filesize = v_len_in
TABLES
otf = i_otf
lines = i_tline
EXCEPTIONS
err_max_linewidth = 1
err_format = 2
err_conv_not_possible = 3
others = 4.
Fehlerhandling
if sy-subrc <> 0.
endif.
or u can use the standard program RSTXPDFT4 to download the script into PDF format onto a particular location
follow this link for sample program.
http://searchsap.techtarget.com/tip/0,289483,sid21_gci1121833,00.html
check...
How to send smart form via email
/people/pavan.bayyapu/blog/2005/08/30/sending-html-email-from-sap-crmerp
Regards
Anji -
To convert Sap Script output to PDF format and send it via email.
Hi Friends,
Could any one please tell me, how to convert the Sap Script output to PDF format and send it via email. If any one have the code, kindly mail me to [email protected]
Thanks & Regards,
JohnPlese check this sample code from other thread.
REPORT zzz_jaytest .
Types Declaration
TYPES : BEGIN OF ty_pa0001,
pernr TYPE pa0001-pernr,
bukrs TYPE pa0001-bukrs,
werks TYPE pa0001-werks,
END OF ty_pa0001.
Internal Table Declaration
DATA : i_pa0001 TYPE STANDARD TABLE OF ty_pa0001, "For pa0001 Details
i_otf TYPE STANDARD TABLE OF itcoo, "For OTF data
i_content_txt TYPE soli_tab, "Content
i_content_bin TYPE solix_tab, "Content
i_objhead TYPE soli_tab,
Work Area Declaration
w_pa0001 TYPE ty_pa0001, "For pa0001 Details
w_res TYPE itcpp, "SAPscript output
"parameters
w_otf TYPE itcoo, "For OTF
w_pdf TYPE solisti1, "For PDF
w_transfer_bin TYPE sx_boolean, "Content
w_options TYPE itcpo, "SAPscript output
"interface
Variable Declaration
v_len_in TYPE so_obj_len,
v_size TYPE i.
Constants Declaration
CONSTANTS : c_x TYPE c VALUE 'X', "X
c_locl(4) TYPE c VALUE 'LOCL', "Local Printer
c_otf TYPE sx_format VALUE 'OTF', "OTF
c_pdf TYPE sx_format VALUE 'PDF', "PDF
c_printer TYPE sx_devtype VALUE 'PRINTER', "PRINTER
c_bin TYPE char10 VALUE 'BIN', "BIN
c_name TYPE string VALUE 'C:\ZZZ_JAYTEST.PDF',"Downloading
"File Name
c_form(11) TYPE c VALUE 'ZZZ_JAYTEST'. "Form Name
START-OF-SELECTION.
Selecting the records from pa0001
SELECT pernr bukrs werks FROM pa0001
INTO TABLE i_pa0001 UP TO 10 ROWS.
Setting the options
w_options-tdcopies = 1 ."Number of copies
w_options-tdnoprev = c_x."No print preview
w_options-tdgetotf = c_x."Return of OTF table
w_options-tddest = c_locl."Spool: Output device
Opening the form
CALL FUNCTION 'OPEN_FORM'
EXPORTING
form = c_form
device = c_printer
language = sy-langu
OPTIONS = w_options
IMPORTING
RESULT = w_res.
LOOP AT i_pa0001 INTO w_pa0001.
Writting into the form
CALL FUNCTION 'WRITE_FORM'
EXPORTING
element = 'MAIN'
window = 'MAIN'.
ENDLOOP.
Closing the form
CALL FUNCTION 'CLOSE_FORM'
IMPORTING
RESULT = w_res
TABLES
otfdata = i_otf
EXCEPTIONS
unopened = 1
bad_pageformat_for_print = 2
send_error = 3
spool_error = 4
codepage = 5
OTHERS = 6.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
Converting OTF data to single line
LOOP AT i_otf INTO w_otf.
CONCATENATE w_otf-tdprintcom w_otf-tdprintpar
INTO w_pdf.
APPEND w_pdf TO i_content_txt.
ENDLOOP.
Converting to PDF Format
CALL FUNCTION 'SX_OBJECT_CONVERT_OTF_PDF'
EXPORTING
format_src = c_otf
format_dst = c_pdf
devtype = c_printer
CHANGING
transfer_bin = w_transfer_bin
content_txt = i_content_txt
content_bin = i_content_bin
objhead = i_objhead
len = v_len_in
EXCEPTIONS
err_conv_failed = 1
OTHERS = 2.
v_size = v_len_in.
Downloading the PDF File
CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
bin_filesize = v_size
filename = c_name
filetype = c_bin
TABLES
data_tab = i_content_bin.
The extension is put the it_mailpack-obj_name parameter of 'SO_NEW_DOCUMENT_ATT_SEND_API1'. -
Auto emailing of PO's of particular purchasing groups to common mail Id
Hello All,
There is a need to have all the PO's created with multiple purchasing groups to be sent to a common mail Id.
For Example , there are various purchasing groups like PG1, PG2, PG3,....and so on & the need is to send all the PO's created with these purchasing groups (PG1,PG2,PG3....) to be sent to a common mail ID
Kindly advise how to proceed further regarding this.
Thanks & Regards,
Ravindra
Edited by: Ravi Bhalerao on May 5, 2011 8:41 AMYuo can have this as follows:-
Create a customized program which choose PO detail based on PO PR group. Then write a funtion module to send mail to external mail ID POs as PDF attachment.
Here is the sample code for Function module:-
REPORT ZREPORT_TO_EMAIL NO STANDARD PAGE HEADING LINE-SIZE 200.
DATA : BEGIN OF ITAB OCCURS 0,
PERNR LIKE PA0001-PERNR,
ENAME LIKE PA0001-ENAME,
END OF ITAB.
DATA: message_content LIKE soli OCCURS 10 WITH HEADER LINE,
receiver_list LIKE soos1 OCCURS 5 WITH HEADER LINE,
packing_list LIKE soxpl OCCURS 2 WITH HEADER LINE,
listobject LIKE abaplist OCCURS 10,
compressed_attachment LIKE soli OCCURS 100 WITH HEADER LINE,
w_object_hd_change LIKE sood1,
compressed_size LIKE sy-index.
START-OF-SELECTION.
SELECT PERNR ENAME
INTO CORRESPONDING FIELDS OF TABLE ITAB
FROM PA0001
WHERE PERNR < 50.
LOOP AT ITAB.
WRITE :/02 SY-VLINE , ITAB-PERNR, 15 SY-VLINE , ITAB-ENAME, 50
SY-VLINE.
ENDLOOP.
Receivers
receiver_list-recextnam = 'EXTERNAL-MAIL-ID'. "-->
EMAIL ADDRESS
RECEIVER_list-RECESC = 'E'. "<-
RECEIVER_list-SNDART = 'INT'."<-
RECEIVER_list-SNDPRI = '1'."<-
APPEND receiver_list.
General data
w_object_hd_change-objla = sy-langu.
w_object_hd_change-objnam = 'Object name'.
w_object_hd_change-objsns = 'P'.
Mail subject
w_object_hd_change-objdes = 'Message subject'.
Mail body
APPEND 'Message content' TO message_content.
Attachment
CALL FUNCTION 'SAVE_LIST'
EXPORTING
list_index = '0'
TABLES
listobject = listobject.
CALL FUNCTION 'TABLE_COMPRESS'
IMPORTING
compressed_size = compressed_size
TABLES
in = listobject
out = compressed_attachment.
DESCRIBE TABLE compressed_attachment.
CLEAR packing_list.
packing_list-transf_bin = 'X'.
packing_list-head_start = 0.
packing_list-head_num = 0.
packing_list-body_start = 1.
packing_list-body_num = sy-tfill.
packing_list-objtp = 'ALI'.
packing_list-objnam = 'Object name'.
packing_list-objdes = 'Attachment description'.
packing_list-objlen = compressed_size.
APPEND packing_list.
CALL FUNCTION 'SO_OBJECT_SEND'
EXPORTING
object_hd_change = w_object_hd_change
object_type = 'RAW'
owner = sy-uname
TABLES
objcont = message_content
receivers = receiver_list
packing_list = packing_list
att_cont = compressed_attachment. -
Regarding the Email attachment again....
Hi guys its still pending....
Am using the function module SO_NEW_DOCUMENT_ATT_SEND_API1 to send Email.
I have 2 issues...
1) I cannot send the file as attachment. Its going in the body of the mail.
2) The max column size is 256 but i need to send 537 and is must.
Please help me out...
Thanks in advance
Abhi....HI
GOOD
HERE I AM GIVING SOME DETAILS ABOUT SENDING MAIL, YOU CAN TRY WITH THEM.I HOPE THIS WILL HELP YOU TO SOLVE YOUR PROBLEM.
Sending External email through SAP
What is the FM for sending the external email through SAP by attaching layout set to it?
These are the FM for sending external email :-
SO_DOCUMENT_SEND_API1
SAPoffice: Send new document with attachments via RFC
SO_NEW_DOCUMENT_ATT_SEND_API1
(In 4.6C only, You can go to SE37 and click the documentation on how to use it. A sample program is provided there.)
SAPoffice: Send new document with attachments via RFC
Note : If you are using FM SO_NEW_DOCUMENT_ATT_SEND_API1 then Export Parameter DOCUMENT_DATA-OBJ_DESCR contains the Subject.
SO_NEW_DOCUMENT_SEND_API1
SAPoffice: Send new document
How to send a report to an external mail-id?
Try this sample code :-
REPORT ZREPORT_TO_EMAIL NO STANDARD PAGE HEADING LINE-SIZE 200.
DATA : BEGIN OF ITAB OCCURS 0,
PERNR LIKE PA0001-PERNR,
ENAME LIKE PA0001-ENAME,
END OF ITAB.
DATA: message_content LIKE soli OCCURS 10 WITH HEADER LINE,
receiver_list LIKE soos1 OCCURS 5 WITH HEADER LINE,
packing_list LIKE soxpl OCCURS 2 WITH HEADER LINE,
listobject LIKE abaplist OCCURS 10,
compressed_attachment LIKE soli OCCURS 100 WITH HEADER LINE,
w_object_hd_change LIKE sood1,
compressed_size LIKE sy-index.
START-OF-SELECTION.
SELECT PERNR ENAME
INTO CORRESPONDING FIELDS OF TABLE ITAB
FROM PA0001
WHERE PERNR < 50.
LOOP AT ITAB.
WRITE :/02 SY-VLINE , ITAB-PERNR, 15 SY-VLINE , ITAB-ENAME, 50
SY-VLINE.
ENDLOOP.
Receivers
receiver_list-recextnam = '[email protected]'. "-->
EMAIL ADDRESS
RECEIVER_list-RECESC = 'E'. "<-
RECEIVER_list-SNDART = 'INT'."<-
RECEIVER_list-SNDPRI = '1'."<-
APPEND receiver_list.
General data
w_object_hd_change-objla = sy-langu.
w_object_hd_change-objnam = 'Object name'.
w_object_hd_change-objsns = 'P'.
Mail subject
w_object_hd_change-objdes = 'Message subject'.
Mail body
APPEND 'Message content' TO message_content.
Attachment
CALL FUNCTION 'SAVE_LIST'
EXPORTING
list_index = '0'
TABLES
listobject = listobject.
CALL FUNCTION 'TABLE_COMPRESS'
IMPORTING
compressed_size = compressed_size
TABLES
in = listobject
out = compressed_attachment.
DESCRIBE TABLE compressed_attachment.
CLEAR packing_list.
packing_list-transf_bin = 'X'.
packing_list-head_start = 0.
packing_list-head_num = 0.
packing_list-body_start = 1.
packing_list-body_num = sy-tfill.
packing_list-objtp = 'ALI'.
packing_list-objnam = 'Object name'.
packing_list-objdes = 'Attachment description'.
packing_list-objlen = compressed_size.
APPEND packing_list.
CALL FUNCTION 'SO_OBJECT_SEND'
EXPORTING
object_hd_change = w_object_hd_change
object_type = 'RAW'
owner = sy-uname
TABLES
objcont = message_content
receivers = receiver_list
packing_list = packing_list
att_cont = compressed_attachment.
GO THROUGH THIS LINK
http://mailman.mit.edu/pipermail/sap-wug/2006-April/022007.html
THANKS
MRUTYUN -
Dear All
i have written the program for send payslip through email and its working fine
But problem is that i am not getting the correct format in PDF
Regards
ArunHi All
Plz find my code here which i am using to send Payslip through email, its working fine
But when i received the email with attachment, PDF is not coming in correct format
You can see the output of PDF given below after my code
REPORT zsendmail.
TABLES:pa0001.
DATA : BEGIN OF rgdir OCCURS 0.
INCLUDE STRUCTURE pc261.
DATA END OF rgdir.
DATA : country LIKE t001p-molga VALUE 'IN',
v_pabrj LIKE t549q-pabrj,
v_pabrp LIKE t549q-pabrp,
v_vabrj LIKE t549q-vabrj,
v_vabrp LIKE t549q-vabrp,
v_fpper1 LIKE rgdir-fpper,
v_fpper2 LIKE rgdir-fpper,
return LIKE bapireturn1,
*payslip LIKE bapi7004_payslip OCCURS 0 WITH HEADER LINE,
payslip TYPE xstring,
*slip LIKE pc408,
bin_file TYPE xstring,
pdf_fsize TYPE i,
x TYPE i,
x1 TYPE i,
v_srno LIKE pa0000-pernr.
DATA BEGIN OF slip OCCURS 0.
INCLUDE STRUCTURE pc408.
DATA END OF slip.
DATA BEGIN OF slip1 OCCURS 0.
INCLUDE STRUCTURE pc407.
DATA END OF slip1.
DATA: BEGIN OF i_pernr OCCURS 0,
pernr LIKE pa0000-pernr,
seqnr LIKE hrpy_rgdir-seqnr,
abkrs LIKE hrpy_rgdir-abkrs,
fpper LIKE hrpy_rgdir-fpper,
inper LIKE hrpy_rgdir-inper,
ipend LIKE hrpy_rgdir-ipend,
usrid_long LIKE pa0105-usrid_long,
nachn LIKE pa0002-nachn,
vorna LIKE pa0002-vorna,
anred LIKE pa0002-anred,
ename LIKE pa0001-ename,
END OF i_pernr.
DATA result TYPE pay99_result.
DATA lv_buffer TYPE xstring. " added later
DATA ihrpy LIKE hrpy_rgdir OCCURS 0.
DATA whpr TYPE hrpy_rgdir.
DATA : bt_header TYPE LINE OF hrpay99_bt,
rt_header TYPE LINE OF hrpay99_rt.
DATA : objhex LIKE solix OCCURS 0 WITH HEADER LINE,
objhex1 TYPE solix.
*************************Added Later
DATA : objbin LIKE solix OCCURS 0 WITH HEADER LINE,
objbin1 TYPE solix.
DATA: y TYPE i ,
z TYPE i,
mname TYPE string.
DATA: mail_attachment_lines TYPE i,
lv_tablines LIKE sy-tabix.
DATA: objpack LIKE sopcklsti1 OCCURS 2 WITH HEADER LINE.
DATA: objtxt LIKE solisti1 OCCURS 10 WITH HEADER LINE.
DATA: i_reclist LIKE somlreci1 OCCURS 5 WITH HEADER LINE,
wa_reclist TYPE somlreci1 .
DATA: doc_chng LIKE sodocchgi1,
l_date(10) TYPE c,
l_time(8) TYPE c.
DATA: objhead TYPE soli_tab.
DATA : w_repid LIKE sy-repid,
w_dynpro LIKE sy-dynnr.
SELECTION-SCREEN BEGIN OF BLOCK b1 .
PARAMETERS : p_bukrs LIKE pa0001-bukrs OBLIGATORY,
p_permo LIKE t549q-permo.
SELECT-OPTIONS:s_date FOR pa0001-begda NO-EXTENSION OBLIGATORY,
s_abkrs FOR pa0001-abkrs OBLIGATORY,
s_persg FOR pa0001-persg,
s_pernr FOR pa0001-pernr.
SELECTION-SCREEN END OF BLOCK b1.
LOAD-OF-PROGRAM.
MOVE sy-repid TO w_repid. MOVE sy-dynnr TO w_dynpro.
WRITE: sy-datum TO l_date, sy-uzeit TO l_time.
START-OF-SELECTION.
PERFORM select_data.
*& Form SELECT_DATA
FORM select_data .
SELECT SINGLE pabrj pabrp vabrj vabrp FROM t549q INTO (v_pabrj,v_pabrp,v_vabrj,v_vabrp) WHERE permo = p_permo AND begda >= s_date-low AND endda <= s_date-high.
CONCATENATE v_pabrj v_pabrp INTO v_fpper1.
CONCATENATE v_vabrj v_vabrp INTO v_fpper2.
CASE v_pabrp.
WHEN '01'. CONCATENATE 'APRIL' s_date-high+0(4) INTO mname SEPARATED BY space.
WHEN '02'. CONCATENATE 'MAY' s_date-high+0(4) INTO mname SEPARATED BY space.
WHEN '03'. CONCATENATE 'JUNE' s_date-high+0(4) INTO mname SEPARATED BY space.
WHEN '04'. CONCATENATE 'JULY' s_date-high+0(4) INTO mname SEPARATED BY space.
WHEN '05'. CONCATENATE 'AUGUST' s_date-high+0(4) INTO mname SEPARATED BY space.
WHEN '06'. CONCATENATE 'SEPTEMBER' s_date-high+0(4) INTO mname SEPARATED BY space.
WHEN '07'. CONCATENATE 'OCTOBER' s_date-high+0(4) INTO mname SEPARATED BY space.
WHEN '08'. CONCATENATE 'NOVEMEBR' s_date-high+0(4) INTO mname SEPARATED BY space.
WHEN '09'. CONCATENATE 'DECEMBER' s_date-high+0(4) INTO mname SEPARATED BY space.
WHEN '10'. CONCATENATE 'JANUARY' s_date-high+0(4) INTO mname SEPARATED BY space.
WHEN '11'. CONCATENATE 'FEBRUARY' s_date-high+0(4) INTO mname SEPARATED BY space.
WHEN '12'. CONCATENATE 'MARCH' s_date-high+0(4) INTO mname SEPARATED BY space.
ENDCASE.
hrpy_rgdir table is getting filled once the payroll is run.
SELECT hrpy_rgdirpernr hrpy_rgdirseqnr hrpy_rgdirabkrs hrpy_rgdirfpper hrpy_rgdirinper hrpy_rgdiripend pa0105usrid_long pa0002nachn pa0002vorna pa0002anred pa0001~ename
FROM hrpy_rgdir
JOIN pa0105 ON hrpy_rgdirpernr = pa0105pernr AND subty = '0010'
JOIN pa0002 ON hrpy_rgdirpernr = pa0002pernr
JOIN pa0001 ON hrpy_rgdirpernr = pa0001pernr
INTO CORRESPONDING FIELDS OF TABLE i_pernr
WHERE inper > v_fpper2
AND inper <= v_fpper1
AND fpper > v_fpper2
AND fpper <= v_fpper1
AND hrpy_rgdir~pernr IN s_pernr
AND srtza = 'A'
AND pa0105~endda >= s_date-high
AND pa0002~endda >= s_date-high
AND pa0001~endda >= s_date-high
AND pa0001~bukrs = p_bukrs
AND pa0001~abkrs IN s_abkrs
AND pa0001~persg IN s_persg.
LOOP AT i_pernr.
REFRESH : objhex , objpack , objtxt ,i_reclist.
CLEAR : objhex1, y,z,x1,x, mail_attachment_lines, wa_reclist, doc_chng , objhead.
CALL FUNCTION 'BAPI_GET_PAYSLIP_PDF'
EXPORTING
employeenumber = i_pernr-pernr
sequencenumber = i_pernr-seqnr
payslipvariant = 'ZOFF'
IMPORTING
RETURN =
payslip = payslip
pdf_fsize = pdf_fsize.
x = pdf_fsize / 255.
z = pdf_fsize - 255.
DO x TIMES.
IF x1 > z .
EXIT.
ENDIF.
objhex1-line = payslip+x1(255).
APPEND objhex1 TO objhex.
objbin1-line = payslip+x1(255).
APPEND objbin1 TO objbin.
x1 = x1 + 255.
ENDDO.
y = pdf_fsize - x1 .
objhex1-line = payslip+x1(y) .
APPEND objhex1 TO objhex.
DESCRIBE TABLE objhex LINES mail_attachment_lines.
doc_chng-obj_name = 'PAYSLIP'.
CONCATENATE 'PAYSLIP FOR' mname INTO doc_chng-obj_descr SEPARATED BY space .
CASE i_pernr-anred.
WHEN 1.
CONCATENATE 'Dear' 'Mr.' i_pernr-vorna i_pernr-nachn INTO objtxt-line SEPARATED BY ' '.
WHEN 2. CONCATENATE 'Dear' 'Ms.' i_pernr-vorna i_pernr-nachn INTO objtxt-line SEPARATED BY ' '.
WHEN 3. CONCATENATE 'Dear' 'Dr.' i_pernr-vorna i_pernr-nachn INTO objtxt-line SEPARATED BY ' '.
WHEN OTHERS. CONCATENATE 'Dear' i_pernr-vorna i_pernr-nachn INTO objtxt-line SEPARATED BY ' '.
ENDCASE.
CLEAR objtxt.
APPEND objtxt.
CONCATENATE 'Please find attached payslip for' mname INTO objtxt-line SEPARATED BY space.
APPEND objtxt.
CLEAR objtxt.
WRITE: sy-datum TO l_date,
sy-uzeit TO l_time.
CONCATENATE 'SAP System generated statement (on' l_date 'At' l_time 'IST) enclosed which does not REQUIRE SIGNATURE.' INTO objtxt-line SEPARATED BY space.
APPEND objtxt.
CLEAR objtxt.
*--FOR EMPTY LINE APPEND objtxt.
objtxt-line = 'Regards,'.
APPEND objtxt.
CLEAR objtxt.
objtxt-line = 'TEAM HR.'.
APPEND objtxt.
CLEAR objtxt.
CASE i_pernr-abkrs.
WHEN 'ZO'.
objtxt-line = 'ENGLISH LTD'.
WHEN 'Z2'. objtxt-line = 'ENGLISH LTD'.
WHEN 'Z8'. objtxt-line = 'ENGLISH LTD'.
WHEN 'Z5'. objtxt-line = 'ENGLISH LTD'.
WHEN OTHERS. objtxt-line = ''.
ENDCASE.
APPEND objtxt.
CLEAR objtxt.
APPEND objtxt.
DESCRIBE TABLE objtxt LINES lv_tablines.
READ TABLE objtxt INDEX lv_tablines TRANSPORTING ALL FIELDS.
doc_chng-doc_size = ( lv_tablines - 1 ) * 255 + STRLEN( objtxt ).
CLEAR objpack-transf_bin.
objpack-head_start = 1.
objpack-head_num = 0.
objpack-body_start = 1.
objpack-body_num = lv_tablines.
objpack-doc_type = 'RAW'.
APPEND objpack.
Pack to PDF.
objpack-transf_bin = 'X'.
objpack-head_start = 1.
objpack-head_num = 1.
objpack-body_start = 1.
objpack-body_num = mail_attachment_lines.
objpack-doc_type = 'PDF'.
objpack-obj_name = 'Noti'.
objpack-doc_size = pdf_fsize.
objpack-doc_size = mail_attachment_lines * 255.
objpack-obj_descr = 'payslip.pdf'.
APPEND objpack.
CLEAR: wa_reclist.
REFRESH i_reclist[].
CLEAR wa_reclist.
wa_reclist-receiver = i_pernr-usrid_long.
wa_reclist-rec_type = 'U'.
APPEND wa_reclist TO i_reclist.
CLEAR wa_reclist.
CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
EXPORTING
document_data = doc_chng
put_in_outbox = 'X'
commit_work = 'X'
TABLES
packing_list = objpack
object_header =
contents_bin = objbin
contents_txt = objtxt
contents_hex = objhex
contents_hex = slip
receivers = i_reclist
EXCEPTIONS
too_many_receivers = 1
document_not_sent = 2
document_type_not_exist = 3
operation_no_authorization = 4
parameter_error = 5
x_error = 6
enqueue_error = 7
OTHERS = 8.
IF sy-subrc = 0.
* message i000 with 'Error When Sending the File'.
ELSE.
WAIT UP TO 5 SECONDS.
SUBMIT rsconn01 WITH mode = 'INT' AND RETURN.
ENDIF.
ENDIF.
ENDLOOP.
IF sy-subrc = 0.
WRITE : / 'Sucess','Emp No',
i_pernr-pernr.
ELSE.
WRITE : 'Not Sucess','Emp No',
i_pernr-pernr.
ENDIF.
ENDFORM. " SELECT_DATA
PDF Output
Bank Name Account No. Amount = Earnings - Deductions +
Adjustment
UTI002 12112112 24,287.00 = 27,950.00 - 3,663.00
+ 0.00
|----
|Earnings |Deductions
Perks/Other income/Exemptptions/Rebates
-||--
|
Basic Salary
18,000.00
Income Tax
3,663.00 ||Agg of Chapter VI | 122,000.00 |
Children Education Allow
1,200.00
Special Allowance
5,000.00
Conveyance Allowance
3,500.00
Medical Allowance - T
250.00
Total
27,950.00
Total
3,663.00 || | |
Net Pay
24,287.00 Recovery 0.00
Form 16 summary |
Gross Salary 335,400.00 |
Balance 335,400.00 |
Incm under Hd Salary 335,400.00 |
Gross Tot Income 335,400.00 |
Agg of Chapter VI 122,000.00 |
Total Income 213,400.00 |
Tax on total Income 42,680.00 |
Tax payable and surcharg 43,960.00 |
Tax deducted so far 3,663.00 |
Income Tax 3,663.00 |
|
|
|
|
|
This is a computer generated statement and signature is not required. -
Error in sending email to users(outside sap)
Hello experts,
We just transported my program to QAS server and I just tested it now if my program to send messages to emails outside works. Unfortunately, it doesn't. I am using FM SO_NEW_DOCUMENT_SEND_API1 and the sy-subrc = 2 whcih means document not sent. Also, there is window that popped up that says
Database error for <ADDR_PERS_COMP_COMM_GET> <0>
Again, thank you guys for all your help and take care!Hi,
Check this
Sending mail To Standard SAP MAIL Box
http://www.sap-img.com/abap/sending-email-with-attachment.htm
SCOT settings
http://www.sap-img.com/basis/basis-faq.htm
Sending External email through SAP
http://www.geocities.com/mpioud/Z_EMAIL_ABAP_REPORT.html
http://www.sapdevelopment.co.uk/reporting/email/attach_xls.htm
http://www.sapdevelopment.co.uk/reporting/rep_spooltopdf.htm
http://www.sapdevelopment.co.uk/reporting/email/emailhome.htm\
http://www.sap-img.com/abap/sending-email-with-attachment.htm
Sample Code
Sending External email through SAP
What is the FM for sending the external email through SAP by attaching layout set to it?
These are the FM for sending external email :-
SO_DOCUMENT_SEND_API1
SAPoffice: Send new document with attachments via RFC
SO_NEW_DOCUMENT_ATT_SEND_API1
(In 4.6C only, You can go to SE37 and click the documentation on how to use it. A sample program is provided there.)
SAPoffice: Send new document with attachments via RFC
Note : If you are using FM SO_NEW_DOCUMENT_ATT_SEND_API1 then Export Parameter DOCUMENT_DATA-OBJ_DESCR contains the Subject.
SO_NEW_DOCUMENT_SEND_API1
SAPoffice: Send new document
How to send a report to an external mail-id?
<b>
Try this sample code :-</b>
REPORT ZREPORT_TO_EMAIL NO STANDARD PAGE HEADING LINE-SIZE 200.
DATA : BEGIN OF ITAB OCCURS 0,
PERNR LIKE PA0001-PERNR,
ENAME LIKE PA0001-ENAME,
END OF ITAB.
DATA: message_content LIKE soli OCCURS 10 WITH HEADER LINE,
receiver_list LIKE soos1 OCCURS 5 WITH HEADER LINE,
packing_list LIKE soxpl OCCURS 2 WITH HEADER LINE,
listobject LIKE abaplist OCCURS 10,
compressed_attachment LIKE soli OCCURS 100 WITH HEADER LINE,
w_object_hd_change LIKE sood1,
compressed_size LIKE sy-index.
START-OF-SELECTION.
SELECT PERNR ENAME
INTO CORRESPONDING FIELDS OF TABLE ITAB
FROM PA0001
WHERE PERNR < 50.
LOOP AT ITAB.
WRITE :/02 SY-VLINE , ITAB-PERNR, 15 SY-VLINE , ITAB-ENAME, 50
SY-VLINE.
ENDLOOP.
Receivers
receiver_list-recextnam = '[email protected]'. "-->
EMAIL ADDRESS
RECEIVER_list-RECESC = 'E'. "<-
RECEIVER_list-SNDART = 'INT'."<-
RECEIVER_list-SNDPRI = '1'."<-
APPEND receiver_list.
General data
w_object_hd_change-objla = sy-langu.
w_object_hd_change-objnam = 'Object name'.
w_object_hd_change-objsns = 'P'.
Mail subject
w_object_hd_change-objdes = 'Message subject'.
Mail body
APPEND 'Message content' TO message_content.
Attachment
CALL FUNCTION 'SAVE_LIST'
EXPORTING
list_index = '0'
TABLES
listobject = listobject.
CALL FUNCTION 'TABLE_COMPRESS'
IMPORTING
compressed_size = compressed_size
TABLES
in = listobject
out = compressed_attachment.
DESCRIBE TABLE compressed_attachment.
CLEAR packing_list.
packing_list-transf_bin = 'X'.
packing_list-head_start = 0.
packing_list-head_num = 0.
packing_list-body_start = 1.
packing_list-body_num = sy-tfill.
packing_list-objtp = 'ALI'.
packing_list-objnam = 'Object name'.
packing_list-objdes = 'Attachment description'.
packing_list-objlen = compressed_size.
APPEND packing_list.
CALL FUNCTION 'SO_OBJECT_SEND'
EXPORTING
object_hd_change = w_object_hd_change
object_type = 'RAW'
owner = sy-uname
TABLES
objcont = message_content
receivers = receiver_list
packing_list = packing_list
att_cont = compressed_attachment.
<b>
2nd Program</b>
REPORT ZSENDEXTERNAL.
DATA: OBJPACK LIKE SOPCKLSTI1 OCCURS 2 WITH HEADER LINE.
DATA: OBJHEAD LIKE SOLISTI1 OCCURS 1 WITH HEADER LINE.
DATA: OBJBIN LIKE SOLISTI1 OCCURS 10 WITH HEADER LINE.
DATA: OBJTXT LIKE SOLISTI1 OCCURS 10 WITH HEADER LINE.
DATA: RECLIST LIKE SOMLRECI1 OCCURS 5 WITH HEADER LINE.
DATA: DOC_CHNG LIKE SODOCCHGI1.
DATA: TAB_LINES LIKE SY-TABIX.
Creation of the document to be sent
File Name
DOC_CHNG-OBJ_NAME = 'SENDFILE'.
Mail Subject
DOC_CHNG-OBJ_DESCR = 'Send External Mail'.
Mail Contents
OBJTXT = 'Minimum bid : $250000'.
APPEND OBJTXT.
OBJTXT = 'A representation of the pictures up for auction'.
APPEND OBJTXT.
OBJTXT = 'was included as attachment.'.
APPEND OBJTXT.
DESCRIBE TABLE OBJTXT LINES TAB_LINES.
READ TABLE OBJTXT INDEX TAB_LINES.
DOC_CHNG-DOC_SIZE = ( TAB_LINES - 1 ) * 255 + STRLEN( OBJTXT ).
Creation of the entry for the compressed document
CLEAR OBJPACK-TRANSF_BIN.
OBJPACK-HEAD_START = 1.
OBJPACK-HEAD_NUM = 0.
OBJPACK-BODY_START = 1.
OBJPACK-BODY_NUM = TAB_LINES.
OBJPACK-DOC_TYPE = 'RAW'.
APPEND OBJPACK.
Creation of the document attachment
(Assume that the data in OBJBIN is in BMP format)
*OBJBIN = ' \O/ '. APPEND OBJBIN.
*OBJBIN = ' | '. APPEND OBJBIN.
*OBJBIN = ' / \ '. APPEND OBJBIN.
*DESCRIBE TABLE OBJBIN LINES TAB_LINES.
*OBJHEAD = 'PICTURE.BMP'.
*APPEND OBJHEAD.
Creation of the entry for the compressed attachment
*OBJPACK-TRANSF_BIN = 'X'.
*OBJPACK-HEAD_START = 1.
*OBJPACK-HEAD_NUM = 1.
*OBJPACK-BODY_START = 1.
*OBJPACK-BODY_NUM = TAB_LINES.
*OBJPACK-DOC_TYPE = 'BMP'.
*OBJPACK-OBJ_NAME = 'PICTURE'.
*OBJPACK-OBJ_DESCR = 'Representation of object 138'.
*OBJPACK-DOC_SIZE = TAB_LINES * 255.
*APPEND OBJPACK.
Completing the recipient list
RECLIST-RECEIVER = '[email protected]'.
RECLIST-REC_TYPE = 'U'.
APPEND RECLIST.
*RECLIST-RECEIVER = 'SAPUSERNAME'.
*RECLIST-REC_TYPE = 'P'.
*APPEND RECLIST.
Sending the document
CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
EXPORTING
DOCUMENT_DATA = DOC_CHNG
PUT_IN_OUTBOX = 'X'
TABLES
PACKING_LIST = OBJPACK
OBJECT_HEADER = OBJHEAD
CONTENTS_BIN = OBJBIN
CONTENTS_TXT = OBJTXT
RECEIVERS = RECLIST
EXCEPTIONS
TOO_MANY_RECEIVERS = 1
DOCUMENT_NOT_SENT = 2
OPERATION_NO_AUTHORIZATION = 4
OTHERS = 99.
CASE SY-SUBRC.
WHEN 0.
WRITE: / 'Result of the send process:'.
LOOP AT RECLIST.
WRITE: / RECLIST-RECEIVER(48), ':'.
IF RECLIST-RETRN_CODE = 0.
WRITE 'The document was sent'.
ELSE.
WRITE 'The document could not be sent'.
ENDIF.
ENDLOOP.
WHEN 1.
WRITE: / 'No authorization for sending to the specified number',
'of recipients'.
WHEN 2.
WRITE: / 'Document could not be sent to any recipient'.
WHEN 4.
WRITE: / 'No send authorization'.
WHEN OTHERS.
WRITE: / 'Error occurred while sending'.
ENDCASE.
Message was edited by: Manoj Gupta -
Program To Send Email with attachemnts in PDF / Excel with Subject
Hi All,
I have been given an Object to Develop a report to Send Email with attachemnts in PDF / Excel with Subject.
Please provide the way to go about.
Regards,
MohsinREPORT ZREPORT_TO_EMAIL NO STANDARD PAGE HEADING LINE-SIZE 200.
DATA : BEGIN OF ITAB OCCURS 0,
PERNR LIKE PA0001-PERNR,
ENAME LIKE PA0001-ENAME,
END OF ITAB.
DATA: message_content LIKE soli OCCURS 10 WITH HEADER LINE,
receiver_list LIKE soos1 OCCURS 5 WITH HEADER LINE,
packing_list LIKE soxpl OCCURS 2 WITH HEADER LINE,
listobject LIKE abaplist OCCURS 10,
compressed_attachment LIKE soli OCCURS 100 WITH HEADER LINE,
w_object_hd_change LIKE sood1,
compressed_size LIKE sy-index.
START-OF-SELECTION.
SELECT PERNR ENAME
INTO CORRESPONDING FIELDS OF TABLE ITAB
FROM PA0001
WHERE PERNR < 50.
LOOP AT ITAB.
WRITE :/02 SY-VLINE , ITAB-PERNR, 15 SY-VLINE , ITAB-ENAME, 50
SY-VLINE.
ENDLOOP.
Receivers
receiver_list-recextnam = 'type your email address here'. "-->
EMAIL ADDRESS
RECEIVER_list-RECESC = 'E'. "<-
RECEIVER_list-SNDART = 'INT'."<-
RECEIVER_list-SNDPRI = '1'."<-
APPEND receiver_list.
General data
w_object_hd_change-objla = sy-langu.
w_object_hd_change-objnam = 'Object name'.
w_object_hd_change-objsns = 'P'.
Mail subject
w_object_hd_change-objdes = 'Message subject'.
Mail body
APPEND 'Message content' TO message_content.
Attachment
CALL FUNCTION 'SAVE_LIST'
EXPORTING
list_index = '0'
TABLES
listobject = listobject.
CALL FUNCTION 'TABLE_COMPRESS'
IMPORTING
compressed_size = compressed_size
TABLES
in = listobject
out = compressed_attachment.
DESCRIBE TABLE compressed_attachment.
CLEAR packing_list.
packing_list-transf_bin = 'X'.
packing_list-head_start = 0.
packing_list-head_num = 0.
packing_list-body_start = 1.
packing_list-body_num = sy-tfill.
packing_list-objtp = 'ALI'.
packing_list-objnam = 'Object name'.
packing_list-objdes = 'Attachment description'.
packing_list-objlen = compressed_size.
APPEND packing_list.
CALL FUNCTION 'SO_OBJECT_SEND'
EXPORTING
object_hd_change = w_object_hd_change
object_type = 'RAW'
owner = sy-uname
TABLES
objcont = message_content
receivers = receiver_list
packing_list = packing_list
att_cont = compressed_attachment.
Hope it helps,
regards,
kushagra -
Email attachment problem - unicode?
Hi All,
I've copied some of the examples from SDN on how to send an attachment via email from ABAP.
The problem is that the text file attachments are incorrect. Each character is separated by another character. If I create a text attachment that reads "Hello" in the ABAP, the resulting text attachment is "H E L L O ".
The SAP system is unicode. I have tried both SO_NEW_DOCUMENT_ATT_SEND_API1 and SO_DOCUMENT_ATT_SEND_API1. Both have the same effect.
Does anyone have any idea how to ensure the email attachments retain the same format?
Cheers
RichardHi Richard,
Please refer to the below mentioned code and compare the Function modules used in your program and the below one.
Program: ZRAT Creation Date: 12.04.2007 *
Program Title : Retirement Age Trigger *
Program Author: Puneet Jhari *
Program Type : Executable *
Object ID : *
Technical Specification Version: *
Technical Specification Author: *
Code Quality Reviewer : *
Transport No. : SRDK906499 *
Program Description: *
Inputs *
Tables: *
Parameters *
External files: *
Outputs *
Reports: *
Tables: *
Databases: *
Screens: *
Parameters *
External files: *
Other objects: *
Return codes set by ABAP: *
Modification Informaion *
Program Version: *
Date : DD-MMM-YYYY *
Author : *
Description : *
Transport No.: *
REPORT zrat NO STANDARD PAGE HEADING.
*DATA DECLARATION
DATA : BEGIN OF wa_ccode,
bukrs TYPE t001-bukrs,
END OF wa_ccode.
DATA : itab_ccode LIKE TABLE OF wa_ccode.
DATA : BEGIN OF wa_emp,
pernr TYPE pa0001-pernr,
sachp TYPE pa0001-sachp,
sname TYPE pa0001-sname,
END OF wa_emp.
DATA : itab_emp LIKE TABLE OF wa_emp.
DATA : BEGIN OF wa_bdate,
nachn LIKE pa0002-nachn,
vorna LIKE pa0002-vorna,
pernr TYPE pa0002-pernr,
gbdat TYPE pa0002-gbdat,
END OF wa_bdate.
DATA : itab_bdate LIKE TABLE OF wa_bdate.
DATA : new_date LIKE sy-datum.
DATA : diff TYPE i.
DATA : years LIKE p0347-scryy,
months LIKE p0347-scrmm,
days LIKE p0347-scrdd.
DATA : sup_code LIKE pa0001-sachp,
itab_usrid LIKE t526-usrid,
sup_pernr LIKE pa0105-pernr.
DATA : BEGIN OF wa_email,
usrid_long LIKE pa0105-usrid_long,
END OF wa_email.
DATA : sup_email LIKE TABLE OF wa_email.
DATA : gwa_document_data LIKE sodocchgi1,
gc_name TYPE so_obj_nam VALUE 'RETIREMENT',
gc_senst TYPE so_obj_sns VALUE 'P',
gc_size TYPE so_doc_siz VALUE '510',
gi_obj_cnt LIKE TABLE OF solisti1 WITH HEADER LINE,
gi_recievers LIKE somlreci1 OCCURS 0 WITH HEADER LINE,
gwa_obj_cnt LIKE LINE OF gi_obj_cnt.
DATA : smtp_addr LIKE adr6-smtp_addr.
DATA : wa_date LIKE sy-datum,
entries LIKE sy-tabix,
name(15),
line1(18) TYPE c,
line2(20) TYPE c,
line3(20) TYPE c,
line4(23) TYPE c,
line5(10) TYPE c,
line6(45) type c,
date(2) TYPE c,
month(2) TYPE c,
year(4) TYPE c.
*START OF SELECTION
SELECT bukrs
FROM t001
INTO TABLE itab_ccode
WHERE land1 EQ 'GB'.
SORT itab_ccode.
DELETE ADJACENT DUPLICATES FROM itab_ccode.
SELECT pernr sachp sname
FROM pa0001
INTO TABLE itab_emp
FOR ALL ENTRIES IN itab_ccode
WHERE bukrs EQ itab_ccode-bukrs AND begda LE sy-datum AND
endda GE sy-datum and persg eq '1'.
SELECT nachn vorna pernr gbdat
FROM pa0002
INTO TABLE itab_bdate
FOR ALL ENTRIES IN itab_emp
WHERE pernr EQ itab_emp-pernr.
*TO CHECK EMPLOYEES WHOSE AGE IS NEAR 75 YEARS.
LOOP AT itab_bdate INTO wa_bdate.
new_date = wa_bdate-gbdat.
*TO CALCULATE THE AGE TILL DATE
CALL FUNCTION 'HR_HK_DIFF_BT_2_DATES'
EXPORTING
date1 = sy-datum
date2 = new_date
output_format = '05'
IMPORTING
years = years
months = months
days = days
IF sy-subrc <> 0.
ENDIF.
IF years EQ 64 AND months EQ 4.
IF days GE 23 AND days LE 31.
*FETCH THE DATA IF THE AGE IS NEARING 75 YEARS
SELECT SINGLE sachp FROM pa0001 INTO sup_code WHERE pernr EQ
wa_bdate-pernr AND begda LE sy-datum AND endda GE sy-datum.
SELECT SINGLE usrid FROM t526 INTO itab_usrid WHERE sachx EQ
sup_code.
SELECT SINGLE pernr FROM pa0105 INTO sup_pernr WHERE usrid EQ
itab_usrid AND subty EQ '0001'.
clear sup_email[].
SELECT usrid_long FROM pa0105 INTO TABLE sup_email WHERE pernr EQ
sup_pernr AND subty EQ '0010'.
*EMAIL ADDRESS OF THE SUPERVISOR TO BE NOTIFIED
CLEAR gi_obj_cnt.
CLEAR gi_recievers.
CLEAR gwa_document_data.
Loop at sup_email into wa_email.
write sy-uline+0(5).
write sy-uline+10(5).
write sy-uline+20(5).
write sy-uline+30(5).
write sy-uline+40(5).
write sy-uline+50(5).
write sy-uline+60(5).
write sy-uline+70(5).
smtp_addr = wa_email-usrid_long.
gi_recievers-receiver = smtp_addr.
gi_recievers-rec_type = 'U'.
gi_recievers-com_type = 'INT'.
APPEND gi_recievers.
Endloop.
smtp_addr = '[email protected]'.
gi_recievers-receiver = smtp_addr.
gi_recievers-rec_type = 'U'.
gi_recievers-com_type = 'INT'.
APPEND gi_recievers.
gwa_document_data-obj_name = gc_name.
gwa_document_data-obj_descr = 'RETIRE'.
gwa_document_data-sensitivty = gc_senst.
gwa_document_data-obj_langu = sy-langu.
*CONTENT OF THE EMAIL TO BE SENT
line1 = 'Please note that '.
line2 = wa_bdate-vorna.
line3 = wa_bdate-nachn.
line4 = ' will be 65 years on '.
line50(4) = wa_bdate-gbdat4(4).
date = line5+2(2).
month = line5+0(2).
year = wa_bdate-gbdat+0(4) + 65.
CONCATENATE date month year INTO line5 SEPARATED BY '.'.
line6 = '.Please complete the Retirement Procedure.'.
CONCATENATE line1 line2 line3 line4 line5 line6 INTO gwa_obj_cnt
SEPARATED BY space.
APPEND gwa_obj_cnt TO gi_obj_cnt.
CLEAR gwa_obj_cnt.
DESCRIBE TABLE gi_obj_cnt LINES entries.
READ TABLE gi_obj_cnt INDEX entries.
gwa_document_data-doc_size = ( entries - 1 ) * 255 + STRLEN( gi_obj_cnt
*FUNCTION MODULE TO SEND THE EMAIL TO THE CONCERNED PERSONS
CALL FUNCTION 'SO_NEW_DOCUMENT_SEND_API1'
EXPORTING
document_data = gwa_document_data
document_type = 'RAW'
commit_work = 'X'
TABLES
object_content = gi_obj_cnt
receivers = gi_recievers
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
*MESSAGE TO BE DISPLAYED AFTER THE EXECUTION
endif.
CASE sy-subrc.
WHEN 0.
LOOP AT gi_recievers.
IF gi_recievers-receiver = space.
name = gi_recievers-rec_id.
ELSE.
name = gi_recievers-receiver.
ENDIF.
IF gi_recievers-retrn_code = 0.
WRITE: / name, ': succesfully sent'.
ELSE.
WRITE: / name, ': error occured'.
ENDIF.
ENDLOOP.
WHEN 1.
WRITE: / 'Too many receivers specified !'.
WHEN 2.
WRITE: / 'No receiver got the document !'.
WHEN 4.
WRITE: / 'Missing send authority !'.
WHEN OTHERS.
WRITE: / 'Unexpected error occurred !'.
ENDCASE.
ENDIF.
ENDIF.
ENDLOOP.
In case you have any further clarifications,do let me know.
Regards,
Puneet Jhari. -
Is there a Function module to send email ?
Hi all,
is there a FM that can be used to send E mails?
i found so_document_send_api on the SDN, but it doesnt exist.
any pointers?
Thanks,
SonalHi Sonal,
http://www.sap-img.com/fu016.htm
SO_DOCUMENT_SEND_API1
SO_NEW_DOCUMENT_ATT_SEND_API1
How to send a report to an external mail-id?
REPORT ZREPORT_TO_EMAIL NO STANDARD PAGE HEADING LINE-SIZE 200.
DATA : BEGIN OF ITAB OCCURS 0,
PERNR LIKE PA0001-PERNR,
ENAME LIKE PA0001-ENAME,
END OF ITAB.
DATA: message_content LIKE soli OCCURS 10 WITH HEADER LINE,
receiver_list LIKE soos1 OCCURS 5 WITH HEADER LINE,
packing_list LIKE soxpl OCCURS 2 WITH HEADER LINE,
listobject LIKE abaplist OCCURS 10,
compressed_attachment LIKE soli OCCURS 100 WITH HEADER LINE,
w_object_hd_change LIKE sood1,
compressed_size LIKE sy-index.
START-OF-SELECTION.
SELECT PERNR ENAME
INTO CORRESPONDING FIELDS OF TABLE ITAB
FROM PA0001
WHERE PERNR < 50.
LOOP AT ITAB.
WRITE :/02 SY-VLINE , ITAB-PERNR, 15 SY-VLINE , ITAB-ENAME, 50
SY-VLINE.
ENDLOOP.
Receivers
receiver_list-recextnam = '[email protected]'. "-->
EMAIL ADDRESS
RECEIVER_list-RECESC = 'E'. "<-
RECEIVER_list-SNDART = 'INT'."<-
RECEIVER_list-SNDPRI = '1'."<-
APPEND receiver_list.
General data
w_object_hd_change-objla = sy-langu.
w_object_hd_change-objnam = 'Object name'.
w_object_hd_change-objsns = 'P'.
Mail subject
w_object_hd_change-objdes = 'Message subject'.
Mail body
APPEND 'Message content' TO message_content.
Attachment
CALL FUNCTION 'SAVE_LIST'
EXPORTING
list_index = '0'
TABLES
listobject = listobject.
CALL FUNCTION 'TABLE_COMPRESS'
IMPORTING
compressed_size = compressed_size
TABLES
in = listobject
out = compressed_attachment.
DESCRIBE TABLE compressed_attachment.
CLEAR packing_list.
packing_list-transf_bin = 'X'.
packing_list-head_start = 0.
packing_list-head_num = 0.
packing_list-body_start = 1.
packing_list-body_num = sy-tfill.
packing_list-objtp = 'ALI'.
packing_list-objnam = 'Object name'.
packing_list-objdes = 'Attachment description'.
packing_list-objlen = compressed_size.
APPEND packing_list.
CALL FUNCTION 'SO_OBJECT_SEND'
EXPORTING
object_hd_change = w_object_hd_change
object_type = 'RAW'
owner = sy-uname
TABLES
objcont = message_content
receivers = receiver_list
packing_list = packing_list
att_cont = compressed_attachment.
http://www.sap-img.com/abap/sending-mail-with-attachment-report-in-background.htm
Here is the sample code:
z_send_email_fax_global
FUNCTION-POOL z_gfaian_mail_fax. "MESSAGE-ID ..
WORK TABLE AREAS
TABLES: tsp01.
INTERNAL TABLES
DATA: lt_rec_tab LIKE STANDARD TABLE OF soos1 WITH HEADER LINE,
lt_note_text LIKE STANDARD TABLE OF soli WITH HEADER LINE,
lt_attachments LIKE STANDARD TABLE OF sood5 WITH HEADER LINE.
DATA: lt_objcont LIKE STANDARD TABLE OF soli WITH HEADER LINE,
lt_objhead LIKE STANDARD TABLE OF soli WITH HEADER LINE.
DATA: pdf_format LIKE STANDARD TABLE OF tline WITH HEADER LINE.
TYPES: BEGIN OF y_files,
file(60) TYPE c,
END OF y_files.
DATA: lt_files TYPE STANDARD TABLE OF y_files WITH HEADER LINE.
DATA: l_objcont LIKE soli OCCURS 0 WITH HEADER LINE.
DATA: l_objhead LIKE soli OCCURS 0 WITH HEADER LINE.
STRUCTURES
DATA: folder_id LIKE soodk,
object_id LIKE soodk,
link_folder_id LIKE soodk,
g_document LIKE sood4,
g_header_data LIKE sood2,
g_folmem_data LIKE sofm2,
g_header_data LIKE sood2,
g_receive_data LIKE soos6,
g_ref_document LIKE sood4,
g_new_parent LIKE soodk,
l_folder_id LIKE sofdk,
v_email(50).
DATA: hd_dat like sood1.
VARIABLES
DATA: client LIKE tst01-dclient,
name LIKE tst01-dname,
objtype LIKE rststype-type,
type LIKE rststype-type.
DATA: numbytes TYPE i,
arc_idx LIKE toa_dara,
pdfspoolid LIKE tsp01-rqident,
jobname LIKE tbtcjob-jobname,
jobcount LIKE tbtcjob-jobcount,
is_otf.
DATA: outbox_flag LIKE sonv-flag VALUE 'X',
store_flag LIKE sonv-flag,
delete_flag LIKE sonv-flag,
owner LIKE soud-usrnam,
on LIKE sonv-flag VALUE 'X',
sent_to_all LIKE sonv-flag,
g_authority LIKE sofa-usracc,
w_objdes LIKE sood4-objdes.
DATA: c_file LIKE rlgrap-filename,
n_spool(6) TYPE n.
DATA: cancel.
DATA: desired_type LIKE sood-objtp,
real_type LIKE sood-objtp,
attach_type LIKE sood-objtp,
otf LIKE sood-objtp VALUE 'OTF', " SAPscript Ausgabeformat
ali LIKE sood-objtp VALUE 'ALI'. " ABAP lists
CONSTANTS
CONSTANTS: ou_fol LIKE sofh-folrg VALUE 'O',
c_objtp LIKE g_document-objtp VALUE 'RAW',
c_file_ext LIKE g_document-file_ext VALUE 'TXT'.
=================================================================================
z_send_email_fax2
FUNCTION z_faian_mail_fax2.
""Interface local:
*" IMPORTING
*" REFERENCE(SRC_SPOOLID) LIKE TSP01-RQIDENT
*" REFERENCE(FAX_MAIL_NUMBER) TYPE SO_NAME
*" REFERENCE(HEADER_MAIL) TYPE SO_OBJ_DES
*" REFERENCE(OBJECT_TYPE) TYPE SO_ESCAPE
*" TABLES
*" LT_BODY_EMAIL STRUCTURE SOLI
*" EXCEPTIONS
*" ERR_NO_ABAP_SPOOLJOB
Fist part: Verify if the spool really exists
SELECT SINGLE * FROM tsp01 WHERE rqident = src_spoolid.
IF sy-subrc NE 0.
RAISE err_no_abap_spooljob. "doesn't exist
ELSE.
client = tsp01-rqclient.
name = tsp01-rqo1name.
CALL FUNCTION 'RSTS_GET_ATTRIBUTES'
EXPORTING
authority = 'SP01'
client = client
name = name
part = 1
IMPORTING
type = type
objtype = objtype
EXCEPTIONS
fb_error = 1
fb_rsts_other = 2
no_object = 3
no_permission = 4
OTHERS = 5.
IF objtype(3) = 'OTF'.
desired_type = otf.
ELSE.
desired_type = ali.
ENDIF.
CALL FUNCTION 'RSPO_RETURN_SPOOLJOB'
EXPORTING
rqident = src_spoolid
desired_type = desired_type
IMPORTING
real_type = real_type
TABLES
buffer = l_objcont
EXCEPTIONS
no_such_job = 14
type_no_match = 94
job_contains_no_data = 54
no_permission = 21
can_not_access = 21
read_error = 54.
IF sy-subrc EQ 0.
attach_type = real_type.
ENDIF.
CALL FUNCTION 'SO_FOLDER_ROOT_ID_GET'
EXPORTING
owner = sy-uname
region = ou_fol
IMPORTING
folder_id = l_folder_id
EXCEPTIONS
OTHERS = 5.
fill out informations about the header of the email
CLEAR: g_document.
g_document-foltp = l_folder_id-foltp.
g_document-folyr = l_folder_id-folyr.
g_document-folno = l_folder_id-folno.
g_document-objtp = c_objtp.
g_document-objdes = header_mail.
g_document-file_ext = c_file_ext.
g_header_data-objdes = header_mail.
CALL FUNCTION 'SO_DOCUMENT_REPOSITORY_MANAGER'
EXPORTING
method = 'SAVE'
office_user = sy-uname
IMPORTING
authority = g_authority
TABLES
objcont = lt_body_email
attachments = lt_attachments
CHANGING
document = g_document
header_data = g_header_data
EXCEPTIONS
OTHERS = 1.
folder_id-objtp = l_folder_id-foltp.
folder_id-objyr = l_folder_id-folyr.
folder_id-objno = l_folder_id-folno.
object_id-objtp = c_objtp.
object_id-objyr = g_document-objyr.
object_id-objno = g_document-objno.
link_folder_id-objtp = l_folder_id-foltp.
link_folder_id-objyr = l_folder_id-folyr.
link_folder_id-objno = l_folder_id-folno.
REFRESH lt_rec_tab.
CLEAR lt_rec_tab.
lt_rec_tab-sel = 'X'.
lt_rec_tab-recesc = object_type. "This field for FAX/MAIL
lt_rec_tab-recnam = 'U-'.
lt_rec_tab-deliver = 'X'.
lt_rec_tab-not_deli = 'X'.
lt_rec_tab-read = 'X'.
lt_rec_tab-mailstatus = 'E'.
lt_rec_tab-adr_name = fax_mail_number.
lt_rec_tab-sortfield = fax_mail_number.
lt_rec_tab-recextnam = fax_mail_number.
lt_rec_tab-sortclass = '5'.
APPEND lt_rec_tab.
lt_rec_tab-recextnam = fax_mail_number.
lt_rec_tab-recesc = object_type.
lt_rec_tab-sndart = 'INT'.
lt_rec_tab-sndpri = 1.
APPEND lt_rec_tab.
lt_files-file = c_file.
APPEND lt_files.
begin of insertion by faianf01
hd_dat-objdes = header_mail.
CALL FUNCTION 'SO_ATTACHMENT_INSERT'
EXPORTING
object_id = object_id
attach_type = attach_type
object_hd_change = hd_dat
owner = sy-uname
TABLES
objcont = l_objcont
objhead = l_objhead
EXCEPTIONS
active_user_not_exist = 35
communication_failure = 71
object_type_not_exist = 17
operation_no_authorization = 21
owner_not_exist = 22
parameter_error = 23
substitute_not_active = 31
substitute_not_defined = 32
system_failure = 72
x_error = 1000.
IF sy-subrc > 0.
ENDIF.
end of insertion by faianf01
send email from SAPOFFICE
CALL FUNCTION 'SO_OBJECT_SEND'
EXPORTING
folder_id = folder_id
object_id = object_id
outbox_flag = outbox_flag
link_folder_id = link_folder_id
owner = sy-uname
check_send_authority = 'X'
TABLES
receivers = lt_rec_tab
note_text = lt_note_text
EXCEPTIONS
active_user_not_exist = 35
communication_failure = 71
component_not_available = 1
folder_no_authorization = 5
folder_not_exist = 6
forwarder_not_exist = 8
object_no_authorization = 13
object_not_exist = 14
object_not_sent = 15
operation_no_authorization = 21
owner_not_exist = 22
parameter_error = 23
substitute_not_active = 31
substitute_not_defined = 32
system_failure = 72
too_much_receivers = 73
user_not_exist = 35.
ENDIF.
ENDFUNCTION.
=================================================================================
z_send_email_fax
FUNCTION ZCBFS_SEND_MAIL.
""Interface local:
*" IMPORTING
*" REFERENCE(SRC_SPOOLID) LIKE TSP01-RQIDENT
*" REFERENCE(HEADER_MAIL) TYPE SO_OBJ_DES
*" TABLES
*" LIST_FAX_MAIL_NUMBER STRUCTURE SOLI
*" EXCEPTIONS
*" ERR_NO_ABAP_SPOOLJOB
DATA: vg_achou(1) TYPE n.
Fist part: Verify if the spool really exists
vg_achou = 1.
DO 60 TIMES.
SELECT SINGLE * FROM tsp01 WHERE rqident = src_spoolid.
IF sy-subrc IS INITIAL.
CLEAR vg_achou.
EXIT.
ELSE.
WAIT UP TO 1 SECONDS.
ENDIF.
ENDDO.
IF vg_achou = 1.
RAISE err_no_abap_spooljob. "doesn't exist
ENDIF.
client = tsp01-rqclient.
name = tsp01-rqo1name.
CALL FUNCTION 'RSTS_GET_ATTRIBUTES'
EXPORTING
authority = 'SP01'
client = client
name = name
part = 1
IMPORTING
type = type
objtype = objtype
EXCEPTIONS
fb_error = 1
fb_rsts_other = 2
no_object = 3
no_permission = 4
OTHERS = 5.
IF objtype(3) = 'OTF'.
desired_type = otf.
ELSE.
desired_type = ali.
ENDIF.
CALL FUNCTION 'RSPO_RETURN_SPOOLJOB'
EXPORTING
rqident = src_spoolid
desired_type = desired_type
IMPORTING
real_type = real_type
TABLES
buffer = l_objcont
EXCEPTIONS
no_such_job = 14
type_no_match = 94
job_contains_no_data = 54
no_permission = 21
can_not_access = 21
read_error = 54.
IF sy-subrc EQ 0.
attach_type = real_type.
ENDIF.
CALL FUNCTION 'SO_FOLDER_ROOT_ID_GET'
EXPORTING
owner = sy-uname
region = ou_fol
IMPORTING
folder_id = l_folder_id
EXCEPTIONS
OTHERS = 5.
fill out informations about the header of the email
CLEAR: g_document.
g_document-foltp = l_folder_id-foltp.
g_document-folyr = l_folder_id-folyr.
g_document-folno = l_folder_id-folno.
g_document-objtp = c_objtp.
g_document-objdes = header_mail.
g_document-file_ext = c_file_ext.
g_header_data-objdes = header_mail.
CALL FUNCTION 'SO_DOCUMENT_REPOSITORY_MANAGER'
EXPORTING
method = 'SAVE'
office_user = sy-uname
IMPORTING
authority = g_authority
TABLES
attachments = lt_attachments
CHANGING
document = g_document
header_data = g_header_data
EXCEPTIONS
OTHERS = 1.
folder_id-objtp = l_folder_id-foltp.
folder_id-objyr = l_folder_id-folyr.
folder_id-objno = l_folder_id-folno.
object_id-objtp = c_objtp.
object_id-objyr = g_document-objyr.
object_id-objno = g_document-objno.
link_folder_id-objtp = l_folder_id-foltp.
link_folder_id-objyr = l_folder_id-folyr.
link_folder_id-objno = l_folder_id-folno.
REFRESH lt_rec_tab.
LOOP AT LIST_FAX_MAIL_NUMBER.
lt_rec_tab-recextnam = LIST_FAX_MAIL_NUMBER-LINE.
lt_rec_tab-recesc = 'U'.
lt_rec_tab-sndart = 'INT'.
lt_rec_tab-sndpri = 1.
APPEND lt_rec_tab.
ENDLOOP.
lt_files-file = c_file.
APPEND lt_files.
hd_dat-objdes = header_mail.
CALL FUNCTION 'SO_ATTACHMENT_INSERT'
EXPORTING
object_id = object_id
attach_type = attach_type
object_hd_change = hd_dat
owner = sy-uname
TABLES
objcont = l_objcont
objhead = l_objhead
EXCEPTIONS
active_user_not_exist = 35
communication_failure = 71
object_type_not_exist = 17
operation_no_authorization = 21
owner_not_exist = 22
parameter_error = 23
substitute_not_active = 31
substitute_not_defined = 32
system_failure = 72
x_error = 1000.
IF sy-subrc > 0.
ENDIF.
send email from SAPOFFICE
CALL FUNCTION 'SO_OBJECT_SEND'
EXPORTING
folder_id = folder_id
object_id = object_id
outbox_flag = outbox_flag
link_folder_id = link_folder_id
owner = sy-uname
TABLES
receivers = lt_rec_tab
note_text = lt_note_text
EXCEPTIONS
active_user_not_exist = 35
communication_failure = 71
component_not_available = 1
folder_no_authorization = 5
folder_not_exist = 6
forwarder_not_exist = 8
object_no_authorization = 13
object_not_exist = 14
object_not_sent = 15
operation_no_authorization = 21
owner_not_exist = 22
parameter_error = 23
substitute_not_active = 31
substitute_not_defined = 32
system_failure = 72
too_much_receivers = 73
user_not_exist = 35.
ENDFUNCTION.
Regards,
Srilatha. -
Email sending after validation
Hi ,
I am working on a user exit.It is a BAdI.I have to validate the name of the person who signed the PO invoice.Once approved the person has to receive an email with a standard subject text and email text.I dont know how I should proceed for email sending.Can you please help me out on this.
Points will be rewarded .Thanks in advance.
Thanks,
Renihi,
<b><i>how to send email.</i></b>
chk this sample code.
Try this sample code :-
REPORT ZREPORT_TO_EMAIL NO STANDARD PAGE HEADING LINE-SIZE 200.
DATA : BEGIN OF ITAB OCCURS 0,
PERNR LIKE PA0001-PERNR,
ENAME LIKE PA0001-ENAME,
END OF ITAB.
DATA: message_content LIKE soli OCCURS 10 WITH HEADER LINE,
receiver_list LIKE soos1 OCCURS 5 WITH HEADER LINE,
packing_list LIKE soxpl OCCURS 2 WITH HEADER LINE,
listobject LIKE abaplist OCCURS 10,
compressed_attachment LIKE soli OCCURS 100 WITH HEADER LINE,
w_object_hd_change LIKE sood1,
compressed_size LIKE sy-index.
START-OF-SELECTION.
SELECT PERNR ENAME
INTO CORRESPONDING FIELDS OF TABLE ITAB
FROM PA0001
WHERE PERNR < 50.
LOOP AT ITAB.
WRITE :/02 SY-VLINE , ITAB-PERNR, 15 SY-VLINE , ITAB-ENAME, 50
SY-VLINE.
ENDLOOP.
* Receivers
receiver_list-recextnam = '[email protected]'. "-->
* EMAIL ADDRESS
RECEIVER_list-RECESC = 'E'. "<-
RECEIVER_list-SNDART = 'INT'."<-
RECEIVER_list-SNDPRI = '1'."<-
APPEND receiver_list.
* General data
w_object_hd_change-objla = sy-langu.
w_object_hd_change-objnam = 'Object name'.
w_object_hd_change-objsns = 'P'.
* Mail subject
w_object_hd_change-objdes = 'Message subject'.
* Mail body
APPEND 'Message content' TO message_content.
* Attachment
CALL FUNCTION 'SAVE_LIST'
EXPORTING
list_index = '0'
TABLES
listobject = listobject.
CALL FUNCTION 'TABLE_COMPRESS'
IMPORTING
compressed_size = compressed_size
TABLES
in = listobject
out = compressed_attachment.
DESCRIBE TABLE compressed_attachment.
CLEAR packing_list.
packing_list-transf_bin = 'X'.
packing_list-head_start = 0.
packing_list-head_num = 0.
packing_list-body_start = 1.
packing_list-body_num = sy-tfill.
packing_list-objtp = 'ALI'.
packing_list-objnam = 'Object name'.
packing_list-objdes = 'Attachment description'.
packing_list-objlen = compressed_size.
APPEND packing_list.
CALL FUNCTION 'SO_OBJECT_SEND'
EXPORTING
object_hd_change = w_object_hd_change
object_type = 'RAW'
owner = sy-uname
TABLES
objcont = message_content
receivers = receiver_list
packing_list = packing_list
att_cont = compressed_attachment.
rgds
anver
Maybe you are looking for
-
Hi All, Can anybody describe me the functonality of SBO Mailer. How to configure it and how it works? Is it possible to Schedule reports with SBO mailer at a particular time in a day?
-
How do I copy and paste only the text from a cell?
Hi - Every time I want to move text to a different cell, copy and paste copies all styles as well. How do I just copy and paste the text while leaving the style of the receiving cell in tact? Thanks. Chris
-
Itunes volume adjust doesn't take in ipod
i ripped an audio book on my imac because the optical drive on my powerbook stopped working. then i moved the audio book over to my powerbook and put it on my ipod. the volume was too soft so i adjusted it in itunes and resynched. there was really no
-
How to insert page break in smartforms?
Hi. I want to insert page break after printing 15 rows on each page.how to do it. please give me solution
-
How do I find an old version of a file on my Mac Air?
The version that I have saved is missing some info I need that was in the first version I created. I remember retrieving an old file once...it was almost like magic.