In this blog I will talk about requirement in which from SAP Web UI Attachment assignment block,  selected attachment can be added to Outlook Email as below. It brings convenient to users if they want to mail attachments.SAP by standard provides download functionality in GS_CM/DocList view controller, which converts selected attachments to unique zip file URL which calls pop up for user action.We need to create a new button for ‘send attachment by email’ and use the logic of download attachment to get lv_zip_file which is hexa based Xstring of zip file. This file is converted to Binary and uploaded to application server and its full file path is stored in a global static attribute zl_outlook=>g_path of BOR class (which will be consumed later in BOR class method PREPARE_DATA_FLOW as shown later in blog). Then Transaction launcher ZOUTLOOK is called which calls OLE report ZOUTLOOK (in GUI mode as OLE report is not supported in WEBGUI mode).

*   Constants
    CONSTANTS: lc_extension        TYPE char20 VALUE'email.zip', 
               lc_outlook_call     TYPE string VALUE 'ZOUTLOOK'. "Transaction Launcher for Outlook page

    DATA: lt_solix_tab   TYPE TABLE OF w3mime-line, "Binary Tab
          l_solix        TYPE w3mime-line,          "Binary wa
          l_filename     TYPE dxfile-filename,      "Full Filename
          lr_nav_service TYPE REF TO if_crm_ui_navigation_service, "Navigation service instance
          l_msg          TYPE boolean,              "Error flag
          l_system       TYPE tbdls-logsys. "Current system

*        Convert Zip file To Binary
          CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'
            EXPORTING
              buffer        = lv_zip_file
            IMPORTING
              output_length = lv_length
            TABLES
              binary_tab    = lt_solix_tab.

*         Write file to server
            OPEN DATASET l_filename FOR OUTPUT IN BINARY MODE.
            LOOP AT lt_solix_tab INTO l_solix.
              lv_length = xstrlen( l_solix ).
              TRANSFER l_solix TO l_filename LENGTH lv_length.
              IF sy-subrc NE 0.
                l_msg = abap_true.
                EXIT.
              ENDIF.
            ENDLOOP.
            CLOSE DATASET l_filename.
*           Write file name to BOR class
            zl_outlook=>g_path = l_filename.

*   Call Transaction Launcher which calls T-code ZOUTLOOK
      lr_nav_service = cl_crm_ui_navigation_service=>get_instance( ).
      IF lr_nav_service IS NOT INITIAL.
        lr_nav_service->navigate( EXPORTING iv_link_id = lc_outlook_call ).
      ENDIF.

Report ZOUTLOOK main functionality is to take input as application server file path (as generated previously), download file in user local desktop and call Outlook OLE to open Outlook mail page with added attachment as downloaded in local desktop.

INCLUDE : ole2incl.
* Constants
CONSTANTS: lc_directory        TYPE char100 VALUE '\vdhupndesktop$desktop&uname&Desktop&ufile&', 
           lc_physical         TYPE dxfile-filetype VALUE 'P', "Physical server
           lc_path_param       TYPE char10 VALUE 'p_path',    "Path Parameter name
           lc_binary           TYPE char10 VALUE 'BIN'.       "Binary Type
* Declarations
DATA: out             TYPE  ole2_object, "Outlook Application
      outmail         TYPE  ole2_object, "Create Outlook Item
      desti           TYPE  ole2_object, "Destinations
*      att     TYPE  ole2_object, "Attachments
      atts            TYPE  ole2_object, "Attachments
      l_directory(30).
DATA l_zipped_data TYPE xstring.              "Zipped data
DATA: l_file_length TYPE i.                   "length
DATA: lt_file_tab TYPE w3mimetabtype.         "Binary data

*Parameters
PARAMETERS: p_path TYPE dxfile-filename. "Path

AT SELECTION-SCREEN OUTPUT.
*Fill path from memory if found initial
  IF p_path IS INITIAL.
    GET PARAMETER ID lc_path_param FIELD p_path.
  ENDIF.

* Start of selection
START-OF-SELECTION.
....
        l_source_filename = p_path.

*       Get zipped data from presentation server
          OPEN DATASET l_source_filename IN BINARY MODE FOR INPUT.
          READ DATASET l_source_filename INTO l_zipped_data.
          CLOSE DATASET l_source_filename.
          "convert to table
          CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'
            EXPORTING
              buffer        = l_zipped_data
            IMPORTING
              output_length = l_file_length
            TABLES
              binary_tab    = lt_file_tab.
          "Save the file
          CALL METHOD cl_gui_frontend_services=>gui_download
            EXPORTING
              bin_filesize            = l_file_length        " File length for binary files
              filename                = l_target_filename    " Name of file
              filetype                = lc_binary            " File type (ASCII, binary ...)
            CHANGING
              data_tab                = lt_file_tab          " Transfer table
          IF sy-subrc = 0.
            CALL FUNCTION 'DX_FILE_DELETE'
              EXPORTING
                filetype                    = lc_physical       "Physical
                filename                    = l_source_filename "Filename
              EXCEPTIONS
                file_handling_error         = 1
                no_authority_to_delete_file = 2
                file_doesnot_exist          = 3
                file_is_used                = 4
                db_error                    = 5
                no_authority                = 6
                OTHERS                      = 7.
            IF sy-subrc <> 0.
              CLEAR l_source_filename.
            ENDIF.
          ELSE.
            CLEAR l_target_filename.
          ENDIF.

*Call OLE Outlook
  CREATE OBJECT out 'Outlook.Application'.
  CALL METHOD OF out 'CREATEITEM' = outmail  EXPORTING #1 = 0.
  SET PROPERTY OF outmail 'SUBJECT' = TEXT-001.
  SET PROPERTY OF outmail 'BODY' = TEXT-002.
  CALL METHOD OF outmail 'RECIPIENTS' = desti.
*CALL METHOD OF desti'ADD' EXPORTING #1 = 'user @ yyy.com'.
  CALL METHOD OF outmail 'ATTACHMENTS' = atts.
*Fill Attachment when found
  IF l_target_filename IS NOT INITIAL.
    CALL METHOD OF atts 'ADD' EXPORTING #1 = l_target_filename.
  ENDIF.
  CALL METHOD OF outmail 'DISPLAY'.

Now coming back to transaction launcher, I have created BOR (with input parameters) based transaction launcher which requires BOR object copied from TSTC object (in SWO1) and add method with parameters which passes generated Application server file path to transaction ZOUTLOOK, with the help of SET/GET parameter ID.

begin_method execute_param changing container.
DATA:
  lv_param1     TYPE cpidlist,
  lv_param2     TYPE zcpidlist_ol,
  lv_skipscreen TYPE char1.

swc_get_element container 'param1' lv_param1.
swc_get_element container 'param2' lv_param2.
swc_get_element container 'SKIPSCREEN' lv_skipscreen.

*BREAK-POINT.

IF lv_param1 IS NOT INITIAL.
  SET PARAMETER ID: lv_param1-pid FIELD lv_param1-value.
ENDIF.
IF lv_param2 IS NOT INITIAL.
  SET PARAMETER ID: lv_param2-pid FIELD lv_param2-value.
ENDIF.

CALL FUNCTION 'AUTHORITY_CHECK_TCODE'
  EXPORTING
    tcode  = object-key-code
  EXCEPTIONS
    ok     = 0
    not_ok = 1
    OTHERS = 2.
IF sy-subrc NE 0.
  MESSAGE s059(eu) WITH object-key-code.
*   Sie haben keine Berechtigung für die Transaktion &
ELSE.
  IF lv_skipscreen IS NOT INITIAL.
    CALL TRANSACTION object-key-code AND SKIP FIRST SCREEN.
  ELSE.
    CALL TRANSACTION object-key-code.
  ENDIF.
ENDIF.
end_method.

While creating transaction launcher make sure to select below check box  to open transaction ZOUTLOOK in a separate window/session in GUI mode so that current session page is not effected. Also make sure to activate SICF service /default_host/sap/bc/bsp/sap/ltx_sapgui_strt which calls gui session.

METHOD if_crm_ic_action_handler~prepare_data_flow.
...
    param2-pid = 'p_path'.
    param2-value = g_path.
    CLEAR g_path.

    me->set_container_data(
      iv_name  = gc_param2
       iv_value = param2 ).

    skipscreen-pid = 'SKIPSCREEN'.
    skipscreen-value = 'X'.

    me->set_container_data(
      iv_name  = gc_skipscreen
       iv_value = skipscreen ).

    icwebclientborkeyparameter = 'ZOUTLOOK'.

    me->set_container_object(
      iv_name        = '<*MAINOBJ*>'
      iv_object_key  = icwebclientborkeyparameter
      iv_object_type = gv_bortype ).

* Data flow is complete - set to false if data is missing
    gv_data_flow_complete = abap_true.

  ENDMETHOD.

Lastly, transaction launcher logical link need to be added to Navigation bar profile either as workcenter, direct link or generic outbound mapping for it to work successfully in user session.

Tcode: crmc_ui_nblinksHope blog helps to bring clarity on topic related to requirement. As this is my initial blogs, your inputs would help me to improve. Let me know if any further clarification/comments.

Sara Sampaio

Sara Sampaio

Author Since: March 10, 2022

0 0 votes
Article Rating
Subscribe
Notify of
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x