Execute Standard SAP Transaction from BSP using dynamically created shortcut

The ABAP/HTML code below shows you how to execute a standard SAP transaction from your BSP application, the example is built around calling tcode PA20 but this is just for demonstration purposes and you can use whichever transaction you want.

If you have not created a BSP before you will need to look the following example of creating a simple BSP application just to get an understanding of the basic components. You can then use the information below to build the BSP.

Properties Tab


Layout Tab

<%@page language="abap"%>
<%@extension name="htmlb" prefix="htmlb"%>
<form>
<% if display_url is not initial. %>
     <a href="<%=display_url%>"> PA20</a>
<% endif.%>
</form>

Page Attributes Tab
display_url TYPE STRING


Event Handler Tab - OnInitialization

types: begin of t_shortcut_par,
    fieldname(60) type c,
    fieldvalue(255) type c,
  end of t_shortcut_par.
data: ld_userid type  syuname,
      ld_transaction type  tcode value 'PA20',
      ld_shortcut type  string,
      it_shortcut_param type standard table of t_shortcut_par,
      wa_shortcut_param like line of it_shortcut_param,
      sapworkdir     type     sdok_chtrd.
data ld_response type ref to if_http_response.
data: ld_guid        type     guid_32 ,
      ld_pagename   type     string,
      wa_parameters  type     tihttpnvp.
**** Declaration for shortcut content
DATA: ld_tcodefields TYPE text255.
* code is based on that in OSS note: 103019
  ld_userid = sy-uname.
* Check if transaction code is available
  SELECT SINGLE tcode FROM tstc
                INTO ld_transaction
                WHERE tcode EQ ld_transaction.
  REFRESH it_shortcut_param.
  TRANSLATE ld_transaction to UPPER CASE.
  CASE ld_transaction.
* This is an example of how to pre-populate fields on the transaction
    when 'PA20'.
      wa_shortcut_param-fieldname = 'RP50G-PERNR'.
      wa_shortcut_param-fieldvalue = '910650'. "Employee number
      APPEND wa_shortcut_param to it_shortcut_param.
      wa_shortcut_param-fieldname = 'RP50G-CHOIC'. "Infotype field
      wa_shortcut_param-fieldvalue = '0002'.  "Org Infotype
      APPEND wa_shortcut_param to it_shortcut_param.
      wa_shortcut_param-fieldname = 'RP50G-TIMR1'. "Period field
      wa_shortcut_param-fieldvalue = 'X'.     "Today selected"
      APPEND wa_shortcut_param to it_shortcut_param.
  endcase.
* Populate the parameters to be passed to the tcode shortcut
  IF NOT it_shortcut_param[] IS INITIAL.
    CLEAR ld_tcodefields.
    LOOP AT it_shortcut_param into wa_shortcut_param.
      CONCATENATE ld_tcodefields wa_shortcut_param-fieldname '='
      wa_shortcut_param-fieldvalue ';' INTO ld_tcodefields.
    ENDLOOP.
  ENDIF.
*Create the shortcut details for the required transaction
* Adding the * to the begining of the tcode is supposed to skip first screen
* but not sure this works
  CONCATENATE '*' ld_transaction into ld_transaction.
  CALL FUNCTION 'SWN_CREATE_SHORTCUT'
    EXPORTING
      i_transaction           = ld_transaction
*      I_SYSTEM_COMMAND        = 'DIS'
      i_parameter             = ld_tcodefields
      i_sysid                 = sy-sysid
      i_client                = sy-mandt
      i_user                  = ld_userid
      i_language              = sy-langu
      i_windowsize            = 'Normal window'
    IMPORTING
      shortcut_string         = ld_shortcut
    EXCEPTIONS
      inconsistent_parameters = 1
      OTHERS                  = 2.
  CREATE OBJECT ld_response TYPE cl_http_response
    EXPORTING
      add_c_msg = 1.
  ld_response->set_cdata( ld_shortcut ).
  ld_response->set_header_field( name  = if_http_header_fields=>content_type
                                 value = 'application/octet-stream' ).
  ld_response->set_status( code = 200 reason = 'OK' ).
  ld_response->server_cache_expire_rel( expires_rel = 180 ).
  CALL FUNCTION 'GUID_CREATE'
    IMPORTING
      ev_guid_32 = ld_guid.
  CONCATENATE ld_guid '.sap' INTO ld_pagename.
* Get Absolute URL (Protocol, Host, Port, ...) of BSP Application
  CALL METHOD cl_http_ext_webapp=>create_url_for_bsp_application
    EXPORTING
      bsp_application      = runtime->application_url
      bsp_start_page       = ld_pagename
      bsp_start_parameters = wa_parameters
    IMPORTING
      abs_url              = display_url.
* Activates the url so that it is valid and ready to use
  cl_http_server=>server_cache_upload( url      = display_url
                                       response = ld_response ).

See here for ... BSP code and examples


Related Articles

Javascript to capture when a user closes or leaves sap bsp html page
Using AJAX functionality within our SAP BSP
Close BSP Session (type 'Pluggin HTTP') including when in SAP portal
SAP BSP to auto select region when user selects country using HTML and Javascript
HTML and Javascript code to force enter key to perform tab
JavaScrip command getElementById useful examples
MVC BSP input field - Demonstrate how to retrieve a value entered into text input field
Allowing multiple instances of a BSP application to be run by a user
Uplaod file within SAP BSP application using HTML and ABAP coding
UUseful SAP BSP application code - ABAP, HTML, HTMLB, Javascript, CSS
Creating a BSP Application class to help store and pass data betwenn your BSP pages
Training Course and Workshop Booking Form
BSP checkboxes using HTML and the OnInputProcessing BSP Event
BSP checkboxes using HTML and the OnInputProcessing BSP Event
Check HTML checkbox is checked using Javascript within your SAP BSP
BSP Dropdown List - create a BSP dropdown list which allows user selection!!
ABAP BSP to allow user to select from SAP HR org structure - CSS file
Java script to display tree structure on your SAP BSP web page
Create a Simple BSP - Simple BSP to display text and call section BSP page using HTML
SAP BSP Training course booking - Creating an example training course booking form using BSP
Creating an SAP BSP which executes an ABAP report to retrieve data for use within BSP application
org selection BSP - detials.htm page
Display page of the SAP BSP example application to store favourite tcodes as a cookie
Execute.htm page of the SAP BSP example application to store favourite tcodes as a cookie
Favourites cookie bsp - initial page to display input fields and retrieve user input
BSP using cookies - Demonstrate use of cookies within a BSP to store user favourits
ABAP Export data to memory - Demonstrate use of ABAP program to retrieve data for use in BSP
MVC BSP HTMLB input field - Demonstrate how to retrieve a value entered into text input field
BSP development using standard HTML code instead of Business HTML (HTMLB)
Business HTML (HTMLB) - List of business HTML tags you can use within your BSP
Adding JavaScript to BSP (HTML) pages - Shows how to add javascript to your BSP pages
Example JavaScript code which can be added to your BSP application
BSP MIME Objects for Org. search application
Call onInputProcessing event from SAP BSP page via href or button
Organisation selection BSP - close internet window using javascript
Organisation selection BSP - get server side cookie ( get_server_cookie )
orgaisation selection BSP - set and get server side cookie ( set_server_cookie )
Display orgaisation selection BSP
BSP which allows HR Organisation Structure search and selection using javascript
Organisation update program - get server side cookie ( get_server_cookie )
BSP to capture user entry into HTML input fields
Capture BSP radiobutton selection using HTML and the OnInputProcessing BSP Event
BSP checkboxes using HTML and the OnInputProcessing BSP Event
Stateful and stateless BSP applications
Get user entry into HTML input fields with SAP BSP
Javascript to capture when a user closes or leaves sap bsp html page
Creating a BSP using the Model View Controller ( MVC ) technique
Using SAP Model View Controller (MVC) development techniques to develop BSPs
Adding a JavaScript date selection field to a BSP
Creating a BSP using the Model View Controller ( MVC ) technique
Creating a BSP using the Model View Controller(MVC) technique
Creating a BSP using the Model View Controller ( MVC ) technique
Retrieve value from input text field within a model view controller ( MVC) BSP
Web Application Development - Example code and information on development using BSP
SAP BSP / Business Server Pages combine ABAP and other web technologies such as HTML, CSS
BSP development screen - developing application using business server pages
Standard Program created in SE38 or SE80