Skip to Content

In my scenario I will call a BSP application from a web template. The web template is a generic template that supported a couple of queries, like the 0ANALYSIS_PATTERN template.

 

 

The BSP application is an IT support application. Users can initialize a ticket by pressing a button in the template.

 

For better support the action behind the button will first create a bookmark in the backend and then call the BSP application. The web template will hand over the ID of the newly created bookmark by parameter to the BSP application.

 

 

The web template will be embedded in an iView and the template query will be dynamically set by URL BI_COMMAND parameter.

 

First action in the button command is to generate a bookmark; this will be done by using standard BI_COMMANDs. The newly generated ID will hand over to the BSP application. Both actions must be done in one request!

 

From this two problems will arise:

 

  • 1. Where do I get the bookmark ID from
  • 2. How can I generate an BSP application call in the same request as the SAVE_BOOKMAR BI_COMMAND

 

One possible solution:

 

Point 1.

I insert a hidden message block item into the web template (in the current template all messages should be hidden). It is important that not the message block property “visibility” is set to hidden, this will lead to the fact that the message block item will not been generated in the template output. To make sure that the item will be generated as a hidden item we must put it inside a container. That can be a CONTAINER item or a native HTML DIV- tag and the container gets the hidden attribute. I’ve used a DIV tag and set the display style to none.

 

The ID for the newly generated bookmark can be read by a JavaScript function. I’ve talked with some colleagues from the development and got the information that the ID will be available as a JavaScript variable in one of the further WAD versions.

 

var MESSAGES_LIST_ITEM       = ‘MESSAGES_LIST_ITEM_1’;

var MESSAGES_LIST_ITEM_BLOCK = MESSAGES_LIST_ITEM + ‘_AcMess_mrx’;

var MESSAGES_LIST_ITEM_FIELD = MESSAGES_LIST_ITEM + ‘_AcMess_BiMessageItem-txt’;

 

function getBookmarkID(){

  var bookmarkID;

  var msgSpanTag;

  var msgText;

  

  // Get the div block which contains all message items

  if((msgBlock = document.getElementById(MESSAGES_LIST_ITEM_BLOCK)) != null){ // DIV-Tag

 

    // Get all span tag child nodes

    // !! Is debug mode on and debug level set high there

    // !! are more than 1000 childs are possible   

    var spanItems = msgBlock.getElementsByTagName(“SPAN”);

 

    for (i=0; i< spanItems.length; i++){

      if((spanItems[i].id = MESSAGES_LIST_ITEM_FIELD) &&

            (spanItems[i].firstChild.nodeName!=”IMG”) &&

            (spanItems[i].innerHTML != null)){

         

           if(spanItems[i].innerHTML.indexOf(“BOOKMARK=”) != -1){

          // alert(‘[‘ + i + ‘]’ +spanItems[i].id + ‘ : ‘ + spanItems[i].className + ‘ : ‘ + spanItems[i].innerHTML);

               

          msgText = spanItems[i].innerHTML.substring(spanItems[i].innerHTML.indexOf(“BOOKMARK=”) + 9, spanItems[i].innerHTML.length);

          // alert(msgText);

          bookmarkID = msgText.substring(0, msgText.indexOf(‘”‘));

          // alert(“BookmarkID: ” + msgText);

                 

          return bookmarkID;

           }

         }

       }

  }

}

 

Point 2.

The SAVE_BOOKMARK command generates a server round trip. After the response is complete we must read the bookmark ID by using the above described JavaScript function. But here is the problem. We cannot add a second command behind the SAVE_BOOKMARK command to call the BSP application in the same request.

 

We need a solution that we can automatically call the BSP application when the response from the ticket button is complete.

 

We insert a customer exit item into the template.

 

The customer exit item generates a JavaScript block, the script block will be put into the template output. This is the only way The script block is only one function call that adds the ticket call function to the wondow.onLoad function (complete ABAP class source code see below).

 

    CONCATENATE ”
          INTO l_string.

 

The HTML event added function callFeedbackDialog will be called after the response is completely processed. Now the callFeedbackDialog method can get the generated bookmark ID (see described function in point 1) and concatenate the ID add the BSP ticket application URL.

 

JavaScript function addLoadEvent:

 

function addLoadEvent(func) {

  var oldonload = window.onload;

  if (typeof window.onload != ‘function’) {

    window.onload = func;

  }

  else {

    window.onload = function() {

      oldonload();

      func();

    }

  }

}

 

Now we are sure that after every roundtrip the callFeedbackDialoag function is called.

 

Background information: I it not possible to insert a JavaScript function at the WebTemplate start function.

 

Now we need a solution, how we identify the last action that triggered the roundtrip. To identify our call ticket system function I’ve inserted a input field item into the hidden DIV block. Before we call the SAVE_BOOKMARK BI_COMMAND we set the value of this field to ‘IT_TICKET’.

 

In the top area of the callFeedBackDialog I check the value of this input field isn’t it set to IT_TICKET I leave the function and do nothing.

The value of the hidden input field is also saved by the bookmark. This bring us to the effect, that when the it guys open the bookmark the WebTemplate will create a new ticket  ;-]

To stop this circle I check the response for a new created bookmark in this roundtrip.

 

The first action after this checks Is to reset the input filed (function resetCommandField is created by the javascript wizard)

 

function callFeedbackDialog(){

  // alert(“callFeedbackDialog”);

  var bookmarkID = getBookmarkID();

 

  if((bookmarkID == null) ||

     (document.getElementById( ‘IF_COMMAND_input_inp’ ).title != ‘IT_TICKET’ )){

         return;

       }     

 

resetCommandField();

 

  var urlFeedback = window.location.protocol + ‘//’ +

                    window.location.hostname + ‘:’ + BSP_APPL_PORT +

                    ‘/’ + BSP_APPL_Z_BC_TICKET + ‘/’ + BSP_PAGE_IT_TICKET +

                    ‘?EMAILACCOUNT=’ + SUPPORT_MAIL_RECIPIENT +

                    ‘&BOOKMARKID=’ + bookmarkID;

          

  // alert(urlFeedback);

 

  window.open(urlFeedback, “_blank”, “width=800,height=500,left=30,top=50”); 

}

 

 

Here the customer exit ABAP class source cod:

 

 

CLASS-POOL.

*———————————————————————-*

*       CLASS ZCL_BICS_CONS_WEBITEM_ABAP  DEFINITIO

*———————————————————————-*

*

*———————————————————————-*

CLASS zcl_bics_cons_webitem_abap DEFINITION

  PUBLIC

  CREATE PUBLIC.

 

  PUBLIC SECTION.

 

    INTERFACES if_bics_cons_webitem_cust_exit.

 

  PROTECTED SECTION.

  PRIVATE SECTION.

ENDCLASS.                    “ZCL_BICS_CONS_WEBITEM_ABAP  DEFINITIO

*———————————————————————*

*                       REDIFINITIONS

*———————————————————————*

*

*                                                                     *

*———————————————————————*

*                       IMPLEMENTATION

*———————————————————————*

*

*                                                                     *

*——————————————————————————

* Methode:      IF_BICS_CONS_WEBITEM_CUST_EXIT~EXECUTE

*

* Description:  In case the global command is CALL_IT_TICKET there will

*               inserted a javascript code segment which append the it ticket

*               call method at the window on load event method.

*

* Parameters:

*   Importing:  I_XML

*               I_REQUESTED_RESULT_FORMAT

*

*   Returning:  none

*   Exporting:  E_XML

*

*   Changing:   none

*   Exceptions: none

*

* Created: Torsten Kessler (D051309) – 27.07.2008

* Company: SAP Deutschland AG & Co. KG

*

*——————————————————————————

METHOD if_bics_cons_webitem_cust_exit~execute.

 

  DATA:

    l_string TYPE  string.

 

  CLEAR e_xml.

 

    CONCATENATE ”

          INTO l_string.

 

  TRY.

*     The customer exit returns HTML data to be displayed.

*     The result HTML needs to be stored in E_XML using UTF-8 encoding.

*     You can convert simple ABAP-strings to UTF-8 by calling the

*     following the method:

*     ==================================================================

      CALL METHOD cl_bics_cons_webitem_util=>string_2_utf8_xstring

        EXPORTING

          i_string       = l_string

        RECEIVING

          r_utf8_xstring = e_xml.

 

    CATCH cx_bics_cons_webitem_error.

*     exception handling

  ENDTRY.

 

ENDMETHOD.                    “if_bics_cons_webitem_cust_exit~execute

*——————————————————————————

* Methode:      IF_BICS_CONS_WEBITEM_CUST_EXIT~FREE

*

* Description:  Nothing to do here

*

* Parameters:

*   Importing:  none

*   Returning:  none

*   Exporting:  none

*   Changing:   none

*   Exceptions: none

*

* Created: Torsten Kessler (D051309) – 27.07.2008

* Company: SAP Deutschland AG & Co. KG

*

*——————————————————————————

METHOD if_bics_cons_webitem_cust_exit~free.

  ” nothing to do here

ENDMETHOD.                    “IF_BICS_CONS_WEBITEM_CUST_EXIT~FREE

*——————————————————————————

* Methode:      IF_BICS_CONS_WEBITEM_CUST_EXIT~INITIALIZE

*

* Description:  Nothing to do here

*

* Parameters:

*   Importing:  I_T_PROPERTIES

*

*   Returning:  none

*   Exporting:  none

*   Changing:   none

*   Exceptions: none

*

* Created: Torsten Kessler (D051309) – 27.07.2008

* Company: SAP Deutschland AG & Co. KG

*

*——————————————————————————

METHOD if_bics_cons_webitem_cust_exit~INITIALize.

  ” nothing to do here

NDMETHOD.                    “if_bics_cons_webitem_cust_exit~INITIALize

To report this post you need to login first.

7 Comments

You must be Logged on to comment or reply to a post.

  1. Pranay Nayyar
    Hi,
    Very useful blog. I too have a requirement in which I need to add the language parmater at the end of the bookmark URL.
    Can you please help me as in how can i do it.
    Regards,
    Pranay
    (0) 
    1. Torsten Kessler Post author
      Hi Pranay,
      you can adjust the language by using the URL parameter &language=DE for german or &language=FR to switch the language to france.

      Torsten

      (0) 
  2. Omri Cohen

    Hi Torsten,

    I know this is a very old blog.

    The content is messed up (I guess because of the change from SDN to SCN…).

    Can you post the blog content again?

    Regards,

    Omri

    (0) 
        1. Torsten Kessler Post author

          Hi Omri,

          here the whole class export:

          CLASS-POOL.
          *———————————————————————-*
          *       CLASS ZCL_BICS_CONS_WEBITEM_ABAP  DEFINITIO
          *———————————————————————-*
          *
          *———————————————————————-*
          CLASS zcl_bics_cons_webitem_abap DEFINITION
            PUBLIC
            CREATE PUBLIC.

            PUBLIC SECTION.

              INTERFACES if_bics_cons_webitem_cust_exit.

              DATA p_command TYPE string.
            PROTECTED SECTION.
            PRIVATE SECTION.
          ENDCLASS.                    “ZCL_BICS_CONS_WEBITEM_ABAP  DEFINITIO
          *———————————————————————*
          *                       REDIFINITIONS
          *———————————————————————*
          *
          *                                                                     *
          *———————————————————————*
          *                       IMPLEMENTATION
          *———————————————————————*
          *
          *                                                                     *
          *——————————————————————————
          * Methode:      IF_BICS_CONS_WEBITEM_CUST_EXIT~EXECUTE
          *
          * Description:  In case the global command is CALL_IT_TICKET there will
          *               inserted a javascript code segment which append the it ticket
          *               call method at the window on load event method.
          *
          * Parameters:
          *   Importing:  I_XML
          *               I_REQUESTED_RESULT_FORMAT
          *
          *   Returning:  none
          *   Exporting:  E_XML
          *
          *   Changing:   none
          *   Exceptions: none
          *
          * Created: Torsten Kessler (D051309) – 27.06.2008
          * Company: SAP Deutschland AG & Co. KG
          *
          * Modified: Torsten Kessler (D051309) – 21.07.2008
          *           Set global sap_language variable
          *——————————————————————————
          METHOD if_bics_cons_webitem_cust_exit~execute.

            DATA:
              l_string TYPE  string,
                  l_iso    TYPE laiso.

            CLEAR e_xml.

            CALL FUNCTION ‘LANGUAGE_CODE_SAP_TO_ISO’
              EXPORTING
                sap_code = sy-langu
              IMPORTING
                iso_code = l_iso
              EXCEPTIONS
                OTHERS   = 1.

              CONCATENATE ‘<script>’
                          ‘  sap_language=”’ l_iso ”’;’
                          ‘  addLoadEvent( callFeedbackDialog ); ‘
                          ‘ </script>’
                    INTO l_string.

            TRY.
          *     The customer exit returns HTML data to be displayed.
          *     The result HTML needs to be stored in E_XML using UTF-8 encoding.
          *     You can convert simple ABAP-strings to UTF-8 by calling the
          *     following the method:
          *     ==================================================================
                CALL METHOD cl_bics_cons_webitem_util=>string_2_utf8_xstring
                  EXPORTING
                    i_string       = l_string
                  RECEIVING
                    r_utf8_xstring = e_xml.

              CATCH cx_bics_cons_webitem_error.
          *     exception handling
            ENDTRY.

          ENDMETHOD.

          *——————————————————————————
          * Methode:      IF_BICS_CONS_WEBITEM_CUST_EXIT~FREE
          *
          * Description:  Nothing to do here
          *
          * Parameters:
          *   Importing:  none
          *   Returning:  none
          *   Exporting:  none
          *   Changing:   none
          *   Exceptions: none
          *
          * Created: Torsten Kessler (D051309) – 27.07.2008
          * Company: SAP Deutschland AG & Co. KG
          *
          *——————————————————————————
          METHOD if_bics_cons_webitem_cust_exit~free.
            ” nothing to do here
          ENDMETHOD.                    “IF_BICS_CONS_WEBITEM_CUST_EXIT~FREE
          *——————————————————————————
          * Methode:      IF_BICS_CONS_WEBITEM_CUST_EXIT~INITIALIZE
          *
          * Description:  Set the global attribut when the given parameter value is a
          *               command string.
          *
          * Parameters:
          *   Importing:  I_T_PROPERTIES
          *
          *   Returning:  none
          *   Exporting:  none
          *   Changing:   none
          *   Exceptions: none
          *
          * Created: Torsten Kessler (D051309) – 27.07.2008
          * Company: SAP Deutschland AG & Co. KG
          *
          *——————————————————————————
          METHOD if_bics_cons_webitem_cust_exit~INITIALize.

            DATA: l_s_name_value TYPE rsbolap_s_name_value.

            CLEAR p_command.
            LOOP AT i_t_properties INTO l_s_name_value.
              IF l_s_name_value-name EQ ‘COMMAND’.
                MOVE l_s_name_value-value TO p_command.
              ENDIF.
            ENDLOOP.
          ENDMETHOD.                    “if_bics_cons_webitem_cust_exit~INITIALize

          That’s everything I could find.

          Hope this helps.

          BR

          Torsten

          (0) 

Leave a Reply