cancel
Showing results for 
Search instead for 
Did you mean: 

Sending smartform output as PDF attachment, Error opening PDF attachment

Former Member
0 Kudos

Hi Experts,

I am using the code form the following link to send a smartform output as PDF attachment. I can able to see the message, but can not open PDF document.

https://www.sdn.sap.com/irj/sdn/wiki?path=/display/snippets/convertSmartformtoPDFformat&

The information should be on my smartform are some text, company logo and a barcode.

With all of these received error: "There was an error opening this document. The file is damaged and could not be repaired."

I tried different ways like only text, text with company logo, text with barcode. I got the following errors:

An unrecognized token 'Td0' was found

There was problem reading this document(16).

There was problem reading this document(111).

Does anyone have idea of these ? Your help is greatly appreciated.

Thank you,

Surya

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

please see this code ... for sending the Email as PDF attach file,

*   
*&---------------------------------------------------------------------*
*& Report  ZSPOOLTOPDF                                                 *
*&                                                                     *
*&---------------------------------------------------------------------*
*& Converts spool request into PDF document and emails it to           *
*& recipicant.                                                         *
*&                                                                     *
*& Execution                                                           *
*& ---------                                                           *
*& This program must be run as a background job in-order for the write *
*& commands to create a Spool request rather than be displayed on      *
*& screen                                                              *
*&---------------------------------------------------------------------*
REPORT  zspooltopdf.

PARAMETER: p_email1 LIKE somlreci1-receiver
                                    DEFAULT 'abap@sapdev.co.uk',
           p_sender LIKE somlreci1-receiver
                                    DEFAULT 'abap@sapdev.co.uk',
           p_delspl  AS CHECKBOX.

*DATA DECLARATION
DATA: gd_recsize TYPE i.

* Spool IDs
TYPES: BEGIN OF t_tbtcp.
        INCLUDE STRUCTURE tbtcp.
TYPES: END OF t_tbtcp.
DATA: it_tbtcp TYPE STANDARD TABLE OF t_tbtcp INITIAL SIZE 0,
      wa_tbtcp TYPE t_tbtcp.

* Job Runtime Parameters
DATA: gd_eventid LIKE tbtcm-eventid,
      gd_eventparm LIKE tbtcm-eventparm,
      gd_external_program_active LIKE tbtcm-xpgactive,
      gd_jobcount LIKE tbtcm-jobcount,
      gd_jobname LIKE tbtcm-jobname,
      gd_stepcount LIKE tbtcm-stepcount,
      gd_error    TYPE sy-subrc,
      gd_reciever TYPE sy-subrc.


DATA:  w_recsize TYPE i.

DATA: gd_subject   LIKE sodocchgi1-obj_descr,
      it_mess_bod LIKE solisti1 OCCURS 0 WITH HEADER LINE,
      it_mess_att LIKE solisti1 OCCURS 0 WITH HEADER LINE,
      gd_sender_type     LIKE soextreci1-adr_typ,
      gd_attachment_desc TYPE so_obj_nam,
      gd_attachment_name TYPE so_obj_des.

* Spool to PDF conversions
DATA: gd_spool_nr LIKE tsp01-rqident,
      gd_destination LIKE rlgrap-filename,
      gd_bytecount LIKE tst01-dsize,
      gd_buffer TYPE string.

* Binary store for PDF
DATA: BEGIN OF it_pdf_output OCCURS 0.
        INCLUDE STRUCTURE tline.
DATA: END OF it_pdf_output.

CONSTANTS: c_dev LIKE  sy-sysid VALUE 'DEV',
           c_no(1)     TYPE c   VALUE ' ',
           c_device(4) TYPE c   VALUE 'LOCL'.

************************************************************************
*START-OF-SELECTION.
START-OF-SELECTION.

* Write statement to represent report output. Spool request is created
* if write statement is executed in background. This could also be an
* ALV grid which would be converted to PDF without any extra effort
  WRITE 'Hello World'.
  new-page.
  commit work.
  new-page print off.

  IF sy-batch EQ 'X'.
    PERFORM get_job_details.
    PERFORM obtain_spool_id.

************************************
*** Alternative way could be to submit another program and store spool
*** id into memory, will be stored in sy-spono.
*submit ZSPOOLTOPDF2
*        to sap-spool
*        spool parameters   %_print
*        archive parameters %_print
*        without spool dynpro
*        and return.
************************************

* Get spool id from program called above 
*  IMPORT w_spool_nr FROM MEMORY ID 'SPOOLTOPDF'.

    PERFORM convert_spool_to_pdf.
    PERFORM process_email.

    if p_delspl EQ 'X'.
      PERFORM delete_spool.
    endif.

    IF sy-sysid = c_dev.
      wait up to 5 seconds.
      SUBMIT rsconn01 WITH mode   = 'INT'
                      WITH output = 'X'
                      AND RETURN.
    ENDIF.
  ELSE.
    SKIP.
    WRITE:/ 'Program must be executed in background in-order for spool',
            'request to be created.'.
  ENDIF.


*---------------------------------------------------------------------*
*       FORM obtain_spool_id                                          *
*---------------------------------------------------------------------*
FORM obtain_spool_id.
  CHECK NOT ( gd_jobname IS INITIAL ).
  CHECK NOT ( gd_jobcount IS INITIAL ).

  SELECT * FROM  tbtcp
                 INTO TABLE it_tbtcp
                 WHERE      jobname     = gd_jobname
                 AND        jobcount    = gd_jobcount
                 AND        stepcount   = gd_stepcount
                 AND        listident   <> '0000000000'
                 ORDER BY   jobname
                            jobcount
                            stepcount.

  READ TABLE it_tbtcp INTO wa_tbtcp INDEX 1.
  IF sy-subrc = 0.
    message s004(zdd) with gd_spool_nr.
    gd_spool_nr = wa_tbtcp-listident.
    MESSAGE s004(zdd) WITH gd_spool_nr.
  ELSE.
    MESSAGE s005(zdd).
  ENDIF.
ENDFORM.


*---------------------------------------------------------------------*
*       FORM get_job_details                                          *
*---------------------------------------------------------------------*
FORM get_job_details.
* Get current job details
  CALL FUNCTION 'GET_JOB_RUNTIME_INFO'
       IMPORTING
            eventid                 = gd_eventid
            eventparm               = gd_eventparm
            external_program_active = gd_external_program_active
            jobcount                = gd_jobcount
            jobname                 = gd_jobname
            stepcount               = gd_stepcount
       EXCEPTIONS
            no_runtime_info         = 1
            OTHERS                  = 2.
ENDFORM.


*---------------------------------------------------------------------*
*       FORM convert_spool_to_pdf                                     *
*---------------------------------------------------------------------*
FORM convert_spool_to_pdf.

  CALL FUNCTION 'CONVERT_ABAPSPOOLJOB_2_PDF'
       EXPORTING
            src_spoolid              = gd_spool_nr
            no_dialog                = c_no
            dst_device               = c_device
       IMPORTING
            pdf_bytecount            = gd_bytecount
       TABLES
            pdf                      = it_pdf_output
       EXCEPTIONS
            err_no_abap_spooljob     = 1
            err_no_spooljob          = 2
            err_no_permission        = 3
            err_conv_not_possible    = 4
            err_bad_destdevice       = 5
            user_cancelled           = 6
            err_spoolerror           = 7
            err_temseerror           = 8
            err_btcjob_open_failed   = 9
            err_btcjob_submit_failed = 10
            err_btcjob_close_failed  = 11
            OTHERS                   = 12.

  CHECK sy-subrc = 0.

* Transfer the 132-long strings to 255-long strings
  LOOP AT it_pdf_output.
    TRANSLATE it_pdf_output USING ' ~'.
    CONCATENATE gd_buffer it_pdf_output INTO gd_buffer.
  ENDLOOP.

  TRANSLATE gd_buffer USING '~ '.

  DO.
    it_mess_att = gd_buffer.
    APPEND it_mess_att.
    SHIFT gd_buffer LEFT BY 255 PLACES.
    IF gd_buffer IS INITIAL.
      EXIT.
    ENDIF.
  ENDDO.
ENDFORM.


*---------------------------------------------------------------------*
*       FORM process_email                                            *
*---------------------------------------------------------------------*
FORM process_email.
  DESCRIBE TABLE it_mess_att LINES gd_recsize.
  CHECK gd_recsize > 0.
  PERFORM send_email USING p_email1.
*  perform send_email using p_email2.
ENDFORM.


*---------------------------------------------------------------------*
*       FORM send_email                                               *
*---------------------------------------------------------------------*
*  -->  p_email                                                       *
*---------------------------------------------------------------------*
FORM send_email USING p_email.
  CHECK NOT ( p_email IS INITIAL ).

  REFRESH it_mess_bod.

* Default subject matter
  gd_subject         = 'Subject'.
  gd_attachment_desc = 'Attachname'.
*  CONCATENATE 'attach_name' ' ' INTO gd_attachment_name.
  it_mess_bod        = 'Message Body text, line 1'.
  APPEND it_mess_bod.
  it_mess_bod        = 'Message Body text, line 2...'.
  APPEND it_mess_bod.

* If no sender specified - default blank
  IF p_sender EQ space.
    gd_sender_type  = space.
  ELSE.
    gd_sender_type  = 'INT'.
  ENDIF.


* Send file by email as .xls speadsheet
  PERFORM send_file_as_email_attachment
                               tables it_mess_bod
                                      it_mess_att
                                using p_email
                                      'Example .xls documnet attachment'
                                      'PDF'
                                      gd_attachment_name
                                      gd_attachment_desc
                                      p_sender
                                      gd_sender_type
                             changing gd_error
                                      gd_reciever.
ENDFORM.


*---------------------------------------------------------------------*
*       FORM delete_spool                                             *
*---------------------------------------------------------------------*
FORM delete_spool.
  DATA: ld_spool_nr TYPE tsp01_sp0r-rqid_char.

  ld_spool_nr = gd_spool_nr.

  CHECK p_delspl <> c_no.
  CALL FUNCTION 'RSPO_R_RDELETE_SPOOLREQ'
       EXPORTING
            spoolid = ld_spool_nr.
ENDFORM.


*&---------------------------------------------------------------------*
*&      Form  SEND_FILE_AS_EMAIL_ATTACHMENT
*&---------------------------------------------------------------------*
*       Send email
*----------------------------------------------------------------------*
FORM send_file_as_email_attachment tables it_message
                                          it_attach
                                    using p_email
                                          p_mtitle
                                          p_format
                                          p_filename
                                          p_attdescription
                                          p_sender_address
                                          p_sender_addres_type
                                 changing p_error
                                          p_reciever.


  DATA: ld_error    TYPE sy-subrc,
        ld_reciever TYPE sy-subrc,
        ld_mtitle LIKE sodocchgi1-obj_descr,
        ld_email LIKE  somlreci1-receiver,
        ld_format TYPE  so_obj_tp ,
        ld_attdescription TYPE  so_obj_nam ,
        ld_attfilename TYPE  so_obj_des ,
        ld_sender_address LIKE  soextreci1-receiver,
        ld_sender_address_type LIKE  soextreci1-adr_typ,
        ld_receiver LIKE  sy-subrc.

data:   t_packing_list like sopcklsti1 occurs 0 with header line,
        t_contents like solisti1 occurs 0 with header line,
        t_receivers like somlreci1 occurs 0 with header line,
        t_attachment like solisti1 occurs 0 with header line,
        t_object_header like solisti1 occurs 0 with header line,
        w_cnt type i,
        w_sent_all(1) type c,
        w_doc_data like sodocchgi1.


  ld_email   = p_email.
  ld_mtitle = p_mtitle.
  ld_format              = p_format.
  ld_attdescription      = p_attdescription.
  ld_attfilename         = p_filename.
  ld_sender_address      = p_sender_address.
  ld_sender_address_type = p_sender_addres_type.


* Fill the document data.
  w_doc_data-doc_size = 1.

* Populate the subject/generic message attributes
  w_doc_data-obj_langu = sy-langu.
  w_doc_data-obj_name  = 'SAPRPT'.
  w_doc_data-obj_descr = ld_mtitle .
  w_doc_data-sensitivty = 'F'.

* Fill the document data and get size of attachment
  CLEAR w_doc_data.
  READ TABLE it_attach INDEX w_cnt.
  w_doc_data-doc_size =
     ( w_cnt - 1 ) * 255 + STRLEN( it_attach ).
  w_doc_data-obj_langu  = sy-langu.
  w_doc_data-obj_name   = 'SAPRPT'.
  w_doc_data-obj_descr  = ld_mtitle.
  w_doc_data-sensitivty = 'F'.
  CLEAR t_attachment.
  REFRESH t_attachment.
  t_attachment[] = it_attach[].

* Describe the body of the message
  CLEAR t_packing_list.
  REFRESH t_packing_list.
  t_packing_list-transf_bin = space.
  t_packing_list-head_start = 1.
  t_packing_list-head_num = 0.
  t_packing_list-body_start = 1.
  DESCRIBE TABLE it_message LINES t_packing_list-body_num.
  t_packing_list-doc_type = 'RAW'.
  APPEND t_packing_list.

* Create attachment notification
  t_packing_list-transf_bin = 'X'.
  t_packing_list-head_start = 1.
  t_packing_list-head_num   = 1.
  t_packing_list-body_start = 1.

  DESCRIBE TABLE t_attachment LINES t_packing_list-body_num.
  t_packing_list-doc_type   =  ld_format.
  t_packing_list-obj_descr  =  ld_attdescription.
  t_packing_list-obj_name   =  ld_attfilename.
  t_packing_list-doc_size   =  t_packing_list-body_num * 255.
  APPEND t_packing_list.

* Add the recipients email address
  CLEAR t_receivers.
  REFRESH t_receivers.
  t_receivers-receiver = ld_email.
  t_receivers-rec_type = 'U'.
  t_receivers-com_type = 'INT'.
  t_receivers-notif_del = 'X'.
  t_receivers-notif_ndel = 'X'.
  APPEND t_receivers.

  CALL FUNCTION 'SO_DOCUMENT_SEND_API1'
       EXPORTING
            document_data              = w_doc_data
            put_in_outbox              = 'X'
            sender_address             = ld_sender_address
            sender_address_type        = ld_sender_address_type
            commit_work                = 'X'
       IMPORTING
            sent_to_all                = w_sent_all
       TABLES
            packing_list               = t_packing_list
            contents_bin               = t_attachment
            contents_txt               = it_message
            receivers                  = t_receivers
       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.

* Populate zerror return code
  ld_error = sy-subrc.

* Populate zreceiver return code
  LOOP AT t_receivers.
    ld_receiver = t_receivers-retrn_code.
  ENDLOOP.
ENDFORM.

reward points if it is usefull ....

Girish

Former Member
0 Kudos

Hi Girish,

I don't whether this code works for my requirement or not. My requirement is to send samrtform output as an email attachement. I don't know how to create from smartform output as spool. Can you make clear of that part ?

Thank you,

Surya.

Former Member
0 Kudos

Hi surya,

First of all, you need to set a parameter to the forms to says that you want to retrieve the form as an OTF table, for this set the paremeter getotf of structure ssfcrescl to "X".

Then when you call your smartforms, add a table parameters to the function module . The table must be define as TSFOTF structure .

Then after calling the forms , you will retrieve the content as OTF and you can use function module "CONVERT_OTF" to obtains a PDF .

Hope this help you.

Best regards.

PS : look at this link it'll help you

http://help.sap.com/saphelp_nw04/helpdata/en/8a/8c8a4cdef411d3969600a0c930660b/frameset.htm

Former Member
0 Kudos

Surya,

In your smartforms function module you got the standard parameter JOB_OUTPUT_INFO . it's inside this one you can retrieve forms as OTF .

Former Member
0 Kudos

Hi Bertrand,

Thanks for your reply. I passed 'X' to getotf of control paramaeter. Also the structure of job_output_info is SSFCRESCL, not the one you mentioned. Correct me if I am worng. Here is the link of my code...

https://www.sdn.sap.com/irj/sdn/wiki?path=/display/snippets/smartformtoMailasPDF+attachment&

I appreciate your help in advance.

Thank you,

Surya

Former Member
0 Kudos

Hi Surya,

I hope with setting parameters GET_OTF to X that's work better .

Also in which SAP version are you working with becasue with ECC you got new functionnality to send document by mail and thoses new functionnality correct some bugs while using "SO_DOCUMENT"

Best regards.

Former Member
0 Kudos

Hi Bertrand,

I working on version ECC 5.0. Could you please let me know that new functionality of sending email?

Thank you,

Surya

Former Member
0 Kudos

Hi Surya,

With ECC 5.0 you add new class available for sending mail without any trouble when you add document into the mail.

Please find below a code i wrote for a customer, i send Excel file with this one but you can adapt it to send PDF while using XSTRING.

Note that you have to configure SMTP communication for your SAP system .

Hope this will help you .

Best regards.

Report ZTESTBDE_MAIL

----


  • CLASS-DEFINITIONS *

----


DATA: send_request TYPE REF TO cl_bcs.

DATA: document TYPE REF TO cl_document_bcs.

DATA: sender TYPE REF TO cl_sapuser_bcs.

DATA: recipient TYPE REF TO if_recipient_bcs.

----


  • INTERNAL TABLES *

----


DATA: l_mailtext TYPE soli_tab.

DATA: l_mailhex TYPE solix_tab. " => to use with XSTRING Value

DATA: iaddsmtp TYPE bapiadsmtp OCCURS 0 WITH HEADER LINE.

DATA: ireturn TYPE bapiret2 OCCURS 0 WITH HEADER LINE.

----


  • VARIABLES *

----


DATA: mail_line LIKE LINE OF l_mailtext.

DATA: mailx_line LIKE LINE OF l_mailhex. " To use with Xsting only

DATA: bapiadsmtp TYPE bapiadsmtp.

  • Procedure

TRY.

  • Create persistent send request

send_request = cl_bcs=>create_persistent( ).

  • Get sender object

sender = cl_sapuser_bcs=>create( sy-uname ).

  • Add sender

CALL METHOD send_request->set_sender

EXPORTING

i_sender = sender.

  • Read the E-Mail address for the user

CALL FUNCTION 'BAPI_USER_GET_DETAIL'

EXPORTING

username = recipients_line-uname

TABLES

return = ireturn

addsmtp = iaddsmtp.

LOOP AT iaddsmtp WHERE std_no = 'X'.

CLEAR bapiadsmtp.

MOVE iaddsmtp TO bapiadsmtp.

ENDLOOP.

if bapiadsmtp-e_mail is initial.

  • No e-mail for user , add a default one if necessary.

bapiadsmtp-e_mail = c_defmail.

endif.

recipient = cl_cam_address_bcs=>create_internet_address( bapiadsmtp-e_mail ).

  • Add recipient with its respective attributes to send request

  • You can repeat this for all e-mail you want to send the mail , the system will

  • delete duplicates e-mail value

CALL METHOD send_request->add_recipient

EXPORTING

i_recipient = recipient

i_express = 'X'

i_copy = space

i_blind_copy = space

i_no_forward = space.

  • Set that you don't need a Return Status E-mail

CALL METHOD send_request->set_status_attributes

EXPORTING

i_requested_status = 'E'

i_status_mail = 'E'.

  • set send immediately flag - with this flag no job have to be define in SCOT to

  • send mail

send_request->set_send_immediately( 'X' ).

*set the subject of the mail

Subject = 'This is the subject of the mail'.

*Set text of the mail in table

mail_line = 'this the text of the mail'.

append mail_line to l_mailtext.

  • Build the document

document = cl_document_bcs->create_document(

i_type = 'RAW'

i_text = l_mailtext

i_subject = subject ).

  • Add attachement to document

call method document->add_attachement

exporting

i_attachement_type = 'CSV'

i_attachement_subject = 'Sample_Excel_File'

i_att_content_text = it_file. " U should replace it by PDF file in Hexa

  • Add document to send request

call method send_request->set_document( document ).

  • Send document

call method send_request->send( ).

commit work.

catch cx_send_req_bcs into w_except.

call method w_except->if_message~get_longtext

receiving

result = text.

catch cx_address_bcs into w_except.

call method w_except->if_message~get_longtext

receiving

result = text.

catch cx_document_bcs into w_except.

call method w_except->if_message~get_longtext

receiving

result = text.

endtry.

Former Member
0 Kudos

Hi Bertrand,

Thanks for your code. I will test this code today. I was wondering to know the way to send some message as email body using this method. Please let me know.

Thank you,

Surya

Former Member
0 Kudos

Hi surya,

I hope my code help you.

For your last question, you want to send mail with not only attachement document but with email body , i'm wright ?

In this case you got sample in my code to send mail with body look's well.

If you want i can have a look in my code to set a nice email body like html data .

Let me know and remember to rewards.

Best regards.

Former Member
0 Kudos

Hi Bertrand,

When I try to activate I am receiving syntax error "Field cl_document_bcs is unknown. If you possible could you please send me the full code.

Thank you,

Surya

Former Member
0 Kudos

Hi Surya,

Give me your mail and i'll send you a file with all code .

Best regards .

Bertrand

Former Member
0 Kudos

Hi Bertrand,

It is manthena.varma at gmail.com

Thank you,

Surya

Former Member
0 Kudos

Hi surya,

Do you receive my mail ? Does it work know ?

Best regards.

Former Member
0 Kudos

Hi Bertrand,

I received your email. Thank you so much. I am working on it to send smartform output as PDF attachment. I did a small sample, just changed the file type of your program to PDF, and that can able to send email, but the attachment is not opening.

Thank you,

Surya

Former Member
0 Kudos

Hi surya,

For PDF file , you should use the method ADD_ATTACHEMENT like this :

CALL METHOD document->add_attachement

EXPORTING

i_attachement_type = 'PDF'

i_attachement_subject = 'This is a PDF File' " it's a sample name

i_att_content_hex = content_hex "

Content_Hex should contains your PDF file in hexadecimals .

Try it and i think that'll work fine.

Best regards

Former Member
0 Kudos

Surya,

The hexa file of your pdf should come from function module CONVERT_OTF in parameters lines.

Best regards

Former Member
0 Kudos

Hi Bertrand,

How to convert Smartform to hexadecimal data? I know to convert Smartform to OTF and then to PDF using CONVERT_OTF FM. Please help me.

Thank you,

Surya

Former Member
0 Kudos

Hi Surya,

Sorry for the delay but i was in holidays.

When you use FM CONVERT_OTF you can retrieve the content as hexadecimals in export paremeters BIN_FILE.

Best regards.

Former Member
0 Kudos

Hy Surya,

Do you solved your issue ? I made it for a client and that works fine to send the forms as PDF .

Let me know

Best regards.

Former Member
0 Kudos

Hi Bertrand,

As you mentioned I got hexadecimal from FM CONVERT_OTF into bin_file. But when I try to send this to create attachment, giving syntax error saying types are not compatible.

CALL METHOD document->add_attachment

EXPORTING

i_attachment_type = 'PDF'

i_attachment_subject = 'Price_Catalog'

  • i_att_content_text = it_soli.

i_att_content_hex = bin_file. "bin_file is from CONVERT_OTF

Any clues please let me know.

Thank you,

Surya

Former Member
0 Kudos

Hi Surya,

After calling FM Convert_OTF use FM SCMS_XSTRING_TO_BINARY ,you will got the binary file to send . Look at the code below ( it works fine ) .

Let me know.

<i>

data : file_to_send TYPE xstring ,

pdf_document TYPE solix_tab .

*Convert Smartforms into PDF

CALL FUNCTION 'CONVERT_OTF'

EXPORTING

format = 'PDF'

max_linewidth = 132

IMPORTING

bin_filesize = file_size

bin_file = file_to_send

TABLES

otf = tab_otf

lines = i_tline

EXCEPTIONS

err_max_linewidth = 1

err_format = 2

err_conv_not_possible = 3

OTHERS = 4.

  • add attachment to document

CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'

EXPORTING

buffer = file_to_send

TABLES

binary_tab = pdf_document.

CALL METHOD document->add_attachment

EXPORTING

i_attachment_type = 'PDF'

i_attachment_subject = att_subject

i_att_content_hex = pdf_document.

</i>

Former Member
0 Kudos

Hi Bertrand,

Thank you so much. This worked :-). Awarding full points.

Thank you,

Surya

Former Member
0 Kudos

Hi Surya,

Nice if it works fine .

Do not hesitate to send me mail if you got any others problems .

Best regards

Former Member
0 Kudos

Hi Bertrand,

There is a little change in the requirement. Sender and Recipient are stored in a table. They are picked from the table. Both are internet email addreses. In this case how to get sender object ?

Currently it is sender = cl_sapuser_bcs=>create( sy-uname ). uses sap username. Your help is appreciated.

OR

If I use the FM WFMC_PREPARE_SMART_FORM, Is there a way to make recipient object with multple email ids ? As I know with this FM only one email address added to recipient, which is from vendor master. Can we specifiy multiple email addresses in vendor master ? If so Can we access them using this FM WFMC_PREPARE_SMART_FORM ?

Thank you,

Surya

Former Member
0 Kudos

Hi,

I am also getting the same problem in opening the pdf file when i am using FM. Can you send me your code so that i can check where should i have to make changes to work properly.

Thanks

Former Member
0 Kudos

Hi Surya,

Process as foloowing to set the sender base on a specific e-mail adress ( store on table or a defautl sender adress as you want ) .

1 - Change Sender data definition

*DATA: sender TYPE REF TO cl_sapuser_bcs.

data: sender TYPE REF TO if_sender_bcs.

2 - Change the sender object creation ( email_adress represent your value ).

  • Get sender object

  • sender = cl_sapuser_bcs=>create( sy-uname ).

sender = cl_cam_address_bcs=>create_internet_address( <i>email_adress</i> ) .

That's all .

Best regards.

Former Member
0 Kudos

Hi Ben,

Give me your e-mail and 'ill send you a sample code to send a smartforms or a Sapscript in PDF with WAS 6.4 or higher.

Best regards.

Former Member
0 Kudos

Hi Bertrand,

How are you ? Sorry for bothering you again. I have another question. What will be getting in "text" in the following ?

I am trying to create a FM, so that it can be used commonly. I want to raise some exceptions. I would need your help in identifying them in appropriate places of the code. What followong would do ?

CATCH cx_send_req_bcs INTO w_except.

CALL METHOD w_except->if_message~get_longtext

RECEIVING

result = text.

CATCH cx_address_bcs INTO w_except.

CALL METHOD w_except->if_message~get_longtext

RECEIVING

result = text.

CATCH cx_document_bcs INTO w_except.

CALL METHOD w_except->if_message~get_longtext

RECEIVING

result = text.

Thank you,

Sasi Manthena

Former Member
0 Kudos

Hi Surya,

I'm fine thanks . I just start a new project on Interactive Adobe Forms . And you what's new ?

Concerning your question, when you use some class you can have exception raise . That's why I encapsulate it in a TRY...ENDTRY statement .

This code allow the program to retrieve the text linked to the exception and then you can write it.

What you can do is something like this.

<i>Try.

Call method ....

...

...

CATCH cx_send_req_bcs INTO w_except.

Raise exception "Error in SEND_BCS class".

CATCH cx_address_bcs INTO w_except.

Raise exception "Error in ADRESS_BCS class".

CATCH cx_document_bcs INTO w_except.

Raise exception "Error in DOCUMENT_BCS class".

</i>

Hope this help you .

Former Member
0 Kudos

Hi Bertrand,

I am fine and I have been working on couple of projects related to smartforms and some production support issues. Good that you are working on Adobe forms.

I have some more questions:

1. How to supress "Important" flag that is coming along with email message.

2. So as per your response below, Shold I create these exceptions in my FM ?

3. Are these the only exceptions encounter in this code ?

4. I tried passing an email without '@' and no error when I tried to create sender object. But errored out in SOST. The email did not go. How to catch this ? Should the email be validated before passing to creation method of sender?

Your time will be appreciated.

Thank you,

Surya.

Former Member
0 Kudos

Surya,

I don't have important flag comming, perhaps there's somethnig wrong in your code . You can send it by mail if you want.

If you write my code, yes you need to create the new Exception in your FM

Normaly that's th only one but you can check in the class uses , you should find there if there's another execption class

For your last question, have a look in SAP i think there's a function module which can check an email adress but i'm not sure.

Hope this help you

Former Member
0 Kudos

Hi Bertrand,

I have tried the following different options to set the important flag. But not able to turn off the important flag.

1.

  • Build Document

document = cl_document_bcs=>create_document(

i_type = 'RAW'

i_importance = '9'

i_subject = pi_subject ).

2.

  • Set priority

CALL METHOD send_request->set_priority

EXPORTING

i_priority = '9'.

3.

  • Set importance

CALL METHOD document->set_importance

EXPORTING

i_importance = '9'.

Any clue please let me know.

Thank you,

Surya

Former Member
0 Kudos

Hi Surya,

There's no issue in your code . I don't get this issue in my system .

I think that comes from SMTP server configuration , can you try to use another one?

Also in SAP Business workplace, try to create an mail and send-it you'll see if you still got "Important" Flag comin in your mail.

Hope it's help you.

Best regards

Former Member
0 Kudos

Hi Bertrand,

I am not sure of checking SMTP server configuration. How to check SMTP configuration ?

But I checked sending self email from SAP Business workplace, it did not give any important flag. That means what ?

Have a nice weekend...

Thank you,

Surya

Former Member
0 Kudos

Hi Surya,

It's very strange if you send an e-mail thru SAP Business Workplace and no important flag come . That mean's the important flag comes from the code or from the user who send the mail.

Can you try to change the sender of the mail ( you for example ) and check if the flag comes .

Best regards

Answers (2)

Answers (2)

Former Member
0 Kudos

hi surya

Assign a t.code to this program RSTXPDFT4..this is to "Convert a file to PDF".

Get the spool number, and give it in the selection screen of this program and u can display it in PDF format

regards

Sailendra Kolakaluri

Former Member
0 Kudos

Hi,

Have you tried introducing some error handling into the code? A number of the function modules used in this sample code return exceptions, if any of these are set it may give you a clearer view of where things are gong wrong.

Regards,

Nick

Former Member
0 Kudos

Hi Nick,

I have never used it. Can you give some example of doing it ?

Thank you,

Surya

Former Member
0 Kudos

The simplest approach would be to take all of the lines of the program

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

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

that are currently commented out with * and take off the *.

This will mean that if any of those function modules produce an error it will be displayed on your screen when you run the report.

Regards,

Nick

Former Member
0 Kudos

I already did this, No errors in all of the function modules. My problem is I can not open the PDF document. I can see that there is an attachment in SBWP, but not able to open it. getting different errors in different contexts

Thank you,

Surya

Former Member
0 Kudos

Sorry, I'm a bit confused. The program in the url in your original message (<a href="https://www.sdn.sap.com/irj/sdn/wiki?path=/display/snippets/convertSmartformtoPDFformat&">https://www.sdn.sap.com/irj/sdn/wiki?path=/display/snippets/convertSmartformtoPDFformat&</a>) creates a PDF on the frontend, not attached to a message. In think I'm looking at the wrong piece of code.

Nick

Former Member
0 Kudos

Hi Nick,

I am sorry, I gave you the wrong link and here is the correct link...

https://www.sdn.sap.com/irj/sdn/wiki?path=/display/snippets/smartformtoMailasPDF+attachment&

Thank you,

Surya

Former Member
0 Kudos

That's clearer!

I think there are changes in the function module SO_NEW_DOCUMENT_ATT_SEND_API1 in more recent SAP releases which mean this program is not working. Specifically table CONTENTS_BIN is marked as obsolete, being replaced by CONTENTS_HEX.

Regards,

Nick