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: 

Sending Email with pdf-attachment from Adobe Interactive spool job

Former Member

Hi I'm trying to send an email with a pdf attached. The PDF is created with Adobe Interactive. All ways i try lead to the problem, that the attached pdf is corrupt. I'm using the exporting parameter /1bcdwb/formoutput  of the Adobe FM. I'm wondering because just its component xml is filled with hexadecimal content. When I'm calling transaction sp01 I can see that the spool job is created sucessful and I can also open the created pdf. The content of pdf is ok there.

I think my use of FM SCMS_XSTRING_TO_BINARY  or of amethod add_attachment is wrong.

Maybe you can give me a hint, what I'm doing wrong. Thanks for your help in advance.

This is my code:

* Get function module for Adobe form

  TRY.

      CALL FUNCTION 'FP_FUNCTION_MODULE_NAME'

        EXPORTING

          i_name     = lv_form

        IMPORTING

          e_funcname = lv_fm_name.

    CATCH cx_fp_api_repository

          cx_fp_api_usage

          cx_fp_api_internal

          INTO lo_cx.

      MESSAGE s004(/scwm/print)

           DISPLAY LIKE 'E'

           WITH lv_form.

      RETURN.

  ENDTRY.

* Open the spool job

  CALL FUNCTION 'FP_JOB_OPEN'

    CHANGING

      ie_outputparams = ls_outputparams

    EXCEPTIONS

      cancel          = 1

      usage_error     = 2

      system_error    = 3

      internal_error  = 4

      OTHERS          = 5.

  IF sy-subrc <> 0.

    MESSAGE ID sy-msgid TYPE 'S' NUMBER sy-msgno

         DISPLAY LIKE 'E'

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

    RETURN.

  ENDIF.

* call Adobe Form

  CALL FUNCTION lv_fm_name

    EXPORTING

      /1bcdwb/docparams  = ls_docparams

      pickinglist_data   = ls_pickinglist_data

    IMPORTING

      /1bcdwb/formoutput = ls_formoutput

    EXCEPTIONS

      usage_error        = 1

      system_error       = 2

      internal_error     = 3

      OTHERS             = 4.

  IF sy-subrc <> 0.

    CALL FUNCTION 'FP_GET_LAST_ADS_ERRSTR'

      IMPORTING

        e_adserrstr = lf_adserrstr.

    MESSAGE ID sy-msgid TYPE 'S' NUMBER sy-msgno

         DISPLAY LIKE 'E'

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

    MESSAGE lf_adserrstr TYPE 'I'.

    RETURN.

  ENDIF.

* Close the spool job

  CALL FUNCTION 'FP_JOB_CLOSE'

    IMPORTING

      e_result       = ls_joboutput

    EXCEPTIONS

      usage_error    = 1

      system_error   = 2

      internal_error = 3

      OTHERS         = 4.

 

   CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'

    EXPORTING

      BUFFER                = ls_FORMOUTPUT-xml

*   APPEND_TO_TABLE       = ' '

* IMPORTING

*   OUTPUT_LENGTH         =

    TABLES

      BINARY_TAB            = lt_att_content_hex .

ATA: lt_email_text TYPE  bcsy_text,

        ls_email_text TYPE  soli,

        lv_email_subject TYPE  so_obj_des.

*        ls_address TYPE  SDPRT_ADDR_S.

  ls_email_text-line = 'hello'.

  lv_email_subject = 'Test'.

  APPEND ls_email_text TO lt_email_text.

  lo_send_request = cl_bcs=>create_persistent( ).

  CALL METHOD cl_document_bcs=>create_document

    EXPORTING

      i_type     = 'TXT'

      i_subject  = 'Picklist'

*     I_LENGTH   =

      i_language = sy-langu

      i_text     = lt_email_text

    RECEIVING

      result     = lo_bcs_document.

  lv_buf = ls_formoutput-xml.

  DO.

    ls_bcs_pdf-line = lv_buffer.

    APPEND ls_bcs_pdf TO lt_bcs_pdf.

    SHIFT lv_buffer LEFT BY 255 PLACES.

    IF lv_buffer IS INITIAL.

      EXIT.

    ENDIF.

  ENDDO.

  CALL METHOD lo_bcs_document->add_attachment

    EXPORTING

      i_attachment_type     = 'PDF'

      i_attachment_size     = lv_pdf_size

      i_attachment_subject  = lv_email_subject

      i_attachment_language = sy-langu

      i_att_content_hex     = lt_att_content_hex."lt_bcs_pdf.

  CALL METHOD cl_cam_address_bcs=>create_internet_address

    EXPORTING

      i_address_string = 'mailadress@mail.com'

    RECEIVING

      result           = lo_recipient.

  CALL METHOD lo_send_request->set_document( lo_bcs_document ).

*--- Add the sender

      CALL METHOD lo_send_request->set_sender

        EXPORTING

          i_sender = lo_sender.

*--- Add the recipient

      CALL METHOD lo_send_request->add_recipient

        EXPORTING

          i_recipient = lo_recipient.

*--- Send the document

DATA EV_SEND_TO_ALL TYPE  OS_BOOLEAN.

      CALL METHOD lo_send_request->send

        EXPORTING

          i_with_error_screen = abap_true

        RECEIVING

          result              = ev_send_to_all.

1 ACCEPTED SOLUTION

Private_Member_7726
Active Contributor

Hi,

I have no real experience with Adobe forms..., but:

1) is there any particular reason you are using ls_FORMOUTPUT-xml and not the ls_FORMOUTPUT-pdf? Is it not filled as well?

2) if you must use the SCMS_XSTRING_TO_BINARY..., do import OUTPUT_LENGTH = lv_pdf_size from it...

What happens is: unless the length of pdf xstring is a multiple of internal table line length, the last line of internal table will get padded with x'00' during conversion. Whoever then uses this internal table (cl_document_bcs->add_attachment( ) for example) has to know (where) to cut off those hex nulls when the content gets converted to "end format". For cl_document_bcs->add_attachment( ) the only sure way to "instruct" the code to cut away hex nulls persist the attachment with the correct length is to pass the correct length...

It's somewhat exasperating seeing how many people have problems when SCMS_* stuff is involved. If I were in charge I'd either forbid the use of SCMS_* (to try to force people to think what they are doing ) or wrap the cl_document_bcs functionality behind foolproof interface and then forbid its direct use...

cheers

Jānis

Message was edited by: Jānis B

4 REPLIES 4

Private_Member_7726
Active Contributor

Hi,

I have no real experience with Adobe forms..., but:

1) is there any particular reason you are using ls_FORMOUTPUT-xml and not the ls_FORMOUTPUT-pdf? Is it not filled as well?

2) if you must use the SCMS_XSTRING_TO_BINARY..., do import OUTPUT_LENGTH = lv_pdf_size from it...

What happens is: unless the length of pdf xstring is a multiple of internal table line length, the last line of internal table will get padded with x'00' during conversion. Whoever then uses this internal table (cl_document_bcs->add_attachment( ) for example) has to know (where) to cut off those hex nulls when the content gets converted to "end format". For cl_document_bcs->add_attachment( ) the only sure way to "instruct" the code to cut away hex nulls persist the attachment with the correct length is to pass the correct length...

It's somewhat exasperating seeing how many people have problems when SCMS_* stuff is involved. If I were in charge I'd either forbid the use of SCMS_* (to try to force people to think what they are doing ) or wrap the cl_document_bcs functionality behind foolproof interface and then forbid its direct use...

cheers

Jānis

Message was edited by: Jānis B

0 Kudos

Hi ls_FORMOUTPUT-pdf is empty.

I'm now using the output_length, but my attached pdf file is still corrupt.

Kind regards,

Stefan

0 Kudos

That's probably because ls_formoutout-xml does not contain (or contains not only) valid pdf data then...

Have you tried passing ls_outputparams-getpdf = 'X' (with ls_outputparams-getxml = space, if necessary) ? I'd expect that ls_FORMOUTPUT-pdf would be filled then.

cheers

Janis

0 Kudos

Hi Jänis B.

thank you very much for your replies. with your help I was able to solve my problem.

Kind regards,

Stefan