Skip to Content
avatar image
Former Member

Sending a smartform as a PDF attachment in an email

Hi,

I have used the following code to send a smartform as a pdf attachment through an email. But when I open the attachment I get an error saying 'Unable to read the data'. Can anybody help me on this? the commented code refers to all the options I have tried.

thank you,

Geetha

W_CTRLOP-GETOTF = 'X'.

W_CTRLOP-NO_DIALOG = 'X'.

W_COMPOP-TDNOPREV = 'X'.

CALL FUNCTION LV_NAME

EXPORTING

USER_SETTINGS = 'X'

OUTPUT_OPTIONS = W_COMPOP

CONTROL_PARAMETERS = W_CTRLOP

ZEITRAUM = LV_ZEITRAUM

IV_LIFNR = LS_ABC-LIFNR

IV_EKORG = MV_EKORG

IV_ACTION_CONT = ' '

IMPORTING

JOB_OUTPUT_INFO = LS_JOB_OUTPUT_INFO

TABLES

AT_DATA = LT_DATA

MSEG = LT_MSEG

IT_EKORG = MT_EKORG

IT_SPMON = MT_SPMON. " SR001

IF SY-SUBRC EQ 0.

I_OTF[] = LS_JOB_OUTPUT_INFO-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.

  • CALL FUNCTION 'CONVERT_OTF_2_PDF'

  • EXPORTING

  • USE_OTF_MC_CMD = 'X'

  • IMPORTING

  • BIN_FILESIZE = V_LEN_IN

  • TABLES

  • OTF = I_OTF

  • DOCTAB_ARCHIVE = IT_DOCTAB

  • LINES = I_TLINE

  • EXCEPTIONS

  • ERR_CONV_NOT_POSSIBLE = 1

  • ERR_OTF_MC_NOENDMARKER = 2

  • OTHERS = 3.

*

  • Fehlerhandling

  • IF SY-SUBRC <> 0.

*

  • ENDIF.

  • Change the PDF format from 132 to 255.

  • CALL FUNCTION 'SX_TABLE_LINE_WIDTH_CHANGE'

  • EXPORTING

  • line_width_src = '132'

  • line_width_dst = '255'

  • transfer_bin = 'X'

  • TABLES

  • content_in = i_tline

  • content_out = i_record

  • EXCEPTIONS

  • err_line_width_src_too_long = 1

  • err_line_width_dst_too_long = 2

  • err_conv_failed = 3

  • OTHERS = 4.

  • LOOP AT I_TLINE INTO WA_TLINE.

    TRANSLATE WA_TLINE USING '~'.

    CONCATENATE WA_BUFFER WA_TLINE INTO WA_BUFFER.

    ENDLOOP.

    TRANSLATE WA_BUFFER USING '~'.

    DO.

    WA_RECORD = WA_BUFFER.

    APPEND WA_RECORD TO 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[].

    • I_OBJBIN[] = I_TLINE[].

    • Create Message Body

  • Title and Description

  • CLEAR WA_OBJTXT.

    WA_OBJTXT = 'sMARTFORM'.

    APPEND WA_OBJTXT TO I_OBJTXT.

    APPEND WA_OBJTXT TO I_OBJTXT.

    APPEND WA_OBJTXT TO I_OBJTXT.

    CLEAR WA_OBJTXT.

    DESCRIBE TABLE I_OBJTXT LINES V_LINES_TXT.

    READ TABLE I_OBJTXT INTO WA_OBJTXT INDEX V_LINES_TXT.

    WA_DOC_CHNG-OBJ_NAME = 'Vendor Evaluation Statistics'.

    WA_DOC_CHNG-EXPIRY_DAT = SY-DATUM + 10.

    WA_DOC_CHNG-OBJ_DESCR = 'Vendor Evaluation Statistics'.

    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 WA_OBJPACK-TRANSF_BIN.

    WA_OBJPACK-HEAD_START = 1.

    WA_OBJPACK-HEAD_NUM = 0.

    WA_OBJPACK-BODY_START = 1.

    WA_OBJPACK-BODY_NUM = V_LINES_TXT.

    WA_OBJPACK-DOC_TYPE = 'RAW'.

    APPEND WA_OBJPACK TO I_OBJPACK.

    • Attachment

  • (pdf-Attachment)

  • WA_OBJPACK-TRANSF_BIN = 'X'.

    WA_OBJPACK-HEAD_START = 1.

    WA_OBJPACK-HEAD_NUM = 0.

    WA_OBJPACK-BODY_START = 1.

    • Länge des Attachment ermitteln

    DESCRIBE TABLE I_OBJBIN LINES V_LINES_BIN.

    READ TABLE I_OBJBIN INTO WA_OBJBIN INDEX V_LINES_BIN.

    WA_OBJPACK-DOC_SIZE = V_LINES_BIN * 255 .

    WA_OBJPACK-BODY_NUM = V_LINES_BIN.

    WA_OBJPACK-DOC_TYPE = 'PDF'.

    WA_OBJPACK-OBJ_NAME = 'smart'.

    CONCATENATE LS_ABC_DATA-LIFNR '_' SY-DATUM INTO

    WA_OBJPACK-OBJ_DESCR .

    APPEND WA_OBJPACK TO I_OBJPACK.

    CLEAR WA_RECLIST.

    WA_RECLIST-RECEIVER = 'SADDEV@YAHOO.com'.

    WA_RECLIST-REC_TYPE = 'U'.

    APPEND WA_RECLIST TO 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.

    IF SY-SUBRC EQ 0.

    MESSAGE S990(ZZLIB).

    ENDIF.

    ELSE.

    ENDIF.

    Add comment
    10|10000 characters needed characters exceeded

    • Follow
    • Get RSS Feed

    2 Answers

    • avatar image
      Former Member
      Mar 27, 2007 at 04:02 PM

      Hi,

      I have actually taken the same code. But this is not working. Its very urgent, please do let me know if there is an other way of doing this?

      Thank you,

      Geetha

      Add comment
      10|10000 characters needed characters exceeded

    • avatar image
      Former Member
      Mar 27, 2007 at 03:56 PM

      Geetha,

      chk this similar sample code, check where exactly u r going wrong.....

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

      ~~Guduri

    Add comment
    10|10000 characters needed characters exceeded