E-Mail with Multiple Attachments (Using Web Dynpro for ABAP)

...Previous

Step11:

Now go back to main view and inside onactionsend write the following code.

method ONACTIONSEND.
  
DATA lo_nd_mail TYPE REF TO if_wd_context_node.
  
DATA lo_el_mail TYPE REF TO if_wd_context_element.
  
DATA ls_mail TYPE wd_this->element_mail.

  
data email like ls_mail-email.
  
data subject  like ls_mail-subject.

* navigate from <CONTEXT> to <MAIL> via lead selection
  lo_nd_mail = wd_context->get_child_node( name = wd_this->wdctx_mail ).

* get element via lead selection
  lo_el_mail = lo_nd_mail->get_element(  ).

* get all declared attributes
  lo_el_mail->get_static_attributes(
    
IMPORTING
      static_attributes = ls_mail ).

lo_el_mail->get_attribute(
EXPORTING
  name = 
'EMAIL'
  
IMPORTING
    
value = email ).

lo_el_mail->get_attribute(
EXPORTING
  name = 
'SUBJECT'
  
IMPORTING
    
value = subject ).

data sub(50type c.
sub = subject.

  
DATA lo_nd_it TYPE REF TO if_wd_context_node.
  
DATA lo_el_it TYPE REF TO if_wd_context_element.
  
DATA ls_it TYPE wd_this->element_it.
  
data lt_it like table of ls_it.

* navigate from <CONTEXT> to <IT> via lead selection
  lo_nd_it = wd_context->get_child_node( name = wd_this->wdctx_it ).

* @TODO handle not set lead selection
  
IF lo_nd_it IS INITIAL.
  
ENDIF.

* get element via lead selection
  lo_el_it = lo_nd_it->get_element(  ).

* @TODO handle not set lead selection
  
IF lo_el_it IS INITIAL.
  
ENDIF.

* get all declared attributes
  lo_el_it->get_static_attributes(
    
IMPORTING
      static_attributes = ls_it ).

CALL METHOD lo_nd_it->get_static_attributes_table
  
EXPORTING
    
from   = 1
    
to     = 2147483647
  
IMPORTING
    
table  = lt_it .

DATA : l_o_send_request TYPE REF TO cl_bcs, " email request object
         l_o_document 
TYPE REF TO cl_document_bcs, " documents object
         l_o_document_att 
TYPE REF TO cl_document_bcs, " documents object
         l_o_sender 
TYPE REF TO cl_cam_address_bcs, " sender object
         l_o_recipient 
TYPE REF TO cl_cam_address_bcs, " recipient object
         bcs_exception 
TYPE REF TO cx_bcs, " exceptions

      
" address
       sd_addr 
TYPE ADR6-SMTP_ADDR VALUE 'thrinathkumar.k@kaaviansys.com',
       rc_addr 
TYPE ADR6-SMTP_ADDR,

      
" document contents
       l_it_contents 
TYPE bcsy_text,
       l_wa_contents 
TYPE LINE OF bcsy_text.

       rc_addr = email.

DATA T_ATT_CONTENT_HEX TYPE SOLIX_TAB.

       
loop at lt_it into ls_it.
         
CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'
           
EXPORTING
             
buffer                = ls_it-source
           
tables
             binary_tab            = T_ATT_CONTENT_HEX .

  
DATA LV_NAME(50). " SO_OBJ_DES

  
TRY.
  
at first.
    
" create email objects
    l_o_send_request = cl_bcs=>create_persistent( ).

" sender
*TRY.
 
CALL METHOD cl_cam_address_bcs=>create_internet_address
   
EXPORTING
      i_address_string =  sd_addr
   receiving
      RESULT           = l_o_sender.

*l_o_sender = cl_cam_address_bcs=>create_internet_address( 'rameshkumar.r@kaaviansys.com' ).
   l_o_send_request->set_sender( i_sender = l_o_sender ).


" recipient TO
  
CALL METHOD cl_cam_address_bcs=>create_internet_address
    
EXPORTING
      i_address_string =  rc_addr
    receiving
      RESULT           = l_o_recipient.

  l_o_send_request->add_recipient(
  i_recipient = l_o_recipient
  i_copy = 
'' " CC indicator
  ).

**********************************************************************
" email contents
  
CLEAR l_wa_contents.
  l_wa_contents-
line = 'Dear Recipients,'.
  
APPEND l_wa_contents TO l_it_contents.

  
CLEAR l_wa_contents.
  l_wa_contents-
line = subject.
  
APPEND l_wa_contents TO l_it_contents.

  
CLEAR l_wa_contents.
  l_wa_contents-
line = 'with Regards'.
  
APPEND l_wa_contents TO l_it_contents.

  
CLEAR l_wa_contents.
  l_wa_contents-
line = 'thrinath'.
  
APPEND l_wa_contents TO l_it_contents.

" create documents
  l_o_document = cl_document_bcs=>create_document(
  i_type = 
'RAW' " RAW document format
  i_text = l_it_contents
  i_subject = SUB
"'Simple Email'
  ).
 
ENDAT.

   LV_NAME = Ls_IT-FILE.
   
CALL METHOD l_o_document->add_attachment
     
EXPORTING
       i_attachment_type     = Ls_IT-
type
       i_attachment_subject  = LV_NAME
       i_att_content_hex     = T_ATT_CONTENT_HEX

    .
    l_o_send_request->set_document( l_o_document ).
      
CATCH cx_bcs INTO bcs_exception.
* exceptions, do something
        
ENDTRY.

         
endloop.

L_O_SEND_REQUEST->SET_SEND_IMMEDIATELY( 
'X' ).
" send email
  l_o_send_request->send( ).

commit work .
endmethod.

Step12:

Create inbound and outbound plugs for the two views.

Step13:

Embed the view in to the window and create navigation link from outbound plug of view main to inbound plug of view attachment and also create navigation link from outbound plug of view attachment to inbound plug of view main.

Step14:

Create the Web Dynpro application.

Save and Activate it.

Test the application.

 

Please send us your feedback/suggestions at webmaster@SAPTechnical.COM 

HomeContribute About Us Privacy Terms Of Use • Disclaimer • SafeCompanies: Advertise on SAPTechnical.COM | Post JobContact Us  

Graphic Design by Round the Bend Wizards

footer image footer image