Liquid UI - Documentation - 10.05 Determine authorizations using SAP Roles and Profiles

10.05 Determine authorizations using SAP Roles and Profiles


Prerequisites


Purpose

Learn how to determine the user roles and authorizations using a function module (BAPI USER GET DETAIL) call. Here, we use a pushbutton to make a function module call on the SAP Easy Access screen. We’ll walk you through the following steps:

  1. Delete the image container from the SAP Easy Access screen using the del command.
  2. Add a toolbar pushbutton to call the function
  3. Add a function to read user SAP role and profile
  4. Add a function to check if the current user has the roleName match
  5. Add a function to check if the current user has the tableLayoutRegion match
  6. Add a function to capture authorization details into variables
  7. Add a function to test and print the output on the console window

User Interface

//Create this file inside your script folder for adding functionality to the SAP Easy Access screen: SAPLSMTR_NAVIGATION.E0100.sjs
//Now, let's start adding the Liquid UI script to the above file and save it.


Customization

    1. Logon to SAP and delete the image container using the del command on the SAP Easy Access screen, as shown below.
       
      // Deletes an image container on the easy access screen
      del("X[IMAGE_CONTAINER]");
       

       

Screen Script

  1. Add a toolbar pushbutton with the label Get Roles to call the function CheckAuthorizations, when clicked.
     
    // Creates a pushbutton with the label as Get Roles to call the function, when clicked.
    pushbutton( [TOOLBAR], "@48@Get Roles", "?", {"process":CheckAuthorizations});
     
     
  2. Add a function to validate if the variable holds a blank or null value, as defined below.
     
    //Purpose: Function is called to validate if the variable holds blank or null value
    function isBlank(jvar){
    if(typeof jvar == 'string') {
    jvar = jvar.trim();
    }
    return(jvar == 'undefined' || jvar == null || jvar == "" || jvar == void 0);
    }
  3. Now, add a trim function to remove the blank spaces.
     
    //Purpose: Function is called to remove blank spaces
    function trim(str){
    str = str.replace(/^\s+|\s+$/g,"");
    return str;
    }
    Note: You need to call the function module BAPI_USER_GET_DETAIL to read the user details.
     
  4. Add a function to read the user SAP role and profile, as defined below.
     
    //Purpose: Function is called to read user SAP role and profile
    function getAuthorizations(){

    call('BAPI_USER_GET_DETAIL', {"in.USERNAME":"&V[_user]","table.ACTIVITYGROUPS":"Z_ROLES",'table.PARAMETER':'arParam'});
    }
  5. Add a function to check whether the current user has the roleName match, as defined below.
     
    //Function is called to see if current user has the roleName match
    function roleExists(roleName){
    for (i = 0; i < Z_ROLES.length; i++) {
    var z_userrole = Z_ROLES.toString().substring(0,25).trim();
    if(z_userrole == roleName) {
    return true;
    }
    }
    return false;
    }

  6. Add a function to check if the current user has the tableLayoutRegion match, as defined below.
     
    //Function is called to see if the current user has the tableLayoutRegion match
    function tableLayout(tableLayoutRegion) {
    for (i = 0; i < arParam.length; i++) {
    var z_layout = arParam.toString().substring(0,16).trim();
    if(z_layout == tableLayoutRegion) {
    layout_check_value=arParam.toString().substring(17,30);
    layout_check_value=layout_check_value.trim();
    return layout_check_value;
    }
    }
    return 'DEFAULT';
    }


  7. Add a function to test and print the output on the console window, as defined below.
     
    //Main Function to test and print the output on the console
    function CheckAuthorizations(){ // Test for role
    getAuthorizations();
    checkAccess=roleExists("SAP_BC_DWB_ABAPDEVELOPER");
    tableLayoutStyle=tableLayout("WLC");
    // Below println's to print the values of the variables on the console output
    println('\n------checkAccess:'+checkAccess);
    println('\n------tableLayoutStyle:'+tableLayoutStyle);
     

SAP Process

  1. Now, refresh the SAP Easy Access Screen, and click on the Get Roles toolbar pushbutton. Then, the CheckAuthorizations will call the BAPI_USER_GET_DETAIL function module and the output is printed on the Cornelius window, as shown in the following image.
     
     

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