Quantcast
Channel: SCN: Message List
Viewing all articles
Browse latest Browse all 3327

X_ERROR exception in the email FM, SO_DOCUMENT_SEND_API1

$
0
0

Hi,

 

When executing the FM, SO_DOCUMENT_SEND_API1 for sending out an email with a PDF document attachment, it always ends up with the exception, X_ERROR.

 

My codes are written as below. In my tests, everything is correctly populated up to the point of the FM call, SO_DOCUMENT_SEND_API1 - but this always ends up with the same exception, X_ERROR so no email could be sent out eventually.

 

What could be wrong here, and how may I fix the error?

 

Appreciate any help here.

 

Much thanks.

 

* Get the attachment list for the input business object type and name

CALL FUNCTION 'BDS_ALL_CONNECTIONS_GET'

  EXPORTING

    classname        = lv_classname

    classtype        = lc_classtype_bo

    objkey           = lv_objkey

    client           = sy-mandt

    all              = 'X'

    no_gos_docs      = space

  IMPORTING

    count            = lv_num_docs

  TABLES

    all_connections  = lt_all_connections

  EXCEPTIONS

    no_objects_found = 1

    error_kpro       = 2

    internal_error   = 3

    not_authorized   = 4

    OTHERS           = 5.

 

IF sy-subrc = 0.

  SORT lt_all_connections BY docuclass.

  DELETE lt_all_connections WHERE docuclass <> c_pdf.

 

  IF lt_all_connections IS NOT INITIAL.

    SORT lt_all_connections BY crea_time DESCENDING.

 

    LOOP AT lt_all_connections ASSIGNING <lwa_all_connections>.

      IF <lwa_all_connections>-descript = lv_document.

        EXIT.

      ENDIF.

    ENDLOOP.

  ENDIF.

 

  IF <lwa_all_connections> IS ASSIGNED.

    lv_document_id = <lwa_all_connections>-loio_id.

 

* Read the data

    CALL FUNCTION 'SO_DOCUMENT_READ_API1'

      EXPORTING

        document_id                = lv_document_id

      IMPORTING

        document_data              = lwa_document_data

      TABLES

        object_content             = lt_object_content_l

      EXCEPTIONS

        document_id_not_exist      = 1

        operation_no_authorization = 2

        x_error                    = 3

        OTHERS                     = 4.

 

    IF sy-subrc = 0.

* Prepare the data

      CLEAR lwa_plist.

      lwa_plist-transf_bin = c_true.

      lwa_plist-head_start = 0.

      lwa_plist-head_num = 0.

      lwa_plist-body_start = 0.

      lwa_plist-body_num = 0.

      lwa_plist-doc_type = 'RAW'.

      lwa_plist-obj_descr = lwa_document_data-obj_descr.

      APPEND lwa_plist TO lt_plist.

 

      CLEAR lwa_plist.

      lwa_plist-transf_bin = c_true.

      lwa_plist-head_start = 0.

      lwa_plist-head_num = 0.

 

      IF sy-tabix = 1.

        lwa_plist-body_start = 1.

      ELSE.

        DESCRIBE TABLE lt_object_content_l.

        lwa_plist-body_start = sy-tfill + 1.

      ENDIF.

 

      DESCRIBE TABLE lt_object_content_l LINES lwa_plist-body_num.

      lwa_plist-doc_type = lwa_document_data-obj_type.

 

* Get the size

      READ TABLE lt_object_content_l

        INTO lwa_object_content

        INDEX lwa_plist-body_num.

 

      IF sy-subrc = 0.

        lwa_plist-doc_size = ( lwa_plist-body_num - 1 ) * lv_line_size

                              + strlen( lwa_object_content ).

        APPEND lwa_plist TO lt_plist.

      ENDIF.

 

* Move the values to the main internal table

      APPEND LINES OF lt_object_content_l TO lt_object_content.

    ENDIF.

 

* Move the receiver address

    CLEAR: lv_email_address, lt_email_address.

 

    lv_email_address = p_email.

    SPLIT lv_email_address AT ';' INTO TABLE lt_email_address.

 

    LOOP AT lt_email_address ASSIGNING <lwa_email_address>.

      CLEAR lwa_rec_tab.

 

      lwa_rec_tab-receiver = <lwa_email_address>-str.

      CONDENSE lwa_rec_tab-receiver.

      lwa_rec_tab-rec_type = 'U'.

      lwa_rec_tab-com_type = 'INT'.

 

      APPEND lwa_rec_tab TO lt_rec_tab.

    ENDLOOP.

 

* Set the language.

    lwa_doc_data-obj_langu = sy-langu.

 

* Email subject

      lwa_doc_data-obj_descr = 'Attachment'.

    ENDIF.

 

 

    IF lwa_email_addtxt IS NOT INITIAL.

      lv_sender_address = 'noreply@abc.com'.

 

      CALL FUNCTION 'READ_TEXT'

        EXPORTING

          client                  = sy-mandt

          id                      = 'ST'

          language                = 'E'

          name                    = 'ZEMAIL_BODY'

          object                  = 'TEXT'

        TABLES

          lines                   = lt_lines

        EXCEPTIONS

          id                      = 1

          language                = 2

          name                    = 3

          not_found               = 4

          object                  = 5

          reference_check         = 6

          wrong_access_to_archive = 7

          OTHERS                  = 8.

 

      IF sy-subrc = 0.

        CALL FUNCTION 'CONVERT_ITF_TO_STREAM_TEXT'

          EXPORTING

            language     = sy-langu

            lf           = ' '

          IMPORTING

            stream_lines = lt_stream_lines

          TABLES

            itf_text     = lt_lines

            text_stream  = lt_text_stream.

 

        IF lt_text_stream IS NOT INITIAL.

* Send the email

          CALL FUNCTION 'SO_DOCUMENT_SEND_API1'

            EXPORTING

              document_data              = lwa_doc_data

              sender_address             = lv_sender_address

              sender_address_type        = 'U'

            TABLES

              packing_list               = lt_plist

              contents_bin               = lt_object_content

              contents_txt               = lt_text_stream

              receivers                  = lt_rec_tab

            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.

* Commit work

            COMMIT WORK.

 

* Send the email immediately

            SUBMIT rsconn01 WITH mode = 'INT' AND RETURN.

          ENDIF.

        ENDIF.

      ENDIF.

    ENDIF.

  ENDIF.


Viewing all articles
Browse latest Browse all 3327

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>