cancel
Showing results for 
Search instead for 
Did you mean: 

sending sapscript form through Email

Former Member
0 Kudos

Hi,

I modifyed a std sapscript form for customer statement and that output i want to send to the customer through Email.So now i need a help for further what are the steps need to be do for sending that form by email.Pls be in details so that for me easy to solve this.

Thanks,

Rajendra.

Accepted Solutions (0)

Answers (3)

Answers (3)

Former Member
0 Kudos

solved

Former Member
0 Kudos

Hello,

when you already use SAP Script standard output and the document you want to send by email can / should look the same and PDF is a solution do it like this.

- Define the output type valid for external send (5)

- Define the PDF printer (when not already done in your system).

- Maintain output conditions to print to PDF mail with the transmission medium 5

- When you have email settings in the system active, email will be send to customer email address with PDF attachment.

Best regards,

Volker

Former Member
0 Kudos

Hi Volker,

will you pls explain me in detail so that i can follow the steps and do.Hope i expect the feedback soon from you.Thanks a lot.

Thanks,

Rajendra.

Former Member
0 Kudos

hi,

There is paramter call GET_OTF in the output_options, set that to X. In the oputput paramter you will have the OTF table. Take that table and use the funciton CONVERT_OTF_2_PDF FUNCTION and the output will be PDF format.

Once you have the form in PDF format download it to some location using GUI_Download FM and send it as an attachment using SO_NEW_DOCUMENT_ATT_SEND_API1.

Hope this helps.

Regards,

Richa

Former Member
0 Kudos

Hi Richa,

If you provide the sample codeings for that will be more usefull for me to do.Pls help me to complete this and thanks.

Thanks,

Rajendra.

Former Member
0 Kudos

Hi ,

I done the below coding and it works fine i think because it shows the sy-subrc eq 0 of FM SO_DOCUMENT_SEND_API1.but i cant receive the mail why? is there any other setting i have to do further to receive the mail are any othere problem.pls help to solve the isuues and thanks.

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_MESS_BOD

RECEIVERS = T_RECEIVERS

EXCEPTIONS

TOO_MANY_RECEIVERS = 1

DOCUMENT_NOT_SENT = 2

DOCUMENT_TYPE_NOT_EXIST = 3

OPERATION_NO_AUTHORIZATION = 4

PARAMETER_ERROR = 5

X_ERROR = 6

ENQUEUE_ERROR = 7

OTHERS = 8.

If SY-subrc = 0.

write:/ 'Message sent'.

else.

write:/ 'Error encountered'.

endif.

My prog says Message send but i never received the mail.

Thanks,

Rajendra.

Former Member
0 Kudos

hi Rajendra,

Here is the sample code.

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,

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,

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

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_TEST1'
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.

endif.

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 = 'test with pdf-Attachment!'.
append i_objtxt.
describe table i_objtxt lines v_lines_txt.
read table i_objtxt index v_lines_txt.
wa_doc_chng-obj_name = 'smartform'.
wa_doc_chng-expiry_dat = sy-datum + 10.
wa_doc_chng-obj_descr = 'smartform'.
wa_doc_chng-sensitivty = 'F'.
wa_doc_chng-doc_size = v_lines_txt * 255.

**** Main Text
* wa_doc_chng-doc_size = ( v_lines_txt - 1 ) * 255 + strlen( i_objtxt )
*.
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.
* Länge des Attachment ermitteln
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 = 'smart'.
i_objpack-obj_descr = 'test'.
append i_objpack.

clear i_reclist.
i_reclist-receiver = give ur mail id
i_reclist-rec_type = 'U'.
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.

Also check out the other sample code in this link.

Regards,

Richa

Former Member
0 Kudos

Hi Richa,

Thanks for your code and i had a problem only the email is not going to the destination.when i debugg and check i have all the data in the internal table i_reclist.but After pass into the FM 'SO_NEW_DOCUMENT_ATT_SEND_API1' when i check from receivers = i_reclist mail id is missing but even though the sy-subrc is 0.so what is the problem in my codeing pls solve my issue.

Thanks,

Rajendra.

Former Member
0 Kudos

Hello,

the idea was like this.

A) You want to send the SAP Script as PDF yourself (version > 4.5):

Create output device "PDF mail" please search regarding SAP notes.

System < then 4.7 needs upload of device type ZPDF, higher should include PDF1.

Maintain output conditions using printer "PDF mail". The system will convert the SAP Script document into a PDF document. There are no code changes or corrections needed.

Email sending depends on other SAP system settings (SAP Connect!). But with this method you will already find the sending email in your SAP business work place outbox.

B) You want to send the same way document external:

Output condtion must allow medium "5" for external send.

Maintain output conditions either with the same output device like metioned above or maybe that was not even needed (I do not remember 100% if the system automatically conversts SAP Script to PDF in that cases).

There is a transaction existing when you want to convert one document to PDF (of course I do not remember that by hard) and there are function modules existing for PDF conversion. But our solutions are without code corrections.

BR, Volker

Former Member
0 Kudos

I just checked once more:

In newer versions you can define in the SAPConncet what conversion happens with SAP-Scripts in case of sending emails. When you choose "PDF" it is converted automatic.

jan_krohn
Active Participant
0 Kudos

Have you checked transaction SOST to see if SAP has tried to send the email out?

Former Member
0 Kudos

Hi ,

Please Check this this may Help you

*Please mark useful Answers

Former Member
0 Kudos

Hi ,

I am using the below code to send the form output by mail but it is not working for me.pls correct my code where i want to change so that i can solve my issues.

DATA: itcpo LIKE itcpo,

tab_lines LIKE sy-tabix.

  • Variables for EMAIL functionality

DATA: maildata LIKE sodocchgi1.

DATA: mailpack LIKE sopcklsti1 OCCURS 2 WITH HEADER LINE.

DATA: mailhead LIKE solisti1 OCCURS 1 WITH HEADER LINE.

DATA: mailbin LIKE solisti1 OCCURS 10 WITH HEADER LINE.

DATA: mailtxt LIKE solisti1 OCCURS 10 WITH HEADER LINE.

DATA: mailrec LIKE somlrec90 OCCURS 0 WITH HEADER LINE.

DATA: solisti1 LIKE solisti1 OCCURS 0 WITH HEADER LINE.

parameter: p_email1 like somlreci1-receiver .

PERFORM send_form_via_email.

************************************************************************

  • FORM SEND_FORM_VIA_EMAIL *

************************************************************************

FORM send_form_via_email.

CLEAR: maildata, mailtxt, mailbin, mailpack, mailhead, mailrec.

REFRESH: mailtxt, mailbin, mailpack, mailhead, mailrec.

  • Creation of the document to be sent File Name

maildata-obj_name = 'TEST'.

  • Mail Subject

maildata-obj_descr = 'Subject'.

  • Mail Contents

mailtxt-line = 'Here is your file'.

APPEND mailtxt.

  • Prepare Packing List

PERFORM prepare_packing_list.

  • Set recipient - email address here!!!

mailrec-receiver = p_email1.

mailrec-rec_type = 'U'.

APPEND mailrec.

  • Sending the document

CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'

EXPORTING

document_data = maildata

put_in_outbox = ' '

TABLES

packing_list = mailpack

object_header = mailhead

contents_bin = mailbin

contents_txt = mailtxt

receivers = mailrec

EXCEPTIONS

too_many_receivers = 1

document_not_sent = 2

operation_no_authorization = 4

OTHERS = 99.

ENDFORM.

************************************************************************

  • Form PREPARE_PACKING_LIST

************************************************************************

FORM prepare_packing_list.

CLEAR: mailpack, mailbin, mailhead.

REFRESH: mailpack, mailbin, mailhead.

DESCRIBE TABLE mailtxt LINES tab_lines.

READ TABLE mailtxt INDEX tab_lines.

maildata-doc_size = ( tab_lines - 1 ) * 255 + STRLEN( mailtxt ).

  • Creation of the entry for the compressed document

CLEAR mailpack-transf_bin.

mailpack-head_start = 1.

mailpack-head_num = 0.

mailpack-body_start = 1.

mailpack-body_num = tab_lines.

mailpack-doc_type = 'RAW'.

APPEND mailpack.

  • Creation of the document attachment

  • This form gets the OTF code from the SAPscript form.

  • If you already have your OTF code, I believe that you may

  • be able to skip this form. just do the following code, looping thru

  • your SOLISTI1 and updating MAILBIN.

PERFORM get_otf_code.

LOOP AT solisti1.

MOVE-CORRESPONDING solisti1 TO mailbin.

APPEND mailbin.

ENDLOOP.

DESCRIBE TABLE mailbin LINES tab_lines.

mailhead = 'TEST.OTF'.

APPEND mailhead.

    • Creation of the entry for the compressed attachment

mailpack-transf_bin = 'X'.

mailpack-head_start = 1.

mailpack-head_num = 1.

mailpack-body_start = 1.

mailpack-body_num = tab_lines.

mailpack-doc_type = 'OTF'.

mailpack-obj_name = 'TEST'.

mailpack-obj_descr = 'Subject'.

mailpack-doc_size = tab_lines * 255.

APPEND mailpack.

ENDFORM.

************************************************************************

  • Form GET_OTF_CODE

************************************************************************

FORM get_otf_code.

DATA: BEGIN OF otf OCCURS 0.

INCLUDE STRUCTURE itcoo .

DATA: END OF otf.

DATA: itcpo LIKE itcpo.

DATA: itcpp LIKE itcpp.

CLEAR itcpo.

itcpo-tdgetotf = 'X'.

  • Start writing OTF code

CALL FUNCTION 'OPEN_FORM'

EXPORTING

form = 'Z2006FICSE'

language = sy-langu

options = itcpo

dialog = ' '

EXCEPTIONS

OTHERS = 1.

CALL FUNCTION 'START_FORM'

EXCEPTIONS

error_message = 01

OTHERS = 02.

CALL FUNCTION 'WRITE_FORM'

EXPORTING

window = 'MAIN'

EXCEPTIONS

error_message = 01

OTHERS = 02.

  • Close up Form and get OTF code

CALL FUNCTION 'END_FORM'

EXCEPTIONS

error_message = 01

OTHERS = 02.

MOVE-CORRESPONDING itcpo TO itcpp.

CALL FUNCTION 'CLOSE_FORM'

IMPORTING

result = itcpp

TABLES

otfdata = otf

EXCEPTIONS

OTHERS = 1.

  • Move OTF code to structure SOLI form email

CLEAR solisti1. REFRESH solisti1.

LOOP AT otf.

solisti1-line = otf.

APPEND solisti1.

ENDLOOP.

ENDFORM.

Hope i can expect the feedback soon from you guys.

Thanks,

Rajendra.

Former Member
0 Kudos

Hi rajender ,

it is not possible to say wat the mistake straight away.

u can verify by urself by using GUI_download .if u can download the file correctly on to ur system then ur code is right .and the 'SO_NEW_DOCUMENT_ATT_SEND_API1' is probably right so goahead and download .

Former Member
0 Kudos

Hi,

I am not able to send mail because in the itab APPEND WA_RECEIVERS TO T_RECEIVERS[]. i have the mail id but after pass to the FM the mail id is missing in RECEIVERS = T_RECEIVERS[]

.below is code i used

CLEAR T_RECEIVERS.

REFRESH T_RECEIVERS.

WA_RECEIVERS-RECEIVER = LD_EMAIL.

WA_RECEIVERS-REC_TYPE = 'U'.

**WA_RECEIVERS-REC_TYPE = 'C_U'.

WA_RECEIVERS-COM_TYPE = 'INT'.

WA_RECEIVERS-NOTIF_DEL = 'X'.

WA_RECEIVERS-NOTIF_NDEL = 'X'.

APPEND WA_RECEIVERS TO 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[]

object_header = wa_objhead

CONTENTS_BIN = T_ATTACHMENT[]

CONTENTS_TXT = IT_MESS_BOD[]

RECEIVERS = T_RECEIVERS[]

EXCEPTIONS

TOO_MANY_RECEIVERS = 1

DOCUMENT_NOT_SENT = 2

DOCUMENT_TYPE_NOT_EXIST = 3

OPERATION_NO_AUTHORIZATION = 4

PARAMETER_ERROR = 5

X_ERROR = 6

ENQUEUE_ERROR = 7

OTHERS = 8.

If SY-subrc = 0.

write:/ 'Message sent'.

else.

write:/ 'Error encountered'.

endif.

but in my case sy-subrc = 0.

but i can receive the mail.pls help me to solve the issue.

Thanks,

Rajendra.

Former Member
0 Kudos

1.

CLEAR T_RECEIVERS.

REFRESH T_RECEIVERS.

WA_RECEIVERS-RECEIVER = LD_EMAIL.

WA_RECEIVERS-REC_TYPE = 'U'.

**WA_RECEIVERS-REC_TYPE = 'C_U'.

WA_RECEIVERS-COM_TYPE = 'INT'.

WA_RECEIVERS-NOTIF_DEL = 'X'.

WA_RECEIVERS-NOTIF_NDEL = 'X'.

<b>APPEND WA_RECEIVERS TO T_RECEIVERS</b>.

2.

<b>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

object_header = wa_objhead

CONTENTS_BIN = T_ATTACHMENT

CONTENTS_TXT = IT_MESS_BOD

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.</b>

3.Check the status of ur mails in tcode <b>SCOT</b> .

Regards

Prabhu

Former Member
0 Kudos

Hi Prabhu,

Still the same problem i am not able to receive the mail.but in the internal table i can see the maild id.but after pass in ti the FM the mail id is missing.so how to solve the issue.

Thanks,

Rajendra.