cancel
Showing results for 
Search instead for 
Did you mean: 

smartforms as pdf attachment

Former Member
0 Kudos

Hi,

can someone help me with the code to send smartforms as pdf attachments in emails.

I have referred the codes given on the previous threads but I get a blank pdf file as on output. (pdf gets generated for saving on local server but not for emails)

Thanks

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi

https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/d937ec90-0201-0010-0ca8-b6cb3b6d...

Go through this thread...if u cannot come up...then I can send u an document..

or check sdn ...

regards,

chaithanya

Answers (2)

Answers (2)

Former Member
0 Kudos

Thanks for the links Chaitanya and Sai Ram Reddy,

I went over the codes which is very similar to what I have done. I am attaching my code below. Kindly point out the mistakes if any as I am unable to figure out where exactly I am going wrong.

The problem with the output of the below written code is :

-the attached pdf file sent in the mail is blank.

( it works perfectly for pdf download, also the mail is successfully sent with an attachment )

&----


*& Report Z_SALESORDER

*&

&----


*&

*&

&----


report Z_SALESORDER.

data: ITAB_PO_HEADER type BAPIEKKOL occurs 0 with header line.

data: ITAB_PO_ADDRESS type BAPIADDRESS occurs 0 with header line.

data: ITAB_PO_ITEMS type BAPIEKPO occurs 0 with header line.

data: LV_FUNCT_NAME type RS38L_FNAM.

data: wa_job_output_info type ssfcrescl.

parameters: PO_NUM type EKKO-EBELN.

&----


*& Calling the form

&----


call function 'SSF_FUNCTION_MODULE_NAME'

exporting

FORMNAME = 'Z_SALESORDER_TEST'

importing

FM_NAME = LV_FUNCT_NAME .

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 GETDETAIL_BAPI

&----


*& This Bapi is for getting the items for the form

&----


call function 'BAPI_PO_GETDETAIL'

exporting

PURCHASEORDER = PO_NUM

ITEMS = 'X'

ACCOUNT_ASSIGNMENT = 'X'

SCHEDULES = 'X'

HISTORY = 'X'

ITEM_TEXTS = 'X'

HEADER_TEXTS = 'X'

SERVICES = 'X'

CONFIRMATIONS = 'X'

SERVICE_TEXTS = 'X'

EXTENSIONS = 'X'

importing

PO_HEADER = ITAB_PO_HEADER

PO_ADDRESS = ITAB_PO_ADDRESS

tables

PO_ITEMS = ITAB_PO_ITEMS.

*&----


*& calling the function module

*&----


data: wa_control_parameters type SSFCTRLOP.

wa_control_parameters-GETOTF = 'X'.

call function LV_FUNCT_NAME

exporting

CONTROL_PARAMETERS = wa_control_parameters

WA_PO_HEADER = ITAB_PO_HEADER

WA_PO_ADDRESS = ITAB_PO_ADDRESS

IMPORTING

JOB_OUTPUT_INFO = WA_JOB_OUTPUT_INFO

tables

IT_TAB_PO_ITEMS = ITAB_PO_ITEMS .

if SY-SUBRC <> 0.

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

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

endif.

&----


*& Converting to pdf

&----


data: it_conv_lines type table of tline.

data: wa_conv_lines type tline.

data: v_len_in like sood-objlen.

call function 'CONVERT_OTF'

EXPORTING

FORMAT = 'PDF'

MAX_LINEWIDTH = 132

IMPORTING

BIN_FILESIZE = v_len_in

tables

OTF = WA_JOB_OUTPUT_INFO-OTFDATA[]

LINES = it_conv_lines .

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: 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.

  • Prepare Packing List

PERFORM PREPARE_PACKING_LIST.

  • Mail Contents

MAILTXT-LINE = 'Here is your file'.

APPEND MAILTXT.

data: v_lines_txt type i.

describe table MAILTXT lines v_lines_txt.

  • Creation of the document to be sent File Name

MAILDATA-OBJ_NAME = 'TEST'.

  • Mail Subject

MAILDATA-OBJ_DESCR = 'Subject'.

MAILDATA-sensitivty = 'F'.

MAILDATA-doc_size = v_lines_txt * 255.

  • Set recipient - email address here!!!

MAILREC-RECEIVER = 'soumya.moily@gmail.com'.

MAILREC-REC_TYPE = 'U'.

mailrec-com_type = 'INT'.

APPEND MAILREC.

  • Sending the document

CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'

EXPORTING

DOCUMENT_DATA = MAILDATA

PUT_IN_OUTBOX = 'X'

commit_work = 'X'

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.

if sy-subrc = 0.

write: 'success'.

endif.

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

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

MAILPACK-BODY_START = 1.

MAILPACK-BODY_NUM = TAB_LINES.

MAILPACK-DOC_TYPE = 'PDF'.

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: wa_buffer type string.

loop at it_conv_lines into wa_conv_lines.

translate wa_conv_lines using '~'.

concatenate wa_buffer wa_conv_lines into wa_buffer.

endloop.

translate wa_buffer using '~'.

CLEAR SOLISTI1. REFRESH SOLISTI1.

do.

SOLISTI1 = wa_buffer.

append SOLISTI1.

shift wa_buffer left by 255 places.

if wa_buffer is initial.

exit.

endif.

enddo.

ENDFORM.

*&----


**& storing the pdf file

*&----


*data: lv_bin_filesize type i.

*lv_bin_filesize = v_len_in.

*call function 'GUI_DOWNLOAD'

  • exporting

  • BIN_FILESIZE = lv_bin_filesize

  • FILENAME = 'c:\test.pdf'

  • 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'

    • IMPORTING

    • FILELENGTH =

  • TABLES

  • DATA_TAB = it_conv_lines

    • 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.

former_member196280
Active Contributor
0 Kudos

Go through this link, it may help you to close this thread.

<a href="https://www.sdn.sap.comhttp://www.sdn.sap.comhttp://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/8cd6adbb-0301-0010-39ba-938c601d5db9">Sample</a>

Regards,

SaiRam