8 Replies Latest reply: Mar 17, 2012 11:07 AM by Krupa Janiji RSS

How to use CONTENTS_HEX in the FM SO_DOCUMENT_SEND_API1

Avinash Avinash
Currently Being Moderated

Hi Experts,

I have to send a mail to outlook the data of an Internal table.

I am using the FM SO_DOCUMENT_SEND_API1

My Internal table width is around 400 characters, But the CONTENTS_BIN will allow only 255 characters.

So I am trying to use CONTENTS_HEX. To my knowledge we have to pass binary content to CONTENTS_HEX table.

I have used SCMS_STRING_TO_XSTRING to convert my string to XString and then used SCMS_XSTRING_TO_BINARY to convert XString to Binary.

See the below code for reference.

CALL FUNCTION 'SCMS_STRING_TO_XSTRING'

       EXPORTING

         text           = lf_string

*       MIMETYPE       = ' '

*       ENCODING       =

      IMPORTING

        buffer         = lf_xstring

      EXCEPTIONS

        failed         = 1

        OTHERS         = 2.

     IF sy-subrc <> 0.

       MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno

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

     ENDIF.

     CLEAR: lf_output_length.

     CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'

       EXPORTING

         buffer          = lf_xstring

         append_to_table = 'LT_CONTENTS_HEX'

       IMPORTING

         output_length   = lf_output_length

       TABLES

         binary_tab      = lt_contents_hex[].

 

I have filled the PACKING_LIST table as below.

ls_packing_list-transf_bin = 'X'.

   ls_packing_list-head_start = 1.

   ls_packing_list-head_num   = 1.

   ls_packing_list-body_start = 1.

   ls_packing_list-doc_type   =  'PDF'.

   ls_packing_list-obj_descr  =  'Object Description Packing List1'.

   ls_packing_list-obj_name   =  'Object Name Packing List1'.

DESCRIBE TABLE lt_contents_hex  LINES ls_packing_list-body_num.  

ls_packing_list-doc_size   =  ls_packing_list-body_num * 255.

 

I am able to get the mail with PDF attachment, But the PDF is not opening.

Can any one let me know how to resolve this Issue?

Is the Packing list is Incorrect(If so how to fill the PACKING_LIST for CONTENT_HEX table

or the Binary data it self is incorrect(If so How to convert the string into Binary.

Or else Is there any other way to send internal table which has 400 characters width as a PDF attachment to an out look mail?

 

Thanks in Advance.

Have a nice day.

Regards

Avinash

  • Re: How to use CONTENTS_HEX in the FM SO_DOCUMENT_SEND_API1
    Harish Kumar
    Currently Being Moderated

    Hi,

    Instead of "ls_packing_list-doc_size   =  ls_packing_list-body_num * 255." try giving

    ls_packing_list-doc_size   =  lf_output_length. received from 'SCMS_XSTRING_TO_BINARY' FM.

    • Re: How to use CONTENTS_HEX in the FM SO_DOCUMENT_SEND_API1
      Avinash Avinash
      Currently Being Moderated

      Hi Harish,

      I have used the LF_OUTPUT_LENGTH which will come from 'SCMS_XSTRING_TO_BINARY' but still the same problem(PDF is not Opening).

      I have have also used by adding all the line Items LF_OUTPUT_LENGTH also, but of no use.

      All the cases I am able to send the PDF, but while opening the PDF it is showing the below error.

      Adobe Open Error.jpg

      For each line Item I am getting the output length as 648, Also for each line Item the CONTENTS_HEX is filling with 3 lines. Is that making any Issue? Refer the below code shown.

      CLEAR: ls_conditions.

         LOOP AT lt_conditions[] INTO ls_conditions.

           MOVE-CORRESPONDING ls_conditions TO ls_string.

           CLEAR: lf_string.

           CONCATENATE  ls_string-condition_type

      ls_string-condition_no

      ls_string-condition_item

      ls_string-sales_org

      ls_string-customer

      ls_string-material_group

      ls_string-hierarchy_node

      ls_string-valid_from

      ls_string-valid_to

      ls_string-material_no

      ls_string-min_order_qty

      ls_string-estimated_vol

      ls_string-bogoff_material

           ls_string-bogoff_qty

      ls_string-list_price

      ls_string-discount_perc

      ls_string-customer_price

      ls_string-net_price

      ls_string-question

      ls_string-answer

      ls_string-created_by

      ls_string-created_date

      ls_string-current_approver

      ls_string-approver_level

      ls_string-status

      ls_string-status_text

      ls_string-coment_by

      ls_string-current_coment

      lf_cr_lf

      INTO lf_string

      SEPARATED BY space

      RESPECTING BLANKS.

           CLEAR: lf_xstring.

           CALL FUNCTION 'SCMS_STRING_TO_XSTRING'

             EXPORTING

               text           = lf_string

      *       MIMETYPE       = ' '

      *       ENCODING       =

            IMPORTING

              buffer         = lf_xstring

            EXCEPTIONS

              failed         = 1

              OTHERS         = 2.

           IF sy-subrc <> 0.

             MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno

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

           ENDIF.

           CLEAR: lf_output_length.

           CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'

             EXPORTING

               buffer          = lf_xstring

               append_to_table = 'LT_CONTENTS_HEX'

             IMPORTING

               output_length   = lf_output_length

             TABLES

               binary_tab      = lt_contents_hex[].

          lf_total_length = lf_total_length + lf_output_length.

           CLEAR: ls_conditions.

         ENDLOOP.

  • Re: How to use CONTENTS_HEX in the FM SO_DOCUMENT_SEND_API1
    Break Point
    Currently Being Moderated

    I don't understand why one would be using the old API to send email, rather than utilizing SAP current technology, BCS.  If you look at the BCS demo programs named like BCS* in SE38, you will see a fine example of how to send PDF via email, utilizing the classes/methods of BCS.  IMHO, BCS is a much simpler process from a coding viewpoint.

    • Re: How to use CONTENTS_HEX in the FM SO_DOCUMENT_SEND_API1
      Avinash Avinash
      Currently Being Moderated

      Hi David

      I have used CL_BCS also, but the same issue is coming. I have searched in almost all the SDN forums, but I could not find any one exactly related to this.Some links explained 'How to convert String to Binary and just calling the FM, But not explained how to fill the PACKING_LIST'.

      I think in CL_BCS we dont find any packing list.

      I have used the below code to attach the PDF.

      i_attachment_size = lf_output_length.

             CALL METHOD document->add_attachment

               EXPORTING

                 i_attachment_type    = 'PDF'

                 i_attachment_size    = i_attachment_size

                 i_attachment_subject = 'i_attachment_subject'

                 i_att_content_hex    = binary_content.

      PDF Attachment is reaching the mail ID but PDF is not opening.

       

      If you have any Complete Example showing 'How to send more than 600 char width of internal table lines as a PDF attachment to an outlook mail either with FM or CL_BLS'

      Please send me.

      Thanks in Advance.

      Have a nice day.

       

      Regards,

      Avinash.

  • Re: How to use CONTENTS_HEX in the FM SO_DOCUMENT_SEND_API1
    Break Point
    Currently Being Moderated

    Your file type for the download is 'BIN' and your internal table is binary after the SCMS function xstring to binary.  This is the way to transfer a PDF to desktop.  The example program in BCS_EXAMPLE_6 works marvelously.  If you must use the old API, look at SAP Note 609696 for working code example and corrected documentation.  Also, note that to get the length of an xstring (for your transfer to desktop), we use something like: lv_len = xstrlen( xstring_field ).

  • Re: How to use CONTENTS_HEX in the FM SO_DOCUMENT_SEND_API1
    Aravindhan Palanivel
    Currently Being Moderated

    Hi,

    Try this

     

    * Packing list
           ls_packing_list-transf_bin = space.
           ls_packing_list-head_start = 1.
           ls_packing_list-head_num = 0.
           ls_packing_list-body_start = 1.
           ls_packing_list-body_num = l_cnt.
           ls_packing_list-doc_type = 'HTM'.    "'RAW'.
           APPEND ls_packing_list TO lt_packing_list.

           CLEAR:l_tabx1.
           DESCRIBE TABLE lt_attachment LINES l_tabx1.
           ls_packing_list-doc_size   =  l_tabx1 * 255.
           ls_packing_list-transf_bin = 'X'.
           ls_packing_list-head_start = 1.
           ls_packing_list-head_num   = 1.
           ls_packing_list-body_start = 1.
           ls_packing_list-body_num   = l_tabx1.
           ls_packing_list-doc_type   =  'PDF'.
           ls_packing_list-obj_descr  = 
    Object Name Packing List1'.

           ls_packing_list-obj_name   = 'Object Name Packing List1'.


           APPEND ls_packing_list TO lt_packing_list.

     

    Regards,

    Aravind

    • Re: How to use CONTENTS_HEX in the FM SO_DOCUMENT_SEND_API1
      Krupa Janiji
      Currently Being Moderated

      CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'
             EXPORTING
               buffer        = filex
             IMPORTING
               output_length = file_length
             TABLES
               binary_tab    = gt_objbin.

      DESCRIBE TABLE gt_objbin LINES gv_tab_lines.
         CLEAR gs_objbin.
         READ TABLE gt_objbin INTO gs_objbin INDEX gv_tab_lines.
         IF sy-subrc = 0.
           gs_objpack-doc_size = ( gv_tab_lines - 1 ) * 255 + STRLEN( gs_objbin ).
           gs_objpack-transf_bin = 'X'.
           gs_objpack-head_start = 1.
           gs_objpack-head_num = 0.
           gs_objpack-body_start = 1.
           gs_objpack-body_num = gv_tab_lines.
           gs_objpack-doc_type = 'PDF'.
          gs_objpack-obj_name = 'INVOICE'.
           gs_objpack-obj_descr = 'Invoice Order'.
           APPEND gs_objpack TO gt_objpack.

      CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'

          EXPORTING

            document_data                    = gs_docdata

           put_in_outbox                    = 'X'

           commit_work                      = 'X'

          TABLES

            packing_list                     = gt_objpack

       

           contents_bin                     = gt_objbin

           contents_txt                     = i_objtxt

            receivers                        = gt_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

Actions