cancel
Showing results for 
Search instead for 
Did you mean: 

Email Invoice as PDF

Former Member
0 Kudos

Hi folks,

I'm trying to send a sapscript/smartform invoice as a PDF attached to an email. I've been reading a number of posting on this topic but it is still unclear to me how to get this to work. (R/3 4.7)

I need to setup a new output type with transmission media 5. Is that correct? The email address will be pulled from the customer's master data record. Correct?

What do I use as the processing routine? Do I have to create a custom routine?

Do I need to define a communications strategy with communication type INT?

As I understand it, the system will automatically convert to PDF as long as SCOT is configured that way (default).

What else am I missing?

Thanks everyone,

Clint

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Go through this link it will give you solution, it contains screen shots also, similar requirement to you.

https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/8cd6adbb-0301-0010-39ba-938c601d...

Thanks & regard,

Khasimsa Shaik

Former Member
0 Kudos

Hi Khasimsa Shaik,

I actually had already seen this document/program, but I don't understand how to use it to automate my process. That is the key to my problem, automation. We could go into SO01 and attach a PDF document and send it, but that is a lot of work for the user.

Do you still think this program would solve the problem? Can you provide an example variant?

Thanks,

Clint

Answers (3)

Answers (3)

Former Member
0 Kudos

Hi,

You need to first create the new output type in v/40 transaction for the invoice to send externally(i.e as Email attachment). Output type ZD05 and Application V3. In the mail Title and texts enter the title (Subject). In the processing routines select medium as External Send and program RLB_INVOICE , Form routine as ENTRY and ur smartform (I presume that u have created Z smartform layout)name in the PDF/Smartform form.In the partner function tree, select bill-to-party(BP) for External send. SAVE it.

Go to SCOT transaction check if you have node for INT , for example for us we have EMAIL, if not create one using the create button. (These things shud be created by BASIS). Dounbel click the node and a window will popup, hope that all the SMTP details are entered like Mail Host , Mail Port. Now go to Supportted Adress types, select the Internet and press the SET button. now select PDF for SAP Scripts/ Smartforms and save. thats it.

I presume that you know how to go to invoice and select the ZD05 output type and send the email. and also maintain email id for the customer or Bill-to-party.

Hope this helps. All the best

Former Member
0 Kudos

Hi

Tryed this last process, but don't appears to work in my case (ECC600) . A question: i must create a ad hoc Smartforms? I cannot use my normal printer Sapscript (with custom program) for this?

Thanks

Davide

Former Member
0 Kudos

Hi,

you dont need to configure anything,just convert the smart form in to pdf and send that pdf through mail.

1.converting smartform to PDF

Summury: Converting the smartfrom to PDF is process of 3 simple steps.

• Calling the Smart form, then it returns the OTF data in Return.

• Converting the OTF data into required format using the Function Module CONVERT_OTF_2_PDF.

• Download the File

&----


*& Report ZTEST_NREDDY_PDF

*&

&----


*&

*&

&----


REPORT ZTEST_NREDDY_PDF.

DATA: it_otf TYPE STANDARD TABLE OF itcoo,

it_docs TYPE STANDARD TABLE OF docs,

it_lines TYPE STANDARD TABLE OF tline,

st_job_output_info TYPE ssfcrescl,

st_document_output_info TYPE ssfcrespd,

st_job_output_options TYPE ssfcresop,

st_output_options TYPE ssfcompop,

st_control_parameters TYPE ssfctrlop,

v_len_in TYPE so_obj_len,

v_language TYPE sflangu VALUE 'E',

v_e_devtype TYPE rspoptype,

v_bin_filesize TYPE i,

v_name TYPE string,

v_path TYPE string,

v_fullpath TYPE string,

v_filter TYPE string,

v_uact TYPE i,

v_guiobj TYPE REF TO cl_gui_frontend_services,

v_filename TYPE string,

v_fm_name TYPE rs38l_fnam.

CONSTANTS c_formname TYPE tdsfname VALUE 'ZTEST'.

CALL FUNCTION 'SSF_GET_DEVICE_TYPE'

EXPORTING

i_language = v_language

i_application = 'SAPDEFAULT'

IMPORTING

e_devtype = v_e_devtype.

st_output_options-tdprinter = v_e_devtype.

*st_output_options-tdprinter = 'locl'.

st_control_parameters-no_dialog = 'X'.

st_control_parameters-getotf = 'X'.

.................GET SMARTFORM FUNCTION MODULE NAME.................

CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'

EXPORTING

formname = c_formname

IMPORTING

fm_name = v_fm_name

EXCEPTIONS

no_form = 1

no_function_module = 2

OTHERS = 3.

IF sy-subrc <> 0.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

...........................CALL SMARTFORM............................

CALL FUNCTION v_fm_name

EXPORTING

control_parameters = st_control_parameters

output_options = st_output_options

IMPORTING

document_output_info = st_document_output_info

job_output_info = st_job_output_info

job_output_options = st_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.

ELSE.

.........................CONVERT TO OTF TO PDF.......................

CALL FUNCTION 'CONVERT_OTF_2_PDF'

IMPORTING

bin_filesize = v_bin_filesize

TABLES

otf = st_job_output_info-otfdata

doctab_archive = it_docs

lines = it_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.

........................GET THE FILE NAME TO STORE....................

CONCATENATE 'smrt' '.pdf' INTO v_name.

CREATE OBJECT v_guiobj.

CALL METHOD v_guiobj->file_save_dialog

EXPORTING

default_extension = 'pdf'

default_file_name = v_name

file_filter = v_filter

CHANGING

filename = v_name

path = v_path

fullpath = v_fullpath

user_action = v_uact.

IF v_uact = v_guiobj->action_cancel.

EXIT.

ENDIF.

..................................DOWNLOAD AS FILE....................

MOVE v_fullpath TO v_filename.

CALL FUNCTION 'GUI_DOWNLOAD'

EXPORTING

bin_filesize = v_bin_filesize

filename = v_filename

filetype = 'BIN'

TABLES

data_tab = it_lines

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.

ENDIF.

2. Sending PDF as mail.

CLEAR t_receivers.

REFRESH t_receivers.

t_receivers-receiver = sy-uname.

t_receivers-rec_type = 'B'.

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.

check these links ,definitely useful

http://www.sapdevelopment.co.uk/reporting/rep_spooltopdf.htm

Regards,

Raj.

Former Member
0 Kudos

Hi,

1.No need to create the custom routine.

2.The system default cann't generate the PDF.It generates OTF , Format.

3.We need to convert the OTF into PDF.

4.You have to maintain the Email in SCOT.

The following is the code for sending through mail for script:

Best LInk:

/people/pavan.bayyapu/blog/2005/08/30/sending-html-email-from-sap-crmerp

Observe this:

REPORT Z_SCRIPT .

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.

*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 = 'email.COM'.

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 = 'Z08V3_COLLI'

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

Below points is for ur testing purpose.

U can check the status of the mail in the transaction SOST.

Execute this transaction for the date range. If the traffic light is in yellow colour then do like this.

Utilities->Start send process->Give trans method as INT and press enter. Mail will go immediately.

If the above logic don't work for u then TRY FM SO_OBJECT_SEND for sending mail.

for Smartform converting the OTF to PDF:

REPORT zsuresh_test.

Variable declarations

DATA:

w_form_name TYPE tdsfname VALUE 'ZSURESH_TEST',

w_fmodule TYPE rs38l_fnam,

w_cparam TYPE ssfctrlop,

w_outoptions TYPE ssfcompop,

W_bin_filesize TYPE i, " Binary File Size

w_FILE_NAME type string,

w_File_path type string,

w_FULL_PATH type string.

Internal tables declaration

Internal table to hold the OTF data

DATA:

t_otf TYPE itcoo OCCURS 0 WITH HEADER LINE,

Internal table to hold OTF data recd from the SMARTFORM

t_otf_from_fm TYPE ssfcrescl,

Internal table to hold the data from the FM CONVERT_OTF

T_pdf_tab LIKE tline OCCURS 0 WITH HEADER LINE.

This function module call is used to retrieve the name of the Function

module generated when the SMARTFORM is activated

CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'

EXPORTING

formname = w_form_name

VARIANT = ' '

DIRECT_CALL = ' '

IMPORTING

fm_name = w_fmodule

EXCEPTIONS

no_form = 1

no_function_module = 2

OTHERS = 3

.

IF sy-subrc 0.

MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno

WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

ENDIF.

Calling the SMARTFORM using the function module retrieved above

GET_OTF parameter in the CONTROL_PARAMETERS is set to get the OTF

format of the output

w_cparam-no_dialog = 'X'.

w_cparam-preview = space. " Suppressing the dialog box

" for print preview

w_cparam-getotf = 'X'.

Printer name to be used is provided in the export parameter

OUTPUT_OPTIONS

w_outoptions-tddest = 'LP01'.

CALL FUNCTION w_fmodule

EXPORTING

ARCHIVE_INDEX =

ARCHIVE_INDEX_TAB =

ARCHIVE_PARAMETERS =

control_parameters = w_cparam

MAIL_APPL_OBJ =

MAIL_RECIPIENT =

MAIL_SENDER =

output_options = w_outoptions

USER_SETTINGS = 'X'

IMPORTING

DOCUMENT_OUTPUT_INFO =

job_output_info = t_otf_from_fm

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.

t_otf] = t_otf_from_fm-otfdata[.

Function Module CONVERT_OTF is used to convert the OTF format to PDF

CALL FUNCTION 'CONVERT_OTF'

EXPORTING

FORMAT = 'PDF'

MAX_LINEWIDTH = 132

ARCHIVE_INDEX = ' '

COPYNUMBER = 0

ASCII_BIDI_VIS2LOG = ' '

PDF_DELETE_OTFTAB = ' '

IMPORTING

BIN_FILESIZE = W_bin_filesize

BIN_FILE =

TABLES

otf = T_OTF

lines = T_pdf_tab

EXCEPTIONS

ERR_MAX_LINEWIDTH = 1

ERR_FORMAT = 2

ERR_CONV_NOT_POSSIBLE = 3

ERR_BAD_OTF = 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.

To display File SAVE dialog window

CALL METHOD cl_gui_frontend_services=>file_save_dialog

EXPORTING

WINDOW_TITLE =

DEFAULT_EXTENSION =

DEFAULT_FILE_NAME =

FILE_FILTER =

INITIAL_DIRECTORY =

WITH_ENCODING =

PROMPT_ON_OVERWRITE = 'X'

CHANGING

filename = w_FILE_NAME

path = w_FILE_PATH

fullpath = w_FULL_PATH

USER_ACTION =

FILE_ENCODING =

EXCEPTIONS

CNTL_ERROR = 1

ERROR_NO_GUI = 2

NOT_SUPPORTED_BY_GUI = 3

others = 4

.

IF sy-subrc 0.

MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

Use the FM GUI_DOWNLOAD to download the generated PDF file onto the

presentation server

CALL FUNCTION 'GUI_DOWNLOAD'

EXPORTING

BIN_FILESIZE = W_bin_filesize

filename = w_FULL_PATH

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 =

tables

data_tab = T_pdf_tab

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.

Regards,

If helpful give points(Don't forget)

Former Member
0 Kudos

Thek you for the report Z_SCRIPT, but I don't understand how to link it into the process. Where does this code go?

Thanks,

Clint