Saturday, 5 October 2013

Code for sending external mail


  DATA: lo_document    TYPE REF TO   cl_document_bcs VALUE IS INITIAL,
        lo_send_request    TYPE REF TO   cl_bcs VALUE IS INITIAL,
        lo_sender              TYPE REF TO   if_sender_bcs VALUE IS INITIAL,
        lo_recipient           TYPE REF TO   if_recipient_bcs VALUE IS INITIAL,
        lt_message_body  TYPE bcsy_text VALUE IS INITIAL,
        ls_soli                   TYPE soli,
        li_approver1         TYPE bcsy_text,
        lv_subject             TYPE so_obj_des,
        lv_generic_mail     TYPE ad_smtpadr,
        lv_mail_subj         TYPE so_obj_des,
        lv_sent_to_all       TYPE os_boolean,
        lv_wait                 TYPE bapiwait,
        lv_return              TYPE bapiret2.


* MESSAGE BODY AND SUBJECT
    lv_mail_subj = 'Business Partner '.

    ls_soli-line = 'Dear Partner,'.
    APPEND ls_soli TO li_approver1.
    CLEAR ls_soli.
    ls_soli-line = ''.
    APPEND ls_soli TO li_approver1.
    CLEAR ls_soli.
    ls_soli-line = ''.
    APPEND ls_soli TO li_approver1.
    CLEAR ls_soli.
    ls_soli-line = lv_mail_subj.
    APPEND ls_soli TO li_approver1.
    CLEAR ls_soli.
    APPEND ls_soli TO li_approver1.
    CLEAR ls_soli.
    ls_soli-line = ''.
    APPEND ls_soli TO li_approver1.
    ls_soli-line = ''.
    APPEND ls_soli TO li_approver1.
    CLEAR ls_soli.
    ls_soli-line = 'Thank you,'.
    APPEND ls_soli TO li_approver1.
    CLEAR ls_soli.


  CLASS cl_bcs DEFINITION LOAD.
  TRY .
      lo_send_request = cl_bcs=>create_persistent( ).
    CATCH cx_root.

  ENDTRY.
  lv_subject         = lv_mail_subj.
  lt_message_body    = li_approver1.

  TRY .
      lo_document = cl_document_bcs=>create_document(
      i_type = 'RAW'
      i_text = lt_message_body
      i_subject = lv_subject
      ).
    CATCH cx_root.
  ENDTRY.

  TRY .
      lo_send_request->set_document( lo_document ).
    CATCH cx_root.

  ENDTRY.


*----------------------------------------------------------------------*
** Create and Set Sender
*----------------------------------------------------------------------*
  TRY .
      lo_sender = cl_sapuser_bcs=>create( sy-uname ).
    CATCH cx_root .

  ENDTRY.

  TRY .
      lo_send_request->set_sender( EXPORTING i_sender = lo_sender ).
    CATCH cx_root .

  ENDTRY.


*----------------------------------------------------------------------*
** Create and Set Recipeint
*----------------------------------------------------------------------*
  lv_generic_mail = iv_email_id. "ls_adr6-smtp_addr.

  TRY .
      lo_recipient = cl_cam_address_bcs=>create_internet_address(
                                lv_generic_mail ).
    CATCH cx_root.
  ENDTRY.

  TRY .
      lo_send_request->add_recipient(
      EXPORTING
      i_recipient = lo_recipient
      i_express = 'X'
      i_copy    = 'X'        ).
    CATCH cx_root.

  ENDTRY.

*----------------------------------------------------------------------*
**Send mail to all reciepients
*----------------------------------------------------------------------*
  TRY .
      lo_send_request->send(
      EXPORTING
      i_with_error_screen = 'X'
      RECEIVING
      result = lv_sent_to_all ).
    CATCH cx_root.

  ENDTRY.

*----------------------------------------------------------------------*
** Commit work
*----------------------------------------------------------------------*
  lv_wait = 'X'.
  CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
    EXPORTING
      wait   = lv_wait
    IMPORTING
      return = lv_return.

Friday, 4 October 2013

To know the Text ids and Text objects of long text

Requirement:
If we want to read text or to create text for particular object using function modules, etc then we have to know their ids and text object.

Process:
Go to transaction for which you want to create long text or short text in editable mode.
Then go to the editor where we are creating text,
Then click on 'GO TO' -> 'HEADER'.
Then a window is displayed .In that we can find the details of the long text.
1. Text Name
2. Language
3. Text ID
4. Text Object


For example:
Go to MM01. Select Bacic Data 1.

 

 Following window gets displayed .Click on Basic Data Text.
 

Click Editor button.

 

Then click on 'GO TO' -> 'HEADER'.
 
 

 
A popup window is displayed .In that we can find the details of the long text.
1. Text Name
2. Language
3. Text ID &
4. Text Object


 
Done! :)