INTRODUCTION
Emails are one of the common methods of notifying users about various changes performed in the system. But when the user needs to view/process the data he/she needs to manually login to the system through the required transactions to access the data. SAP shortcuts come handy in these situations enabling the users to login to the required transactions or custom Webdynpro application directly.
Using SAP shortcuts through email will benefit the users in the following ways:
- Delivered to a single inbox, hence user does not have to keep checking the UWL/SBWP or other inboxes
- User does not need to remember the different transactions that he/she needs to work on.
Detailed Requirements / Technical Description
Consider a scenario when service entry sheet is created in other system like SUS. Now once the SES receives in ERP a notification email is sent to the responsible agent for approval process. In a normal scenario the agent needs to log into the system manually and enter the required transaction. Then the required details need to be entered for approval.
This process can be simplified by sending a shortcut which will navigate the user to the required transaction or custom Webdynpro application. The sample code for this process is given below
Steps to follow:-
1. Created a Webdynpro application “Z_SES_SHORTCUT_APPROVE” as below, where agent can see the details of the service entry sheet and decides to approve or reject.
2. For the above application we create the transaction code “Z_SES_APPROVAL”.
3. The sample code for this requirement is given below and the FM can be used in triggering point where SES receives in ERP. (Example in proxy class in XI interface etc)
FUNCTION Z_SEND_SHORTCUT_LINK_BY_MAIL.
*"----------------------------------------------------------------------
*"*"Local Interface:
*" IMPORTING
*" REFERENCE(USER) TYPE UNAME
*" REFERENCE(SUBJECT) TYPE ANY
*" REFERENCE(TEXTNAME) TYPE TEXTNAME
*" REFERENCE(IS_ESSR) TYPE ESSR
*" REFERENCE(SHORTCUT_TCODE) TYPE TCODE
*" REFERENCE(LINK_WD_APPL) TYPE ANY
*" TABLES
*" ET_RETURN TYPE BAPIRETURN1_TABTYPE
*"----------------------------------------------------------------------
DATA lv_appl_link TYPE string.
DATA send_request TYPE REF TO cl_bcs.
DATA document TYPE REF TO cl_document_bcs
DATA bcs_exception TYPE REF TO cx_bcs.
DATA lv_subject_attach TYPE so_obj_des.
DATA lv_len_obj TYPE so_obj_len.
DATA lv_langu TYPE sy-langu.
DATA main_text TYPE bcsy_text.
DATA sent_to_all TYPE os_boolean.
DATA lv_text TYPE string.
DATA lv_text1 TYPE string.
DATA lv_text2 TYPE string.
DATA lv_string TYPE string.
DATA lv_url TYPE string.
DATA lt_shortcut TYPE soli_tab.
DATArecipient TYPE REF TO if_recipient_bcs.
DATAlv_type TYPEso_obj_tp.
DATAwa_return TYPEbapireturn1.
IF link_wd_appl IS NOT INITIAL.
lv_type = 'HTM'.
lv_text1 = 'You have been indendified as responsible agent for Service entry sheet no'.
lv_text2 = 'Please approve it'.
CONCATENATE lv_text1 IS_ESSR-lblni lv_text2 INTO lv_text separated by space.
cl_wd_utilities=>construct_wd_url(EXPORTINGapplication_name = lv_appl_link
IMPORTING out_absolute_url = lv_url ).
lv_string = 'Start'.
CONCATENATE lv_text
`<p><a href="`
lv_url
`" target="_top"><b>`
lv_string
'</b></a>'
INTO lv_text.
main_text = cl_document_bcs=>string_to_soli( lv_text ).
ELSEIF shortcut_tcode IS NOT INITIAL.
lv_type = 'RAW'.
lv_text = 'You have been indendified as responsible agent for SES please approve it'.
main_text = cl_document_bcs=>string_to_soli( lv_text ).
ENDIF.
* create persistent send request
TRY.
send_request = cl_bcs=>create_persistent( ).
CATCH cx_send_req_bcs INTO bcs_exception.
CLEAR wa_return.
wa_return-type = 'E'.
wa_return-message = bcs_exception->get_longtext( ).
IF wa_return-message IS INITIAL.
wa_return-message = bcs_exception->get_text( ).
ENDIF.
APPEND wa_return TO et_return.
ENDTRY.
* create and set document with attachment
TRY.
document = cl_document_bcs=>create_document(
i_type = lv_type
i_text = main_text
i_subject = lv_subject ).
CATCH cx_document_bcs INTO bcs_exception.
CLEAR wa_return.
wa_return-type = 'E'.
wa_return-message = bcs_exception->get_longtext( ).
IF wa_return-message IS INITIAL.
wa_return-message = bcs_exception->get_text( ).
ENDIF.
APPEND wa_return TO et_return.
ENDTRY.
IF shortcut_tcode IS NOT INITIAL.
CONCATENATE '/n*' shortcut_tcode INTO lv_command.
* Create the shortcut as table
CALL FUNCTION 'SWN_CREATE_SHORTCUT'
EXPORTING
i_transaction = shortcut_tcode
* i_system_command = lv_command
i_saplogon_id = space
* i_sysid = space
i_user = user
i_language = lv_langu
i_windowsize = 'Normal window'
IMPORTING
shortcut_table = lt_shortcut
EXCEPTIONS
inconsistent_parameters = 1
OTHERS = 2.
TRY.
lv_len_obj = lines( lt_shortcut ) * 255.
CATCH cx_sy_arithmetic_overflow cx_sy_conversion_overflow.
ENDTRY.
lv_subject_attach = 'Personal worklist'.
* create and set document with attachment
TRY.
document->add_attachment(
i_attachment_type = 'SAP'
i_attachment_subject = lv_subject_attach
i_attachment_size = lv_len_obj
i_att_content_text = lt_shortcut ).
CATCH cx_document_bcs INTO bcs_exception.
CLEAR wa_return.
wa_return-type = 'E'.
wa_return-message = bcs_exception->get_longtext( ).
IF wa_return-message IS INITIAL.
wa_return-message = bcs_exception->get_text( ).
ENDIF.
APPEND wa_return TO et_return.
ENDTRY.
ENDIF.
* add document object to send request
TRY.
send_request->set_document( document ).
CATCH cx_send_req_bcs INTO bcs_exception.
CLEAR wa_return.
wa_return-type = 'E'.
wa_return-message = bcs_exception->get_longtext( ).
IF wa_return-message IS INITIAL.
wa_return-message = bcs_exception->get_text( ).
ENDIF.
APPEND wa_return TO et_return.
ENDTRY.
* create recipient object & add recipient (e-mail address)
TRY.
recipient ?= cl_sapuser_bcs=>create( user ).
CATCH cx_address_bcs INTO bcs_exception.
CLEAR wa_return.
wa_return-type = 'E'.
wa_return-message = bcs_exception->get_longtext( ).
IF wa_return-message IS INITIAL.
wa_return-message = bcs_exception->get_text( ).
ENDIF.
APPEND wa_return TO et_return.
ENDTRY.
* add recipient object to send request
TRY.
send_request->add_recipient( recipient ).
CATCH cx_send_req_bcs INTO bcs_exception.
CLEAR wa_return.
wa_return-type = 'E'.
wa_return-message = bcs_exception->get_longtext( ).
IF wa_return-message IS INITIAL.
wa_return-message = bcs_exception->get_text( ).
ENDIF.
APPEND wa_return TO et_return.
ENDTRY.
* send document ---------------------------------------
TRY.
sent_to_all = send_request->send( i_with_error_screen = space ).
CATCH cx_bcs INTO bcs_exception.
CLEAR wa_return.
wa_return-type = 'E'.
wa_return-message = bcs_exception->get_longtext( ).
IF wa_return-message IS INITIAL.
wa_return-message = bcs_exception->get_text( ).
ENDIF.
APPEND wa_return TO et_return.
MESSAGE i865(so) WITH bcs_exception->error_type.
ROLLBACK WORK.
EXIT.
ENDTRY.
COMMIT WORK.
ENDFUNCTION.
4. When the FM is executed with the following parameters, agent can directly navigated to the required transaction or custom Webdynpro application from his inbox .
Optional that we can either give SHORTCUT_TCODE i.e. Transaction code or LINK_WD_APPL i.e. Webdynpro application name
When we click on Personal worklist it will get navigated to the required transaction or custom Webdynpro application.
5. Note:
When the user double clicks on the attachment the pop up window for entering the password is opened as shown below,
Once the user enters the password and clicks on "Log on" the required transaction is opened up directly as shown below.
The system on which the shortcut is executed should have SAP GUI installed and have the target system configured in the SAP logon pad. If the configuration is not already available then on launching the shortcut the system asks for the logon details as shown below,
1.3 SUMMARY
This document provides the following details:
- Defines how to create a SAP short cut.
- Describes how to send a mail with SAP short cut attachment .
Thanks and regards,
Praveen Srivastava