cancel
Showing results for 
Search instead for 
Did you mean: 

Smartforms Sending through mail.

Former Member
0 Kudos

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

Accepted Solutions (0)

Answers (2)

Answers (2)

Former Member
0 Kudos

Hi,

Try this code to send email

REPORT zemail_gm.

*********Variable Declarations *****************************

DATA: gv_form_name TYPE rs38l_fnam, " Used to store the function module generated by Smartform

gv_bin_filesize TYPE i, " Store the file size

gv_pos TYPE i,

gv_len TYPE i,

gv_tab_lines TYPE i.

********Constants *******************************************

Data : gc_text(11) type c value 'Form Output',

gc_tst(3) type c value 'TST',

gc_testing(7) type c value 'Testing'.

*********Work Area Declarations *****************************

DATA: gs_docdata TYPE sodocchgi1, " Data of an object which can be changed

gs_ctrlop TYPE ssfctrlop, " Smart Forms: Control structure

gs_outopt TYPE ssfcompop, " SAP Smart Forms: Smart Composer (transfer) options

gs_otfdata TYPE ssfcrescl, " Smart Forms: Return value at end of form printing

gs_reclist TYPE somlreci1, " SAPoffice: Structure of the API Recipient List

gs_pdf_tab TYPE tline, " Workarea for SAP Script Text Lines

gs_objbin TYPE solisti1, " SAPoffice: Single List with Column Length 255

gs_objpack TYPE sopcklsti1. " SAPoffice: Description of Imported Object Components

*********Internal tables Declarations *****************************

DATA: gt_reclist TYPE TABLE OF somlreci1, " SAPoffice: Structure of the API Recipient List

gt_pdf_tab TYPE TABLE OF tline, " SAPscript: Text Lines

gt_otf TYPE TABLE OF itcoo, " OTF Structure

gt_objbin TYPE TABLE OF solisti1, " SAPoffice: Single List with Column Length 255

gt_objpack TYPE TABLE OF sopcklsti1. " SAPoffice: Description of Imported Object Components

CLEAR : gv_form_name,

gs_ctrlop,

gs_outopt,

gs_otfdata,

gv_bin_filesize,

gv_pos,

gv_len,

gv_tab_lines.

START-OF-SELECTION.

  • Generate Function Module name

CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'

EXPORTING

formname = 'ZPDF_G'

IMPORTING

fm_name = gv_form_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.

  • Assigning values to Form Control Structure and Form Composer

gs_ctrlop-getotf = 'X'.

gs_ctrlop-no_dialog = 'X'.

gs_outopt-tdnoprev = 'X'.

  • Getting the OTFDATA

CALL FUNCTION gv_form_name

EXPORTING

control_parameters = gs_ctrlop

output_options = gs_outopt

user_settings = 'X'

IMPORTING

job_output_info = gs_otfdata

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.

  • Assigning the OTFDATA to OTF Structure table

CLEAR gt_otf.

gt_otf[] = gs_otfdata-otfdata[].

  • Convert the OTF DATA to SAP Script Text lines

CLEAR gt_pdf_tab.

CALL FUNCTION 'CONVERT_OTF'

EXPORTING

format = 'PDF'

max_linewidth = 132

IMPORTING

bin_filesize = gv_bin_filesize

TABLES

otf = gt_otf

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

  • Assigning the Description of the object sent in the mail

CLEAR gs_docdata.

gs_docdata-obj_name = gc_tst.

gs_docdata-obj_descr = gc_testing.

  • Assigning the email id to Structure of the API Recipient List table

CLEAR : gt_reclist, gs_reclist.

gs_reclist-receiver = 'minal.nampalliwar@wipro.com'.

gs_reclist-rec_type = 'U'.

APPEND gs_reclist TO gt_reclist.

  • Passing the SAP Script text lines to SAPoffice: Single List with Column Length 255 table

CLEAR : gs_objbin, gs_pdf_tab.

LOOP AT gt_pdf_tab INTO gs_pdf_tab.

gv_pos = 255 - gv_len.

IF gv_pos > 134. "length of pdf_table

gv_pos = 134.

ENDIF.

gs_objbin+gv_len = gs_pdf_tab(gv_pos).

gv_len = gv_len + gv_pos.

IF gv_len = 255. "length of out (contents_bin)

APPEND gs_objbin TO gt_objbin.

CLEAR: gs_objbin, gv_len.

IF gv_pos < 134.

gs_objbin = gs_pdf_tab+gv_pos.

gv_len = 134 - gv_pos.

ENDIF.

ENDIF.

ENDLOOP.

IF gv_len > 0.

APPEND gs_objbin TO gt_objbin.

ENDIF.

  • Filling the details in SAPoffice: Description of Imported Object Components table

DESCRIBE TABLE gt_objbin LINES gv_tab_lines.

CLEAR gs_objbin.

READ TABLE gt_objbin INTO gs_objbin INDEX gv_tab_lines.

IF sy-subrc = 0.

gs_objpack-doc_size = ( gv_tab_lines - 1 ) * 255 + STRLEN( gs_objbin ).

gs_objpack-transf_bin = 'X'.

gs_objpack-head_start = 1.

gs_objpack-head_num = 0.

gs_objpack-body_start = 1.

gs_objpack-body_num = gv_tab_lines.

gs_objpack-doc_type = 'PDF'.

gs_objpack-obj_name = 'ATTACHMENT'.

gs_objpack-obj_descr = 'test'.

APPEND gs_objpack TO gt_objpack.

ENDIF.

  • Sending the Form Output in the PDF format to email

CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'

EXPORTING

document_data = gs_docdata

put_in_outbox = 'X'

commit_work = 'X'

TABLES

packing_list = gt_objpack

contents_bin = gt_objbin

receivers = gt_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.

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

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

ELSE.

WRITE 'Sent Successfully'.

ENDIF.

SUBMIT rsconn01

WITH mode EQ 'INT'

AND RETURN.

END-OF-SELECTION.

Former Member
0 Kudos

Hi

chk this sample code.

* Internal Table declarations
 
DATA: i_otf TYPE itcoo OCCURS 0 WITH HEADER LINE,
      i_tline TYPE TABLE OF tline WITH HEADER LINE,
      i_receivers TYPE TABLE OF somlreci1 WITH HEADER LINE,
      i_record LIKE solisti1 OCCURS 0 WITH HEADER LINE,
* Objects to send mail.
      i_objpack LIKE sopcklsti1 OCCURS 0 WITH HEADER LINE,
      i_objtxt LIKE solisti1 OCCURS 0 WITH HEADER LINE,
      i_objbin LIKE solisti1 OCCURS 0 WITH HEADER LINE,
      i_reclist LIKE somlreci1 OCCURS 0 WITH HEADER LINE,
 
* Work Area declarations
      wa_objhead TYPE soli_tab,
      w_ctrlop TYPE ssfctrlop,
      w_compop TYPE ssfcompop,
      w_return TYPE ssfcrescl,
      wa_doc_chng typE sodocchgi1,
      w_data TYPE sodocchgi1,
      wa_buffer TYPE string,"To convert from 132 to 255
 
* Variables declarations
      v_form_name TYPE rs38l_fnam,
      v_len_in LIKE sood-objlen,
      v_len_out LIKE sood-objlen,
      v_len_outn TYPE i,
      v_lines_txt TYPE i,
      v_lines_bin TYPE i.
 
call function 'SSF_FUNCTION_MODULE_NAME'
     exporting
          formname           = 'ZZZ_TEST1'
     importing
          fm_name            = v_form_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.
 
 
w_ctrlop-getotf = 'X'.
w_ctrlop-no_dialog = 'X'.
w_compop-tdnoprev = 'X'.
 
CALL FUNCTION v_form_name
     EXPORTING
          control_parameters = w_ctrlop
          output_options     = w_compop
          user_settings      = 'X'
     IMPORTING
          job_output_info    = w_return
     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.
 
i_otf[] = w_return-otfdata[].
 
call function 'CONVERT_OTF'
       EXPORTING
            format                = 'PDF'
            max_linewidth         = 132
       IMPORTING
            bin_filesize          = v_len_in
       TABLES
            otf                   = i_otf
            lines                 = i_tline
       EXCEPTIONS
            err_max_linewidth     = 1
            err_format            = 2
            err_conv_not_possible = 3
            others                = 4.
*   Fehlerhandling
  if sy-subrc <> 0.
 
  endif.
 
  loop at i_tline.
    translate i_tline using '~'.
    concatenate wa_buffer i_tline into wa_buffer.
  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 = 'zyz@wipro.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
              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.

Reward if usefull

Former Member
0 Kudos

Hi Naresh,

I have tried with your sample code.

i am getting an error message when opening a PDF file.

" There was an error opening this document, The file is damaged and could not be repaired".

what could be the problem.

Thanks

Jey.