Menu

How to Attach Executable SAP Transaction Links to E-Mails

DevWorkbench    Tuesday August 12th, 2014   

Sending executable transaction links in e-mails

So how do we make that work for e-mails? The only possibility we have is to attach an SAP shortcut to the e-mail. I already discussed how to send e-mails with attachments from SAP ERP, so I’m building on that knowledge here.

Assume we’ve already filled the body content of our e-mail table. What we need to do now is create the SAP shortcut (never heard of these? Check out this SCN wiki entry). Please don’t try to do that manually! There’s a much more convenient way, namely the function module  SWN_CREATE_SHORTCUT. It is used like this:

CALL FUNCTION 'SWN_CREATE_SHORTCUT'
  EXPORTING
    i_transaction           'IE03'
  IMPORTING
    shortcut_table          lt_shortcut
  EXCEPTIONS
    inconsistent_parameters 1
    OTHERS                  2.

You simply provide the name of the transaction you want to execute and the function module will output the constructed SAP shortcut in an internal table. You can provide many more parameters to specify user name, system to be used, et cetera.

After we’ve constructed the shortcut, all we need to do is move it to the e-mail content table. That’s easily done since both tables have the same structure:

 APPEND LINES OF lt_shortcut TO lt_objcont.

All that remains to do is to fill the packing list (check out the sample program on page 4 for the full code) and send off the e-mail by using  SO_NEW_DOCUMENT_ATT_SEND_API1. The document type that you have to provide in the packing list is “SAP”.

Adding parameters to SAP Shortcuts

So far, we’ve only created a shortcut that opens a transaction. That’s nice, but not very useful if you want to point your users towards a specific set of data. Adding parameters to an SAP shortcut is not that easy, but can be done with a little “hacking”.

Adding the parameter is relatively easy. Find out the batch input name of the screen fields you want to fill. In my example, I’ve used IE03. Press F1 to get the field help, then click “Technical Information” in the F1 help popup to get this screen.

Technical Information for SAP Field

Press F1, then choose “Technical Information” to get this popup.

You can find the needed field name at the bottom under “Field Description for Batch Input”. You can pass the parameter name and value as a text string in the i_parameter parameter of the function module  SWN_CREATE_SHORTCUT. There’s one additional trick: If you put an asterisk before the transaction name, the first screen will be skipped – by the way, this also works when you call a transaction directly in the SAPGui (you need to put an additional slash before the asterisk then). The final call looks like this:

CALL FUNCTION 'SWN_CREATE_SHORTCUT'
  EXPORTING
    i_transaction           '*IE03'
    i_parameter             'RM63E-EQUNR=ABCDE123'
  IMPORTING
    shortcut_table          lt_shortcut
  EXCEPTIONS
    inconsistent_parameters 1
    OTHERS                  2.

This will open the transaction IE03 with the “Equipment” field filled with the value “ABCDE123” and skip the first screen. Proceed as discussed earlier to attach this shortcut to an e-mail and enjoy! The sample programs can be found on the next two pages.