Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Problem in mailing smartforms output using so_new_document_send_API1

Former Member
0 Likes
637

Hi All,

In smartforms , my requirement is to mail the output page.

In report , I am converting the output to PDF.

Everything is fine upto this point.

After that I am making each line to 255 characters and then using SO_NEW_DOCUMENT_SEND_API1.

I am getting the mail .But I am unable to view the attached PDF due to some problem in encoding/decoding.

Here is my coding….

CALL FUNCTION 'CONVERT_OTF'

EXPORTING

format = 'PDF'

max_linewidth = 132

IMPORTING

bin_filesize = w_bin_filesize

TABLES

otf = t_otf

lines = t_pdf_tab

EXCEPTIONS

err_max_linewidth = 1

err_format = 2

err_conv_not_possible = 3

OTHERS = 4.

IF sy-subrc <> 0.

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

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

ENDIF.

i_receivers-receiver = 'jayanthi.gayathri@wipro.com'.

i_receivers-rec_type = 'U'.

append i_receivers.

CALL FUNCTION 'SX_TABLE_LINE_WIDTH_CHANGE'

EXPORTING

LINE_WIDTH_DST = '255'

TABLES

content_in = t_pdf_tab

content_out = i_lines2

EXCEPTIONS

ERR_LINE_WIDTH_SRC_TOO_LONG = 1

ERR_LINE_WIDTH_DST_TOO_LONG = 2

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

i_data-obj_descr = 'Testing'.

CALL FUNCTION 'SO_NEW_DOCUMENT_SEND_API1'

EXPORTING

document_data = i_data

DOCUMENT_TYPE = 'PDF'

PUT_IN_OUTBOX = 'X'

commit_work = 'X'

tables

OBJECT_CONTENT = i_lines2

receivers = i_receivers.

IF sy-subrc <> 0.

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

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

ENDIF.

Can anyone help me to solve the problem?

Thanks and Regards,

J.Jayanthi

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
529

Hi Jayaraman,

Try doing the next step, instead of use FM CALL FUNCTION 'SX_TABLE_LINE_WIDTH_CHANGE' to convert from 132 to 255.

LOOP AT t_pdf_tab.

TRANSLATE t_pdf_tab USING ' ~'.

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

And then use it_mess_att...

I will paste the whole rutine to you understand better...

It is sending the mail from an output type.

FORM send_mail_pdf.

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.

Regards,

PabloX.

3 REPLIES 3
Read only

Former Member
0 Likes
530

Hi Jayaraman,

Try doing the next step, instead of use FM CALL FUNCTION 'SX_TABLE_LINE_WIDTH_CHANGE' to convert from 132 to 255.

LOOP AT t_pdf_tab.

TRANSLATE t_pdf_tab USING ' ~'.

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

And then use it_mess_att...

I will paste the whole rutine to you understand better...

It is sending the mail from an output type.

FORM send_mail_pdf.

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.

Regards,

PabloX.

Read only

0 Likes
529

Hi,

Thanks a lot for your suggestion.

I tried as you suggested.

I replaced the 'SX_TABLE_LINE_WIDTH_CHANGE' with

LOOP AT t_pdf_tab.

TRANSLATE t_pdf_tab USING ' ~'.

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

and then I passed that IT_mess_att in the below function module.

CALL FUNCTION 'SO_NEW_DOCUMENT_SEND_API1'

EXPORTING

document_data = i_data

DOCUMENT_TYPE = 'PDF'

PUT_IN_OUTBOX = 'X'

commit_work = 'X'

tables

OBJECT_CONTENT = IT_mess_att

receivers = i_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

.

But

I am getting mail and unable to open attachment .It is saying

'Adobe Reader could not open 'Testing1.PDF' because it is either not a supported file type or because the file has been corrupted'.

Could you tell me what I did wrong in 'SO_NEW_DOCUMENT_SEND_API1?

It is working fine with SO_NEW_DOCUMENT_ATT_SEND_API1.

Thanks a lot.

Thanks and Rgds,

J.Jayanthi

Message was edited by: Jayanthi Jayaraman

Read only

0 Likes
529

Hi Jayanthi,

Could you please help me to sove out the same problem.

I am also facing the same problem in opening the PDF attachement. I developed a print program for Script in which i have to send the layout in the form of PDF attachement to the customer. The email is going successfully but the problem is in opening the document.

I also used the same logic like CONVERT_OTF FM for converting OTF format to PDF format, after that i used the SO_DOCUMENT_SEND fm for sending an email.

Your immeadiate help will be appreciated.

Thanks & Regards,

Satish.