Quantcast
Channel: SCN: Message List - ABAP Connectivity
Viewing all articles
Browse latest Browse all 3125

Re: SO_NEW_DOCUMENT_ATT_SEND_API1

$
0
0

  Hi Zakiya,

 

Instead of SO_NEW_DOCUMENT_ATT_SEND_API1, use cls_bcs.. refer this code.

 

DATAlo_send_request TYPE REF TO cl_bcs VALUE IS INITIAL.

   CLASS cl_bcs DEFINITION LOAD.

   DATA : lo_document TYPE REF TO cl_document_bcs VALUE IS INITIAL. "document object

   DATA : i_text TYPE bcsy_text. "Table for body

   DATA : w_text LIKE LINE OF i_text. "work area for message body

   DATA : lo_sender TYPE REF TO if_sender_bcs VALUE IS INITIAL. "sender

   DATA : lo_recipient TYPE REF TO if_recipient_bcs VALUE IS INITIAL. "recipient

 

   DATA : lv_string TYPE string,

          lv_data_string TYPE string,

          lv_xstring TYPE xstring,

          lv_code TYPE e1edl24-werks.

 

   DATA : lit_binary_content TYPE solix_tab,

          l_attsubject       TYPE sood-objdes.

 

   lo_send_request = cl_bcs=>create_persistent( ).

 

*-----Message Body & Subject

 

   w_text = 'This is a system generated email, please dont reply'.

   DATA : p_sub TYPE so_obj_des.

   SHIFT wa_final-vbeln LEFT DELETING LEADING '0'.

   CONCATENATE 'Delivery Notification' wa_final-vbeln into p_sub SEPARATED BY '-'.

   APPEND w_text TO i_text.

   CLEAR w_text.

   w_text-line = ' '.

   lo_document = cl_document_bcs=>create_document( "create document

   i_type = 'TXT' "Type of document HTM, TXT etc

   i_text i_text  "email body internal table

   i_subject = p_sub ). "email subject here p_sub input parameter

 

* Pass the document to send request

   lo_send_request->set_document( lo_document ).

 

   CONSTANTS : v_mat(24TYPE c VALUE 'Client''s delivery no',

               v_mat1(16) TYPE c VALUE 'Consignee''s SKU',

               v_mat3(46) TYPE c VALUE 'Client''s customer''s order number /PO number'.

 

 

   CONCATENATE                   v_mat

                                'Order Date'

                                'Consignee contact name'

                                'Consignee company name'

                                'Consignee Address1'

                                'Consignee Address2'

                                'Consignee Address3'

                                'Consignee Address4'

                                'Consignee City'

                                'Consignee State'

                                'Consignee Zip'

                                'Consignee country'

                                 v_mat3

                                'Carrier'

                                'Carrier Shipping Instructions'

                                'Order line number'

                                'SKU'

                                 v_mat1

                                'Order Quantity'

                                'UOM'

 

    INTO lv_string SEPARATED BY cl_abap_char_utilities=>horizontal_tab.

   CONCATENATE lv_data_string lv_string INTO lv_data_string. " SEPARATED BY '|' .

* SEPARATED BY CL_ABAP_CHAR_UTILITIES=>NEWLINE.

 

 

   LOOP AT it_final INTO wa_final.

     CONCATENATE wa_final-vbeln

           wa_final-erdat

           wa_final-v_person

           wa_final-name1

           wa_final-str_suppl2

           wa_final-street

           wa_final-str_suppl3

           wa_final-location

           wa_final-city1

           wa_final-regio

           wa_final-postl_cod1

           wa_final-country1

           wa_final-bstkd

           wa_final-bezei

           wa_final-s_inst

           wa_final-posnr

           wa_final-matnr

           wa_final-kdmat

           wa_final-lfimg

           wa_final-vrkme

 

     INTO lv_string SEPARATED BY cl_abap_char_utilities=>horizontal_tab.

     CONCATENATE lv_data_string lv_string  INTO lv_data_string SEPARATED BY cl_abap_char_utilities=>newline.

 

   ENDLOOP.

 

**Convert string to xstring

   CALL FUNCTION 'HR_KR_STRING_TO_XSTRING'

     EXPORTING

      codepage_to      = '8300'

       unicode_string   = lv_data_string

*     OUT_LEN          =

     IMPORTING

       xstring_stream   = lv_xstring

     EXCEPTIONS

       invalid_codepage = 1

       invalid_string   = 2

       OTHERS           = 3.

   IF sy-subrc <> 0.

     IF sy-subrc = 1 .

 

     ELSEIF sy-subrc = 2 .

       WRITE:/ 'invalid string ' .

     ENDIF.

   ENDIF.

 

***Xstring to binary

   CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'

     EXPORTING

       buffer     = lv_xstring

     TABLES

       binary_tab = lit_binary_content.

**add attachment

   CLEAR l_attsubject .

 

*-----Starting of file naming convention

 

SHIFT wa_final-vbeln LEFT DELETING LEADING '0'.

 

if lv_code is NOT INITIAL.

CONCATENATE lv_code wa_final-vbeln 'FUTGRA001' 'WD' SY-DATUM INTO l_attsubject SEPARATED BY '_'.

ELSEIF lv_code is INITIAL.

     CONCATENATE wa_final-lgnum  wa_final-vbeln 'FUTGRA001' 'WD' SY-DATUM INTO l_attsubject SEPARATED BY '_'.

   endif.

CONDENSE lv_code.

* Create Attachment

   TRY.

     lo_document->add_attachment( EXPORTING

                                     i_attachment_type = 'XLS'

                                     i_attachment_subject = l_attsubject

                                     i_att_content_hex = lit_binary_content  ).

 

 

   ENDTRY.

 

   TRY.

 

     lo_sender = cl_sapuser_bcs=>create( sy-uname ). "sender is the logged in user

* Set sender to send request

     lo_send_request->set_sender(

     EXPORTING

     i_sender = lo_sender ).

*    CATCH CX_ADDRESS_BCS.

****Catch exception here

   ENDTRY.

 

   DATA: l_recipient TYPE ad_smtpadr.

**Set recipient for send request

   lo_recipient = cl_cam_address_bcs=>create_internet_address( 'Shailendra.karada@gmail.com').

 

 

   TRY.

     lo_send_request->add_recipient(

         EXPORTING

         i_recipient = lo_recipient

         i_express = 'X' ).

 

   ENDTRY.

   TRY.

     lo_send_request->send(

     EXPORTING

     i_with_error_screen = 'X' ).

     IF sy-subrc = 0.

     ENDIF.

   ENDTRY.


Viewing all articles
Browse latest Browse all 3125

Trending Articles



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