cancel
Showing results for 
Search instead for 
Did you mean: 

To send the output thro

Former Member
0 Kudos

Hi all,

After generating output using smartforms, i want to send the output thro Email.

How to do the above?

Expecting reply.

Accepted Solutions (0)

Answers (4)

Answers (4)

Former Member
0 Kudos

Hi

Use Fm CALL FUNCTION 'SO_NEW_DOCUMENT_SEND_API1'

TABLES: ekko, lfa1, adr6.

  • Para llamada a generacion de smartform.

DATA: output TYPE ssfcrescl.

  • Smartform in OTF.

DATA : BEGIN OF t_otfdata OCCURS 0.

INCLUDE STRUCTURE itcoo.

DATA : END OF t_otfdata.

  • To Get PDF.

DATA: t_lines LIKE tline OCCURS 0 WITH HEADER LINE.

  • Objects to send mail.

DATA: objpack LIKE sopcklsti1 OCCURS 2 WITH HEADER LINE.

DATA: objtxt LIKE solisti1 OCCURS 10 WITH HEADER LINE.

DATA: objbin LIKE solisti1 OCCURS 10 WITH HEADER LINE.

DATA: reclist LIKE somlreci1 OCCURS 5 WITH HEADER LINE.

DATA: doc_chng LIKE sodocchgi1.

DATA : objhead TYPE soli_tab.

DATA : len_in LIKE sood-objlen,

len_out LIKE sood-objlen,

len_outn TYPE i.

DATA righe_attachment TYPE i.

DATA righe_testo TYPE i.

  • To convert from 132 to 255.

DATA: gd_buffer TYPE string.

DATA: it_mess_att LIKE solisti1 OCCURS 0 WITH HEADER LINE.

DATA: w_cnt TYPE i.

  • Call Smartform to get OTF.

ssfctrlop-getotf = 'X'.

CALL FUNCTION fm_name

EXPORTING

ekko = itekko

werks = v_werks

control_parameters = ssfctrlop

IMPORTING

job_output_info = output

TABLES

ekpo = itekpo

esll = itesll.

t_otfdata[] = output-otfdata[].

  • Convert OTF to PDF (132 per line).

CALL FUNCTION 'CONVERT_OTF'

EXPORTING

format = 'PDF'

  • MAX_LINEWIDTH = 132

  • ARCHIVE_INDEX = ' '

IMPORTING

bin_filesize = len_in

TABLES

otf = t_otfdata

lines = t_lines

  • EXCEPTIONS

  • ERR_MAX_LINEWIDTH = 1

  • ERR_FORMAT = 2

  • ERR_CONV_NOT_POSSIBLE = 3

  • OTHERS = 4

.

IF sy-subrc <> 0.

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

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

ENDIF.

  • Convert PDF from 132 to 255.

LOOP AT t_lines.

TRANSLATE t_lines USING ' ~'.

CONCATENATE gd_buffer t_lines 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.

*

len_outn = len_out = len_in.

CLEAR: reclist, reclist[],

objhead, objhead[],

objtxt, objtxt[],

objbin, objbin[],

objpack, objpack[].

  • Object with PDF.

CLEAR objbin.

REFRESH objbin.

objbin[] = it_mess_att[].

DESCRIBE TABLE objbin LINES righe_attachment.

  • Object with main text of the mail.

objtxt = 'Test for PO - Line 1'.APPEND objtxt.

objtxt = 'Test for PO - Line 2'.APPEND objtxt.

objtxt = 'Test for PO - Line 3'.APPEND objtxt.

DESCRIBE TABLE objtxt LINES righe_testo.

  • Document information.

doc_chng-obj_name = 'URGENT'.

doc_chng-expiry_dat = sy-datum + 10.

CONCATENATE 'Alto Parana - Peticion de Oferta' itekko-ebeln

INTO doc_chng-obj_descr SEPARATED BY space.

doc_chng-sensitivty = 'F'.

doc_chng-doc_size = righe_testo * 255.

  • Pack to main body.

CLEAR objpack-transf_bin.

objpack-head_start = 1.

objpack-head_num = 0.

objpack-body_start = 1.

objpack-body_num = righe_testo.

objpack-doc_type = 'RAW'.

APPEND objpack.

  • Pack to PDF.

objpack-transf_bin = 'X'.

objpack-head_start = 1.

objpack-head_num = 1.

objpack-body_start = 1.

objpack-body_num = righe_attachment.

objpack-doc_type = 'PDF'.

objpack-obj_name = 'TEST'.

CONCATENATE itekko-lifnr '-' itekko-ebeln '.pdf'

INTO objpack-obj_descr.

objpack-doc_size = righe_attachment * 255.

APPEND objpack.

CLEAR reclist.

reclist-copy = 'X'.

  • e-mail receivers.

reclist-receiver = 'tito@tito.com'.

reclist-express = 'X'.

reclist-rec_type = 'U'.

reclist-notif_del = 'X'. " request delivery notification

reclist-notif_ndel = 'X'. " request not delivered notification

APPEND reclist.

  • Llamada a funcion de envio de mail.

CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'

EXPORTING

document_data = doc_chng

put_in_outbox = 'X'

TABLES

packing_list = objpack

object_header = objhead

contents_hex = objbin

contents_txt = objtxt

receivers = reclist

EXCEPTIONS

too_many_receivers = 1

document_not_sent = 2

document_type_not_exist = 3

operation_no_authorization = 4

parameter_error = 5

x_error = 6

enqueue_error = 7

OTHERS = 8.

http://sap.ittoolbox.com/groups/technical-functional/sap-dev/smart-forms-81507?cv=expanded#

Former Member
0 Kudos

Hi Guys,

This is Maha. I was sending a mail to my ID. I am recieving a mail but it

was unable to display the details of document which is in the PDF format. Please do the needful.

When I was opening PDF which i have recieved through mail, it is throughing a message saying that " <b>There was an error processing a page. Too few Operands </b>".

Former Member
0 Kudos

Hi

REPORT Z_RAJ_SEND_SPOOL_MAIL_ATT .

----


PARAMETERS : P_SPOOL TYPE TSP01-RQIDENT OBLIGATORY .

PARAMETERS : P_MAIL TYPE char100 OBLIGATORY .

----


TYPES : TY_LINE type string.

DATA: IT_ATTACHMENT TYPE soli OCCURS 0 WITH HEADER LINE.

DATA: IT_ATTACHMENT_LONG TYPE TY_LINE OCCURS 0 WITH HEADER LINE.

DATA: LV_PDF_SIZE type i.

DATA: LT_PDF type standard table of tline with header line.

----


PERFORM SEND_EMAIL USING P_SPOOL P_MAIL.

----


  • FORM send_email

----


  • --> X_SPOOL_ID

  • --> X_EMAIL

----


FORM send_email USING X_SPOOL_ID X_EMAIL.

DATA: LT_OBJPACK LIKE sopcklsti1 OCCURS 2 WITH HEADER LINE,

LT_OBJHEAD LIKE solisti1 OCCURS 1 WITH HEADER LINE,

LT_OBJBIN LIKE solisti1 OCCURS 10 WITH HEADER LINE,

LT_OBJTXT LIKE solisti1 OCCURS 10 WITH HEADER LINE,

LT_RECLIST LIKE somlreci1 OCCURS 5 WITH HEADER LINE,

LV_DOCUMENT_DATA TYPE sodocchgi1.

DATA: L_ATT_LINES TYPE i.

DATA : LV_SPOOL_DESC(68) type c.

CHECK NOT ( X_EMAIL IS INITIAL ).

CLEAR: LT_RECLIST, LT_RECLIST[],

LT_OBJHEAD, LT_OBJHEAD[],

LT_OBJTXT, LT_OBJTXT[],

LT_OBJBIN, LT_OBJBIN[],

LT_OBJPACK, LT_OBJPACK[].

CLEAR LV_DOCUMENT_DATA.

  • Read spool and get the pdf internal table and name of spool

PERFORM READ_SPOOL USING X_SPOOL_ID LV_SPOOL_DESC.

CHECK NOT ( LT_PDF[] IS INITIAL ).

  • Convert pdf itab to 255 line itab.

data :LV_COUNTER type i.

data :LV_FROM type i.

loop at LT_PDF.

translate LT_PDF using ' ~' .

concatenate IT_ATTACHMENT_LONG LT_PDF into it_attachment_long.

endloop.

translate IT_ATTACHMENT_LONG using '~ ' .

append IT_ATTACHMENT_LONG.

clear : LV_COUNTER.

DO.

LV_COUNTER = strlen( IT_ATTACHMENT_LONG ).

if LV_COUNTER ge 255.

IT_ATTACHMENT = IT_ATTACHMENT_LONG(255).

append IT_ATTACHMENT.

SHIFT IT_ATTACHMENT_LONG by 255 places.

else.

IT_ATTACHMENT = IT_ATTACHMENT_LONG(lv_counter).

append IT_ATTACHMENT.

exit.

endif.

ENDDO.

  • Body of email

MOVE 'Email sent to you from SAP' TO LT_OBJTXT.

APPEND LT_OBJTXT.

LV_DOCUMENT_DATA-obj_name = 'SpoolMail'.

  • Title of the email as spool name

LV_DOCUMENT_DATA-obj_descr = LV_SPOOL_DESC.

LV_DOCUMENT_DATA-sensitivty = 'O'.

LV_DOCUMENT_DATA-expiry_dat = SY-datum + 15.

LV_DOCUMENT_DATA-doc_size = STRLEN( LT_OBJTXT ).

  • e-mail body

CLEAR LT_OBJPACK.

LT_OBJPACK-head_start = 1.

LT_OBJPACK-head_num = 0.

LT_OBJPACK-body_start = 1.

LT_OBJPACK-body_num = 1.

LT_OBJPACK-doc_type = 'RAW'.

LT_OBJPACK-doc_size = STRLEN( LT_OBJTXT ).

APPEND LT_OBJPACK.

  • For e-mail attachment

DESCRIBE TABLE IT_ATTACHMENT LINES L_ATT_LINES.

READ TABLE IT_ATTACHMENT INDEX L_ATT_LINES.

CLEAR LT_OBJPACK.

LT_OBJPACK-transf_bin = 'X'.

LT_OBJPACK-head_start = 1.

LT_OBJPACK-head_num = 1.

LT_OBJPACK-body_start = 1.

LT_OBJPACK-body_num = L_ATT_LINES.

LT_OBJPACK-doc_type = 'PDF'.

LT_OBJPACK-obj_name = 'email'.

LT_OBJPACK-obj_descr = LV_SPOOL_DESC.

LT_OBJPACK-doc_size = ( 255 * ( L_ATT_LINES - 1 ) ) + STRLEN(

IT_ATTACHMENT-line ).

APPEND LT_OBJPACK.

  • make recipient list

LT_RECLIST-receiver = X_EMAIL.

LT_RECLIST-rec_type = 'U'. "To external email id

APPEND LT_RECLIST.

  • send mail with attachment

CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'

EXPORTING

document_data = LV_DOCUMENT_DATA

put_in_outbox = 'X'

TABLES

packing_list = LT_OBJPACK

object_header = LT_OBJHEAD

contents_bin = IT_ATTACHMENT

contents_txt = LT_OBJTXT

receivers = LT_RECLIST

EXCEPTIONS

too_many_receivers = 1

document_not_sent = 2

document_type_not_exist = 3

operation_no_authorization = 4

parameter_error = 5

x_error = 6

enqueue_error = 7

OTHERS = 8.

If SY-subrc = 0.

write:/ 'Message sent'.

else.

write:/ 'Error encountered'.

endif.

ENDFORM. " send_email

&----


*& Form read_spool

&----


FORM read_spool USING X_SPOOL_ID Y_SPOOL_DESC.

DATA : LV_SPOOL_TYPE TYPE TSP01-RQDOCTYPE.

SELECT SINGLE RQDOCTYPE RQTITLE

INTO (lv_spool_type, y_spool_desc)

FROM TSP01

WHERE RQIDENT eq X_SPOOL_ID.

IF Y_SPOOL_DESC IS INITIAL.

concatenate 'Spool-' X_SPOOL_ID into Y_SPOOL_DESC.

ENDIF.

IF LV_SPOOL_TYPE eq 'LIST'. " If spool is a list

CALL FUNCTION 'CONVERT_ABAPSPOOLJOB_2_PDF'

EXPORTING

SRC_SPOOLID = X_SPOOL_ID

  • NO_DIALOG =

  • DST_DEVICE =

  • PDF_DESTINATION =

IMPORTING

PDF_BYTECOUNT = LV_PDF_SIZE

  • PDF_SPOOLID =

  • LIST_PAGECOUNT =

  • BTC_JOBNAME =

  • BTC_JOBCOUNT =

TABLES

PDF = LT_PDF

EXCEPTIONS

ERR_NO_ABAP_SPOOLJOB = 1

ERR_NO_SPOOLJOB = 2

ERR_NO_PERMISSION = 3

ERR_CONV_NOT_POSSIBLE = 4

ERR_BAD_DESTDEVICE = 5

USER_CANCELLED = 6

ERR_SPOOLERROR = 7

ERR_TEMSEERROR = 8

ERR_BTCJOB_OPEN_FAILED = 9

ERR_BTCJOB_SUBMIT_FAILED = 10

ERR_BTCJOB_CLOSE_FAILED = 11

OTHERS = 12

.

IF SY-SUBRC <> 0.

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

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

ENDIF.

ELSE. " If spool is OTF

CALL FUNCTION 'CONVERT_OTFSPOOLJOB_2_PDF'

EXPORTING

SRC_SPOOLID = X_SPOOL_ID

  • NO_DIALOG =

  • DST_DEVICE =

  • PDF_DESTINATION =

IMPORTING

PDF_BYTECOUNT = LV_PDF_SIZE

  • PDF_SPOOLID =

  • OTF_PAGECOUNT =

  • BTC_JOBNAME =

  • BTC_JOBCOUNT =

TABLES

PDF = LT_PDF

EXCEPTIONS

ERR_NO_OTF_SPOOLJOB = 1

ERR_NO_SPOOLJOB = 2

ERR_NO_PERMISSION = 3

ERR_CONV_NOT_POSSIBLE = 4

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

ENDIF.

ENDIF.

ENDFORM. " read_spool

Regards,

Raj

Former Member
0 Kudos

Hi Raj,

i had tried ur code. but i don't know what should i pass the values in parameters. i.e. P_SPOOL & P_MAIL.

Former Member
0 Kudos

First you need to convert it into PDF form. Then you can send it through mail.

Smart Forms does not support direct output in PDF format. Instead, the OTF output has to be converted to PDF. The function module generated by the SmartForm has to be supplied with Control Structure parameters that will export the SmartForm output to OTF format. The Output Text Format (OTF) is the established SAP output format for printing forms. It consists of a number of simple, device-independent commands, thus allowing output to be directed to different output devices such as line printers and laser printers, or as an on-screen print preview. OTF is an explicit output format, which means that once SAP Smart Forms has generated an OTF output, no modifications can be made.

The procedure for the form to be returned as a table in OTF format is as follows:

1. Define a structure of type SSFCTRLOP (control structure, standard parameter CONTROL_PARAMETERS) and another structure of type SSFCRESCL (to contain the output results, standard parameter JOB_OUTPUT_INFO):

DATA: my_control_pars TYPE ssfctrlop. "For CONTROL_PARAMETERS

DATA: my_output_info TYPE ssfcrescl. "For JOB_OUTPUT_INFO

2. To deactivate the dialogs and to inform SAP Smart Forms that you only want the OTF table to be returned, set the parameters NO_DIALOG and GETOTF of the control structure:

my_control_pars-no_dialog = 'X'.

my_control_pars-getotf = 'X'.

3. Pass both structures in the call of the generated function module.

Now access the OTF table in the formal parameter JOB_OUTPUT_INFO using the OTFDATA parameter of your structure.

4. Get the OTF output from table OTFDATA of the standard parameter JOB_OUTPUT_INFO.

5. To convert the OTF output to PDF, transfer the OTF table to the function module CONVERT_OTF. To do this, set the parameter FORMAT to 'PDF'. The output can be returned either as a binary string (parameter BIN_FILE) or as a character table (parameter LINES). SAP recommends the first variant.

You can then store the PDF output using the function module GUI_DOWNLOAD, for example, as a local file on your PC.

Function Module : Convert_OTF

CALL FUNCTION "CONVERT_OTF"

EXPORTING FORMAT = "PDF"

IMPORTING BIN_FILESIZE = FILE_LEN

TABLES OTF = OTFDATA

LINES = PDFDATA

EXCEPTIONS

ERR_MAX_LINEWIDTH = 1

ERR_FORMAT = 2

ERR_CONV_NOT_POSSIBLE = 3

OTHERS = 4.

Have a look at this link.

http://searchsap.techtarget.com/ateQuestionNResponse/0,289625,sid21_gci1027361_tax294895,00.html

Have a look at below link for sending mail.

http://sap-basis-abap.com/abap021.htm

Best Regards,

Vibha

*Please mark all the helpful answers

Former Member
0 Kudos

this thread should help u