Application Development 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: 

smartform (otf) as pdf and sending as email-attachment

MarkusKlein
Active Contributor
0 Kudos

Hello everybody,

when trying to convert a smartform to pdf and sending it with the FM 'SO_NEW_DOCUMENT_ATT_SEND_API1' i get an error when opening the pdf-file. It says ' a non identified Token w62.10 was found' and the pdf is all empty.

The problem seems to be somewhere between getting the pdf output data from the FM 'convert_otf' and trying to create a bin-object for the attachment.

Here is the code:


  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
  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
  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-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 - 1 ) * 255 + strlen( i_objbin ).

  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 = receiver.
  i_reclist-rec_type = RECEIVER_TYPE.
  append i_reclist.

  if not receiver is initial.
    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.

10 REPLIES 10

sergey_korolev
Active Contributor
0 Kudos

Hello Markus,

In my system (4.7) this function 'CONVERT_OTF' has the export parameter BIN_FILE of type XSTRING. In that parameter you have all binary contents of PDF file. The only deed you have to do - just cut this into 255-bytes slices. Try to use it instead of TABLE parameter <b>lines</b>.

If you have 4.6c then in lines table you have already binary PDF content which must not be converted. It could be downloaded on to workstation as-is in binary mode.

Message was edited by: Sergei Korolev

0 Kudos

Hello Sergei,

yes i have indeed 4.6c. The problem is i dont want to download the pdf-content (this does work, i have already tested it useing the FM 'WS_DOWNLOAD'). I want to attach this pdf to an email created in this program and send it.

If i dont convert the pdf_output from the fm 'convert_otf' the pdf-file is all corrupted when trying to open it from the email i received.

jayanthi_jayaraman
Active Contributor
0 Kudos

Hi,

Check this link.

https://sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.km.cm.docs/library/webas/abap/abap code samples/smartforms/smart form in abap.pdf

In this, I am converting the Smartform output to PDF and then sending the output through mail.

Hope this is useful for you.

If so,Kindly reward points by clicking the star on the left side of the reply.If you need more clarifications,get back.

0 Kudos

Hello Jayanthi,

thanks for posting this link, but as you can see from the posted code snippet im already using your solution

Unfortunately its not working, as im getting the error i have posted already when opening the pdf-file attched to the email im receiving.

So any help is much appreciated.

regards,

Markus

0 Kudos

i guess that the issue is in the way you move t_line to i_objbin.

<i>

do.  
  i_record = wa_buffer.  
  append i_record.  
  shift wa_buffer left by 255 places.  
  if wa_buffer is initial. 
     exit.  
  endif.  
enddo.

</i>

t_line record length is 2 + 132 = 134 and

i_objbin record length is 255

so why dont you try to just move line by line from t_line to i_objbin, instead of trying to fill the whole 255 chars of i_objbin.

Give it a try and let us know.

Regards

Raja

0 Kudos

Hi,

I just observed the following.

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.


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.

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 just tried with your coding and then changed to the below coding.Now I am able to open the PDF in mail.

* 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 = 'jayanthi.gayathri@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.

If your problem is solved,kindly close the thread and reward points.If you need clarifications,get back.

0 Kudos

Hello Jayanthi,

unfortunately the problem remains (The last code is your original code from the document, which i tried first). Its still a problem when openening the pdf-document. Is there any other way to convert the pdf-data to a binary file? Because when i use the WS-Download functionality the pdf works all great (which does not really help me, as i dont want to download the file to a local PC), just when i try to convert it to a bin-file in the code itself i get the problem.

0 Kudos

Hello,

I am trying to use CONVERT_OTF to convert Smartform to PDF. What I want to do is save this DPF file on Application server . I tried using SCMS_DOWNLOAD which can download on Presentation and Application Server and by regular Open and Transfer statements.

I am trying to do this in CRM 4.0

Is there any way to do this?

Prasad Sheth

Former Member
0 Kudos

hi,

i got some problem when sending a mail to public id by the above program

i through runtime error while running

" An exception occurred. This exception will be dealt with in more detail

below. The exception, assigned to the class 'CX_SY_DYN_CALL_ILLEGAL_TYPE', was

not caught, which

led to a runtime error. The reason for this exception is:

In the function "SO_NEW_DOCUMENT_ATT_SEND_API1" the STRUCTURE parameter

"CONTENTS_HEX" is typed in such a way

that actual parameters are not valid, unless they are compatible

according to the Unicode fragment view. The actual parameter "I_OBJBIN" does

not, however, have a compatible fragment view."

regards,

Hariharan

0 Kudos

hi refer these links

SMART form to PDF

https://wiki.sdn.sap.com/wiki/display/Snippets/ConvertSmartformtoPDFformat

smartform to MAIL

https://wiki.sdn.sap.com/wiki/display/Snippets/SmartformtoMailasPDF+attachment