Purpose:
Validate the user entry decimal format by checking with SAP decimal format.
Liquid UI Code:
// SAPLSMTR_NAVIGATION.E0100.sjs
// Read User Decimal Format Defaults
if(!READDEFAULTS){
call('BAPI_USER_GET_DETAIL',{'IN.USERNAME':'&V[_user]','OUT.DEFAULTS':'userDefaults'});
USERDECIMALFORMAT = userDefaults.substring(28,29);
READDEFAULTS = true;
}
// Remove blank spaces
String.prototype.trim=function(){return this.replace(/^\s+|\s+$/g,'');}
// Function to check if the string value is blank
function isBlank(jvar){
if(typeof jvar == 'string') {
jvar = jvar.trim();
}
if(typeof jvar == 'undefined') {
jvar = '';
}
return(jvar == 'undefined' || jvar == undefined || jvar == null || jvar == "" || jvar == void 0);
}
// Function converts the user decimal format in SAP to a general decimal format (xxxxxx.xx)
function decimalNotationFormat(numberFormat,number,nDec){
var str = "";
if(nDec == void 0) // Default for number of decimal places
nDec = 2;
switch(numberFormat)
{
case 'X':
{
str = number.replace(/\,/g, ''); // Replace , with nothing
}
break;
case 'Y':
{
str = number.replace(/\s+/g,''); // Remove Blank Spaces
str = str.replace(/\,/g, '.'); // Replace , with .
}
break;
default:
{
str = number.replace(/\./g, ''); // Replace . with nothing
str = str.replace(/\,/g, '.'); // Replace , with .
}
break;
}
return parseFloat(str.trim()).toFixed(3);
}
// Function converts the general decimal format to user decimal format in SAP
function userSAPDecimalFormat(nStr,nSeparator){
var str = nStr.split('.');
var offset = str[0].length % 3;
if(nSeparator == ' ')
str[0] = str[0].substring(0, offset) + str[0].substring(offset).replace(/([0-9]{3})/g, ".$1");
if(nSeparator == 'X')
str[0] = str[0].substring(0, offset) + str[0].substring(offset).replace(/([0-9]{3})/g, ",$1");
if(nSeparator == 'Y')
str[0] = str[0].substring(0, offset) + str[0].substring(offset).replace(/([0-9]{3})/g, " $1");
if(offset == 0)
str[0] = str[0].substring(1,str[0].length);
if(nSeparator == 'Y' || nSeparator == ' ') {
return str.join(',');
} else {
return str.join('.');
}
}
// Function to check and convert user entry for decimal format
function changeUserFormat(){
if(isBlank(z_val)){
return('E: Please enter value');
}
z_val = decimalNotationFormat(USERDECIMALFORMAT,z_val.toString(),3);
z_tmp = userSAPDecimalFormat(z_val,USERDECIMALFORMAT);
set('V[z_val_userformat]','&V[z_tmp]');
}
// User Interface
clearscreen();
inputfield([1,1], "Enter Decimal Value", [1,22], {"name":"z_val", "size":15});
inputfield([2,1], "User Format", [2,22], {"name":"z_val_userformat", "size":15, "readonly":true});
pushbutton([1,40], "@01@User Decimal Format", {"process":changeUserFormat});
See attachments for code samples!