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