Author Topic: Determine authorizations using SAP Roles and Profiles  (Read 5126 times)

Benjamin Dasari

  • GuiXT Forum
  • Newbie
  • *
  • Posts: 95
    • View Profile
Determine authorizations using SAP Roles and Profiles
« on: February 08, 2016, 05:32:18 PM »
Purpose:
Utilizing the below scripts where we call the Function Module 'BAPI_USER_GET_DETAIL', we can determine user authorizations based on their roles.

Liquid UI Code:
/*
Function         : getAuthorizations
Parameters     :
Purpose          : Calls function 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'});
}


/*
Function         : roleExists
Parameters     : roleName
Purpose          : Checks 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;
}


/*
Function         : tableLayout
Parameters     : tableLayoutRegion
Purpose          : Checks to see if 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.substring(17,30);
         layout_check_value=layout_check_value.trim();
         return layout_check_value;
      }
   }
   return 'DEFAULT';
}

/*
Function         : CheckAuthorizations
Parameters     :
Purpose          : Capture authorization details into variables which can be used as necessary
*/
function CheckAuthorizations(){    // Test for role
       getAuthorizations();
       var checkAccess=roleExists("Z:SDSAREPINSIDE_ALLNONCRU");
       var tableLayoutStyle=tableLayout("ZGUIXT_VA01_VIEW");
// Below println's to print the values of the variables on the console output
       println('\n------checkAccess:'+checkAccess);         
       println('\n------tableLayoutStyle:'+tableLayoutStyle);   
}


//*******************************************************************************************************************
//Purpose: 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);   

}


pushbutton([TOOLBAR], "@F8@Get Roles", {"process":CheckAuthorizations});


See attachments for code samples!
« Last Edit: March 04, 2016, 10:29:17 AM by Benjamin Dasari »