Convert pdf and send mail
after sending mail ,the attachment doesnt conatin any pdf data.
code is as follows.............
LOOP AT IT_PDF.
TRANSLATE IT_PDF USING ' ~'.
CONCATENATE GD_BUFFER IT_PDF
INTO GD_BUFFER.
ENDLOOP.
TRANSLATE GD_BUFFER USING '~ '.
DO.
I_OBJBIN = GD_BUFFER.
APPEND I_OBJBIN.
SHIFT GD_BUFFER LEFT BY 100 PLACES.
IF GD_BUFFER IS INITIAL.
EXIT.
ENDIF.
ENDDO.
LOOP AT IT_PDF.
TRANSLATE IT_PDF USING '~'.
ENDLOOP.
REFRESH:
I_RECLIST,
I_OBJTXT,
I_OBJBIN,
I_OBJPACK.
CLEAR I_OBJPACK-TRANSF_BIN.
I_OBJPACK-HEAD_START = 1.
I_OBJPACK-HEAD_NUM = 0.
I_OBJPACK-BODY_START = 1.
I_OBJPACK-BODY_NUM = V_LINES_TXT.
I_OBJPACK-DOC_TYPE = 'RAW'.
APPEND I_OBJPACK.
Attachment (pdf-Attachment)
I_OBJPACK-TRANSF_BIN = 'X'.
I_OBJPACK-HEAD_START = 1.
I_OBJPACK-HEAD_NUM = 0.
I_OBJPACK-BODY_START = 1.
DESCRIBE TABLE I_OBJBIN LINES V_LINES_BIN.
READ TABLE I_OBJBIN INDEX V_LINES_BIN.
I_OBJPACK-DOC_SIZE = V_LINES_BIN * 550 .
I_OBJPACK-BODY_NUM = V_LINES_BIN.
I_OBJPACK-DOC_TYPE = 'PDF'.
I_OBJPACK-OBJ_NAME = 'purchase order'.
I_OBJPACK-OBJ_DESCR = 'purchase order'.
APPEND I_OBJPACK.
clear WA_OBJHEAD.
CLEAR I_RECLIST.
I_RECLIST-RECEIVER = P_EMAIL.
I_RECLIST-EXPRESS = 'X'.
I_RECLIST-REC_TYPE = 'U'.
I_CC-COPY = I_CC.
APPEND I_RECLIST.
I_OBJTXT = 'Hi'.
APPEND I_OBJTXT.
I_OBJTXT = ' '.
APPEND I_OBJTXT.
I_OBJTXT = 'Please find the purchase order as an attachment'.
APPEND I_OBJTXT.
I_OBJTXT = 'from meda'.
APPEND I_OBJTXT.
I_OBJTXT = ' '.
APPEND I_OBJTXT.
I_OBJTXT = 'Thanks'.
APPEND I_OBJTXT.
I_OBJTXT = 'purcahse order'.
APPEND I_OBJTXT.
DESCRIBE TABLE I_OBJTXT LINES V_LINES_TXT.
READ TABLE I_OBJTXT INDEX V_LINES_TXT.
WA_DOC_CHNG-OBJ_NAME = 'purcahse order'.
WA_DOC_CHNG-EXPIRY_DAT = SY-DATUM + 10.
WA_DOC_CHNG-OBJ_DESCR = 'Mail from meda'.
WA_DOC_CHNG-SENSITIVTY = 'F'.
WA_DOC_CHNG-DOC_SIZE = V_LINES_TXT * 2255.
CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
EXPORTING
DOCUMENT_DATA = WA_DOC_CHNG
PUT_IN_OUTBOX = 'X'
COMMIT_WORK = 'X'
TABLES
PACKING_LIST = I_OBJPACK
OBJECT_HEADER = WA_OBJHEAD
CONTENTS_BIN = I_OBJBIN
CONTENTS_TXT = I_OBJTXT
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 EQ 0.
WRITE : / 'email sent over' .
ENDIF.
ENDFORM. " EMAIL_DISPLAY
hi check this....
*& Report ZSPOOLTOPDF *
*& Converts spool request into PDF document and emails it to *
*& recipicant. *
*& Execution *
*& This program must be run as a background job in-order for the write *
*& commands to create a Spool request rather than be displayed on *
*& screen *
REPORT zspooltopdf.
PARAMETER: p_email1 LIKE somlreci1-receiver,
p_sender LIKE somlreci1-receiver ,
p_delspl AS CHECKBOX.
*DATA DECLARATION
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'.
*START-OF-SELECTION.
START-OF-SELECTION.
Write statement to represent report output. Spool request is created
if write statement is executed in background. This could also be an
ALV grid which would be converted to PDF without any extra effort
WRITE 'Hello World'.
new-page.
commit work.
new-page print off.
IF sy-batch EQ 'X'.
PERFORM get_job_details.
PERFORM obtain_spool_id.
Alternative way could be to submit another program and store spool
id into memory, will be stored in sy-spono.
*submit ZSPOOLTOPDF2
to sap-spool
spool parameters %_print
archive parameters %_print
without spool dynpro
and return.
Get spool id from program called above
IMPORT w_spool_nr FROM MEMORY ID 'SPOOLTOPDF'.
PERFORM convert_spool_to_pdf.
PERFORM process_email.
if p_delspl EQ 'X'.
PERFORM delete_spool.
endif.
IF sy-sysid = c_dev.
wait up to 5 seconds.
SUBMIT rsconn01 WITH mode = 'INT'
WITH output = 'X'
AND RETURN.
ENDIF.
ELSE.
SKIP.
WRITE:/ 'Program must be executed in background in-order for spool',
'request to be created.'.
ENDIF.
FORM obtain_spool_id *
FORM obtain_spool_id.
CHECK NOT ( gd_jobname IS INITIAL ).
CHECK NOT ( gd_jobcount IS INITIAL ).
SELECT * FROM tbtcp
INTO TABLE it_tbtcp
WHERE jobname = gd_jobname
AND jobcount = gd_jobcount
AND stepcount = gd_stepcount
AND listident <> '0000000000'
ORDER BY jobname
jobcount
stepcount.
READ TABLE it_tbtcp INTO wa_tbtcp INDEX 1.
IF sy-subrc = 0.
message s004(zdd) with gd_spool_nr.
gd_spool_nr = wa_tbtcp-listident.
MESSAGE s004(zdd) WITH gd_spool_nr.
ELSE.
MESSAGE s005(zdd).
ENDIF.
ENDFORM.
FORM get_job_details *
FORM get_job_details.
Get current job details
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.
ENDFORM.
FORM convert_spool_to_pdf *
FORM convert_spool_to_pdf.
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.
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.
ENDFORM.
FORM process_email *
FORM process_email.
DESCRIBE TABLE it_mess_att LINES gd_recsize.
CHECK gd_recsize > 0.
PERFORM send_email USING p_email1.
perform send_email using p_email2.
ENDFORM.
FORM send_email *
--> p_email *
FORM send_email USING p_email.
CHECK NOT ( p_email IS INITIAL ).
REFRESH it_mess_bod.
Default subject matter
gd_subject = 'Subject'.
gd_attachment_desc = 'Attachname'.
CONCATENATE 'attach_name' ' ' INTO gd_attachment_name.
it_mess_bod = 'Message Body text, line 1'.
APPEND it_mess_bod.
it_mess_bod = 'Message Body text, line 2...'.
APPEND it_mess_bod.
If no sender specified - default blank
IF p_sender EQ space.
gd_sender_type = space.
ELSE.
gd_sender_type = 'INT'.
ENDIF.
Send file by email as .xls speadsheet
PERFORM send_file_as_email_attachment
tables it_mess_bod
it_mess_att
using p_email
'Example .xls documnet attachment'
'PDF'
gd_attachment_name
gd_attachment_desc
p_sender
gd_sender_type
changing gd_error
gd_reciever.
ENDFORM.
FORM delete_spool *
FORM delete_spool.
DATA: ld_spool_nr TYPE tsp01_sp0r-rqid_char.
ld_spool_nr = gd_spool_nr.
CHECK p_delspl <> c_no.
CALL FUNCTION 'RSPO_R_RDELETE_SPOOLREQ'
EXPORTING
spoolid = ld_spool_nr.
ENDFORM.
*& Form SEND_FILE_AS_EMAIL_ATTACHMENT
Send email
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-receiver = ld_email.
t_receivers-rec_type = 'U'.
t_receivers-com_type = 'INT'.
t_receivers-notif_del = 'X'.
t_receivers-notif_ndel = 'X'.
APPEND t_receivers.
CALL FUNCTION 'SO_DOCUMENT_SEND_API1'
EXPORTING
document_data = w_doc_data
put_in_outbox = 'X'
sender_address = ld_sender_address
sender_address_type = ld_sender_address_type
commit_work = 'X'
IMPORTING
sent_to_all = w_sent_all
TABLES
packing_list = t_packing_list
contents_bin = t_attachment
contents_txt = it_message
receivers = t_receivers
EXCEPTIONS
too_many_receivers = 1
document_not_sent = 2
document_type_not_exist = 3
operation_no_authorization = 4
parameter_error = 5
x_error = 6
enqueue_error = 7
OTHERS = 8.
Populate zerror return code
ld_error = sy-subrc.
Populate zreceiver return code
LOOP AT t_receivers.
ld_receiver = t_receivers-retrn_code.
ENDLOOP.
ENDFORM.
regards,
venkat.
Similar Messages
-
Convertion of Smart form to pdf and sending mail to vendor for PO
Hello all,
I have modified a standard PO Smartform and running it through ME23N.
In this i have to convert it to a pdf file and then send it through mail to the vendor.
I have found out FMs'CONVERT_OTF'and
'SO_NEW_DOCUMENT_ATT_SEND_API1'
to convert it and send mail. But can u tell me how to go about using it.
As i am using a standard program do i have to copy this prog to zprog and then call the fm out there. I am not sure.
Thanks
SalilHi,
Here is the sample code.If you find this as useful,kindly reward points by clicking the star on the left of reply.
Internal Table declarations
DATA: i_otf TYPE itcoo OCCURS 0 WITH HEADER LINE,
i_tline TYPE TABLE OF tline WITH HEADER LINE,
i_receivers TYPE TABLE OF somlreci1 WITH HEADER LINE,
i_record LIKE solisti1 OCCURS 0 WITH HEADER LINE,
Objects to send mail.
i_objpack LIKE sopcklsti1 OCCURS 0 WITH HEADER LINE,
i_objtxt LIKE solisti1 OCCURS 0 WITH HEADER LINE,
i_objbin LIKE solisti1 OCCURS 0 WITH HEADER LINE,
i_reclist LIKE somlreci1 OCCURS 0 WITH HEADER LINE,
Work Area declarations
w_objhead TYPE soli_tab,
w_ctrlop TYPE ssfctrlop,
w_compop TYPE ssfcompop,
w_return TYPE ssfcrescl,
w_doc_chng typE sodocchgi1,
w_data TYPE sodocchgi1,
w_buffer TYPE string,"To convert from 132 to 255
Variables declarations
v_form_name TYPE rs38l_fnam,
v_len_in LIKE sood-objlen,
v_len_out LIKE sood-objlen,
v_len_outn TYPE i,
v_lines_txt TYPE i,
v_lines_bin TYPE i.
call function 'SSF_FUNCTION_MODULE_NAME'
exporting
formname = 'ZZZ_TEST2'
importing
fm_name = v_form_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.
ENDIF.
w_ctrlop-getotf = 'X'.
w_ctrlop-no_dialog = 'X'.
w_compop-tdnoprev = 'X'.
CALL FUNCTION v_form_name
EXPORTING
control_parameters = w_ctrlop
output_options = w_compop
user_settings = 'X'
IMPORTING
job_output_info = w_return
EXCEPTIONS
formatting_error = 1
internal_error = 2
send_error = 3
user_canceled = 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.
i_otf[] = w_return-otfdata[].
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.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
Convert PDF from 132 to 255.
LOOP AT i_tline.
Replacing space by ~
TRANSLATE i_tline USING ' ~'.
CONCATENATE w_buffer i_tline INTO w_buffer.
ENDLOOP.
Replacing ~ by space
TRANSLATE w_buffer USING '~ '.
DO.
i_record = w_buffer.
Appending 255 characters as a record
APPEND i_record.
SHIFT w_buffer LEFT BY 255 PLACES.
IF w_buffer IS INITIAL.
EXIT.
ENDIF.
ENDDO.
Refresh: i_reclist,
i_objtxt,
i_objbin,
i_objpack.
clear w_objhead.
Object with PDF.
i_objbin[] = i_record[].
DESCRIBE TABLE i_objbin LINES v_lines_bin.
Object with main text of the mail.
i_objtxt = 'Find attached the output of the smart form.'.
APPEND i_objtxt.
i_objtxt = 'Regards,'.
APPEND i_objtxt.
i_objtxt = 'J.Jayanthi'.
APPEND i_objtxt.
DESCRIBE TABLE i_objtxt LINES v_lines_txt.
Document information.
w_doc_chng-obj_name = 'Smartform'.
w_doc_chng-expiry_dat = sy-datum + 10.
w_doc_chng-obj_descr = 'Smart form output'.
w_doc_chng-sensitivty = 'F'. "Functional object
w_doc_chng-doc_size = v_lines_txt * 255.
Pack to main body as RAW.
Obj. to be transported not in binary form
CLEAR i_objpack-transf_bin.
Start line of object header in transport packet
i_objpack-head_start = 1.
Number of lines of an object header in object packet
i_objpack-head_num = 0.
Start line of object contents in an object packet
i_objpack-body_start = 1.
Number of lines of the object contents in an object packet
i_objpack-body_num = v_lines_txt.
Code for document class
i_objpack-doc_type = 'RAW'.
APPEND i_objpack.
Packing as PDF.
i_objpack-transf_bin = 'X'.
i_objpack-head_start = 1.
i_objpack-head_num = 1.
i_objpack-body_start = 1.
i_objpack-body_num = v_lines_bin.
i_objpack-doc_type = 'PDF'.
i_objpack-obj_name = 'Smartform'.
CONCATENATE 'Smartform_output' '.pdf'
INTO i_objpack-obj_descr.
i_objpack-doc_size = v_lines_bin * 255.
APPEND i_objpack.
Document information.
CLEAR i_reclist.
e-mail receivers.
i_reclist-receiver = '[email protected]'.
i_reclist-express = 'X'.
i_reclist-rec_type = 'U'. "Internet address
APPEND i_reclist.
Sending mail.
CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
EXPORTING
document_data = w_doc_chng
put_in_outbox = 'X'
TABLES
packing_list = i_objpack
object_header = w_objhead
contents_hex = i_objbin
contents_txt = i_objtxt
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 ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF. -
Convertion of Smart form to pdf and sending mail to vendor for Invoice
Hi All...
now I am getting the output form of Invoice by the T-code VF02
here Im using Zreport & Zform...
my requirment is to convert smartform output to PDF and send as an e-mail attachment on my Existing report
where I use the FM - CONVERT_OTF_2_PDF ..
here my code
REPORT yinvoice_is.
TABLES: vbrk,vbrp, vbak, vbap, vbkd .
DATA : it_vbap TYPE STANDARD TABLE OF vbap WITH HEADER LINE ,
it_vbrk LIKE STANDARD TABLE OF vbrk with header line,
it_vbkd TYPE STANDARD TABLE OF vbkd WITH HEADER LINE ,
it_vbrp TYPE STANDARD TABLE OF vbrp WITH HEADER LINE ,
it_vbrp1 TYPE STANDARD TABLE OF vbrp WITH HEADER LINE ,
it_vbfa TYPE STANDARD TABLE OF vbfa WITH HEADER LINE ,
it_adrc1 TYPE STANDARD TABLE OF adrc WITH HEADER LINE,
it_adrc2 TYPE STANDARD TABLE OF adrc WITH HEADER LINE.
DATA: sum TYPE vbrp-kzwi5.
DATA: v_vkbur TYPE vkbur,
v_adrnr1 TYPE adrnr,
v_adrnr2 TYPE adrnr,
v_vbelv TYPE vbelv,
v_delch TYPE vbeln,
v_bstkd TYPE bstkd,
v_kdmat TYPE kdmat,
v_kwert TYPE kwert.
DATA : fm_name TYPE rs38l_fnam.
PARAMETER p_inv_no LIKE vbrk-vbeln OBLIGATORY .
Selecting Data
SELECT VBELN
ERDAT
VKORG
KUNRG
STCEG
NETWR
MWSBK
KNUMV
KUNAG
REGIO
FROM vbrk
INTO CORRESPONDING FIELDS OF TABLE it_vbrk
WHERE vbeln = p_inv_no .
SELECT matnr
kzwi1
kzwi2
kzwi3
kzwi4
kzwi5
netwr
mwsbp
meins
fklmg
arktx
FROM vbrp
INTO CORRESPONDING FIELDS OF TABLE it_vbrp
WHERE vbeln = p_inv_no .
Selecting Sales Order No.
SELECT SINGLE vbelv
FROM vbfa
INTO v_vbelv
WHERE vbeln = p_inv_no
AND vbtyp_v = 'C'.
IF sy-subrc = 0.
Selecting Delivery Challan...
SELECT SINGLE vbeln
FROM vbfa
INTO v_delch
WHERE vbelv = v_vbelv
AND vbtyp_n = 'J'.
SELECT SINGLE bstkd
FROM vbkd
INTO v_bstkd
WHERE vbeln = v_vbelv .
SELECT matnr kdmat
FROM vbap
INTO CORRESPONDING FIELDS OF TABLE it_vbap
WHERE vbeln = v_vbelv.
ENDIF.
READ TABLE it_vbrk INDEX 1.
IF sy-subrc = 0.
SELECT SINGLE kwert
FROM konv
INTO v_kwert
WHERE knumv = iT_vbrk-knumv
AND kschl = 'HD00'.
ENDIF.
Selecting From Address
SELECT SINGLE vkbur
FROM vbak
INTO v_vkbur
WHERE vbeln = v_vbelv.
IF sy-subrc = 0.
SELECT SINGLE adrnr
FROM tvbur
INTO v_adrnr1
WHERE vkbur = v_vkbur.
IF sy-subrc = 0.
SELECT SINGLE *
FROM adrc
INTO CORRESPONDING FIELDS OF it_adrc1
WHERE addrnumber = v_adrnr1.
APPEND it_adrc1.
ENDIF.
ENDIF.
APPEND it_adrc.
Selecting TO Address
SELECT SINGLE adrnr
FROM vbpa
INTO v_adrnr2
WHERE vbeln = p_inv_no
AND parvw = 'RE'.
IF sy-subrc = 0.
SELECT SINGLE *
FROM adrc
INTO CORRESPONDING FIELDS OF it_adrc2
WHERE addrnumber = v_adrnr2.
APPEND it_adrc2.
ENDIF.
Calling Function Module
CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'
EXPORTING
formname = 'YINVOICE_IS'
VARIANT = ' '
DIRECT_CALL = ' '
IMPORTING
fm_name = 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.
ENDIF.
Calling Function Module
CALL FUNCTION fm_name
*'/1BCDWB/SF00000496'
EXPORTING
ARCHIVE_INDEX =
ARCHIVE_INDEX_TAB =
ARCHIVE_PARAMETERS =
CONTROL_PARAMETERS =
MAIL_APPL_OBJ =
MAIL_RECIPIENT =
MAIL_SENDER =
OUTPUT_OPTIONS =
USER_SETTINGS = 'X'
i_vbelv = v_vbelv
i_bstkd = v_bstkd
i_kdmat = v_kdmat
i_kwert = v_kwert
i_delch = v_delch
IMPORTING
DOCUMENT_OUTPUT_INFO =
JOB_OUTPUT_INFO =
JOB_OUTPUT_OPTIONS =
TABLES
it_vbrk = it_vbrk
it_vbrp = it_vbrp
it_vbap = it_vbap
it_adrc1 = it_adrc1
it_adrc2 = it_adrc2
EXCEPTIONS
FORMATTING_ERROR = 1
INTERNAL_ERROR = 2
SEND_ERROR = 3
USER_CANCELED = 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.
ENDFORM. "ENTRYhi,
use this code..
DATA: i_otf TYPE itcoo OCCURS 0 WITH HEADER LINE,
i_tline TYPE TABLE OF tline WITH HEADER LINE,
i_record LIKE solisti1 OCCURS 0 WITH HEADER LINE,
Objects to send mail.
i_objpack LIKE sopcklsti1 OCCURS 0 WITH HEADER LINE,
i_objtxt LIKE solisti1 OCCURS 0 WITH HEADER LINE,
i_objbin LIKE solisti1 OCCURS 0 WITH HEADER LINE,
i_reclist LIKE somlreci1 OCCURS 0 WITH HEADER LINE,
Variables declarations
v_len_in LIKE sood-objlen, "#EC NEEDED
v_lines_txt TYPE i,
v_lines_bin TYPE i,
Work Area declarations
w_ctrlop TYPE ssfctrlop,
w_return TYPE ssfcrescl,
w_compop TYPE ssfcompop,
wa_objhead TYPE soli_tab,
wa_doc_chng TYPE sodocchgi1,
wa_buffer TYPE string. "To convert from 132 to 255
Put a IF ELSE condition whether u want form output or E-mail output..
if it is a E-mail.. then call a small Sub-routine within your program..
FORM f_email .
w_ctrlop-getotf = 'X'.
w_ctrlop-no_dialog = 'X'.
w_compop-tdnoprev = 'X'.
CALL FUNCTION fnam
EXPORTING
control_parameters = w_ctrlop
output_options = w_compop
nast = nast
v_tcode = v_tcode
IMPORTING
job_output_info = w_return
TABLES
it_vbdkr = it_tvbdkr[]
it_vbdpr = tvbdpr[]
it_zglentitycode = it_zglentitycode[]
it_vttk = it_vttk[]
it_kna1 = it_kna1[]
it_t005 = it_t005[]
it_adrc = it_adrc[]
it_ekpo = it_ekpo[]
it_ekko = it_ekko[]
it_vbrp = it_vbrp[]
it_mara = it_mara[]
it_vbrk = it_vbrk[]
it_likp = it_likp[]
it_vttp = it_vttp[]
it_t001 = it_t001[]
it_zlogdely = it_zlogdely[]
it_prod = it_prod[]
it_lineitems = it_lineitems[]
it_tvzbt = it_tvzbt[]
it_t173t = it_t173t[]
it_t005t = it_t005t[]
it_zplant = it_zplant[]
it_stxbitmaps = it_stxbitmaps[]
it_prod_desc = it_prod_desc[].
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
i_otf[] = w_return-otfdata[].
*Converting the OFT format data to PDf format
CALL FUNCTION 'CONVERT_OTF'
EXPORTING
format = 'PDF'
max_linewidth = 132
IMPORTING
bin_filesize = v_len_in
TABLES
otf = i_otf
lines = i_tline.
LOOP AT i_tline.
TRANSLATE i_tline USING '~'.
CONCATENATE wa_buffer i_tline INTO wa_buffer.
ENDLOOP.
TRANSLATE wa_buffer USING '~'.
DO.
i_record = wa_buffer.
APPEND i_record.
SHIFT wa_buffer LEFT BY 255 PLACES.
IF wa_buffer IS INITIAL.
EXIT.
ENDIF.
ENDDO.
Attachment
REFRESH:
i_reclist,
i_objtxt,
i_objbin,
i_objpack.
CLEAR wa_objhead.
i_objbin[] = i_record[].
Create Message Body
Title and Description
i_objtxt = 'COMMERCIAL INVOICE'.
APPEND i_objtxt.
DESCRIBE TABLE i_objtxt LINES v_lines_txt.
READ TABLE i_objtxt INDEX v_lines_txt.
wa_doc_chng-obj_name = 'COMMERCIAL INVOICE'.
wa_doc_chng-expiry_dat = sy-datum + 10.
wa_doc_chng-obj_descr = 'COMMERCIAL INVOICE'.
wa_doc_chng-sensitivty = 'F'.
wa_doc_chng-doc_size = v_lines_txt * 255.
CLEAR i_objpack-transf_bin.
i_objpack-head_start = 1.
i_objpack-head_num = 0.
i_objpack-body_start = 1.
i_objpack-body_num = v_lines_txt.
i_objpack-doc_type = 'RAW'.
APPEND i_objpack.
Attachment
(pdf-Attachment)
i_objpack-transf_bin = 'X'.
i_objpack-head_start = 1.
i_objpack-head_num = 0.
i_objpack-body_start = 1.
DESCRIBE TABLE i_objbin LINES v_lines_bin.
READ TABLE i_objbin INDEX v_lines_bin.
i_objpack-doc_size = v_lines_bin * 255 .
i_objpack-body_num = v_lines_bin.
i_objpack-doc_type = 'PDF'.
i_objpack-obj_name = 'COMMERCIAL INVOICE'.
i_objpack-obj_descr = 'COMMERCIAL INVOICE'.
APPEND i_objpack.
IF it_adr6[] IS NOT INITIAL.
LOOP AT it_adr6 INTO wa_adr6.
CLEAR i_reclist.
i_reclist-receiver = wa_adr6-smtp_addr.
i_reclist-rec_type = 'U'.
i_reclist-com_type = 'INT'.
APPEND i_reclist.
ENDLOOP.
CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
EXPORTING
document_data = wa_doc_chng
put_in_outbox = 'X'
TABLES
packing_list = i_objpack
object_header = wa_objhead
contents_bin = i_objbin
contents_txt = i_objtxt
receivers = i_reclist.
ENDIF.
ENDFORM. " f_email
regards
vijay -
Convert sap script to pdf and send mail before close_form
hi experts,
I am converting a sap script to PDF and then sending that pdf to vendor mail ids.
I am getting the Data for the conversion of pdf From close_form.But it contains the data for all the vendors . But i have to Send the mail to the specific vendors.For ex if my script output has 5 sheets each with different vendors . I have to send 1 sheet as a pdf mail for that particular vendor. so,1 sheet each for 5 differrent vendors . But the data i get from close_form is the data for all the 5 vendors. How to split the data ?. can any one help me on this issue.
with thanks in advance,
syedHi,
Change your driver program so that it calls the script n no of times .. and every time send mail to particular vendor ..
Loop at vendors.
call the form ...
send mail ...
endloop ...
Regards,
Srini. -
Smartforms to pdf and send mail
PROGRAM :
*& Report ZDB_PDFMAIL
REPORT zdb_pdfmail.
Internal Table declarations
DATA: i_otf TYPE itcoo OCCURS 0 WITH HEADER LINE,
i_tline TYPE TABLE OF tline WITH HEADER LINE,
i_receivers TYPE TABLE OF somlreci1 WITH HEADER LINE,
i_record LIKE solisti1 OCCURS 0 WITH HEADER LINE,
Objects to send mail.
i_objpack LIKE sopcklsti1 OCCURS 0 WITH HEADER LINE,
i_objtxt LIKE solisti1 OCCURS 0 WITH HEADER LINE,
*i_objbin LIKE solisti1 OCCURS 0 WITH HEADER LINE,
i_reclist LIKE somlreci1 OCCURS 0 WITH HEADER LINE,
*i_record LIKE SOLIX OCCURS 0 WITH HEADER LINE,
i_objbin LIKE solisti1 OCCURS 0 WITH HEADER LINE,
Work Area declarations
w_objhead TYPE soli_tab,
w_ctrlop TYPE ssfctrlop,
w_compop TYPE ssfcompop,
w_return TYPE ssfcrescl,
w_doc_chng TYPE sodocchgi1,
w_data TYPE sodocchgi1,
w_buffer TYPE string,"To convert from 132 to 255
Variables declarations
v_form_name TYPE rs38l_fnam,
v_len_in LIKE sood-objlen,
v_len_out LIKE sood-objlen,
v_len_outn TYPE i,
v_lines_txt TYPE i,
v_lines_bin TYPE i.
DATA doc LIKE docs OCCURS 0 WITH HEADER LINE.
DATA bin_fsize TYPE i.
CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'
EXPORTING
formname = 'ZZZ_TEST2'
IMPORTING
fm_name = v_form_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.
ENDIF.
w_ctrlop-getotf = 'X'.
w_ctrlop-no_dialog = 'X'.
w_compop-tdnoprev = 'X'.
CALL FUNCTION v_form_name
EXPORTING
control_parameters = w_ctrlop
output_options = w_compop
user_settings = 'X'
IMPORTING
job_output_info = w_return
EXCEPTIONS
formatting_error = 1
internal_error = 2
send_error = 3
user_canceled = 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.
i_otf[] = w_return-otfdata[].
*CALL FUNCTION 'CONVERT_OTF_2_PDF'
EXPORTING
USE_OTF_MC_CMD = 'X'
ARCHIVE_INDEX =
IMPORTING
BIN_FILESIZE =
TABLES
otf =
doctab_archive =
lines =
EXCEPTIONS
ERR_CONV_NOT_POSSIBLE = 1
ERR_OTF_MC_NOENDMARKER = 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.
*ENDIF.
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.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
Convert PDF from 132 to 255.
LOOP AT i_tline.
Replacing space by ~
TRANSLATE i_tline USING ' ~'.
CONCATENATE w_buffer i_tline INTO w_buffer.
ENDLOOP.
Replacing ~ by space
TRANSLATE w_buffer USING '~ '.
DO.
i_record = w_buffer.
Appending 255 characters as a record
APPEND i_record.
SHIFT w_buffer LEFT BY 255 PLACES.
IF w_buffer IS INITIAL.
EXIT.
ENDIF.
ENDDO.
*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.
*IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
*ENDIF.
Convert PDF from 132 to 255.
*LOOP AT i_tline.
Replacing space by ~
TRANSLATE i_tline USING ' ~'.
CONCATENATE w_buffer i_tline INTO w_buffer.
*ENDLOOP.
Replacing ~ by space
*TRANSLATE w_buffer USING '~ '.
*DO.
i_record = w_buffer.
Appending 255 characters as a record
APPEND i_record.
SHIFT w_buffer LEFT BY 255 PLACES.
IF w_buffer IS INITIAL.
EXIT.
ENDIF.
*ENDDO.
REFRESH: i_reclist,
i_objtxt,
i_objbin,
i_objpack.
CLEAR w_objhead.
Object with PDF.
i_objbin[] = i_record[].
DESCRIBE TABLE i_objbin LINES v_lines_bin.
Object with main text of the mail.
i_objtxt = 'Find attached the output of the smart form.'.
APPEND i_objtxt.
i_objtxt = 'Regards,'.
APPEND i_objtxt.
i_objtxt = 'J.Jayanthi'.
APPEND i_objtxt.
DESCRIBE TABLE i_objtxt LINES v_lines_txt.
Document information.
w_doc_chng-obj_name = 'Smartform'.
w_doc_chng-expiry_dat = sy-datum + 10.
w_doc_chng-obj_descr = 'Smart form output'.
w_doc_chng-sensitivty = 'F'. "Functional object
w_doc_chng-doc_size = v_lines_txt * 255.
Pack to main body as RAW.
Obj. to be transported not in binary form
CLEAR i_objpack-transf_bin.
Start line of object header in transport packet
i_objpack-head_start = 1.
Number of lines of an object header in object packet
i_objpack-head_num = 0.
Start line of object contents in an object packet
i_objpack-body_start = 1.
Number of lines of the object contents in an object packet
i_objpack-body_num = v_lines_txt.
Code for document class
i_objpack-doc_type = 'RAW'.
APPEND i_objpack.
Packing as PDF.
i_objpack-transf_bin = 'X'.
i_objpack-head_start = 1.
i_objpack-head_num = 1.
i_objpack-body_start = 1.
i_objpack-body_num = v_lines_bin.
i_objpack-doc_type = 'PDF'.
i_objpack-obj_name = 'Smartform'.
CONCATENATE 'Smartform_output' '.pdf'
INTO i_objpack-obj_descr.
i_objpack-doc_size = v_lines_bin * 255.
APPEND i_objpack.
Document information.
CLEAR i_reclist.
e-mail receivers.
i_reclist-receiver = '[email protected]'.
i_reclist-express = 'X'.
i_reclist-rec_type = 'U'. "Internet address
APPEND i_reclist.
Sending mail.
CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
EXPORTING
document_data = w_doc_chng
put_in_outbox = 'X'
TABLES
packing_list = i_objpack
object_header = w_objhead
contents_hex = i_objbin
contents_txt = i_objtxt
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 ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
ERROR:
An exception occurred that is explained in detail below.
The exception, which is assigned to class 'CX_SY_DYN_CALL_ILLEGAL_TYPE', was
not caught and
therefore caused a runtime error.
The reason for the exception is:
In the function "SO_NEW_DOCUMENT_ATT_SEND_API1", the STRUCTURE parameter
"CONTENTS_HEX" is typed in such a way
that only actual parameters are allowed, which are compatible in Unicode
with respect to the fragment view. However, the specified actual
parameter "I_OBJBIN" has an incompatible fragment view.
PLS. TELL ME HOW TO UPDATE . 3KS
WAITING FOR YOUR HELPI HAVE CHECK WHAT YOU SAID.
CONCATENATE f_repid0(9) f_uname0(3) INTO lc_rq2name.
SELECT * FROM tsp01 WHERE rq2name = lc_rq2name
ORDER BY rqcretime DESCENDING.
IN THE TABLE OF TSP01,HAVE NO MY RECORD.
MAYBE MY PRINT REQUEST DOES NOT PUT INTO THE TABLE .
WHY ? HOW TO SETTING ?
OTHER ABAPER USER THE SAME PROGRAM ,HE CAN RUN SUCCESS.
BUT SOMEONE NOT .
Regards -
Convert ALV list to PDF and send mails to respective persons
Hi All,
I have a requirement ..we have written a program which will give o/p in alv list.Now I got a requirement to download that program to ALV format.Kindly help me how to approch for that we have some standard FM's for that like CONVERT_ABAPSPOOLJOB_2_PDF..what are the necessary inputs I have to give for that FM,
Second requirement is I have to send an E mail of that list to respective persons.help me on this also
Regards
KKHi,
Try with this program which will send the spool to email.
PARAMETER: p_email1 LIKE somlreci1-receiver
DEFAULT '[email protected]',
p_sender LIKE somlreci1-receiver
DEFAULT '[email protected]',
p_delspl AS CHECKBOX.
*DATA DECLARATION
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'.
*START-OF-SELECTION.
START-OF-SELECTION.
* Write statement to represent report output. Spool request is created
* if write statement is executed in background. This could also be an
* ALV grid which would be converted to PDF without any extra effort
WRITE 'Hello World'.
new-page.
commit work.
new-page print off.
IF sy-batch EQ 'X'.
PERFORM get_job_details.
PERFORM obtain_spool_id.
*** Alternative way could be to submit another program and store spool
*** id into memory.
*submit ZSPOOLTOPDF2
* to sap-spool
* spool parameters %_print
* archive parameters %_print
* without spool dynpro
* and return.
* Get spool id from program called above
* IMPORT w_spool_nr FROM MEMORY ID 'SPOOLTOPDF'.
PERFORM convert_spool_to_pdf.
PERFORM process_email.
if p_delspl EQ 'X'.
PERFORM delete_spool.
endif.
IF sy-sysid = c_dev.
wait up to 5 seconds.
SUBMIT rsconn01 WITH mode = 'INT'
WITH output = 'X'
AND RETURN.
ENDIF.
ELSE.
SKIP.
WRITE:/ 'Program must be executed in background in-order for spool',
'request to be created.'.
ENDIF.
* FORM obtain_spool_id *
FORM obtain_spool_id.
CHECK NOT ( gd_jobname IS INITIAL ).
CHECK NOT ( gd_jobcount IS INITIAL ).
SELECT * FROM tbtcp
INTO TABLE it_tbtcp
WHERE jobname = gd_jobname
AND jobcount = gd_jobcount
AND stepcount = gd_stepcount
AND listident <> '0000000000'
ORDER BY jobname
jobcount
stepcount.
READ TABLE it_tbtcp INTO wa_tbtcp INDEX 1.
IF sy-subrc = 0.
message s004(zdd) with gd_spool_nr.
gd_spool_nr = wa_tbtcp-listident.
MESSAGE s004(zdd) WITH gd_spool_nr.
ELSE.
MESSAGE s005(zdd).
ENDIF.
ENDFORM.
* FORM get_job_details *
FORM get_job_details.
* Get current job details
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.
ENDFORM.
* FORM convert_spool_to_pdf *
FORM convert_spool_to_pdf.
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.
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.
ENDFORM.
* FORM process_email *
FORM process_email.
DESCRIBE TABLE it_mess_att LINES gd_recsize.
CHECK gd_recsize > 0.
PERFORM send_email USING p_email1.
* perform send_email using p_email2.
ENDFORM.
* FORM send_email *
* --> p_email *
FORM send_email USING p_email.
CHECK NOT ( p_email IS INITIAL ).
REFRESH it_mess_bod.
* Default subject matter
gd_subject = 'Subject'.
gd_attachment_desc = 'Attachname'.
* CONCATENATE 'attach_name' ' ' INTO gd_attachment_name.
it_mess_bod = 'Message Body text, line 1'.
APPEND it_mess_bod.
it_mess_bod = 'Message Body text, line 2...'.
APPEND it_mess_bod.
* If no sender specified - default blank
IF p_sender EQ space.
gd_sender_type = space.
ELSE.
gd_sender_type = 'INT'.
ENDIF.
* Send file by email as .xls speadsheet
PERFORM send_file_as_email_attachment
tables it_mess_bod
it_mess_att
using p_email
'Example .xls documnet attachment'
'PDF'
gd_attachment_name
gd_attachment_desc
p_sender
gd_sender_type
changing gd_error
gd_reciever.
ENDFORM.
* FORM delete_spool *
FORM delete_spool.
DATA: ld_spool_nr TYPE tsp01_sp0r-rqid_char.
ld_spool_nr = gd_spool_nr.
CHECK p_delspl <> c_no.
CALL FUNCTION 'RSPO_R_RDELETE_SPOOLREQ'
EXPORTING
spoolid = ld_spool_nr.
ENDFORM.
*& Form SEND_FILE_AS_EMAIL_ATTACHMENT
* Send email
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-receiver = ld_email.
t_receivers-rec_type = 'U'.
t_receivers-com_type = 'INT'.
t_receivers-notif_del = 'X'.
t_receivers-notif_ndel = 'X'.
APPEND t_receivers.
CALL FUNCTION 'SO_DOCUMENT_SEND_API1'
EXPORTING
document_data = w_doc_data
put_in_outbox = 'X'
sender_address = ld_sender_address
sender_address_type = ld_sender_address_type
commit_work = 'X'
IMPORTING
sent_to_all = w_sent_all
TABLES
packing_list = t_packing_list
contents_bin = t_attachment
contents_txt = it_message
receivers = t_receivers
EXCEPTIONS
too_many_receivers = 1
document_not_sent = 2
document_type_not_exist = 3
operation_no_authorization = 4
parameter_error = 5
x_error = 6
enqueue_error = 7
OTHERS = 8.
* Populate zerror return code
ld_error = sy-subrc.
* Populate zreceiver return code
LOOP AT t_receivers.
ld_receiver = t_receivers-retrn_code.
ENDLOOP.
ENDFORM.
Regards,
Raghav -
Making spool, convert it into PDF and send that PDf throgh EMAIl
Hi,
In my making ALV report. In that i want to make the spool and then convert it into the pdf and send mail to the recepient.
AtulHi,
please try the following code. It works for me.
DATA : itab LIKE tline OCCURS 0 WITH HEADER LINE.
DATA : file_name TYPE string.
DATA : path LIKE pcfile-path.
DATA : extension(5) TYPE c.
DATA : name(100) TYPE c.
DATA:receiver TYPE somlreci1-receiver ,
p_file LIKE rlgrap-filename.
declarations for PDF convertion
DATA: path1 TYPE string ,
fullpath TYPE string.
DATA :textlines LIKE tline OCCURS 100 WITH HEADER LINE.
DATA otf LIKE itcoo OCCURS 1000 WITH HEADER LINE.
DATA it_lines LIKE tline OCCURS 100 WITH HEADER LINE.
DATA options LIKE itcpo.
DATA header LIKE thead.
DATA result LIKE itcpp.
DATA: bin_filesize TYPE i.
fullpath type string.
DATA: docdata LIKE sodocchgi1,
objpack LIKE sopcklsti1 OCCURS 1 WITH HEADER LINE,
objhead LIKE solisti1 OCCURS 1 WITH HEADER LINE,
objtxt LIKE solisti1 OCCURS 10 WITH HEADER LINE,
objbin LIKE solisti1 OCCURS 10 WITH HEADER LINE,
objhex LIKE solix OCCURS 10 WITH HEADER LINE,
reclist LIKE somlreci1 OCCURS 1 WITH HEADER LINE.
DATA: tab_lines TYPE i,
doc_size TYPE i,
att_type LIKE soodk-objtp.
DATA: listobject LIKE abaplist OCCURS 1 WITH HEADER LINE.
DATA: filesize TYPE i,
convcount TYPE i,
cancel(1).
textlines-tdformat = '*'.
textlines-tdline = 'Hello Hao'.
APPEND textlines.
options-tdgetotf = 'X'.
options-tdnoprev = 'X'.
CALL FUNCTION 'PRINT_TEXT'
EXPORTING
APPLICATION = 'TX'
ARCHIVE_INDEX = ' '
ARCHIVE_PARAMS = ' '
DEVICE = 'PRINTER'
dialog = ' '
header = header
OPTIONS = options
IMPORTING
NEW_ARCHIVE_PARAMS =
RESULT = RESULT
tables
lines = textlines
otfdata = otf
EXCEPTIONS
CANCELED = 1
DEVICE = 2
FORM = 3
OPTIONS = 4
UNCLOSED = 5
UNKNOWN = 6
FORMAT = 7
TEXTFORMAT = 8
COMMUNICATION = 9
BAD_PAGEFORMAT_FOR_PRINT = 10
OTHERS = 11
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'
IMPORTING
bin_filesize = filesize
TABLES
otf = otf
lines = it_lines
EXCEPTIONS
err_conv_not_possible = 1
err_bad_otf = 2.
fullpath = 'C:/foldername/test.pdf'.
CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
bin_filesize = bin_filesize
filename = fullpath
filetype = 'BIN'
APPEND = ' '
CODEPAGE = ' '
NO_BYTEORDER_MARK = ' '
IMPORTING
FILELENGTH = c
TABLES
data_tab = it_lines
FORMAT_TAB =
EXCEPTIONS
file_write_error = 1
no_batch = 2
gui_refuse_filetransfer = 3
invalid_type = 4
no_authority = 5
unknown_error = 6.
*filename = fullpath.
CLEAR docdata.
REFRESH objpack.
CLEAR objpack.
REFRESH objhead.
REFRESH objtxt.
CLEAR objtxt.
REFRESH objbin.
CLEAR objbin.
REFRESH objhex.
CLEAR objhex.
REFRESH reclist.
CLEAR reclist.
REFRESH listobject.
CLEAR listobject.
CLEAR tab_lines.
CLEAR doc_size.
CLEAR att_type.
Set Variables
docdata-obj_name = 'Tst'.
docdata-obj_descr = 'Testing'.
reclist-receiver = give the mail id.
reclist-rec_type = 'U'.
APPEND reclist.
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
filename = fullpath
filetype = 'BIN'
TABLES
data_tab = itab
EXCEPTIONS
file_open_error = 1
file_read_error = 2
no_batch = 3
gui_refuse_filetransfer = 4
invalid_type = 5
no_authority = 6
unknown_error = 7
bad_data_format = 8
header_not_allowed = 9
separator_not_allowed = 10
header_too_long = 11
unknown_dp_error = 12
access_denied = 13
dp_out_of_memory = 14
disk_full = 15
dp_timeout = 16
OTHERS = 17.
path = fullpath.
CALL FUNCTION 'PC_SPLIT_COMPLETE_FILENAME'
EXPORTING
complete_filename = path
CHECK_DOS_FORMAT =
IMPORTING
DRIVE =
extension = extension
name = name
NAME_WITH_EXT =
PATH =
EXCEPTIONS
invalid_drive = 1
invalid_extension = 2
invalid_name = 3
invalid_path = 4
OTHERS = 5
DATA : pos TYPE i.
DATA : len TYPE i.
Loop And Put Data
LOOP AT itab.
pos = 255 - len.
IF pos > 134. "length of pdf_table
pos = 134.
ENDIF.
objbin+len = itab(pos).
len = len + pos.
IF len = 255. "length of out (contents_bin)
APPEND objbin.
CLEAR: objbin, len.
IF pos < 134.
objbin = itab+pos.
len = 134 - pos.
ENDIF.
ENDIF.
ENDLOOP.
IF len > 0.
APPEND objbin.
ENDIF.
Packing Info For Text Data
DESCRIBE TABLE objtxt LINES tab_lines.
READ TABLE objtxt INDEX tab_lines.
docdata-doc_size = ( tab_lines - 1 ) * 255 + STRLEN( objtxt ).
CLEAR objpack-transf_bin.
objpack-head_start = 1.
objpack-head_num = 0.
objpack-body_start = 1.
objpack-body_num = tab_lines.
objpack-doc_type = 'TXT'.
APPEND objpack.
Packing Info Attachment
name = extension.
DESCRIBE TABLE objbin LINES tab_lines.
READ TABLE objbin INDEX tab_lines.
objpack-doc_size = ( tab_lines - 1 ) * 255 + STRLEN( objbin ).
objpack-transf_bin = 'X'.
objpack-head_start = 1.
objpack-head_num = 0.
objpack-body_start = 1.
objpack-body_num = tab_lines.
objpack-doc_type = name.
objpack-obj_name = 'ATTACHMENT'.
objpack-obj_descr = name.
APPEND objpack.
CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
EXPORTING
document_data = docdata
put_in_outbox = 'X'
commit_work = 'X' "used from rel. 6.10
TABLES
packing_list = objpack
object_header = objhead
contents_bin = objbin
contents_txt = objtxt
receivers = reclist
EXCEPTIONS
too_many_receivers = 1
document_not_sent = 2
document_type_not_exist = 3
operation_no_authorization = 4
parameter_error = 5
x_error = 6
enqueue_error = 7
OTHERS = 8
IF sy-subrc <> 0.
MESSAGE ID 'SO' TYPE 'S' NUMBER '023'
WITH docdata-obj_name.
ENDIF.
Keerthi -
Smartform to convert as pdf attachment and sending mail.
Program to convert smartform as PDF and send PDF as an atachment to email id.
********Variable Declarations ****************************
DATA: gv_form_name TYPE rs38l_fnam, " Used to store the function module generated by Smartform
gv_bin_filesize TYPE i, " Store the file size
gv_pos TYPE i,
gv_len TYPE i,
gv_tab_lines TYPE i.
*******Constants ******************************************
DATA : gc_text(11) TYPE c VALUE 'Form Output',
gc_tst(3) TYPE c VALUE 'TST',
gc_testing(7) TYPE c VALUE 'Testing'.
CONSTANTS : c_formname TYPE tdsfname VALUE 'ZSMART_T'. "Zsmart_t is the smartform name.
********Work Area Declarations ****************************
DATA: gs_docdata TYPE sodocchgi1, " Data of an object which can be changed
gs_ctrlop TYPE ssfctrlop, " Smart Forms: Control structure
gs_outopt TYPE ssfcompop, " SAP Smart Forms: Smart Composer (transfer) options
gs_otfdata TYPE ssfcrescl, " Smart Forms: Return value at end of form printing
gs_reclist TYPE somlreci1, " SAPoffice: Structure of the API Recipient List
gs_pdf_tab TYPE tline, " Workarea for SAP Script Text Lines
gs_objbin TYPE solisti1, " SAPoffice: Single List with Column Length 255
gs_objpack TYPE sopcklsti1. " SAPoffice: Description of Imported Object Components
********Internal tables Declarations ****************************
DATA: gt_reclist TYPE TABLE OF somlreci1, " SAPoffice: Structure of the API Recipient List
gt_pdf_tab TYPE TABLE OF tline, " SAPscript: Text Lines
gt_otf TYPE TABLE OF itcoo, " OTF Structure
gt_objbin TYPE TABLE OF solisti1, " SAPoffice: Single List with Column Length 255
gt_objpack TYPE TABLE OF sopcklsti1. " SAPoffice: Description of Imported Object Components
DATA: customer TYPE scustom,
bookings TYPE ty_bookings,
connections TYPE ty_connections.
CLEAR : gv_form_name,
gs_ctrlop,
gs_outopt,
gs_otfdata,
gv_bin_filesize,
gv_pos,
gv_len,
gv_tab_lines.
START-OF-SELECTION.
Generate Function Module name
CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'
EXPORTING
formname = c_formname
IMPORTING
fm_name = gv_form_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.
ENDIF.
Assigning values to Form Control Structure and Form Composer
gs_ctrlop-getotf = 'X'.
gs_ctrlop-device = 'PRINTER'.
gs_ctrlop-preview = ''.
gs_ctrlop-no_dialog = 'X'.
gs_outopt-tddest = 'LP01'. "or 'LOCL'.
Getting the OTFDATA
CALL FUNCTION gv_form_name
EXPORTING
control_parameters = gs_ctrlop
output_options = gs_outopt
user_settings = ' '
customer = customer
bookings = bookings
connections = connections
IMPORTING
job_output_info = gs_otfdata
EXCEPTIONS
formatting_error = 1
internal_error = 2
send_error = 3
user_canceled = 4.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
Assigning the OTFDATA to OTF Structure table
CLEAR gt_otf.
gt_otf[] = gs_otfdata-otfdata[].
Convert the OTF DATA to SAP Script Text lines
CLEAR gt_pdf_tab.
CALL FUNCTION 'CONVERT_OTF'
EXPORTING
format = 'PDF'
max_linewidth = 132
IMPORTING
bin_filesize = gv_bin_filesize
TABLES
otf = gt_otf
lines = gt_pdf_tab
EXCEPTIONS
err_max_linewidth = 1
err_format = 2
err_conv_not_possible = 3
OTHERS = 4.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
Assigning the Description of the object sent in the mail
CLEAR gs_docdata.
gs_docdata-obj_name = gc_tst.
gs_docdata-obj_descr = gc_testing.
Assigning the email id to Structure of the API Recipient List table
CLEAR : gt_reclist, gs_reclist.
IF internal mail id
gs_reclist-receiver = sy-uname.
GS_RECLIST-REC_TYPE = 'B'.
if external mail id
gs_reclist-receiver = mailid.com'.
gs_reclist-rec_type = 'U'.
APPEND gs_reclist TO gt_reclist.
Passing the SAP Script text lines to SAPoffice: Single List with Column Length 255 table
CLEAR : gs_objbin, gs_pdf_tab.
LOOP AT gt_pdf_tab INTO gs_pdf_tab.
gv_pos = 255 - gv_len.
IF gv_pos > 134. "length of pdf_table
gv_pos = 134.
ENDIF.
gs_objbin+gv_len = gs_pdf_tab(gv_pos).
gv_len = gv_len + gv_pos.
IF gv_len = 255. "length of out (contents_bin)
APPEND gs_objbin TO gt_objbin.
CLEAR: gs_objbin, gv_len.
IF gv_pos < 134.
gs_objbin = gs_pdf_tab+gv_pos.
gv_len = 134 - gv_pos.
ENDIF.
ENDIF.
ENDLOOP.
IF gv_len > 0.
APPEND gs_objbin TO gt_objbin.
ENDIF.
Filling the details in SAPoffice: Description of Imported Object Components table
DESCRIBE TABLE gt_objbin LINES gv_tab_lines.
CLEAR gs_objbin.
READ TABLE gt_objbin INTO gs_objbin INDEX gv_tab_lines.
IF sy-subrc = 0.
gs_objpack-doc_size = ( gv_tab_lines - 1 ) * 255 + STRLEN( gs_objbin ).
gs_objpack-transf_bin = 'X'.
gs_objpack-head_start = 1.
gs_objpack-head_num = 0.
gs_objpack-body_start = 1.
gs_objpack-body_num = gv_tab_lines.
gs_objpack-doc_type = 'PDF'.
gs_objpack-obj_name = 'ATTACHMENT'.
gs_objpack-obj_descr = 'test'.
APPEND gs_objpack TO gt_objpack.
ENDIF.
Sending the Form Output in the PDF format to email
CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
EXPORTING
document_data = gs_docdata
put_in_outbox = 'X'
commit_work = 'X'
TABLES
packing_list = gt_objpack
contents_bin = gt_objbin
receivers = gt_reclist
EXCEPTIONS
too_many_receivers = 1
document_not_sent = 2
document_type_not_exist = 3
operation_no_authorization = 4
parameter_error = 5
x_error = 6
enqueue_error = 7
OTHERS = 8.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ELSE.
WRITE 'Sent Successfully'.
ENDIF.
SUBMIT rsconn01
WITH mode EQ 'INT'
AND RETURN.
END-OF-SELECTION.Hi
Use function modules
CALL FUNCTION 'CONVERT_OTF'
and CALL FUNCTION 'SX_TABLE_LINE_WIDTH_CHANGE' to convert as a pdf document
for sending mail CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
Regards,
Gopi -
Reg: HRforms converted to PDF and send email to individual employee
Hi Experts,
The requirement is convert the HR form output to pdf and send email to respective employee in standard transaction. I copied RPCEDTX0 to ZRPCEDTX0 and include RPCEDS09 to ZRPCEDS09, the changes need to be done for individual PERNR, I have modified the include as shown below.
CALL FUNCTION 'HRPY_PROCESS_SET_PERNR_STATUS' after this, i have written my code
* start of changes ARAFIQUE
DATA: formname TYPE tdsfname VALUE 'HR_ESS_PAYSLIP_TO_PDF',
fm_name TYPE rs38l_fnam,
pinfo LIKE pc407 OCCURS 0 WITH HEADER LINE,
pform type tt_pc408,
pform_l like pc408 OCCURS 0 WITH HEADER LINE.
IF xform[] IS NOT INITIAL.
pform_l = xform.
APPEND pform_1 TO pform.
pinfo-molga = '99'.
pinfo-forml = 'ZACC'.
APPEND pinfo.
CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'
EXPORTING
formname = formname
* VARIANT = ' '
* DIRECT_CALL = ' '
IMPORTING
fm_name = 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.
ENDIF.
CALL FUNCTION fm_name
EXPORTING
pinfo =
pform = xform[]
EXCEPTIONS
FORMATTING_ERROR = 1
INTERNAL_ERROR = 2
SEND_ERROR = 3
USER_CANCELED = 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.
ENDIF.
* end of changes ARAFIQUE
I found out in internet that the smartform 'HR_ESS_PAYSLIP_TO_PDF' will convert to PDF and then i can send email to PERNRS.Hi Experts,
I have written the below code, the payslip is getting converted to PDF and it is getting saved in presentation server. I need to pick this file and mail, I created a customized function module for sending mail. I'm not able to send email to external addresses.
Please find my code below. I will post the function module later.
* start of changes ARAFIQUE
DATA: "formname TYPE tdsfname VALUE 'HR_ESS_PAYSLIP_TO_PDF',
"fm_name TYPE rs38l_fnam,
p_info LIKE pc407 OCCURS 0 WITH HEADER LINE,
"pform type tt_pc408,
p_form LIKE pc408 OCCURS 0 WITH HEADER LINE,
pdf_content TYPE xstring,
pdf_fsize TYPE i,
lv_output_length TYPE i,
lt_binary_data TYPE STANDARD TABLE OF sdokcntbin,
it_receivers LIKE somlreci1 OCCURS 0 WITH HEADER LINE,
it_message LIKE solisti1 OCCURS 0 WITH HEADER LINE.
IF xform[] IS NOT INITIAL.
p_form[] = xform[].
p_info-molga = '99'.
p_info-forml = 'ZACC'.
p_info-pcols = 1.
p_info-psize = 1.
APPEND p_info.
CALL FUNCTION 'CONVERT_PAYSLIP_TO_PDF'
EXPORTING
p_info = p_info
IMPORTING
pdf_content = pdf_content
pdf_fsize = pdf_fsize
TABLES
p_form = p_form[]
EXCEPTIONS
empty_form = 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.
CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'
EXPORTING
buffer = pdf_content
IMPORTING
output_length = lv_output_length
TABLES
binary_tab = lt_binary_data.
CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
filename = 'C:\Test\Testing.pdf'
filetype = 'BIN'
TABLES
data_tab = lt_binary_data
* FIELDNAMES =
EXCEPTIONS
file_write_error = 1
no_batch = 2
gui_refuse_filetransfer = 3
invalid_type = 4
no_authority = 5
unknown_error = 6
header_not_allowed = 7
separator_not_allowed = 8
filesize_not_allowed = 9
header_too_long = 10
dp_error_create = 11
dp_error_send = 12
dp_error_write = 13
unknown_dp_error = 14
access_denied = 15
dp_out_of_memory = 16
disk_full = 17
dp_timeout = 18
file_not_found = 19
dataprovider_exception = 20
control_flush_error = 21
OTHERS = 22
it_receivers-receiver = 'gmailid'.
it_receivers-rec_type = 'U'.
it_receivers-com_type = 'INT'.
APPEND it_receivers .
it_message-line = 'Test for sending email'.
APPEND it_message.
CALL FUNCTION 'ZSEND_MAIL_ATTACHMENT'
EXPORTING
v_file_path = 'C:\Test\Testing.pdf'
v_subject = 'Test Mail'
TABLES
it_receivers = it_receivers[]
it_message = it_message[].
IF sy-subrc EQ 0.
COMMIT WORK.
* Push mail out from SAP outbox
SUBMIT rsconn01 WITH mode = 'INT' AND RETURN.
ENDIF. -
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 -
Convert smartforms to pdf and sending it as email
hi,
i am converting smart form into PDF and sending it as an attachment with the e-mail. the e-mail is getting delivered but i am unable to open the PDF. it shows error saying "unable to open as it is not a supported file type or it has been damaged".
can any one please help me.Hi Gouthaman,
Check this code.
*& Report ZSPOOLTOPDF *
*& Converts spool request into PDF document and emails it to *
*& recipicant. *
*& Execution *
*& This program must be run as a background job in-order for the write *
*& commands to create a Spool request rather than be displayed on *
*& screen *
REPORT zspooltopdf.
PARAMETER: p_email1 LIKE somlreci1-receiver
DEFAULT '[email protected]',
p_sender LIKE somlreci1-receiver
DEFAULT '[email protected]',
p_delspl AS CHECKBOX.
*DATA DECLARATION
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'.
*START-OF-SELECTION.
START-OF-SELECTION.
Write statement to represent report output. Spool request is created
if write statement is executed in background. This could also be an
ALV grid which would be converted to PDF without any extra effort
WRITE 'Hello World'.
new-page.
commit work.
new-page print off.
IF sy-batch EQ 'X'.
PERFORM get_job_details.
PERFORM obtain_spool_id.
Alternative way could be to submit another program and store spool
id into memory, will be stored in sy-spono.
*submit ZSPOOLTOPDF2
to sap-spool
spool parameters %_print
archive parameters %_print
without spool dynpro
and return.
Get spool id from program called above
IMPORT w_spool_nr FROM MEMORY ID 'SPOOLTOPDF'.
PERFORM convert_spool_to_pdf.
PERFORM process_email.
if p_delspl EQ 'X'.
PERFORM delete_spool.
endif.
IF sy-sysid = c_dev.
wait up to 5 seconds.
SUBMIT rsconn01 WITH mode = 'INT'
WITH output = 'X'
AND RETURN.
ENDIF.
ELSE.
SKIP.
WRITE:/ 'Program must be executed in background in-order for spool',
'request to be created.'.
ENDIF.
FORM obtain_spool_id *
FORM obtain_spool_id.
CHECK NOT ( gd_jobname IS INITIAL ).
CHECK NOT ( gd_jobcount IS INITIAL ).
SELECT * FROM tbtcp
INTO TABLE it_tbtcp
WHERE jobname = gd_jobname
AND jobcount = gd_jobcount
AND stepcount = gd_stepcount
AND listident <> '0000000000'
ORDER BY jobname
jobcount
stepcount.
READ TABLE it_tbtcp INTO wa_tbtcp INDEX 1.
IF sy-subrc = 0.
message s004(zdd) with gd_spool_nr.
gd_spool_nr = wa_tbtcp-listident.
MESSAGE s004(zdd) WITH gd_spool_nr.
ELSE.
MESSAGE s005(zdd).
ENDIF.
ENDFORM.
FORM get_job_details *
FORM get_job_details.
Get current job details
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.
ENDFORM.
FORM convert_spool_to_pdf *
FORM convert_spool_to_pdf.
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.
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.
ENDFORM.
FORM process_email *
FORM process_email.
DESCRIBE TABLE it_mess_att LINES gd_recsize.
CHECK gd_recsize > 0.
PERFORM send_email USING p_email1.
perform send_email using p_email2.
ENDFORM.
FORM send_email *
--> p_email *
FORM send_email USING p_email.
CHECK NOT ( p_email IS INITIAL ).
REFRESH it_mess_bod.
Default subject matter
gd_subject = 'Subject'.
gd_attachment_desc = 'Attachname'.
CONCATENATE 'attach_name' ' ' INTO gd_attachment_name.
it_mess_bod = 'Message Body text, line 1'.
APPEND it_mess_bod.
it_mess_bod = 'Message Body text, line 2...'.
APPEND it_mess_bod.
If no sender specified - default blank
IF p_sender EQ space.
gd_sender_type = space.
ELSE.
gd_sender_type = 'INT'.
ENDIF.
Send file by email as .xls speadsheet
PERFORM send_file_as_email_attachment
tables it_mess_bod
it_mess_att
using p_email
'Example .xls documnet attachment'
'PDF'
gd_attachment_name
gd_attachment_desc
p_sender
gd_sender_type
changing gd_error
gd_reciever.
ENDFORM.
FORM delete_spool *
FORM delete_spool.
DATA: ld_spool_nr TYPE tsp01_sp0r-rqid_char.
ld_spool_nr = gd_spool_nr.
CHECK p_delspl <> c_no.
CALL FUNCTION 'RSPO_R_RDELETE_SPOOLREQ'
EXPORTING
spoolid = ld_spool_nr.
ENDFORM.
*& Form SEND_FILE_AS_EMAIL_ATTACHMENT
Send email
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-receiver = ld_email.
t_receivers-rec_type = 'U'.
t_receivers-com_type = 'INT'.
t_receivers-notif_del = 'X'.
t_receivers-notif_ndel = 'X'.
APPEND t_receivers.
CALL FUNCTION 'SO_DOCUMENT_SEND_API1'
EXPORTING
document_data = w_doc_data
put_in_outbox = 'X'
sender_address = ld_sender_address
sender_address_type = ld_sender_address_type
commit_work = 'X'
IMPORTING
sent_to_all = w_sent_all
TABLES
packing_list = t_packing_list
contents_bin = t_attachment
contents_txt = it_message
receivers = t_receivers
EXCEPTIONS
too_many_receivers = 1
document_not_sent = 2
document_type_not_exist = 3
operation_no_authorization = 4
parameter_error = 5
x_error = 6
enqueue_error = 7
OTHERS = 8.
Populate zerror return code
ld_error = sy-subrc.
Populate zreceiver return code
LOOP AT t_receivers.
ld_receiver = t_receivers-retrn_code.
ENDLOOP.
ENDFORM.
Hope this resolves your query.
Reward all the helpful answers.
Regards -
Smart form to PDF and send it by mail
Hi ,
I have smartform whihc i have to conver into pdf and send by mail. nay inputs is higghly appreciatedHi,
You call the smartform-function module from within your printprogram.
That smartform-function module has some standard import en export
parameters(tables).
One of the parameters (OTF) you have to mark (X).
Than after the processing of the smartform(-function module) you get your
otf back in an internal table.
You have to convert this table to pdf with FM convert_to_pdf (or something
like that).
The output of this FM can be downloaded to the presentation server (pc) (FM
gui_download) or written to the application server (SAP server) (transfer
statement).
Then use this link to send mail
http://www.sap-img.com/abap/sending-email-with-attachment.htm
Reward if useful! -
Hello all,
I have an Internal table and i need to convert the same into PDF and send the mail as an attachment using CL_BCS.
Kindly help with the same by providing a good example.
Regards,
Arun*& Form PROCESS_EMAIL
FORM process_email .
DESCRIBE TABLE gt_mess_att LINES g_recsize.
CHECK g_recsize > 0.
PERFORM send_email USING p_email.
ENDFORM. " PROCESS_EMAIL
*& Form SEND_EMAIL
FORM send_email USING p_email.
CHECK NOT ( p_email IS INITIAL ).
REFRESH gt_mess_bod.
* Default subject matter
g_subject = p_subj.
g_attachment_desc = 'HDM'.
gt_mess_bod = 'Hi,'.
APPEND gt_mess_bod.
gt_mess_bod = ' Please find attached Home Delivery Manifest Report'(003).
APPEND gt_mess_bod.
* If no sender specified - default blank
IF p_rt_eml EQ space.
g_sender_type = space.
ELSE.
g_sender_type = 'INT'.
ENDIF.
* Send file by email as .xls speadsheet
PERFORM send_file_as_email_attachment
TABLES gt_mess_bod
gt_mess_att
USING p_email
g_subject
'PDF'
g_attachment_name
g_attachment_desc
p_rt_eml
g_sender_type
CHANGING g_error
g_reciever.
ENDFORM. " SEND_EMAIL
*& Form SEND_FILE_AS_EMAIL_ATTACHMENT
FORM send_file_as_email_attachment TABLES lt_message
lt_attach
USING p_email
p_mtitle
p_format
p_filename
p_attdescription
p_sender_address
p_sender_addres_type
CHANGING p_error "#EC NEEDED
p_reciever. "#EC NEEDED
DATA: l_error TYPE sy-subrc, "#EC NEEDED
l_reciever TYPE sy-subrc, "#EC NEEDED
l_mtitle LIKE sodocchgi1-obj_descr,
l_email LIKE somlreci1-receiver,
l_format TYPE so_obj_tp ,
l_attdescription TYPE so_obj_nam ,
l_attfilename TYPE so_obj_des ,
l_sender_address LIKE soextreci1-receiver,
l_sender_address_type LIKE soextreci1-adr_typ,
l_receiver LIKE sy-subrc. "#EC NEEDED
DATA: lt_packing_list LIKE sopcklsti1 OCCURS 0 WITH HEADER LINE, "#EC NEEDED
* lt_contents LIKE solisti1 OCCURS 0 WITH HEADER LINE,"#EC NEEDED
lt_receivers LIKE somlreci1 OCCURS 0 WITH HEADER LINE, "#EC NEEDED
lt_attachment LIKE solisti1 OCCURS 0 WITH HEADER LINE, "#EC NEEDED
* lt_object_header LIKE solisti1 OCCURS 0 WITH HEADER LINE,"#EC NEEDED
l_cnt TYPE i,
l_sent_all(1) TYPE c, "#EC NEEDED
ls_doc_data LIKE sodocchgi1.
l_email = p_email.
l_mtitle = p_mtitle.
l_format = p_format.
l_attdescription = p_attdescription.
l_attfilename = p_filename.
l_sender_address = p_sender_address.
l_sender_address_type = p_sender_addres_type.
* Fill the document data.
ls_doc_data-doc_size = 1.
* Populate the subject/generic message attributes
ls_doc_data-obj_langu = sy-langu.
ls_doc_data-obj_name = 'SAPRPT'.
ls_doc_data-obj_descr = l_mtitle .
ls_doc_data-sensitivty = 'F'.
* Fill the document data and get size of attachment
CLEAR ls_doc_data.
READ TABLE lt_attach INDEX l_cnt.
ls_doc_data-doc_size =
( l_cnt - 1 ) * 255 + STRLEN( lt_attach ).
ls_doc_data-obj_langu = sy-langu.
ls_doc_data-obj_name = 'SAPRPT'.
ls_doc_data-obj_descr = l_mtitle.
ls_doc_data-sensitivty = 'F'.
CLEAR lt_attachment.
REFRESH lt_attachment.
lt_attachment[] = lt_attach[].
* Describe the body of the message
CLEAR lt_packing_list.
REFRESH lt_packing_list.
lt_packing_list-transf_bin = space.
lt_packing_list-head_start = 1.
lt_packing_list-head_num = 0.
lt_packing_list-body_start = 1.
DESCRIBE TABLE lt_message LINES lt_packing_list-body_num.
lt_packing_list-doc_type = 'RAW'.
APPEND lt_packing_list.
* Create attachment notification
lt_packing_list-transf_bin = 'X'.
lt_packing_list-head_start = 1.
lt_packing_list-head_num = 1.
lt_packing_list-body_start = 1.
DESCRIBE TABLE lt_attachment LINES lt_packing_list-body_num.
lt_packing_list-doc_type = l_format.
lt_packing_list-obj_descr = l_attdescription.
lt_packing_list-obj_name = l_attfilename.
lt_packing_list-doc_size = lt_packing_list-body_num * 255.
APPEND lt_packing_list.
* Add the recipients email address
CLEAR lt_receivers.
REFRESH lt_receivers.
lt_receivers-receiver = l_email.
lt_receivers-rec_type = 'U'.
lt_receivers-com_type = 'INT'.
lt_receivers-notif_del = 'X'.
lt_receivers-notif_ndel = 'X'.
APPEND lt_receivers.
CALL FUNCTION 'SO_DOCUMENT_SEND_API1'
EXPORTING
document_data = ls_doc_data
put_in_outbox = 'X'
sender_address = l_sender_address
sender_address_type = l_sender_address_type
commit_work = 'X'
IMPORTING
sent_to_all = l_sent_all
TABLES
packing_list = lt_packing_list
contents_bin = lt_attachment
contents_txt = lt_message
receivers = lt_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 s000 WITH 'Document Sent Successfully'(002).
ENDIF.
* Populate zerror return code
l_error = sy-subrc.
* Populate zreceiver return code
LOOP AT lt_receivers.
l_receiver = lt_receivers-retrn_code.
ENDLOOP.
ENDFORM. " SEND_FILE_AS_EMAIL_ATTACHMENT -
Convert Screen(spool) to PDF file sending mail with attach file
Hi :
I'd like convert spool list to pdf and sending file...
so, I read thread about spool convert to PDF before,
and know how to convert Spool to PDF file and send mail with attach file.
but I have a problem.
my solution as:
step 1. Call function: "CONVERT_ABAPSPOOLJOB_2_PDF"
step 2. Call function: "SO_NEW_DOCUMENT_ATT_SEND_API1"
then, I got a mail with attached PDF file, but the PDF file display limited 255 line.( SO_NEW_DOCUMENT_ATT_SEND_API1 limited)
I want to showing word is wider that 255.
and then I find a manual method as:
After program finished.
Function Menu -> system -> List -> Send
use Prog: "Create Document and Send"
I use this prog sending mail and attached file ,
PDF file do <b>NOT</b> have 255 word limit !
finally. my question is, If I want sending mail as Prog: "Create Document and Send", how to do?
which Function I have to use?...
Please help me, Thanks!Hi,
Check this sample code of sending spool as attachment to an email address..
Parameters.
PARAMETERS: p_email(50) LOWER CASE.
PARAMETERS: p_spool LIKE tsp01-rqident.
Data declarations.
DATA: plist LIKE sopcklsti1 OCCURS 2 WITH HEADER LINE.
DATA: document_data LIKE sodocchgi1.
DATA: so_ali LIKE soli OCCURS 100 WITH HEADER LINE.
DATA: real_type LIKE soodk-objtp.
DATA: sp_lang LIKE tst01-dlang.
DATA: line_size TYPE i VALUE 255.
DATA: v_name LIKE soextreci1-receiver.
DATA rec_tab LIKE somlreci1 OCCURS 1 WITH HEADER LINE.
Get the spool data.
CALL FUNCTION 'RSPO_RETURN_SPOOLJOB'
EXPORTING
rqident = p_spool
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.
IF sy-subrc <> 0.
MESSAGE s208(00) WITH 'Error'.
LEAVE LIST-PROCESSING.
ENDIF.
Prepare the data.
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 = 'Test ALV'.
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.
Move the receiver address.
MOVE: p_email TO rec_tab-receiver,
'U' TO rec_tab-rec_type.
APPEND rec_tab.
IF NOT sp_lang IS INITIAL.
document_data-obj_langu = sp_lang.
ELSE.
document_data-obj_langu = sy-langu.
ENDIF.
v_name = sy-uname.
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
receivers = rec_tab
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'.
ENDIF.
COMMIT WORK.
Send the email immediately.
SUBMIT rsconn01
WITH mode = 'INT'
AND RETURN.
Thanks,
Naren -
Dear Experts,
Please provide me a solution to convert the standard Pay slip (PC00_M99_CEDT) Remuneration statement to PDF and send it via email to individual employee by fetching the email ids through the info types.
I checked the forum, few answers our complete but they have not given the solution.
Thanks in advance
Abdur
Moderator message: moved to requirements forum (points-free!)
Edited by: Thomas Zloch on Feb 7, 2011 11:53 AM
Moderator message: moved back to ABAP General.
Edited by: Thomas Zloch on Feb 9, 2011 1:03 PMDear Experts,
As suggested, I have written the below code.
REPORT ztest_period.
DATA : td_listobject LIKE abaplist OCCURS 0 WITH HEADER LINE.
DATA: txtlines(1024) TYPE c OCCURS 0 WITH HEADER LINE.
DATA: list_tab TYPE TABLE OF abaplist,
lt_objbin TYPE TABLE OF solisti1 WITH HEADER LINE.
SUBMIT rpcedtx0 VIA SELECTION-SCREEN EXPORTING LIST TO MEMORY AND RETURN.
CLEAR td_listobject. REFRESH td_listobject.
CALL FUNCTION 'LIST_FROM_MEMORY'
TABLES
listobject = td_listobject
EXCEPTIONS
not_found = 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.
CHECK sy-subrc = 0.
CALL FUNCTION 'TABLE_COMPRESS'
TABLES
in = td_listobject
out = lt_objbin
EXCEPTIONS
compress_error = 1
OTHERS = 2.
&code&
I'm getting the raw data from FM 'LIST_FROM_MEMORY' Please tell me how should i convert it to normal data.
Once i get the data, I need to send an email for individual personnel number for the respective month.
Please advice me the next step.
Thanks and Regards,
Abdur Rafique
Edited by: abdur rafique on Feb 21, 2011 11:39 AM
Maybe you are looking for
-
Qosmio G30-201 connected to LCD - how to fit the whole screen?
Hi I have a Qosmio G30-201 laptop and also using a Toshiba WLT58 32 inch widescreen LCD with a HDMI Connector. I am trying to get the film that I am watching to fill the whole screen and leave the borders off. Is this possible? Cheers Steve
-
Can I pay for Logic Pro X using £139 worth of iTunes vouchers?
I'm 15 years old looking to buy the software, but clearly I don't have any bank information to give... So I really don't want to spend £150 on iTunes vouchers to be told that I have "reached the limit" or "need to provide bank details" or something w
-
Some folders and files are 'missing' in lion.
When I restore them from my SL back up they disappear from there as well. Help
-
Problem loading applet from tomcat
I am facing a problem loading the batik applet from tomcat. I have placed all the jar files of batik in ROOT directory in tomcat. Along with the folder containing the batik applet. Still i receive the following exception when trying to load the html
-
Why the Oracle 8.1.7 PE coundnot have error during start the install stage On Win98?Someone tell me that need one patch for win98,but where can I download it? Thanks