Liquid UI - Documentation - 23.03 Calling a function module

23.03 Calling a function module


Prerequisites


Purpose

You will learn how to call a function module (BAPI_USER_GET_DETAIL ) to display user details on the SAP Easy Access screen. We will walk you through the following steps:

  1. Delete unnecessary elements
  2. Add groupbox
  3. Add a function to trim the string
  4. Call a function to display the user details
  5. Add a for loop to create texts.
  6. Add a function to retrieve user parameters from the function module

//Create this file inside your script folder for customizing SAP Easy Access screen: SAPLSMTR_NAVIGATION.E0100.sjs
//Now let's start adding the content to the above file

  1. Delete the image container on the SAP Easy Access screen.
    del("X[IMAGE_CONTAINER]");
    
     

     
  2. Add a groupbox with a title as Defaults for the user where user name and class is displayed dynamically.
    // Create a group box to hold the data with a title involving the user and the user's class
    box([0,0],[i+1,38],"Defaults for "+_user.trim()+" ("+z_class+")");
    
     

     
  3. Add a function to replace all the special characters in the string with blank spaces.
    // This allows a string to be trimmed of all blank spaces
    String.prototype.trim = function() {
        return this.replace(/^\s+|\s+$/g,"");
    }
    

     
  4. Calls the getDetailFromFM function and executes it.
    // Run the function
    getDetailFromFM();
    

     
  5. Add a for loop to create texts based on the number of parameters available for the user.
     
    // Run a for loop to dynamically create the text
    for(i=0; i<param_id.length; i++)
    {
        text([1+i,0], param_id[i]+": "+param_val[i]);
    }
    

     
  6. Add a function to call a function module BAPI_USER_GET_DETAIL to retrieve required parameter values.
     
    // This function makes the call to the Function Module and pulls the data to display
    function getDetailFromFM(){
        println("In this function.")
        call("BAPI_USER_GET_DETAIL", {"in.USERNAME":"&V[_user]", "out.LOGONDATA":"z_logondata", "table.PARAMETER":"z_parameters"});
        
        // extract the user's class type
        z_class = z_logondata.substring(17,29).trim();
    
            // create two arrays
        param_id = [];
        param_val = [];
        
        // run a for loop to go through the table and store each value we want
        for(i = 0; i<z_parameters.length; i++){
            tmp = z_parameters[i].substring(0,20).trim();
            param_id.push(tmp);
            tmp = z_parameters[i].substring(20,38).trim();
            param_val.push(tmp);
        }
    }
    

     
  7. Open SAP Easy Access screen. You will see the user details displayed as shown below.
     

     


Next Steps

External Database Connection from SAPGUI
Learn how to connect to an external server to your SAP GUI

10 min.

This article is part of the Invoking functions tutorial.


Can't find the answers you're looking for?