Sending smartform output as mail attachment (PDF)
Hi,
I am trying to send a smartform output in PDF format as a mail attachment. This has to be fired in the save of a Invoice.. configured by the output type.
Here is the code which i have .. and it does not work.
DATA: ls_bil_invoice TYPE lbbil_invoice.
tables: nast.
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
wa_objhead TYPE soli_tab,
w_ctrlop TYPE ssfctrlop,
w_compop TYPE ssfcompop,
w_return TYPE ssfcrescl,
wa_doc_chng typE sodocchgi1,
w_data TYPE sodocchgi1,
wa_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 = 'ZSDDLB_BIL_INVOICE'
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'
is_bil_invoice = ls_bil_invoice
is_nast = nast
is_repeat = '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 EQ 0.
endif.
Convert PDF from 132 to 255.
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.
refresh:
i_reclist,
i_objtxt,
i_objbin,
i_objpack.
clear wa_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.
DESCRIBE TABLE i_objtxt LINES v_lines_txt.
Document information.
wa_doc_chng-obj_name = 'Smartform'.
wa_doc_chng-expiry_dat = sy-datum + 10.
wa_doc_chng-obj_descr = 'Smart form output'.
wa_doc_chng-sensitivty = 'F'. "Functional object
wa_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 Smart Forms
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.
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
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.
ENDIF.
Hi Aviroop,
Compare your part of code with the below given code.
*& Report YSSN_SIMPLE_SMARTFORM *
report zhr_bhaskar_pdf_to_email message-id zmsg.
parameters: p_vbeln type vbak-vbeln default '35'.
data: it_items type table of vbap,
v_fm_name type rs38l_fnam,
v_tot_lines type i,
v_sy_tabix type i,
output_data type ssfcrescl. " To hold Output information
constants:
c_sep type c value '-', " Value -
c_x type c value 'X', " Value X
c_space type c value ' '. " Space
*****MAIL START
include .
data: g_mail_rec_obj type swotobjid,
g_mail_sen_obj type swotobjid,
g_mail_app_obj type swotobjid,
g_cont_par type ssfctrlop,
folder type swc_object,
begin of sofmfol_key,
foldertype like sofm-foltp,
folderyear like sofm-folyr,
foldernumber like sofm-folno,
type like sofm-doctp,
year like sofm-docyr,
number like sofm-docno,
forwarder like soub-usrnam,
end of sofmfol_key,
bor_key like swotobjid-objkey,
g_mail TYPE ppfdmailad VALUE '[email protected]',
g_mail type so_name value '[email protected]',
g_mail TYPE ppfdmailad VALUE '[email protected]' ,
g_mail TYPE ppfdmailad VALUE '[email protected]' ,
g_rectype type so_escape value 'U'. " 'B'.
data: job_output_info type ssfcrescl,
hotfdata like itcoo occurs 1 with header line,
htline like tline occurs 1 with header line,
x_objcont like soli occurs 1 with header line,
ld_packing_list like soxpl occurs 1 with header line,
x_object_hd_change like sood1 occurs 1 with header line,
x_objhead like soli occurs 1 with header line,
x_receivers like soos1 occurs 1 with header line,
format_pdf(10) value 'PDF',
doc_size(12) type c,
hltlines type i,
htabix like sy-tabix,
fle1(2) type p,
fle2(2) type p,
off1 type p,
hfeld(500) type c.
tables: soud.
*****MAIL END
select *
into table it_items
from vbap
where vbeln = p_vbeln.
if it_items[] is initial.
exit.
endif.
perform call_smartform.
*& Form call_smartform
text
--> p1 text
<-- p2 text
form call_smartform .
*DATA: lx_control_parameters TYPE SSFCTRLOP,
lx_OUTPUT_OPTIONS type SSFCOMPOP.
lx_OUTPUT_OPTIONS-TDIMMED = ' '.
lx_OUTPUT_OPTIONS-TDfinal = 'X'.
lx_OUTPUT_OPTIONS-TDDELETE = 'X'.
lx_CONTROL_PARAMETERS-NO_CLOSE = 'X'.
lx_CONTROL_PARAMETERS-NO_OPEN = ' '.
data: x_ssfcompop type ssfcompop,
x_ssfctrlop like ssfctrlop,
x_ssfcrescl type ssfcrescl.
**MAIL
g_cont_par-langu = sy-langu.
g_cont_par-no_dialog = 'X'.
g_cont_par-getotf = 'X'.
g_cont_par-device = 'MAIL'.
Get BOR-Objects for Recipient, Sender und Applikation
perform mail_recipient_object changing g_mail_rec_obj.
perform mail_sender_object changing g_mail_sen_obj.
perform mail_appl_object changing g_mail_app_obj.
**MAIL
*--Internal table is having more than 1 record
if v_tot_lines gt 1.
if v_sy_tabix = 1.
*--For first record of table
x_ssfctrlop-no_open = c_space.
x_ssfctrlop-no_close = c_x.
elseif v_sy_tabix = v_tot_lines.
*--For last record of table
x_ssfctrlop-no_open = c_x.
x_ssfctrlop-no_close = c_space.
else.
x_ssfctrlop-no_open = c_x.
x_ssfctrlop-no_close = c_x.
endif.
endif.
IF r_previ = c_x.
x_ssfctrlop-preview = c_x.
x_ssfctrlop-getotf = c_x.
ENDIF.
call function 'SSF_FUNCTION_MODULE_NAME'
exporting
formname = 'YSSN_SMARTFORM'
VARIANT = ' '
DIRECT_CALL = ' '
importing
fm_name = v_fm_name
EXCEPTIONS
NO_FORM = 1
NO_FUNCTION_MODULE = 2
OTHERS = 3
if sy-subrc <> 0.
message i000 with 'Smart form module name failure'.
exit.
endif.
CALL FUNCTION '/1BCDWB/SF00000199'
call function v_fm_name
exporting
ARCHIVE_INDEX =
ARCHIVE_INDEX_TAB =
ARCHIVE_PARAMETERS =
control_parameters = g_cont_par
mail_appl_obj = g_mail_app_obj
mail_recipient = g_mail_rec_obj
mail_sender = g_mail_sen_obj
OUTPUT_OPTIONS = lx_OUTPUT_OPTIONS
USER_SETTINGS = 'X'
t_vbap = it_items
IMPORTING
DOCUMENT_OUTPUT_INFO =
job_output_info = job_output_info
JOB_OUTPUT_OPTIONS =
EXCEPTIONS
FORMATTING_ERROR = 1
INTERNAL_ERROR = 2
SEND_ERROR = 3
USER_CANCELED = 4
OTHERS = 5
perform send_pdf_mail.
endform. " call_smartform
*& Form send_pdf_mail
text
--> p1 text
<-- p2 text
form send_pdf_mail .
data ld_binfile type xstring.
pdf_table type rcl_bag_tline,
data: ld_originator like soos1-recextnam.
convert form
loop at job_output_info-otfdata into hotfdata.
append hotfdata.
endloop.
call function 'CONVERT_OTF'
exporting
format = format_pdf
max_linewidth = 132
importing
bin_filesize = doc_size
bin_file = ld_binfile
tables
otf = output_data-otfdata
lines = htline
exceptions
err_max_linewidth = 1
err_format = 2
err_conv_not_possible = 3
others = 4.
*-Itab 134 Zeichen nach 255 Zeichen überführen
describe table htline lines hltlines.
describe field htline length fle1 in character mode.
describe field x_objcont length fle2 in character mode.
loop at htline.
htabix = sy-tabix.
move htline to hfeld+off1.
if htabix = hltlines.
fle1 = strlen( htline ).
endif.
off1 = off1 + fle1.
if off1 ge fle2.
clear x_objcont.
x_objcont = hfeld(fle2).
append x_objcont.
shift hfeld by fle2 places.
off1 = off1 - fle2.
endif.
if htabix = hltlines.
if off1 gt 0.
clear x_objcont.
x_objcont = hfeld(off1).
append x_objcont.
endif.
endif.
endloop.
x_object_hd_change-objnam = 'EMAIL'.
x_object_hd_change-objdes = 'Smart Form'.
x_object_hd_change-objla = sy-langu.
x_object_hd_change-objsns = 'O'.
x_object_hd_change-objlen = doc_size.
x_object_hd_change-file_ext = 'TXT'.
ld_packing_list-transf_bin = 'X'.
ld_packing_list-head_start = 1.
ld_packing_list-head_num = 0.
ld_packing_list-body_start = 1.
describe table x_objcont lines ld_packing_list-body_num.
ld_packing_list-objtp = 'EXT'.
ld_packing_list-objdes = 'Smart Form'.
ld_packing_list-objla = sy-langu.
ld_packing_list-objlen = doc_size.
ld_packing_list-file_ext = 'PDF'.
append ld_packing_list.
x_receivers-recextnam = g_mail.
x_receivers-recesc = 'E'.
x_receivers-sndart = 'INT'.
append x_receivers.
ld_originator = '[email protected]'.
ld_originator = FSABE-USRNAM.
call function 'SO_OBJECT_SEND'
exporting
object_hd_change = x_object_hd_change
object_type = 'RAW'
originator_type = 'B' "Einfügen
originator = ld_originator "Einfügen
tables
objcont = ld_text
receivers = x_receivers
packing_list = ld_packing_list
att_cont = x_objcont
att_head = x_objhead
exceptions
active_user_not_exist = 1
communication_failure = 2
component_not_available = 3
folder_not_exist = 4
folder_no_authorization = 5
forwarder_not_exist = 6
note_not_exist = 7
object_not_exist = 8
object_not_sent = 9
object_no_authorization = 10
object_type_not_exist = 11
operation_no_authorization = 12
owner_not_exist = 13
parameter_error = 14
substitute_not_active = 15
substitute_not_defined = 16
system_failure = 17
too_much_receivers = 18
user_not_exist = 19
x_error = 20
others = 21.
endform. " send_pdf_mail
*& Form mail_sender_object
text
<--P_G_MAIL_SEN_OBJ text
form mail_sender_object changing p_mail_sen_obj.
call function 'CREATE_SENDER_OBJECT_PPF'
exporting
ip_sender = sy-uname
importing
ep_sender_id = p_mail_sen_obj
exceptions
invalid_sender = 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.
endform. " mail_sender_object
*& Form mail_appl_object
text
<--P_G_MAIL_APP_OBJ text
form mail_appl_object changing p_mail_app_obj.
SELECT * FROM soud WHERE sapnam LIKE sy-uname AND deleted = ' '.
ENDSELECT.
IF sy-subrc NE 0.
call function 'SO_USER_AUTOMATIC_INSERT'
exporting
sapname = sy-uname
exceptions
no_insert = 1
sap_name_exist = 2
x_error = 3
others = 4.
if sy-subrc ne 0.
clear soud.
else.
select * from soud where sapnam like sy-uname and deleted = ' '.
endselect.
endif.
ENDIF.
clear sofmfol_key.
sofmfol_key-type = 'FOL'.
sofmfol_key-year = soud-inbyr.
sofmfol_key-number = soud-inbno.
bor_key = sofmfol_key.
if not bor_key is initial.
swc_create_object folder 'SOFMFOL' bor_key.
if sy-subrc = 0.
swc_object_to_persistent folder p_mail_app_obj.
if sy-subrc ne 0.
clear p_mail_app_obj.
endif.
endif.
else.
clear p_mail_app_obj.
endif.
endform. " mail_appl_object
*& Form mail_recipient_object
text
<--P_G_MAIL_REC_OBJ text
form mail_recipient_object changing p_mail_rec_obj.
call function 'CREATE_RECIPIENT_OBJ_PPF'
exporting
IP_COUNTRY =
IP_FAXNO =
ip_mailaddr = g_mail
ip_type_id = g_rectype " 'U'
importing
ep_recipient_id = p_mail_rec_obj
EP_ADDRESS =
ET_RECIPIENT =
exceptions
invalid_recipient = 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.
endform. " mail_recipient_object
I hope this code should definitely work and helps you a lot.
Do reward me if it helps you.
Cheers,
Sampath
Similar Messages
-
How to send smartform output through mail in PDF Format
Can some one provide me the sample code
Edited by: Revankar Satej on Feb 22, 2008 1:22 PMHi,
try this code,HOPE usefull to u, Reaward points
*& Report ZTEST_SMARTFORM
REPORT ztest_smartform.
DATA: formname TYPE tdsfname,
fm_name TYPE rs38l_fnam,
control_parameters TYPE ssfctrlop,
job_output_info TYPE ssfcrescl,
otf_data TYPE tsfotf,
bin_filesize TYPE i,
otf TYPE TABLE OF itcoo WITH HEADER LINE,
doctab_archive TYPE TABLE OF docs WITH HEADER LINE,
lines TYPE TABLE OF tline WITH HEADER LINE.
INITIALIZATION.
formname = 'UR SMART FORM'.
START-OF-SELECTION.
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.
control_parameters-no_dialog = 'X'.
control_parameters-preview = ''.
control_parameters-getotf = 'X'.
CALL FUNCTION fm_name
EXPORTING
ARCHIVE_INDEX = ARCHIVE_INDEX
ARCHIVE_INDEX_TAB = ARCHIVE_INDEX_TAB
ARCHIVE_PARAMETERS = ARCHIVE_PARAMETERS
control_parameters = control_parameters
MAIL_APPL_OBJ = MAIL_APPL_OBJ
MAIL_RECIPIENT = MAIL_RECIPIENT
MAIL_SENDER = MAIL_SENDER
OUTPUT_OPTIONS = OUTPUT_OPTIONS
USER_SETTINGS = 'X'
IMPORTING
DOCUMENT_OUTPUT_INFO = DOCUMENT_OUTPUT_INFO
job_output_info = job_output_info
JOB_OUTPUT_OPTIONS = JOB_OUTPUT_OPTIONS
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.
otf_data[] = job_output_info-otfdata[].
CALL FUNCTION 'CONVERT_OTF_2_PDF'
EXPORTING
USE_OTF_MC_CMD = 'X'
ARCHIVE_INDEX = ARCHIVE_INDEX
IMPORTING
bin_filesize = bin_filesize
TABLES
otf = otf_data[]
doctab_archive = doctab_archive[]
lines = 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.
DATA: filename TYPE string.
filename = 'c:\test\smart.pdf'.
CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
bin_filesize = bin_filesize
filename = filename
filetype = 'BIN'
APPEND = ' '
WRITE_FIELD_SEPARATOR = ' '
HEADER = '00'
TRUNC_TRAILING_BLANKS = ' '
WRITE_LF = 'X'
COL_SELECT = ' '
COL_SELECT_MASK = ' '
DAT_MODE = ' '
CONFIRM_OVERWRITE = ' '
NO_AUTH_CHECK = ' '
CODEPAGE = ' '
IGNORE_CERR = ABAP_TRUE
REPLACEMENT = '#'
WRITE_BOM = ' '
TRUNC_TRAILING_BLANKS_EOL = 'X'
WK1_N_FORMAT = ' '
WK1_N_SIZE = ' '
WK1_T_FORMAT = ' '
WK1_T_SIZE = ' '
IMPORTING
FILELENGTH = FILELENGTH
TABLES
data_tab = lines[]
FIELDNAMES = 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
IF sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
DATA: document_data LIKE sodocchgi1 ,
contents_txt TYPE TABLE OF solisti1 WITH HEADER LINE,
contents_bin TYPE TABLE OF solisti1 WITH HEADER LINE,
tab_lines TYPE i,
packing_list TYPE TABLE OF sopcklsti1 WITH HEADER LINE,
OBJECT_HEADER type table of SOLISTI1 with header line,
RECEIVERS TYPE TABLE OF SOMLRECI1 WITH HEADER LINE,
l_str(255) ,
v1 TYPE i,
v2 TYPE i,
v3 type i.
CONSTANTS: c_raw TYPE so_obj_tp VALUE 'RAW',
c_pdf TYPE so_obj_tp VALUE 'PDF',
c_255 TYPE i VALUE 255,
c_134 TYPE i VALUE 134,
C_X TYPE C VALUE 'X',
C_U TYPE C VALUE 'U'.
document_data-obj_name = 'EMAIL'.
document_data-obj_descr = 'subject'.
contents_txt = 'THIS IS first line DATA'.
APPEND contents_txt.
CLEAR contents_txt.
contents_txt = 'THIS IS second line DATA'.
APPEND contents_txt.
CLEAR contents_txt.
APPEND contents_txt.
APPEND contents_txt.
DESCRIBE TABLE contents_txt LINES tab_lines.
READ TABLE contents_txt INDEX tab_lines.
document_data-doc_size = ( tab_lines - 1 ) * 255 + STRLEN( contents_txt ).
document_data-doc_size = tab_lines .
CLEAR packing_list-transf_bin.
packing_list-head_start = 1.
packing_list-head_num = 0.
packing_list-body_start = 1.
packing_list-body_num = tab_lines.
packing_list-doc_type = c_raw.
packing_list-doc_size = document_data-doc_size.
APPEND packing_list.
LOOP AT lines.
CLEAR l_str.
l_str+0(2) = lines-tdformat.
l_str+2(132) = lines-tdline.
v2 = v1 + c_134.
IF v2 LE c_255.
contents_bin-line+v1(c_134) = l_str. v1 = v2.
ELSE.
v3 = v2 - c_255.
v2 = c_255 - v1.
IF NOT v2 IS INITIAL.
contents_bin-linev1(v2) = l_str0(v2).
ENDIF.
APPEND contents_bin.
CLEAR contents_bin.
v1 = v3.
v3 = 134 - v1.
IF NOT v1 IS INITIAL.
contents_bin-line0(v1) = l_strv3(v1).
ENDIF.
ENDIF.
ENDLOOP.
APPEND contents_bin.
CLEAR contents_bin.
DESCRIBE TABLE contents_bin LINES tab_lines.
READ TABLE contents_bin INDEX tab_lines.
OBJECT_HEADER = 'objhead'.
APPEND OBJECT_HEADER.
packing_list-transf_bin = c_x.
packing_list-head_start = 1.
packing_list-head_num = 1.
packing_list-body_start = 1.
packing_list-body_num = tab_lines.
packing_list-doc_type = c_pdf.
packing_list-obj_name = 'text1'.
packing_list-obj_descr = 'filename'.
packing_list-doc_size = tab_lines * 255 + STRLEN( contents_bin ).
APPEND packing_list.
RECEIVERS-receiver = 'UR EMAIL ADDRESS IN CAPS'.
RECEIVERS-rec_type = c_u.
APPEND RECEIVERS.
CLEAR RECEIVERS.
CALL FUNCTION 'SO_DOCUMENT_SEND_API1'
EXPORTING
document_data = document_data
PUT_IN_OUTBOX = 'X'
SENDER_ADDRESS = SY-UNAME
SENDER_ADDRESS_TYPE = 'B'
COMMIT_WORK = 'X'
IMPORTING
SENT_TO_ALL =
NEW_OBJECT_ID = NEW_OBJECT_ID
SENDER_ID = SENDER_ID
TABLES
packing_list = packing_list
OBJECT_HEADER = OBJECT_HEADER
CONTENTS_BIN = CONTENTS_BIN
CONTENTS_TXT = CONTENTS_TXT
CONTENTS_HEX = CONTENTS_HEX
OBJECT_PARA = OBJECT_PARA
OBJECT_PARB = OBJECT_PARB
receivers = 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 ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
Regards
SFT -
Error while sending PO output through mail in PDF format - Urgent
Dear friends,
Developed program to send sapscript output through mail in pdf format, the program running properly, even function module SO_NEW_DOCUMENT_ATT_SEND_API1 returning sy-subrc 0. But the external mail is not going to user lying in SAP outbox with message <b>"Wait for communications service"</b> . SCOT is properly configured, tested mails sending through SAP office.
Find below the source code:
REPORT zmm_porder_gm
NO STANDARD PAGE HEADING.
TABLES: ekko, ekpa, t161t, t052, komv, j_1imocomp, t001, esll.
Internal Tables
DATA : txt LIKE tline-tdline, "HEADER LINE
your_ref LIKE ekko-ihrez, "your ref
our_ref LIKE ekko-unsez, "our ref
mcompname LIKE t001-butxt,
itemname LIKE ekpo-txz01,
del_text LIKE tline-tdline, "delivery text
mat_po_text LIKE tline-tdline. "material po text
DATA: g_ind TYPE i.
DATA: it_esll LIKE esll OCCURS 0 WITH HEADER LINE.
DATA: sub_packno LIKE esll-sub_packno.
DATA : po_flag(1) TYPE c.
DATA : it_erev LIKE erev OCCURS 0 WITH HEADER LINE.
DATA : nmebeln LIKE thead-tdname,
obj LIKE thead-tdname.
DATA : tline LIKE tline OCCURS 0 WITH HEADER LINE. "HEADER TEXT
DATA : it_ekko LIKE ekko OCCURS 0 WITH HEADER LINE.
DATA : it_ekpo LIKE ekpo OCCURS 0 WITH HEADER LINE.
DATA : it_zmm_porder LIKE zmm_porder OCCURS 0 WITH HEADER LINE.
DATA : it_konv LIKE konv OCCURS 0 WITH HEADER LINE.
DATA : it_konv_ftr LIKE konv OCCURS 0 WITH HEADER LINE.
DATA : it_konv_rate LIKE konv OCCURS 0 WITH HEADER LINE.
DATA : it_komv_tax LIKE komv OCCURS 0 WITH HEADER LINE. " For Tax Calculation
DATA : it_zmm_house_bank LIKE zmm_house_bank OCCURS 0 WITH HEADER LINE.
*DATA : mrate TYPE konv-kbetr VALUE 0, mrate1(15). rmoved by ganes and added following logic
DATA : mrate TYPE p VALUE 0 DECIMALS 2, mrate1(15).
DATA : mrate_gm TYPE p DECIMALS 2.
DATA : BEGIN OF it_konv1 OCCURS 0,
knumv LIKE konv-knumv,
kschl LIKE konv-kschl,
END OF it_konv1.
DATA : BEGIN OF it_t052u OCCURS 0.
INCLUDE STRUCTURE t052u.
DATA : END OF it_t052u.
DATA : mpay_terms LIKE t052u-text1.
DATA : mwaers LIKE konv-waers.
DATA : BEGIN OF xt052 OCCURS 0.
INCLUDE STRUCTURE t052.
DATA : END OF xt052.
DATA : it_t16ct LIKE t16ct OCCURS 0 WITH HEADER LINE.
DATA : BEGIN OF ztext OCCURS 0.
INCLUDE STRUCTURE ttext.
DATA : END OF ztext.
DATA : it_t001 LIKE t001 OCCURS 0 WITH HEADER LINE.
DATA : mtext(15) TYPE c.
DATA : it_adrc LIKE adrc OCCURS 0 WITH HEADER LINE.
DATA : it_adrc_ven LIKE adrc OCCURS 0 WITH HEADER LINE.
DATA : it_adrc_plt LIKE adrc OCCURS 0 WITH HEADER LINE.
DATA : it_makt LIKE makt OCCURS 0 WITH HEADER LINE.
DATA : it_eket LIKE eket OCCURS 0 WITH HEADER LINE. " Schedulling
DATA : it_eikp LIKE eikp OCCURS 0 WITH HEADER LINE. " Export
DATA : it_t001w LIKE t001w OCCURS 0 WITH HEADER LINE.
DATA : it_t685t LIKE t685t OCCURS 0 WITH HEADER LINE.
DATA : it_t618t LIKE t618t OCCURS 0 WITH HEADER LINE.
DATA : it_t685t_ftr LIKE t685t OCCURS 0 WITH HEADER LINE.
DATA : it_lfa1 LIKE lfa1 OCCURS 0 WITH HEADER LINE.
DATA : it_bapi_mltx_ga LIKE bapi_mltx_ga OCCURS 0 WITH HEADER LINE. "Material long text
DATA : mfirst TYPE i VALUE 0,
mpay_flag(1) TYPE c VALUE 'X',
mwerks LIKE t001w-werks,
msr TYPE i VALUE 0,
l_rate TYPE p DECIMALS 2 VALUE 0,
l_amt TYPE p DECIMALS 2 VALUE 0,
mflag(1) TYPE c,
mlctr TYPE i VALUE 0,
mfamt TYPE p DECIMALS 2 VALUE 0,
mcfamt(15) TYPE c,
mfword(100) TYPE c,
mkschl LIKE konv-kschl,
mchgamt TYPE p DECIMALS 2 VALUE 0,
mkbetr TYPE p DECIMALS 2 VALUE 0,
mkwert TYPE p DECIMALS 2 VALUE 0.
DATA : j_1iexcd TYPE j_1imocomp-j_1iexcd,
j_1icstno TYPE j_1imocomp-j_1icstno,
j_1ilstno TYPE j_1imocomp-j_1ilstno.
DATA : mjmop_r TYPE p DECIMALS 2 VALUE 0,
mjmoq_r TYPE p DECIMALS 2 VALUE 0,
mjecs_r TYPE p DECIMALS 2 VALUE 0,
mjvcs_r TYPE p DECIMALS 2 VALUE 0,
mjvrd_r TYPE p DECIMALS 2 VALUE 0,
mjsep_r TYPE p DECIMALS 2 VALUE 0.
DATA : mjmop_a TYPE p DECIMALS 2 VALUE 0,
mjmoq_a TYPE p DECIMALS 2 VALUE 0,
mjecs_a TYPE p DECIMALS 2 VALUE 0,
mjvcs_a TYPE p DECIMALS 2 VALUE 0,
mjvrd_a TYPE p DECIMALS 2 VALUE 0,
mjsep_a TYPE p DECIMALS 2 VALUE 0.
DATA : mtitle LIKE t161t-batxt.
DATA : no_ammend(10),request_by(50),ver_txt(100),ver_reason(100),stext(200).
begin of Email data declarations**************
DATA: BEGIN OF otf OCCURS 0.
INCLUDE STRUCTURE itcoo .
DATA: END OF otf.
DATA: itcpo LIKE itcpo.
DATA: itcpp LIKE itcpp.
DATA: it_docs TYPE STANDARD TABLE OF docs,
v_bin_filesize TYPE i,
it_lines TYPE STANDARD TABLE OF tline,
wa_lines TYPE tline.
DATA : i_pdf LIKE tline OCCURS 1000 WITH HEADER LINE,
v_pdf_bytecount TYPE i,
v_pdf_spoolid TYPE tsp01-rqident,
v_otf_pagecount TYPE i,
v_btc_jobname TYPE tbtcjob-jobname,
v_btc_jobcount TYPE tbtcjob-jobcount.
DATA: objpack LIKE sopcklsti1 OCCURS 0 WITH HEADER LINE.
DATA: objhead LIKE solisti1 OCCURS 1 WITH HEADER LINE.
DATA: objbin LIKE solisti1 OCCURS 0 WITH HEADER LINE.
DATA: objtxt LIKE solisti1 OCCURS 10 WITH HEADER LINE.
DATA: reclist LIKE somlreci1 OCCURS 0 WITH HEADER LINE.
DATA: doc_chng LIKE sodocchgi1.
DATA: tab_lines LIKE sy-tabix.
DATA: vafilename(100) VALUE 'po_output.pdf'.
DATA: jobdata TYPE sxjobdata.
DATA arc_params TYPE arc_params.
DATA print_params TYPE pri_params.
DATA g_send_prog TYPE syrepid VALUE 'ZVF03_TEST_PROG'.
DATA immediate TYPE btcchar1.
DATA: i_jobname TYPE tbtcp-jobname,
i_jobcount TYPE tbtcp-jobcount,
i_jobstepcount TYPE tbtcp-stepcount.
DATA recipient_obj LIKE swotobjid.
CONSTANTS: sx_true TYPE sx_boolean VALUE 'X'.
TABLES: tbtcp.
end of Email data declarations**************
SELECTION-SCREEN : BEGIN OF BLOCK block1 WITH FRAME TITLE text-001.
SELECT-OPTIONS : mebeln FOR ekko-ebeln OBLIGATORY . " 75
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN POSITION 12.
SELECTION-SCREEN COMMENT (20) text-b01.
PARAMETERS: b1 AS CHECKBOX DEFAULT 'X'.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN : END OF BLOCK block1.
SELECTION-SCREEN: BEGIN OF SCREEN 200 TITLE text-001 AS WINDOW.
PARAMETERS : p_email TYPE ad_smtpadr. "E-Mail Address
SELECTION-SCREEN: END OF SCREEN 200.
INITIALIZATION.
SET PF-STATUS 'ZMMPORD_STAT'.
AT SELECTION-SCREEN.
CASE sy-ucomm.
WHEN 'EMAIL'.
PERFORM zemail.
WHEN '&IC1'.
PERFORM load_data.
PERFORM process.
IF NOT p_email IS INITIAL.
PERFORM send_mail.
ENDIF.
ENDCASE.
*START-OF-SELECTION.
PERFORM load_data.
PERFORM process.
FORM load_data .
DATA : gindex LIKE sy-tabix.
SELECT * FROM t16ct INTO TABLE it_t16ct WHERE spras = 'EN'.
SELECT * FROM ekko INTO TABLE it_ekko WHERE ebeln IN mebeln.
IF sy-subrc EQ 0.
SELECT * FROM erev INTO CORRESPONDING FIELDS OF TABLE it_erev FOR ALL ENTRIES IN it_ekko
WHERE edokn = it_ekko-ebeln AND rscod <> '' .
SORT it_erev BY edokn revno DESCENDING.
LOOP AT it_ekko.
IF NOT ( it_ekko-frgke EQ 'O' OR it_ekko-frgke EQ '0' ) .
MESSAGE e000(zsd) WITH 'Purchase Order is not Realeased'.
ENDIF.
ENDLOOP.
SELECT * FROM ekpo INTO TABLE it_ekpo WHERE ebeln IN mebeln.
IF sy-subrc EQ 0.
SELECT * INTO TABLE it_makt
FROM makt
FOR ALL ENTRIES IN it_ekpo
WHERE matnr EQ it_ekpo-matnr.
SELECT * INTO TABLE it_lfa1
FROM lfa1
FOR ALL ENTRIES IN it_ekko
WHERE lifnr EQ it_ekko-lifnr.
ENDIF.
SELECT *
INTO TABLE it_t052u
FROM t052u
FOR ALL ENTRIES IN it_ekko
WHERE zterm EQ it_ekko-zterm
AND spras EQ 'EN'.
IF sy-subrc EQ 0.
SORT it_t052u BY zterm.
ENDIF.
SELECT * FROM eket INTO TABLE it_eket WHERE ebeln IN mebeln.
IF sy-subrc EQ 0.
SORT it_eket BY ebeln ebelp.
ENDIF.
SELECT *
INTO TABLE it_eikp
FROM eikp
FOR ALL ENTRIES IN it_ekko
WHERE exnum EQ it_ekko-exnum.
IF sy-subrc EQ 0.
SORT it_eikp BY exnum.
SELECT *
INTO TABLE it_t618t
FROM t618t
FOR ALL ENTRIES IN it_eikp
WHERE expvz EQ it_eikp-expvz
AND spras EQ 'E'
AND land1 EQ 'IN'.
IF sy-subrc EQ 0.
SORT it_t618t BY expvz.
ENDIF.
ENDIF.
REFRESH : it_zmm_porder.
CLEAR : it_zmm_porder.
SELECT * INTO TABLE it_zmm_porder
FROM zmm_porder
WHERE flag EQ 'L'.
IF sy-subrc EQ 0.
SORT it_zmm_porder BY kschl.
ENDIF.
SELECT * FROM konv INTO TABLE it_konv
FOR ALL ENTRIES IN it_ekko
WHERE knumv = it_ekko-knumv
AND kwert NE 0.
LOOP AT it_konv.
gindex = sy-tabix.
READ TABLE it_zmm_porder WITH KEY kschl = it_konv-kschl BINARY SEARCH.
IF sy-subrc NE 0.
DELETE it_konv INDEX gindex.
ENDIF.
ENDLOOP.
IF sy-subrc EQ 0.
SORT it_konv BY knumv kherk kschl.
ENDIF.
REFRESH : it_zmm_porder.
CLEAR : it_zmm_porder.
SELECT * INTO TABLE it_zmm_porder
FROM zmm_porder
WHERE flag EQ 'F'.
IF sy-subrc EQ 0.
SORT it_zmm_porder BY kschl.
ENDIF.
SELECT * INTO TABLE IT_KONV_FTR FROM KONV
FOR ALL ENTRIES IN IT_EKKO
WHERE KNUMV = IT_EKKO-KNUMV
AND ( KSCHL = 'ZIN1'
OR KSCHL = 'ZIN2'
OR KSCHL = 'ZINS'
OR KSCHL = 'ZPF1'
OR KSCHL = 'ZPF2'
OR KSCHL = 'ZPF3'
OR KSCHL = 'ZPKG'
OR KSCHL = 'ZPKF'
OR KSCHL = 'FRA1'
OR KSCHL = 'FRB1'
OR KSCHL = 'FRC1'
OR KSCHL = 'FRD1'
OR KSCHL = 'FRD2'
OR KSCHL = 'FRD3'
OR KSCHL = 'FRD4'
OR KSCHL = 'FRD5'
*****Added one condition type below ZFBC as on 05.06.2007 :Rajiv as per mail of Sadiq via mathew sir(RTDK906646)
OR KSCHL = 'ZFBC' )
AND KWERT NE 0
AND KPOSN GT '000000'.
AND ( KRECH = 'B' " RTDK906167
OR KRECH = 'A' ).
SELECT * INTO TABLE it_konv_ftr FROM konv
FOR ALL ENTRIES IN it_ekko
WHERE knumv = it_ekko-knumv
AND kwert NE 0
AND kposn GT '000000'.
LOOP AT it_konv_ftr.
gindex = sy-tabix.
READ TABLE it_zmm_porder WITH KEY kschl = it_konv_ftr-kschl BINARY SEARCH.
IF sy-subrc NE 0.
DELETE it_konv_ftr INDEX gindex.
ENDIF.
ENDLOOP.
IF it_konv_ftr[] IS NOT INITIAL.
SORT it_konv_ftr BY knumv kschl.
ENDIF.
SELECT KNUMV KSCHL INTO CORRESPONDING FIELDS OF TABLE IT_KONV1 FROM KONV
FOR ALL ENTRIES IN IT_EKKO
WHERE KNUMV = IT_EKKO-KNUMV
and kherk = 'D'
AND ( KSCHL = 'ZIN1'
OR KSCHL = 'ZIN2'
OR KSCHL = 'ZINS'
OR KSCHL = 'ZPF1'
OR KSCHL = 'ZPF2'
OR KSCHL = 'ZPF3'
OR KSCHL = 'ZPKG'
OR KSCHL = 'ZPKF'
OR KSCHL = 'FRA1'
OR KSCHL = 'FRB1'
OR KSCHL = 'FRC1'
OR KSCHL = 'FRD1'
OR KSCHL = 'FRD2'
OR KSCHL = 'FRD3'
OR KSCHL = 'FRD4'
OR KSCHL = 'FRD5'
*****Added one condition type below ZFBC as on 05.06.2007 :Rajiv as per mail of Sadiq via mathew sir(RTDK906646)
OR KSCHL = 'ZFBC' )
AND KWERT NE 0.
AND ( KRECH = 'B' RTDK906167
OR KRECH = 'A' ).
SELECT knumv kschl INTO CORRESPONDING FIELDS OF TABLE it_konv1 FROM konv
FOR ALL ENTRIES IN it_ekko
WHERE knumv = it_ekko-knumv
AND kwert NE 0.
DELETE ADJACENT DUPLICATES FROM it_konv1 COMPARING knumv kschl.
LOOP AT it_konv1.
gindex = sy-tabix.
READ TABLE it_zmm_porder WITH KEY kschl = it_konv1-kschl BINARY SEARCH.
IF sy-subrc NE 0.
DELETE it_konv1 INDEX gindex.
ENDIF.
ENDLOOP.
IF sy-subrc EQ 0.
SORT it_konv1 BY knumv kschl.
ENDIF.
SELECT * INTO TABLE it_t685t
FROM t685t
FOR ALL ENTRIES IN it_konv
WHERE kschl EQ it_konv-kschl
AND kappl EQ it_konv-kappl
AND spras EQ 'E'.
SELECT * INTO TABLE it_t685t_ftr
FROM t685t
FOR ALL ENTRIES IN it_konv_ftr
WHERE kschl EQ it_konv_ftr-kschl
AND kappl EQ it_konv_ftr-kappl
AND spras EQ 'E'.
it_t685t_ftr-kschl = 'JVCS'.
it_t685t_ftr-vtext = 'IN CST in vat'.
APPEND it_t685t_ftr.
SELECT * INTO TABLE it_zmm_house_bank
FROM zmm_house_bank
WHERE ebeln IN mebeln.
ELSE.
MESSAGE e899(mm) WITH 'Data not found for selection criteria...'.
ENDIF.
ENDFORM. " Load_data
FORM process .
DATA : mctr TYPE i VALUE 1.
DATA : gindex LIKE sy-tabix.
DATA : mline(75) TYPE c.
DATA : mlifn2 LIKE ekpa-lifn2.
DATA : mv_name LIKE lfa1-name1,
madrnr LIKE lfa1-adrnr.
CLEAR itcpo.
itcpo-tdgetotf = 'X'.
CALL FUNCTION 'OPEN_FORM'
EXPORTING
form = 'ZMM_PORDER'
language = sy-langu
OPTIONS = itcpo
dialog = ' '
EXCEPTIONS
OTHERS = 1.
LOOP AT it_ekko.
CALL FUNCTION 'START_FORM'
EXPORTING
form = 'ZMM_PORDER'.
SELECT SINGLE *
FROM t001
INTO it_t001
WHERE bukrs EQ it_ekko-bukrs.
mcompname = it_t001-butxt.
TRANSLATE mcompname TO UPPER CASE.
Document Type
SELECT SINGLE batxt
INTO mtitle
FROM t161t
WHERE bstyp EQ 'F'
AND spras EQ 'E'
AND bsart EQ it_ekko-bsart.
REFRESH it_adrc.
SELECT SINGLE werks
INTO mwerks
FROM ekpo
WHERE ebeln EQ it_ekko-ebeln.
SELECT SINGLE *
INTO it_t001w
FROM t001w
WHERE werks EQ mwerks.
REFRESH it_adrc.
SELECT SINGLE *
INTO it_adrc_plt
FROM adrc
WHERE addrnumber EQ it_t001w-adrnr.
REFRESH : xt052.
mfamt = 0.
msr = 0.
in 500c this statement failed.
SELECT SINGLE * FROM T052 INTO XT052 WHERE ZTERM = IT_EKKO-ZTERM.
CALL FUNCTION 'FI_TEXT_ZTERM'
EXPORTING
I_T052 = XT052
TABLES
T_ZTEXT = ZTEXT.
As per Preeti... Shipment address should be shown on top as purchase order company address. 27.04.
PERFORM writeform USING 'PLANT' 'PLANT'.
SELECT SINGLE name1 adrnr
INTO (mv_name,madrnr)
FROM lfa1
WHERE lifnr EQ it_ekko-lifnr.
REFRESH it_adrc[].
CLEAR it_adrc[].
FREE it_adrc[].
SELECT SINGLE *
INTO it_adrc_ven
FROM adrc
WHERE addrnumber EQ madrnr.
READ TABLE it_lfa1 WITH KEY lifnr = it_ekko-lifnr.
PERFORM writeform USING 'VENDOR' 'VENDOR'.
Shipment
SELECT SINGLE werks
INTO mwerks
FROM ekpo
WHERE ebeln EQ it_ekko-ebeln.
up to 1 rows.
SELECT SINGLE *
INTO it_t001w
FROM t001w
WHERE werks EQ mwerks.
SELECT SINGLE j_1iexcd j_1icstno j_1ilstno
INTO (j_1iexcd,j_1icstno,j_1ilstno)
FROM j_1imocomp
WHERE werks = mwerks.
REFRESH it_adrc.
SELECT SINGLE *
INTO it_adrc
FROM adrc
WHERE addrnumber EQ it_t001w-adrnr.
PERFORM writeform USING 'SHIPMNT' 'SHIPMNT'.
READ TABLE it_eikp WITH KEY exnum = it_ekko-exnum.
IF sy-subrc EQ 0.
READ TABLE it_t618t WITH KEY expvz = it_eikp-expvz.
ENDIF.
your_ref = it_ekko-ihrez.
our_ref = it_ekko-unsez.
READ TABLE it_erev WITH KEY edokn = it_ekko-ebeln.
IF sy-subrc = 0.
no_ammend = it_erev-revno.
request_by = it_erev-crnam.
ver_txt = it_erev-txz01.
READ TABLE it_t16ct WITH KEY rscod = it_erev-rscod.
IF sy-subrc = 0.
ver_reason = it_t16ct-rstxt.
ELSE.
ver_reason = ''.
ENDIF.
ELSE.
no_ammend = ''.
request_by = ''.
ver_txt = ''.
ver_reason = ''.
ENDIF.
PERFORM writeform USING 'PO_INFO' 'PO_INFO'.
IF it_zmm_house_bank[] IS NOT INITIAL.
READ TABLE it_zmm_house_bank INDEX 1.
PERFORM writeform USING 'BANKDTL' 'BANKDTL'.
ENDIF.
PERFORM writeform USING 'HDR_INFO' 'HDR_INFO'.
PERFORM writeform USING 'BRK_TTL' 'MAIN'.
msr = 1.
mlctr = 1.
*added by ganesh to prevent deleted items to appear in print out
LOOP AT IT_EKPO WHERE EBELN EQ IT_EKKO-EBELN.
LOOP AT it_ekpo WHERE ebeln EQ it_ekko-ebeln AND loekz NE 'L'.
*end of change
CLEAR: mrate, mrate1.
SELECT * FROM konv INTO TABLE it_konv_rate
WHERE knumv EQ it_ekko-knumv
AND kposn EQ it_ekpo-ebelp
AND ( kschl EQ 'PBXX' OR kschl EQ 'PB00' OR kschl EQ 'P001' ).
LOOP AT it_konv_rate.
IF it_konv_rate-kpein > 0. " added by ganesh as per sudhir 12.10.2007
mrate_gm = it_konv_rate-kbetr / it_konv_rate-kpein.
mrate = mrate + mrate_gm. " added by ganesh as per sudhir 12.10.2007
ELSE.
mrate = mrate + it_konv_rate-kbetr.
ENDIF.
IF it_konv_rate-waers IS NOT INITIAL.
mwaers = it_konv_rate-waers.
ENDIF.
ENDLOOP.
For Japanies Yen "RTDK906759
IF it_ekko-waers = 'JPY'.
mrate = mrate * 100.
ENDIF.
End for japanies Yen
mrate1 = mrate.
End rate
mfirst = 0.
MFAMT = MFAMT + ( IT_EKPO-NETPR * IT_EKPO-MENGE ).
mfamt = mfamt + ( mrate * it_ekpo-menge ).
PERFORM get_mat_long_text.
DATA: lt_ctr TYPE i VALUE 0,lt_ctr1 TYPE i, lt_count TYPE i VALUE 0. " Long text counter
DESCRIBE TABLE it_bapi_mltx_ga LINES lt_count.
CLEAR it_bapi_mltx_ga.
*Added by Rajiv 10.05.2007 Read and if condition RTDK906165
READ TABLE it_konv WITH KEY knumv = it_ekko-knumv
kposn = it_ekpo-ebelp.
mkbetr = 0.
mkwert = 0.
IF sy-subrc EQ 0.
LOOP AT it_konv WHERE knumv EQ it_ekko-knumv
AND kposn EQ it_ekpo-ebelp.
IF it_konv-krech EQ 'A'.
mkbetr = it_konv-kbetr / 10.
ELSE.
mkbetr = it_konv-kbetr.
ENDIF.
For Japanies Yen "RTDK906759
IF it_ekko-waers = 'JPY'.
mkbetr = mkbetr * 100.
ENDIF.
End for japaies Yen
IF mkbetr LT '0'.
mkbetr = mkbetr * ( -1 ).
ENDIF.
mkwert = it_konv-kwert.
For Japanies Yen "RTDK906759
IF it_ekko-waers = 'JPY'.
mkwert = mkwert * 100.
ENDIF.
End for japaies Yen
mfamt = mfamt + mkwert.
IF mkwert LT '0'.
mkwert = mkwert * ( -1 ).
ENDIF.
IF it_ekpo-matnr IS INITIAL.
itemname = it_ekpo-txz01.
ELSE.
READ TABLE it_makt WITH KEY matnr = it_ekpo-matnr.
itemname = it_makt-maktx.
ENDIF.
READ TABLE it_t685t WITH KEY kschl = it_konv-kschl BINARY SEARCH.
READ TABLE it_eket WITH KEY ebeln = it_ekpo-ebeln
ebelp = it_ekpo-ebelp BINARY SEARCH.
IF mfirst EQ 0.
PERFORM writeform USING 'BRK_INFO' 'MAIN'.
mfirst = 1.
ELSE.
ADD 1 TO lt_ctr.
CLEAR it_bapi_mltx_ga.
READ TABLE it_bapi_mltx_ga INDEX lt_ctr. "For long text
IF sy-subrc NE 0.
CLEAR it_bapi_mltx_ga.
ENDIF.
PERFORM writeform USING 'BRK_INFO1' 'MAIN'.
ENDIF.
mlctr = mlctr + 1.
ENDLOOP. " it_konv.
ELSE.
IF it_ekpo-matnr IS INITIAL.
itemname = it_ekpo-txz01.
ELSE.
READ TABLE it_makt WITH KEY matnr = it_ekpo-matnr.
itemname = it_makt-maktx.
ENDIF.
READ TABLE IT_T685T WITH KEY KSCHL = IT_KONV-KSCHL BINARY SEARCH.
READ TABLE it_eket WITH KEY ebeln = it_ekpo-ebeln
ebelp = it_ekpo-ebelp BINARY SEARCH.
mfirst = 0.
IF mfirst EQ 0.
PERFORM writeform USING 'BRK_INFO' 'MAIN'.
mfirst = 1.
ELSE.
ADD 1 TO lt_ctr.
CLEAR it_bapi_mltx_ga.
READ TABLE it_bapi_mltx_ga INDEX lt_ctr. "For long text
IF sy-subrc NE 0.CLEAR it_bapi_mltx_ga.ENDIF.
PERFORM writeform USING 'BRK_INFO1' 'MAIN'.
ENDIF.
ENDIF.
*Commented by rajiv 10.05.2007 used this code in above condition.
added by ganesh on 260407 to print record
if it_konv is initial.
READ TABLE IT_MAKT WITH KEY MATNR = IT_EKPO-MATNR.
READ TABLE IT_T685T WITH KEY KSCHL = IT_KONV-KSCHL BINARY SEARCH.
READ TABLE IT_EKET WITH KEY EBELN = IT_EKPO-EBELN
EBELP = IT_EKPO-EBELP BINARY SEARCH.
mFirst = 0.
if mFirst eq 0.
PERFORM WRITEFORM USING 'BRK_INFO' 'MAIN'.
mFirst = 1.
else.
add 1 to lt_ctr.
clear it_bapi_mltx_ga.
read table IT_BAPI_MLTX_GA index lt_ctr. "For long text
if sy-subrc ne 0.clear it_bapi_mltx_ga.endif.
PERFORM WRITEFORM USING 'BRK_INFO1' 'MAIN'.
Endif.
endif.
end of change
REFRESH it_komv_tax.
PERFORM get_tax_cal USING it_ekpo-ebeln
it_ekpo-ebelp.
Changing it_komv_tax.
REFRESH : it_zmm_porder.
CLEAR : it_zmm_porder.
SELECT * INTO TABLE it_zmm_porder
FROM zmm_porder
WHERE flag EQ 'T'.
IF sy-subrc EQ 0.
SORT it_zmm_porder BY kschl.
ENDIF.
LOOP AT it_komv_tax.
gindex = sy-tabix.
READ TABLE it_zmm_porder WITH KEY kschl = it_komv_tax-kschl BINARY SEARCH.
IF sy-subrc NE 0.
DELETE it_komv_tax INDEX gindex.
ENDIF.
ENDLOOP.
LOOP AT it_komv_tax WHERE kwert IS NOT INITIAL.
IF ( IT_KOMV_TAX-KSCHL EQ 'JMOP' OR
IT_KOMV_TAX-KSCHL EQ 'JECS' OR
IT_KOMV_TAX-KSCHL EQ 'JSEP' OR
IT_KOMV_TAX-KSCHL EQ 'JMOQ' OR
IT_KOMV_TAX-KSCHL EQ 'JVCS' OR
IT_KOMV_TAX-KSCHL EQ 'JVRD' OR
IT_KOMV_TAX-KSCHL EQ 'JMIP' OR
* IT_KOMV_TAX-KSCHL EQ 'JEIP' OR
IT_KOMV_TAX-KSCHL EQ 'JSEI' OR
IT_KOMV_TAX-KSCHL EQ 'JSRT' OR
IT_KOMV_TAX-KSCHL EQ 'JEC3' OR
IT_KOMV_TAX-KSCHL EQ 'JVRN' )
AND IT_KOMV_TAX-KWERT IS NOT INITIAL.
SELECT SINGLE vtext
INTO mtext
FROM t685t
WHERE kschl EQ it_komv_tax-kschl
AND spras EQ 'E'.
l_rate = it_komv_tax-kbetr / 10.
l_amt = it_komv_tax-kwert.
For Japanies Yen "RTDK906759
IF it_ekko-waers = 'JPY'.
l_amt = l_amt * 100.
ENDIF.
End for japaies Yen
ADD l_amt TO mfamt.
IF lt_ctr LT lt_count. "Long text
ADD 1 TO lt_ctr.
READ TABLE it_bapi_mltx_ga INDEX lt_ctr.
ELSE.
CLEAR it_bapi_mltx_ga.
ENDIF.
IF l_rate EQ 0 OR l_amt EQ 0.
l_rate = ''.
l_amt = ''.
ENDIF.
PERFORM writeform USING 'TAX_LINE_ITEM' 'MAIN'.
ENDIF.
ENDLOOP.
IF lt_ctr LT lt_count.
DATA mbal_line TYPE i.
mbal_line = ( lt_count - lt_ctr ).
DO mbal_line TIMES.
ADD 1 TO lt_ctr.
READ TABLE it_bapi_mltx_ga INDEX lt_ctr.
IF sy-subrc = 0.
PERFORM writeform USING 'LTEXT' 'MAIN'.
ENDIF.
ENDDO.
ENDIF.
CONCATENATE it_ekko-ebeln it_ekpo-ebelp INTO nmebeln.
REFRESH tline.
CALL FUNCTION 'READ_TEXT'
EXPORTING
id = 'F04'
language = sy-langu
name = nmebeln
object = 'EKPO'
TABLES
lines = tline
EXCEPTIONS
id = 1
language = 2
name = 3
not_found = 4
object = 5
reference_check = 6
wrong_access_to_archive = 7
OTHERS = 8.
IF sy-subrc <> 0.
ENDIF.
LOOP AT tline.
IF tline-tdline IS NOT INITIAL.
del_text = tline-tdline.
ENDIF.
CONDENSE del_text.
ENDLOOP.
CONCATENATE it_ekko-ebeln it_ekpo-ebelp INTO nmebeln.
REFRESH tline.
CALL FUNCTION 'READ_TEXT'
EXPORTING
id = 'F03'
language = sy-langu
name = nmebeln
object = 'EKPO'
TABLES
lines = tline
EXCEPTIONS
id = 1
language = 2
name = 3
not_found = 4
object = 5
reference_check = 6
wrong_access_to_archive = 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.
refresh.
CLEAR : po_flag, mat_po_text.
LOOP AT tline.
IF tline-tdline IS NOT INITIAL.
MOVE tline-tdline TO mat_po_text.
CONDENSE mat_po_text.
PERFORM writeform USING 'MTRL_PO_TEXT' 'MAIN'.
po_flag = 'X'.
CLEAR : mat_po_text.
ENDIF.
ENDLOOP.
*Added lines below for Schedule delivery for line item on 09.05.2007:Rajiv
CLEAR g_ind.
READ TABLE it_eket WITH KEY ebeln = it_ekpo-ebeln
ebelp = it_ekpo-ebelp BINARY SEARCH.
g_ind = sy-tabix.
LOOP AT it_eket FROM g_ind.
IF it_eket-ebeln EQ it_ekpo-ebeln AND it_eket-ebelp = it_ekpo-ebelp.
PERFORM writeform USING 'SCHEDULE' 'MAIN'.
ELSE.
EXIT.
ENDIF.
ENDLOOP.
*End Addition:Rajiv
PERFORM writeform USING 'REQSLP' 'MAIN'.
mlctr = mlctr + 1.
msr = msr + 1.
CLEAR: lt_ctr, lt_ctr1.
following lines added by ganesh to add service po details as per Mr. sadiq 21.08.2007
IF it_ekpo-packno IS NOT INITIAL.
CLEAR sub_packno.
SELECT SINGLE sub_packno INTO sub_packno FROM esll WHERE packno = it_ekpo-packno.
IF sub_packno IS NOT INITIAL.
CLEAR it_esll.
REFRESH it_esll.
SELECT * FROM esll INTO CORRESPONDING FIELDS OF TABLE it_esll
WHERE packno = sub_packno.
IF sy-subrc = 0.
PERFORM writeform USING 'SERVICE_PO_TEXT' 'MAIN'.
ENDIF.
LOOP AT it_esll.
CONCATENATE sub_packno it_esll-introw INTO obj.
CALL FUNCTION 'READ_TEXT' "4500002446 C300
EXPORTING
id = 'LTXT'
language = sy-langu
name = obj
object = 'ESLL'
TABLES
lines = tline
EXCEPTIONS
id = 1
language = 2
name = 3
not_found = 4
object = 5
reference_check = 6
wrong_access_to_archive = 7
OTHERS = 8.
IF sy-subrc <> 0.
ENDIF.
CLEAR stext.
LOOP AT tline.
CONCATENATE stext tline-tdline INTO stext SEPARATED BY space.
ENDLOOP.
FREE tline.
CLEAR tline.
REFRESH tline.
PERFORM writeform USING 'SERVICE_PO' 'MAIN'.
PERFORM writeform USING 'SERVICE_TEXT' 'MAIN'.
ENDLOOP.
ENDIF.
ENDIF.
end of change
ENDLOOP. " it_ekpo.
IF mlctr < 15.
DO 5 TIMES.
PERFORM writeform USING 'LINEFEED' 'MAIN'.
ENDDO.
ENDIF.
added by ganesh for allding line before ECC No.
IF it_ekko-bsart NE 'ZIM'. " IF EXPORT NO NEED TO PRINT ECC.
PERFORM writeform USING 'LIN' 'MAIN'.
PERFORM writeform USING 'WERKS_TAX_DETAIL' 'MAIN'.
ENDIF.
end of change
MFLAG = 'Y'.
PERFORM writeform USING 'TERMS_VAL' 'MAIN'.
LOOP AT it_konv1 WHERE knumv EQ it_ekko-knumv.
mkschl = it_konv1-kschl.
mchgamt = 0.
LOOP AT it_konv_ftr WHERE knumv EQ it_konv1-knumv
AND kschl EQ mkschl.
mchgamt = mchgamt + it_konv_ftr-kwert.
ENDLOOP.
For Japanies Yen "RTDK906759
IF it_ekko-waers = 'JPY'.
mchgamt = mchgamt * 100.
ENDIF.
End for japaies Yen
mfamt = mfamt + mchgamt.
IF mchgamt LT '0'.
mchgamt = mchgamt * ( -1 ).
ENDIF.
READ TABLE it_t685t_ftr WITH KEY kschl = mkschl.
PERFORM writeform USING 'TERMS_FTR_VAL' 'MAIN'.
mlctr = mlctr + 1.
ENDLOOP.
mflag = 'T'.
CALL FUNCTION 'HR_IN_CHG_INR_WRDS'
EXPORTING
amt_in_num = mfamt
IMPORTING
amt_in_words = mfword
EXCEPTIONS
data_type_mismatch = 1
OTHERS = 2.
CONDENSE mebeln.
nmebeln = it_ekko-ebeln.
REFRESH tline.
CALL FUNCTION 'READ_TEXT'
EXPORTING
id = 'F01'
language = sy-langu
name = nmebeln
object = 'EKKO'
TABLES
lines = tline
EXCEPTIONS
id = 1
language = 2
name = 3
not_found = 4
object = 5
reference_check = 6
wrong_access_to_archive = 7
OTHERS = 8.
IF sy-subrc <> 0.
ENDIF.
*---- CHANGED BY MATHEW BECAUSE THIS STATMENT WORKING FINE IN 300 BUT NOT IN 500C.
LOOP AT ZTEXT.
IF ZTEXT-TEXT1 IS NOT INITIAL.
PERFORM WRITEFORM USING 'TERMS_COND_VAL_PAY' 'MAIN'.
ENDIF.
MPAY_FLAG = 'Y'.
ENDLOOP.
READ TABLE it_t052u WITH KEY zterm = it_ekko-zterm.
LOOP AT it_t052u WHERE zterm EQ it_ekko-zterm.
IF it_t052u-text1 IS NOT INITIAL.
PERFORM writeform USING 'TERMS_COND_VAL_PAY' 'MAIN'.
ENDIF.
mpay_flag = 'Y'.
ENDLOOP.
PERFORM writeform USING 'TERMS_COND_VAL' 'MAIN'.
LOOP AT tline.
IF tline-tdline IS NOT INITIAL.
PERFORM writeform USING 'TERMS_COND_VAL_HDR' 'MAIN'.
ENDIF.
CONDENSE txt.
ENDLOOP.
PERFORM writeform USING 'FTR' 'FTR_LIN3'.
PERFORM writeform USING 'FTR_LIN1' 'FTR_LIN1'.
CALL FUNCTION 'END_FORM'.
ENDLOOP. " It_ekko.
CALL FUNCTION 'CLOSE_FORM'
IMPORTING
RESULT = itcpp
RDI_RESULT =
TABLES
otfdata = 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.
ENDFORM. " Process
*& Form WRITEFORM
text
-->P_0150 text
-->P_0151 text
FORM writeform USING value(p_0150)
value(p_0151).
CALL FUNCTION 'WRITE_FORM'Hi
I think some basis related configuartions to be done
Try like this and inform me
A cyclic job runs, which processes the messages seen in the SOST queue.
Are you sure it's not the frequency of the cyclic job, rather than the
number of messages in the queue, that you are observing? In messages
that are queued and before the cyclic job runs, "wait for comm. service"
is the normal status.
If you mean that there are always 4 items queued in SOST regardless of
the cyclic send job, then I have no ideas. I would have thought there
was no way to do that.
when the send job runs it just never
picks them up & sends them, while it picks up many others. The send job
is somehow blind to these; no error message occurs. In this case, I
'delete' them from the queue (in SOST) and then 'undelete' (drop down
menu -> /Go to /Deleted Items) them and then re-queue them. THEN they
actually get picked up & sent when the next cyclic send job executes.
Regards
Pavan -
Hi, im tring to use the SO_DOCUMENT_SEND_API1 FM to send a smartform output by mail. Im able to convert the smartform output to pdf and save it to teh hard drive and works great but when i try to send the pdf doc by mail it comes corrupted... can anyone help me on this... heres a piece of my code
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.
******* I THINK THE ERROR MAYBE ON THIS PIECE OF CODE ************
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.
***************** it message ****************************************
refresh it_message.
it_message = 'Em anexo vai a tabela interna de utilizadores '.
APPEND it_message.
it_message = 'Clique no link '.
APPEND it_message.
**************** Assunto do Email *****************
* Fill the document data and get size of attachment
CLEAR w_doc_data.
DESCRIBE TABLE It_message LINES x.
READ TABLE It_message INDEX x.
w_doc_data-DOC_SIZE =
( x - 1 ) * 255 + STRLEN( It_message ).
w_doc_data-obj_langu = sy-langu.
w_doc_data-obj_name = 'SAPRPT'.
w_doc_data-obj_descr = 'ASSUNTO EMAIL'.
w_doc_data-sensitivty = 'F'.
************************ fim assunto email *********************
data linha type i.
data lv_cntl type i.
CLEAR t_attachment.
REFRESH t_attachment.
************************** Mensagem ******************
* Describe the body of the message
CLEAR t_packing_list.
REFRESH t_packing_list.
clear t_packing_list-transf_bin.
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.
***************************-Filling the attch table with data *************************
CLEAR : L_TABLE_LINES.
* clear wa_objhead.
* loop at i_record.
t_attachment[] = i_tline[].
* append t_attachment.
* endloop.
* 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 L_TABLE_LINES.
t_packing_list-body_num = L_TABLE_LINES.
t_packing_list-obj_descr = 'output'.
t_packing_list-doc_type = 'BIN'.
t_packing_list-doc_size = L_TABLE_LINES * 255.
t_packing_list-obj_langu = sy-langu.
t_packing_list-obj_name = 'Teste'.
APPEND t_packing_list.
*************** Endereços de email dos destinatários *************************
CLEAR receivers.
REFRESH receivers.
receivers-receiver = '[email protected]'.
receivers-rec_type = 'U'.
receivers-com_type = 'INT'.
receivers-notif_del = 'X'.
receivers-EXPRESS = 'X'.
* receivers-notif_ndel = 'X'.
APPEND receivers.
************************Fim de email dos Dest. ******************************
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
* NEW_OBJECT_ID =
* SENDER_ID =
TABLES
PACKING_LIST = t_packing_list
* OBJECT_HEADER = wa_objhead
CONTENTS_BIN = t_attachment
CONTENTS_TXT = it_message
* CONTENTS_HEX = contents_hex
* OBJECT_PARA =
* OBJECT_PARB =
RECEIVERS = 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 ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
wait up to 2 seconds.
if sy-subrc eq 0.
submit rsconn01 "with mode = 'INT'
*with output = 'X'
and return.
endif.Hi Joao,
Try using 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 -
Sending SmartForm as E-mail attachment, with email subject and content
Hi,
I'm, e-mailing a SmartForm using the SmartForm parameters (MAIL_RECIPIENT, MAIL_SENDER and MAIL_APPL_OBJ) using control device 'MAIL'.
Create MAIL_RECEPIENT (swotobjid): CREATE_RECIPIENT_OBJ_PPF
Create MAIL_SENDER (swotobjid): CREATE_SENDER_OBJECT_PPF
Create MAIL_APPL_OBJ: This works a little different. The sender needs to have an SAP Office Inbox (SO_USER_AUTOMATIC_INSERT) where a folder is to be created using the marco's swc_create_object and swc_object_to_persistent (INCLUDE <cntn01>).
Everything works fine.
The mail is being send and the SmartForm can be accessed as attachment, the E-Mail subject (as the name of the attachment) is taken from the title of the SmartForm (output_options-tdtitle).
QUESTION *
No they want to change the E-mail subject en change the content(body) of the mail.
Is this possible within the options of the MAIL_APPL_OBJ.
Or do have to rebuild the SmartForm program, get the SmartForm as OTF, rebuild as PDF en mail the PDF to the recepient using the SO_NEW_DOCUMENT_ATT_SEND_API1.
I was thinking of creating a container and set the elements of that container (swc_set_table ?) but I don't no in the end if this woll work.Refer the following Blog-
http://www.sdn.sap.com/irj/scn/weblogs;jsessionid=(J2EE3417300)ID0426134050DB01517382336190791762End?blog=/pub/wlg/1798
generate filename as yesterday's yyyymmdd format, and it must send file with same name with yyyymmdd
You need to use the following UDF to generate yesterday's date-
Imports: java.text.;java.util.;
public String yesterday(Container container)
long oneDay = (long) 1000.0 * 60 * 60 * 24;
DateFormat dateFormat = new SimpleDateFormat("yyyyMMdd");
java.util.Date today = new java.util.Date(System.currentTimeMillis());
java.util.Date yesterday = new java.util.Date(System.currentTimeMillis()-oneDay);
String b = dateFormat.format(yesterday);
return b;
Map this with Content_Disposition as mentioned in wiki.
XI 3.0 message must be executed one a day automatically (for example at 9.00 Am).
Use 'Availability Time planning' for CC as mentioned above.
http://help.sap.com/saphelp_nw70/helpdata/EN/45/06bd029da31122e10000000a11466f/content.htm -
Send Report output as Email attachment (PDF)
Hi Experts,
i am trying to send the contents of an internal table from my report as email using PDF attachment. I have coded the logic and i get the attachment in the email. When i try to open the attachement, i cannot open it.
The message i get is "_Adobe reader could not open the attachment "attach.pdf" because it is either not a supported file type or the file has been damaged(for example, it was sent as an email attachment and wasn't correctly decoded )._
Not sure where i went wrong.
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. "send_file_as_email_attachmentHello RnB,
You can check the mentioned link for the same:
[Simple Program to generate PDF from ABAP List Output.|http://www.abapmadeeasy.com/2011/02/sap-abap-simple-program-to-generate-pdf.html]
Regards,
Uttam Agrawal -
To send smartform output in an email without attachment
Hi All,
How to send smartform output in an email without attachment?
Thanks & Regards,
Mamta Gupta.Try this,
DATA:
ls_control_param TYPE ssfctrlop, "Control paramters
ls_output_options TYPE ssfcompop. "Output options
DATA:
lv_ip_mailaddr TYPE so_name, "Address of a Mail Recipient
lv_ip_type_id TYPE so_escape, "Recipient type
ls_recipient_id TYPE swotobjid, "Structure for recvr obj ID
ls_sender_id TYPE swotobjid. "Structure for sender obj id
CONSTANTS:
lc_ip_type_id TYPE so_escape VALUE 'U', "For internet address.
lc_smartform TYPE tdsfname VALUE 'ZVSF_ASN_DELNOTE', "Smart form name
lc_mail TYPE tddevice VALUE 'MAIL'. "Mail device
Assign recipient
lv_ip_mailaddr = gv_smtp_addr. "CSAM email id
lv_ip_type_id = lc_ip_type_id. "External address
Create Mail title
CONCATENATE text-001
nast-objky
INTO ls_output_options-tdtitle.
Create recipient object
CALL FUNCTION 'CREATE_RECIPIENT_OBJ_PPF'
EXPORTING
ip_mailaddr = lv_ip_mailaddr
ip_type_id = lv_ip_type_id
IMPORTING
ep_recipient_id = ls_recipient_id
EXCEPTIONS
invalid_recipient = 1
OTHERS = 2.
IF sy-subrc 0.
cf_retcode = sy-subrc.
PERFORM protocol_update.
ENDIF.
Get sender object id.
CALL FUNCTION 'CREATE_SENDER_OBJECT_PPF'
EXPORTING
ip_sender = sy-uname
IMPORTING
ep_sender_id = ls_sender_id
EXCEPTIONS
invalid_sender = 1
OTHERS = 2.
IF sy-subrc 0.
cf_retcode = sy-subrc.
PERFORM protocol_update.
ENDIF.
Assign the smart form name
w_ssfname = lc_smartform.
CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'
EXPORTING
formname = w_ssfname
IMPORTING
fm_name = lf_fm_name
EXCEPTIONS
no_form = 1
no_function_module = 2
OTHERS = 3.
IF sy-subrc 0.
cf_retcode = sy-subrc.
PERFORM protocol_update.
ENDIF.
For Print output:
IF nast-nacha = '1'. "Print output
ls_control_param-preview = 'X'.
ls_control_param-no_dialog = 'X'.
ENDIF.
For Email output.
IF nast-nacha = '2'. "Email
Output options
ls_output_options-tdteleland = gs_kna1-land1.
ls_output_options-tdtelenum = gs_kna1-telfx.
ls_output_options-tdfaxuser = sy-uname.
ls_output_options-BCS_COMMIT = 'X'.
ls_control_param-device = lc_mail.
ENDIF.
dynamically call Fm behind the Smart form
CALL FUNCTION lf_fm_name
EXPORTING
control_parameters = ls_control_param
mail_recipient = ls_recipient_id
mail_sender = ls_sender_id
output_options = ls_output_options
user_settings = ' '
TABLES
delivery = gt_delivery
EXCEPTIONS
formatting_error = 1
internal_error = 2
send_error = 3
user_canceled = 4
OTHERS = 5.
IF sy-subrc 0.
cf_retcode = sy-subrc.
PERFORM protocol_update.
ENDIF.
Regards,
Joan -
How to send SMARTFORMS output as attachment through?
how to send SMARTFORMS output as attachment through e-mail?
after executing SMARTFORMS how to send that output via e-mail.
Help me.
thanks
surya.
Moderator Message: Please search for available information first
Edited by: kishan P on Nov 7, 2010 7:19 PMhi Vinod,
Can you please tell me how you have zipped the file.
I am having a text file in application server. I need to zip that file. Then the middleware moves it to Legacy system.
I used the following code. With this I am having the data in Binary format which my midleware cannot understand.
What I need on the whole is just to reduce the size of the file.
form ZIP_FILE .
DATA: lt_data TYPE TABLE OF x255,
lt_textdata TYPE TABLE OF x255.
DATA: ls_data LIKE LINE OF lt_data.
DATA: lv_dsn1(100) VALUE '/ECD/120/GIS/FTP/IB/DNBPAYDEX.TXT'.
DATA: lv_dsn3(100) VALUE '/ECD/120/GIS/FTP/IB/DNBPAYDEXZIP.zip'.
*DATA: lv_dsn3(100) VALUE '/interfaces/SM5/test.zip'. " Contains sample1.xls and sample2.xls
DATA: lv_file_length TYPE i.
DATA: lv_content TYPE xstring.
DATA: lo_zip TYPE REF TO cl_abap_zip.
CREATE OBJECT lo_zip.
Read the data as a string
clear lv_content .
OPEN DATASET lv_dsn1 FOR INPUT IN BINARY MODE.
READ DATASET lv_dsn1 INTO lv_content .
CLOSE DATASET lv_dsn1.
lo_zip->add( name = 'sample.TXT' content = lv_content ).
lv_content = lo_zip->save( ).
*clear lv_content .
Conver the xstring content to binary
CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'
EXPORTING
buffer = lv_content
IMPORTING
output_length = lv_file_length
TABLES
binary_tab = lt_data.
OPEN DATASET lv_dsn3 FOR OUTPUT IN TEXT MODE ENCODING DEFAULT.
LOOP AT lt_textdata INTO ls_data.
TRANSFER ls_data TO lv_dsn3.
ENDLOOP.
CLOSE DATASET lv_dsn3.
IF sy-subrc EQ '0'.
MESSAGE s999(zfi_ap_gl) WITH text-t10.
ENDIF.
Can you please help.
Thanks Aravind -
How to send smartform output in body of email?
Hi all ,
I have to send smartform output in body of email (not as an attachement in mail) .PLease help me in this regard.
Thanks,
Ananth S.Hi Ananth
See these threads.
[https://forums.sdn.sap.com/click.jspa?searchID=23497094&messageID=6889194]
[https://forums.sdn.sap.com/click.jspa?searchID=23497094&messageID=6861330]
[https://forums.sdn.sap.com/click.jspa?searchID=23497094&messageID=6855364]
Regards
Hareesh Menon -
Very urjent how to send report output in mail
hi experts,
how to send report output in mail which function module should i use wht parameters should i pass.
thanks in addavnce,
points to be awarded.CALL FUNCTION 'GET_PRINT_PARAMETERS'
EXPORTING
destination = '026c'
copies = count
list_name = 'VATS_ASBUILT'
list_text = v_list
immediately = 'X'
release = 'X'
new_list_id = 'X'
expiration = days
line_size = 132
line_count = 65
layout = 'X_65_132'
* sap_cover_page = 'X'
* cover_page = 'X'
receiver = 'SAP*'
department = 'VATS'
no_dialog = 'X'
IMPORTING
out_parameters = params
valid = valid.
SUBMIT zppr_vats_asbuilt WITH p_aufnr EQ v_aufnr
TO SAP-SPOOL WITHOUT SPOOL DYNPRO
SPOOL PARAMETERS params
AND RETURN.
SELECT SINGLE rqident FROM tsp01 INTO l_spoolno
WHERE rqtitle = v_list .
* convert report to PDF format
CALL FUNCTION 'CONVERT_ABAPSPOOLJOB_2_PDF'
EXPORTING
src_spoolid = l_spoolno
no_dialog = 'X'
TABLES
pdf = l_ipdf
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.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
EXIT .
ENDIF.
Now comes the part to send the mail
try.
* -------- create persistent send request ------------------------
send_request = cl_bcs=>create_persistent( ).
clear document.
* -------- create and set document with attachment ---------------
* create document from internal table with text
document = cl_document_bcs=>create_document(
i_type = 'RAW'
i_text = text
i_length = '12'
i_subject = '' ).
*changing the content of the attachment
binary_content[] = l_iobjbin[].
*change the name of the PDF attachment
concatenate 'Build ID' s_buildid_i 'Rev' v_buildid_rev
into i_att_sub separated by space.
* add attachment to document
call method document->add_attachment
exporting
i_attachment_type = 'PDF'
i_attachment_subject = i_att_sub
i_att_content_hex = binary_content.
*setting the option to send an e-mail more than 50 characters
call method send_request->set_message_subject
exporting
ip_subject = t_sub.
* add document to send request
call method send_request->set_document
exporting
i_document = document.
* --------- set sender -------------------------------------------
* note: this is necessary only if you want to set the sender
* different from actual user (SY-UNAME). Otherwise sender is
* set automatically with actual user.
sender = cl_sapuser_bcs=>create( 'VATSUPPORT' ).
call method send_request->set_sender
exporting
i_sender = sender.
*Send the list based on receivers list obtained
loop at l_ireclist.
AD_SMTPADR = l_ireclist-receiver.
* --------- add recipient (e-mail address) -----------------------
* create recipient - please replace e-mail address !!!
recipient = cl_cam_address_bcs=>create_internet_address(
AD_SMTPADR ).
* add recipient with its respective attributes to send request
call method send_request->add_recipient
exporting
i_recipient = recipient
i_express = 'X'.
ENDLOOP.
call method send_request->set_status_attributes
exporting
i_requested_status = 'E'
i_status_mail = 'E'.
* To send the mail immediately
call method send_request->set_send_immediately( 'X' ).
* ---------- send document ---------------------------------------
call method send_request->send( ).
commit work. -
How to send smartform output through email
Hi,
I want to send smartform output through email.....
can u give me sample program to send it through email......
Regards,
Jenifer
MOderator Message: Basic and Frequently asked question. Please search before posting.
Edited by: kishan P on Nov 26, 2010 11:11 AMHi Jenifer,
There are many threads available on SDN.
Just have a look at this thread
<<link removed by moderator>>
Kindly search before you post.
Regard
Abhii
Moderator Message: You have been warned many times against point-hunting. Continuing ignoring of the Moderator warnings will lead to account deletion. Consider this your last warning
Edited by: kishan P on Nov 26, 2010 11:09 AM -
To send smartform output through email and fax
Hi,
I need to send smartform output through email if the email address is present else if the email address is present then it has to be sent through fax.If both the email address and fax are present,then it has to send an email.
Now the issue is I am able to send the email and I am getting the message as 'Output was successfully issued'.But the entry corresponding to this is not shown in SOST transaction.
Can anyone tell me what would be the reason for this?HI,
Try to look in transaction SCOT
Regards,
Egle -
Sending Smartform output as a body of the mail not as the attachement
Hi All,
my requirement is like this...
I need to send a smartform output as the body of a mail. and not as the attachment.
Hope you got my question
Regards
RaghuHi,
I hope the following links might help you,
Smartform output as Email.
Smartform to PDF and e_mail? Urgent
Regards,
Hema.
Reward points if it is useful. -
Sending a smartform output as an attachment in RTF format via E-mail
Hi all,
I have a scenario in which the output displayed using smartforms is to be sent as a e-mail attachment. Also, the attachment should be a word doc(RTF format). Can you please me with this.
Warm Regards,
AbhijeetHI,
See the call to function 'LF_FM_NAME' in standard print program <b>RLB_INVOICE</b>. Notice the preceding call to function WFMC_PREPARE_SMART_FORM? This function does the heavy lifting for you; here, no additional work is needed in either the form or the print program. To generate e-mail output.
See the below link
/people/pavan.bayyapu/blog/2005/08/30/sending-html-email-from-sap-crmerp
Thanks
Sudheer -
Sending smartform output as PDF attachment, Error opening PDF attachment
Hi Experts,
I am using the code form the following link to send a smartform output as PDF attachment. I can able to see the message, but can not open PDF document.
https://www.sdn.sap.com/irj/sdn/wiki?path=/display/snippets/convertSmartformtoPDFformat&
The information should be on my smartform are some text, company logo and a barcode.
With all of these received error: "There was an error opening this document. The file is damaged and could not be repaired."
I tried different ways like only text, text with company logo, text with barcode. I got the following errors:
An unrecognized token 'Td0' was found
There was problem reading this document(16).
There was problem reading this document(111).
Does anyone have idea of these ? Your help is greatly appreciated.
Thank you,
Suryaplease see this code ... for sending the Email as PDF attach file,
*& 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.
reward points if it is usefull ....
Girish
Maybe you are looking for
-
ITunes doesn't recognize IPOD Nano (2nd Gen), but Windows XP does
I'm a longtime happy owner of an IPOD Mini and bought a second Gen IPOD Nano a few months ago that works great. I have two identical P4 Sony Vaios that I back up/clone from one to the other every so often to keep them as identical as possible. It's b
-
I have a 16GB ipod, 5th Gen. i tried to sync a song to it and it deleted all of the songs on my ipod. So i tryed to sync all of my songs again and nothing happens. Does anyone know what to do
-
Where will we find the attached docs for SC or PO?
Hi All, We have a requirement in which we need to send the approval offline email with the attached docs for PO or SC . i checked the FM BBP_PD_SC_GETDETAIL in the table ET_ATTACH . but in these i am getting the attached doc in some other format (D0C
-
Hi to all, I am going for a retail implementation( Like Bigbazar and Wallmart), can any body provide me the list of cubes.. which are required for this kind of Retail Shop. Regards [email protected]
-
Process chain - default job name modification
Hi Guys, When we run a process chain which has RA jobs,,,,,the corresponding job names in sm37 will be with name "BI_PROCESS_REPA_BP" ..... We use the job name in sm37 to spool the file thru abap program....so if 3 RA jobs are run thru proces