SAP Virtual/Onsite Trainings

Document Categories:

What's New?

Contribute?

Sample Specs

What's Hot?

Web Dynpro for ABAP Tutorials 


Join the Mailing List
Enter name and email address below:
Name:
Email:
Subscribe  Unsubscribe 

Offline Workflow Approval in ECC R/3 without SAP Logon from E-Mail (Outlook)

...Previous

Configure and activate the SMTP Service via SMICM transaction

Run transaction SMICM or Report RSMONICM_STANDARDè

Display the services via SHIFT+F1 or menu path as shownè

This displays the Services as shown. Mention the SMTP port (normally 25, your Basis consultant will provide you the port number, this is similar to the port settings done in SCOT transaction for SAP Connect Outbound E-Mail Configuration) and activate the service. The GREEN check will indicate the service is active. The Host Name will also be provided by your Basis / Security Consultant. This Host is also similar to the host maintained in SCOT for the SMTP nodeè

Activate and change the service via the menu as shown belowè

Configure and set the Inbound E-Mail Exit Configuration

Transaction SO50 is used to mention the inbound e-mail exit. This also can be access via SCOT transaction by the menu path SettingsàInbound Processing. This also calls SO50.

You can also run Report BCS_IBND_MAINT to call SO50 Transaction.

We have to write an Inbound Exit Class that will process the Inbound E-Mails. That class should be mentioned here. (We will see later how to create this class)è

Note that we mention our offline e-mail ID here (eccoffline@ecc-dev.yourdomain.com). The class ZZZCL_PROCESS_INBOUND_WORKFLOW is the Exit Class designed to process inbound e-mails as per our need. By default generally the first entry with the CL_APPOINTMENT_REPLY is always present. We include our entry here and set the call sequence. The Document Class / Type is set as “*” to allow all types of documents available in ECC.

Creation of the Inbound Exit Class

This class implements the interface IF_INBOUND_EXIT_BCS (BCS: Exit for Inbound Processing). The properties tab of the class is shownè

The Interfaces Tabè

The Methods Tabè

The CREATE_INSTANCE method is called by standard SAP (via SO50 Configuration) to create a unique instance for each inbound e-mail. The code is written belowè

METHOD if_inbound_exit_bcs~create_instance.
  DATA: ref TYPE REF TO zzzcl_process_inbound_workflow.
* Check if the Instance is initial
  IF ref IS INITIAL.
    CREATE OBJECT ref.
  ENDIF.
* Return the Instance
  ro_ref = ref.
ENDMETHOD.

The interface of the method CREATE_INSTANCE is shownè

The PROCESS_INBOUND method is the place where we write the exit logic. This is where we will process the desired work item of the workflow and process it based on the e-mail action / reply created by the automated e-mail. The interface of method PROCESS_INBOUND is shownè

The code in PROCESS_INBOUND methodè

METHOD if_inbound_exit_bcs~process_inbound.
* Declare for Inbound E-Mail processing (ENJOY :) :) )
  DATA: lo_document     TYPE REF TO if_document_bcs,
        l_mail_attr     TYPE bcss_dbpa,
        l_mail_content  TYPE bcss_dbpc,
        lo_reply        TYPE REF TO cl_send_request_bcs,
        sender          TYPE REF TO if_sender_bcs,
        sender_addr     TYPE string,
        lv_email        TYPE comm_id_long,
        send_request    TYPE REF TO cl_bcs,
        ltext           TYPE bcsy_text,
        body_text       TYPE so_text255,
        document        TYPE REF TO cl_document_bcs,
        ex_sender       TYPE REF TO cl_sapuser_bcs,
        recipient       TYPE REF TO if_recipient_bcs,
        bcs_exception   TYPE REF TO cx_bcs,
        sent_to_all     TYPE os_boolean,
        lv_action       TYPE char01,
        lv_wid          TYPE char12,
        lv_wid_num      TYPE sww_wiid,
        lv_wid_func     TYPE swr_struct-workitemid,
        ls_swwwihead    TYPE swwwihead,
        lv_new_status   TYPE sww_wistat,
        lv_action_text  TYPE char12.
*--------------------------------------------------------------------*
*- Get a pointer to the reply email object -*
*--------------------------------------------------------------------*
  TRY.
      lo_reply = io_sreq->reply( ).
    CATCH cx_send_req_bcs.
  ENDTRY.
**** Check to make sure this is from an approved Sender
  sender = io_sreq->get_sender( ).
  sender_addr =  sender->address_string( ).
  lv_email = sender_addr.
  TRANSLATE sender_addr TO UPPER CASE.
**** Only reply if this message came from within our mail system or domain
**** SPAMMERS Beware, your e-mails will not be processed!!!
  IF sender_addr CS '@YOURDOMAIN.COM'.
**** send reply and inbound processing
*--------------------------------------------------------------------*
*- Get email subject -*
*--------------------------------------------------------------------*
    TRY.
        lo_document = io_sreq->get_document( ).
        l_mail_attr = lo_document->get_body_part_attributes( '1' ).
      CATCH cx_document_bcs.
    ENDTRY.
*--------------------------------------------------------------------*
*- Get mail body, here you can read the REJECTION Reason -*
*--------------------------------------------------------------------*
    TRY.
        l_mail_content = lo_document->get_body_part_content( '1' ).
      CATCH cx_document_bcs.
    ENDTRY.
*--------------------------------------------------------------------*
* YAAAAAHHHHHHOOOO at this point I have the Subject and the Body
*--------------------------------------------------------------------*
* Now read the subject and process the work item
* Condense the subject to remove blank spaces
    CONDENSE l_mail_attr-subject.
* Read the action
    lv_action = l_mail_attr-subject+0(1).
* Read the work item ID
    lv_wid    = l_mail_attr-subject+1(12).
* Pass to variables
    lv_wid_num = lv_wid.
    lv_wid_func = lv_wid_num.
* First check the status of the work item, process only if READY or IN-PROCESS
    SELECT SINGLE *
      FROM swwwihead
      INTO ls_swwwihead
      WHERE wi_id = lv_wid_num.
* If data not found, indicates an invalid e-mail sent to offline ID
    IF sy-subrc NE 0.
      lv_wid = 'INVALID WID'.
    ENDIF.
* Check the status, if COMPLETED, send the notification
    IF ls_swwwihead-wi_stat = 'COMPLETED'.
      TRY.
*     -------- create persistent send request ------------------------
          send_request = cl_bcs=>create_persistent( ).
*     -------- create and set document -------------------------------
*     Build the e-mail Body
          CLEAR: body_text.
          CONCATENATE 'WORK ITEM ID : '
                      lv_wid
                      'is in status "COMPLETED"' INTO body_text SEPARATED BY space.
          APPEND body_text TO ltext.
          CLEAR: body_text.
          CONCATENATE 'This has already been processed '
                      'and cannot be processed again.' INTO body_text SEPARATED BY space.
          APPEND body_text TO ltext.
          document = cl_document_bcs=>create_document(
                                i_type    = 'RAW'
                                i_text    = ltext
                                i_length  = '510'
                                i_subject = 'Work Item has already been processed' ).
*     Add document to send request
          CALL METHOD send_request->set_document( document ).
*     --------- set sender -------------------------------------------
*     note: this is necessary only if you want to set the sender
*           different from actual user (SY-UNAME). Otherwise sender is
*           set automatically with actual user.
          sender = cl_sapuser_bcs=>create( 'ECCOFFLINE' ).
          CALL METHOD send_request->set_sender
            EXPORTING
              i_sender = sender.
*     --------- Add recipient (e-mail address) -----------------------
*     Create recipient - passing the receipient e-mail ID
          recipient = cl_cam_address_bcs=>create_internet_address( lv_email ).
*     Add recipient with its respective attributes to send request
          CALL METHOD send_request->add_recipient
            EXPORTING
              i_recipient = recipient
              i_express   = 'X'.
*     ---------- Send document ---------------------------------------
          CALL METHOD send_request->send(
            EXPORTING
              i_with_error_screen = 'X'
            RECEIVING
              result              = sent_to_all ).
          COMMIT WORK.
        CATCH cx_bcs INTO bcs_exception.
      ENDTRY.
    ELSEIF ls_swwwihead-wi_stat = 'READY' OR
           ls_swwwihead-wi_stat = 'STARTED'.
* First process the Work Item Based on the action
      IF lv_action = 'A'.
* Set the ACTION Text
        lv_action_text = 'APPROVED'.
* If APPROVED
        CALL FUNCTION 'SAP_WAPI_DECISION_COMPLETE'
          EXPORTING
            workitem_id          = lv_wid_func
            language             = sy-langu
            user                 = sy-uname
            decision_key         = '0001' "Approval Node
            do_commit            = 'X'
          IMPORTING
            new_status           = lv_new_status
*  TABLES
*    MESSAGE_LINES        =
*    MESSAGE_STRUCT       =
                  .
      ELSEIF lv_action = 'R'.
* Set the ACTION Text
        lv_action_text = 'REJECTED'.
* If REJECTED
        CALL FUNCTION 'SAP_WAPI_DECISION_COMPLETE'
          EXPORTING
            workitem_id          = lv_wid_func
            language             = sy-langu
            user                 = sy-uname
            decision_key         = '0002' "Rejection Node
            do_commit            = 'X'
          IMPORTING
            new_status           = lv_new_status
*  TABLES
*    MESSAGE_LINES        =
*    MESSAGE_STRUCT       =
                  .
      ENDIF.
* After the action now send the e-mail
      TRY.
*     -------- create persistent send request ------------------------
          send_request = cl_bcs=>create_persistent( ).
*     -------- create and set document -------------------------------
*     Build the e-mail Body
          CLEAR: body_text.
          CONCATENATE 'WORK ITEM ID : '
                      lv_wid
                      'has been'
                      lv_action_text INTO body_text SEPARATED BY space.
          APPEND body_text TO ltext.
          CLEAR: body_text.
          CONCATENATE 'New status of work item is '
                      lv_new_status INTO body_text SEPARATED BY space.
          APPEND body_text TO ltext.
          document = cl_document_bcs=>create_document(
                                i_type    = 'RAW'
                                i_text    = ltext
                                i_length  = '510'
                                i_subject = 'Work Item processing confirmation' ).
*     Add document to send request
          CALL METHOD send_request->set_document( document ).
*     --------- set sender -------------------------------------------
*     note: this is necessary only if you want to set the sender
*           different from actual user (SY-UNAME). Otherwise sender is
*           set automatically with actual user.
          sender = cl_sapuser_bcs=>create( 'ECCOFFLINE' ).
          CALL METHOD send_request->set_sender
            EXPORTING
              i_sender = sender.
*     --------- Add recipient (e-mail address) -----------------------
*     Create recipient - passing the receipient e-mail ID
          recipient = cl_cam_address_bcs=>create_internet_address( lv_email ).
*     Add recipient with its respective attributes to send request
          CALL METHOD send_request->add_recipient
            EXPORTING
              i_recipient = recipient
              i_express   = 'X'.
*     ---------- Send document ---------------------------------------
          CALL METHOD send_request->send(
            EXPORTING
              i_with_error_screen = 'X'
            RECEIVING
              result              = sent_to_all ).
          COMMIT WORK.
        CATCH cx_bcs INTO bcs_exception.
      ENDTRY.
    ELSE.
* This means the work item is in ERROR or some exception status, NOTIFY!!!!!
* Here you can reply back to the user if they send invalid e-mails to ECCOFFLINE other then clicking on the Processing Links
      TRY.
*     -------- create persistent send request ------------------------
          send_request = cl_bcs=>create_persistent( ).
*     -------- create and set document -------------------------------
*     Build the e-mail Body based on the Work Item ID
          IF lv_wid = 'INVALID WID'.
* Build E-Mail for Invalid WID
            CLEAR: body_text.
            CONCATENATE 'This system e-mail is meant only for OFFLINE WORKFLOW Processing.'
                        'Please do not send any e-mails to this ID other then via Workflow Processing Offline Links.' INTO body_text SEPARATED BY space.
            APPEND body_text TO ltext.
            CLEAR: body_text.
            CONCATENATE 'This is a system generated auto e-mail '
                        'Please do not reply to this ID.' INTO body_text SEPARATED BY space.
            APPEND body_text TO ltext.
            document = cl_document_bcs=>create_document(
                                  i_type    = 'RAW'
                                  i_text    = ltext
                                  i_length  = '510'
                                  i_subject = 'System ID - Please do not reply or send E-Mail' ).
          ELSE.
* Build E-Mail body for Valid WID gone in exception status
            CLEAR: body_text.
            CONCATENATE 'WORK ITEM ID '
                        lv_wid
                        'might not have processed as desired.' INTO body_text SEPARATED BY space.
            APPEND body_text TO ltext.
            CLEAR: body_text.
            CONCATENATE 'Please forward this e-mail to the '
                        'System / Workflow Administrator to help you and analyze / solve it.' INTO body_text SEPARATED BY space.
            APPEND body_text TO ltext.
            document = cl_document_bcs=>create_document(
                                  i_type    = 'RAW'
                                  i_text    = ltext
                                  i_length  = '510'
                                  i_subject = 'Work Item exception might have occured' ).
          ENDIF.
*     Add document to send request
          CALL METHOD send_request->set_document( document ).
*     --------- set sender -------------------------------------------
*     note: this is necessary only if you want to set the sender
*           different from actual user (SY-UNAME). Otherwise sender is
*           set automatically with actual user.
          sender = cl_sapuser_bcs=>create( 'ECCOFFLINE' ).
          CALL METHOD send_request->set_sender
            EXPORTING
              i_sender = sender.
*     --------- Add recipient (e-mail address) -----------------------
*     Create recipient - passing the receipient e-mail ID
          recipient = cl_cam_address_bcs=>create_internet_address( lv_email ).
*     Add recipient with its respective attributes to send request
          CALL METHOD send_request->add_recipient
            EXPORTING
              i_recipient = recipient
              i_express   = 'X'.
*     ---------- Send document ---------------------------------------
          CALL METHOD send_request->send(
            EXPORTING
              i_with_error_screen = 'X'
            RECEIVING
              result              = sent_to_all ).
          COMMIT WORK.
        CATCH cx_bcs INTO bcs_exception.
      ENDTRY.
    ENDIF.
* End the IF for checking valid E-Mail
  ENDIF.
ENDMETHOD.

Click here to continue..

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