Skip to end of metadata
Go to start of metadata

Author: Prasath Natesan
Submitted: 04-Jan-2008
Modif 08-Mar-2010: Sandra Rossi
Related Links/References:

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 directly.

Using SAP shortcuts through email will benefit the users in the following ways,

  1. Delivered to a single inbox, hence user does not have to keep checking the UWL/SBWP or other inboxes
  2. User does not need to remember the different transactions that he/she needs to work on.
  3. Option of parameter handling simplifies the job of user by preloading the screen with required information

Creating SAP shortcut at run time

The following function module can be used to create a shortcut for any SAP transaction. Further, certain values available in the transaction can be defaulted by passing the values as parameters to this FM. This shortcut created can then be attached in a mail and sent to the appropriate recipients.

Before creating the function modulen you have to define ZST_SHORTCUT_PAR as a DDIC structure, which 2 components FIELDNAME of type C of length 60, and FIELDVALUE of type C of length 255.

Note: if you want to test the program quickly without creating the function module and the DDIC structure, have a look at appendix 2.

FUNCTION zfm_create_shortcut.
*"---------------------------------------------------------------------
*"*"Local Interface:
*"  IMPORTING
*"     REFERENCE(RECIPIENT_USER_ID) TYPE  SYUNAME
*"     REFERENCE(TRANSACTION) TYPE  TCODE
*"  EXPORTING
*"     REFERENCE(CONTENT) TYPE  STRING
*"  TABLES
*"      SHORTCUT_PARAM STRUCTURE  ZST_SHORTCUT_PAR OPTIONAL
*"---------------------------------------------------------------------

*** Declaration for shortcut content
  DATA :  parameter TYPE text255,
          v_pernr(12) TYPE c.
  DATA :  v_tcode TYPE tcode.

* Check if transaction code is available
  CLEAR v_tcode.
  SELECT SINGLE tcode FROM tstc
                INTO v_tcode
                WHERE tcode EQ transaction.

  IF v_tcode IS INITIAL.
    MESSAGE 'Enter a valid transaction' TYPE 'E' DISPLAY LIKE 'A'.
    EXIT.
  ENDIF.

* Populate the parameters to be passed to the shortcut
  IF NOT shortcut_param[] IS INITIAL.
    CLEAR parameter.
    LOOP AT shortcut_param.
      CONCATENATE parameter shortcut_param-fieldname '='
    shortcut_param-fieldvalue ';'
                INTO parameter.
    ENDLOOP.
  ENDIF.

*** create the shortcut content for the required transaction
  CALL FUNCTION 'SWN_CREATE_SHORTCUT'
    EXPORTING
      i_transaction           = transaction
      i_parameter             = parameter
      i_sysid                 = sy-sysid
      i_client                = sy-mandt
      i_user                  = recipient_user_id
      i_language              = sy-langu
      i_windowsize            = 'Normal window'
    IMPORTING
      shortcut_string         = content
    EXCEPTIONS
      inconsistent_parameters = 1
      OTHERS                  = 2.
  IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.

ENDFUNCTION.

This FM receives RECIPIENT_USER_ID and TRANSACTION as import parameters. The value of parameters if any can be passed through table parameter SHORCTCUT_PARAM. On execution the shortcut content is created and returned through the export parameter "CONTENT". The table SHORTCUT_PARAM refers to a custom structure described in Appendix 1.

Example scenario

Consider a scenario where the employee has requested for a change in address. Now once the change in address is completed a notification email is sent to the employee indicating the successful change in address. In a normal scenario the employee needs to log into the system manually and enter the required transaction. Then the required details (employee number, infotype and subtype) need to be entered before displaying the updated information.

This process can be simplified by sending a shortcut which will navigate the user to the required transaction with all required data pre-loaded. The sample code for this process is given below

*&---------------------------------------------------------------------*
*& Report  ZRP_MAIL_SHORTCUT
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT  zrp_mail_shortcut.

************************************************************************
***    Report to send mail to employee to display temp address   ***
************************************************************************
*** Declarations for attachment creation
DATA: doc_chng  LIKE sodocchgi1.
DATA: tab_lines LIKE sy-tabix,
      body_start LIKE sy-tabix.
DATA: it_objtxt LIKE solisti1 OCCURS 0 WITH HEADER LINE.
DATA: it_objpack   LIKE sopcklsti1 OCCURS 2 WITH HEADER LINE.
DATA: it_objbin    LIKE solisti1 OCCURS 10 WITH HEADER LINE.
DATA: it_reclist   LIKE somlreci1 OCCURS 5 WITH HEADER LINE.
DATA: it_shortcut_param LIKE zst_shortcut_par OCCURS 0 WITH HEADER LINE.
DATA: content TYPE string.

*** Pass the required parameters and create the shortcut
CLEAR it_shortcut_param.
REFRESH it_shortcut_param.

it_shortcut_param-fieldname = 'RP50G-PERNR'.
it_shortcut_param-fieldvalue = '1001'. "Employee number
APPEND it_shortcut_param.

it_shortcut_param-fieldname = 'RP50G-CHOIC'.
it_shortcut_param-fieldvalue = '0006'. " Address Infotype
APPEND it_shortcut_param.

it_shortcut_param-fieldname = 'RP50G-TIMR1'.
it_shortcut_param-fieldvalue = 'X'.    "Period selected as "Today"
APPEND it_shortcut_param.

it_shortcut_param-fieldname = 'RP50G-SUBTY'.
it_shortcut_param-fieldvalue = '2'.    "Temporary address subtype
APPEND it_shortcut_param.

CALL FUNCTION 'ZFM_CREATE_SHORTCUT'
  EXPORTING
    recipient_user_id = 'DEVHYD'
    transaction       = 'PA20'
  IMPORTING
    content           = content
  TABLES
    shortcut_param    = it_shortcut_param.

*** Mail Subject
doc_chng-obj_descr = 'Employee address changed'.
*** Mail Contents
CONCATENATE ' The requested change has been made to your temporary address.'
' Please double click on the attachment and choose display to view the updated address'
INTO it_objtxt.
APPEND it_objtxt.

*** Creation of the entry for the document
DESCRIBE TABLE it_objtxt LINES tab_lines.
CLEAR it_objpack-transf_bin.
it_objpack-head_start = 1.
it_objpack-head_num = 0.
it_objpack-body_start = 1.
it_objpack-body_num = tab_lines.
it_objpack-doc_type = 'RAW'.
APPEND it_objpack.

*** Populate attachment content
CLEAR : tab_lines, it_objbin.
CONCATENATE content it_objbin-line INTO it_objbin-line.
APPEND it_objbin.
DESCRIBE TABLE it_objbin LINES tab_lines.

*** Creation of the entry for the compressed attachment
it_objpack-transf_bin = 'X'. "Will get content from content_bin
it_objpack-head_start = 1.
it_objpack-head_num   = 1.
it_objpack-body_start = 1.
it_objpack-body_num   = tab_lines.
it_objpack-doc_type   = 'EXT'.
it_objpack-obj_name   = 'SAPSHORTCUTMAIL'.
it_objpack-obj_descr  = 'DisplayAddress.SAP'.
it_objpack-doc_size   = tab_lines * 255.
APPEND it_objpack.


*** target recipent(s)
CLEAR it_reclist.
it_reclist-receiver = 'employeemailid@employeecompany.com'.
it_reclist-rec_type = 'U'.
APPEND it_reclist.

*** Sending the document to recipients with the shortcut attachment
CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
  EXPORTING
    document_data              = doc_chng
    put_in_outbox              = 'X'
    commit_work                = 'X'
  TABLES
    packing_list               = it_objpack
    contents_bin               = it_objbin
    contents_txt               = it_objtxt
    receivers                  = it_reclist
  EXCEPTIONS
    too_many_receivers         = 1
    document_not_sent          = 2
    operation_no_authorization = 4
    OTHERS                     = 99.

The above code uses the function module ZFM_CREATE_SHORTCUT to create the required SAP shortcut and then sends it as attachment by email. The user can now double click on the shortcut from his email and reach the transaction directly with required information preloaded.

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,


As highlighted in the above picture the values - Employee number, Period, Infotype and subtype are preloaded when the user reaches the transaction. The user can now hit the display button and view the required data.

Note: 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,

Appendix 1: Structure for passing shortcut parameters

A custom name-value pair structure as shown below was created for passing the shortcut parameters.

Appendix 2: creating the report without the FM and DDIC structure

This section shows how to test the program quickly without creating the function module and the DDIC structure.*

In the program, perform the following changes:

Replace this section

By this section

REPORT  zrp_mail_shortcut.

************************************************************************
***    Report to send mail to employee to display temp address   ***
************************************************************************
REPORT  zrp_mail_shortcut.

DATA : BEGIN OF zst_shortcut_par,
          fieldname   TYPE c LENGTH 60,
          fieldvalue  TYPE c LENGTH 255,
        END OF zst_shortcut_par.

************************************************************************
***    Report to send mail to employee to display temp address   ***
************************************************************************
CALL FUNCTION 'ZFM_CREATE_SHORTCUT'
  EXPORTING
    recipient_user_id = 'DEVHYD'
    transaction       = 'PA20'
  IMPORTING
    content           = content
  TABLES
    shortcut_param    = it_shortcut_param.
PERFORM zfm_create_shortcut
  TABLES
    it_shortcut_param
  USING
    'DEVHYD'
    'PA20'
  CHANGING
    content.

[At the end of the report]

*&---------------------------------------------------------------------*
*&      Form  zfm_create_shortcut
*&---------------------------------------------------------------------*
FORM zfm_create_shortcut
  TABLES
    shortcut_param    STRUCTURE  zst_shortcut_par
  USING
    recipient_user_id TYPE  syuname
    transaction       TYPE  tcode
  CHANGING
     content          TYPE  string.


*** Declaration for shortcut content
  DATA :  parameter TYPE text255,
          v_pernr(12) TYPE c.
  DATA :  v_tcode TYPE tcode.

* Check if transaction code is available
  CLEAR v_tcode.
  SELECT SINGLE tcode FROM tstc
                INTO v_tcode
                WHERE tcode EQ transaction.

  IF v_tcode IS INITIAL.
    MESSAGE 'Enter a valid transaction' TYPE 'E' DISPLAY LIKE 'A'.
    EXIT.
  ENDIF.

* Populate the parameters to be passed to the shortcut
  IF NOT shortcut_param[] IS INITIAL.
    CLEAR parameter.
    LOOP AT shortcut_param.
      CONCATENATE parameter shortcut_param-fieldname '='
    shortcut_param-fieldvalue ';'
                INTO parameter.
    ENDLOOP.
  ENDIF.

*** create the shortcut content for the required transaction
  CALL FUNCTION 'SWN_CREATE_SHORTCUT'
    EXPORTING
      i_transaction           = transaction
      i_parameter             = parameter
      i_sysid                 = sy-sysid
      i_client                = sy-mandt
      i_user                  = recipient_user_id
      i_language              = sy-langu
      i_windowsize            = 'Normal window'
    IMPORTING
      shortcut_string         = content
    EXCEPTIONS
      inconsistent_parameters = 1
      OTHERS                  = 2.
  IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.

ENDFORM.                    "zfm_create_shortcut