Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

Smartforms Sending through mail.

Hi Friends,

I have problem with sending smartform output (PDF) through mail.

I am able to download the PDF file.

But when sending through mails .. i am getting the mail with PDF attachement.

but there where no data in the PDF file.

Below is the code i m using...

*&----


*

*& Report ZMAHA_BACKGROUND_INVOICE

*&

*&----


*

*&

*&

*&----


*

REPORT zmaha_background_invoice.

TABLES : vbrk,

vbrp,

vbpa,

vbkd,

kna1.

DATA: BEGIN OF it_kna1 OCCURS 0,

  • vbeln like kna1-vbeln,

kunnr LIKE kna1-kunnr,

land1 LIKE kna1-land1,

ort01 LIKE kna1-ort01,

pstlz LIKE kna1-pstlz,

regio LIKE kna1-regio,

END OF it_kna1.

DATA: BEGIN OF it_vbrk OCCURS 0,

kunag LIKE vbrk-kunag,

vbeln LIKE vbrk-vbeln,

fkdat LIKE vbrk-fkdat,

bstnk_vf LIKE vbrk-bstnk_vf,

END OF it_vbrk.

DATA: BEGIN OF it_vbpa OCCURS 0,

vbeln LIKE vbpa-vbeln,

posnr LIKE vbpa-posnr,

parvw LIKE vbpa-parvw,

parnr LIKE vbpa-parnr,

adrnr LIKE vbpa-adrnr,

land1 LIKE vbpa-land1,

END OF it_vbpa.

DATA: BEGIN OF it_vbkd OCCURS 0,

vbeln LIKE vbkd-vbeln,

  • POSNR like VBKD-POSNR,

prsdt LIKE vbkd-prsdt,

fkdat LIKE vbkd-fkdat,

END OF it_vbkd.

DATA: BEGIN OF it_vbrp OCCURS 0,

vbeln LIKE vbrp-vbeln,

posnr LIKE vbrp-posnr,

END OF it_vbrp.

DATA : BEGIN OF it_final OCCURS 0.

INCLUDE STRUCTURE zit_final_struc.

DATA : END OF it_final.

SELECTION-SCREEN : BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.

SELECT-OPTIONS : s_vbeln FOR vbrk-vbeln.

SELECTION-SCREEN : END OF BLOCK b1.

SELECT kunag vbeln fkdat bstnk_vf

FROM vbrk

INTO TABLE it_vbrk

WHERE vbeln IN s_vbeln.

IF NOT it_vbrk[] IS INITIAL.

*select KUNNR LAND1 ORT01 PSTLZ REGIO

  • from kna1

  • into table it_kna1

  • for all entries in it_vbrk

  • where kunnr = it_vbrk-kunag.

SELECT vbeln posnr parvw parnr adrnr land1

FROM vbpa

INTO TABLE it_vbpa

FOR ALL ENTRIES IN it_vbrk

WHERE vbeln = it_vbrk-vbeln.

SELECT vbeln prsdt fkdat

FROM vbkd

INTO TABLE it_vbkd

FOR ALL ENTRIES IN it_vbrk

WHERE vbeln = it_vbrk-vbeln.

SELECT vbeln posnr

FROM vbrp

INTO TABLE it_vbrp

FOR ALL ENTRIES IN it_vbrk

WHERE vbeln = it_vbrk-vbeln.

ENDIF.

LOOP AT it_vbrk.

SELECT SINGLE * FROM kna1

WHERE kunnr = it_vbrk-kunag.

IF sy-subrc = 0.

it_final-kunnr = kna1-kunnr.

it_final-land1 = kna1-land1.

it_final-ort01 = kna1-ort01.

it_final-pstlz = kna1-pstlz.

it_final-regio = kna1-regio.

ENDIF.

  • read table it_kna1 with key vbeln = it_vbrk-vbeln.

READ TABLE it_vbpa WITH KEY vbeln = it_vbrk-vbeln.

READ TABLE it_vbkd WITH KEY vbeln = it_vbrk-vbeln.

READ TABLE it_vbrp WITH KEY vbeln = it_vbrk-vbeln.

it_final-vbeln = it_vbrk-vbeln.

it_final-fkdat = it_vbrk-fkdat.

it_final-bstnk_vf = it_vbrk-bstnk_vf.

  • it_final-vbeln = it_kna1-vbeln.

  • it_final-KUNNR = it_kna1-kunnr.

  • it_final-LAND1 = it_kna1-land1.

  • it_final-ORT01 = it_kna1-ort01.

  • it_final-PSTLZ = it_kna1-pstlz.

  • it_final-REGIO = it_kna1-regio.

it_final-vbeln = it_vbpa-vbeln.

  • it_final-POSNR = it_vbpa-posnr.

it_final-parvw = it_vbpa-parvw.

it_final-parnr = it_vbpa-parnr.

it_final-adrnr = it_vbpa-adrnr.

it_final-land1 = it_vbpa-land1.

it_final-vbeln = it_vbkd-vbeln.

  • it_final-POSNR = it_vbkd-posnr.

it_final-prsdt = it_vbkd-prsdt.

  • it_final-FKDAT = it_vbkd-fkdat.

it_final-vbeln = it_vbrp-vbeln.

it_final-posnr = it_vbrp-posnr.

APPEND it_final.

CLEAR it_final.

ENDLOOP.

  • loop at it_final.

  • write : / it_final-vbeln, it_final-posnr, it_final-parvw,

*it_final-prsdt, it_final-kunnr.

*endloop.

*DATA : FM_NAME TYPE RS38L_FNAM.

DATA: cparam TYPE ssfctrlop,

outop TYPE ssfcompop,

fm_name TYPE rs38l_fnam.

DATA : tab_otf_data TYPE ssfcrescl,

  • pdf_tab LIKE tline OCCURS 0 WITH HEADER LINE,

tab_otf_final TYPE itcoo OCCURS 0 WITH HEADER LINE,

file_size TYPE i,

bin_filesize TYPE i.

outop-tddest = 'LP01'.

cparam-no_dialog = 'X'.

cparam-preview = space.

cparam-getotf = 'X'.

CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'

EXPORTING

formname = 'ZMAHA_BACKGROUND_INVOICE'

  • VARIANT = ' '

  • DIRECT_CALL = ' '

IMPORTING

fm_name = 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 FUNCTION fm_name "'/1BCDWB/SF00000127'

EXPORTING

  • ARCHIVE_INDEX =

  • ARCHIVE_INDEX_TAB =

  • ARCHIVE_PARAMETERS =

control_parameters = cparam

  • MAIL_APPL_OBJ =

  • MAIL_RECIPIENT =

  • MAIL_SENDER =

output_options = outop

user_settings = space

IMPORTING

  • DOCUMENT_OUTPUT_INFO =

job_output_info = tab_otf_data

  • JOB_OUTPUT_OPTIONS =

TABLES

it_final = it_final

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

tab_otf_final[] = tab_otf_data-otfdata.

DATA : i_tline TYPE TABLE OF tline WITH HEADER LINE.

*

*CALL FUNCTION 'CONVERT_OTF'

  • EXPORTING

  • FORMAT = 'PDF'

  • MAX_LINEWIDTH = 132

    • ARCHIVE_INDEX = ' '

    • COPYNUMBER = 0

    • ASCII_BIDI_VIS2LOG = ' '

  • IMPORTING

  • BIN_FILESIZE = BIN_FILESIZE

    • BIN_FILE =

  • TABLES

  • OTF = TAB_OTF_FINAL[]

  • LINES = I_TLINE[]

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

*

DATA:i_doc TYPE TABLE OF docs.

CALL FUNCTION 'CONVERT_OTF_2_PDF'

EXPORTING

USE_OTF_MC_CMD = 'X'

  • ARCHIVE_INDEX =

IMPORTING

bin_filesize = bin_filesize

TABLES

otf = tab_otf_final

doctab_archive = i_doc

lines = i_tline

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

CALL FUNCTION 'GUI_DOWNLOAD'

EXPORTING

BIN_FILESIZE = BIN_FILESIZE

FILENAME = 'C:Documents and settingsmm0998Desktopmstest6.pdf'

FILETYPE = 'BIN'

TABLES

DATA_TAB = I_TLINE[]

.

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 FUNCTION 'GUI_DOWNLOAD'

  • EXPORTING

  • BIN_FILESIZE = BIN_FILESIZE

  • FILENAME = 'C:Documents and settingssg0888Desktopmstest6.pdf'

  • FILETYPE = 'BIN'

  • TABLES

  • DATA_TAB = I_TLINE[]

  • .

*IF SY-SUBRC <> 0.

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

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

*ENDIF.

            • sending thru mail

DATA: i_record LIKE solisti1 OCCURS 0 WITH HEADER LINE,

i_reclist LIKE somlreci1 OCCURS 0 WITH HEADER LINE,

i_objtxt LIKE solisti1 OCCURS 0 WITH HEADER LINE,

i_objbin LIKE solisti1 OCCURS 0 WITH HEADER LINE,

i_objpack LIKE sopcklsti1 OCCURS 0 WITH HEADER LINE.

DATA: wa_buffer TYPE string,

wa_objhead TYPE soli_tab,

wa_doc_chng TYPE sodocchgi1.

  • Variables declarations

DATA: v_lines_txt TYPE i,

v_lines_bin TYPE i.

LOOP AT i_tline.

TRANSLATE i_tline USING '~'.

CONCATENATE wa_buffer i_tline INTO wa_buffer.

*translate wa_buffer using '~'.

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 = 'jeyaseelan.gurusamy@cambridge-asia.com'.

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

  • CONTENTS_HEX =

  • OBJECT_PARA =

  • OBJECT_PARB =

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

.

IF sy-subrc = 0.

WRITE: / 'succesfully sent '.

ENDIF.

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

Thanks

Jeyaseelan.G

Former Member
Not what you were looking for? View more on this topic or Ask a question