Liquid UI - WS Reference Library

Unpad Zeroes from String


Prerequisites


Runs On

  SAP GUI Android iOS WM Web
Direct Connect          
Liquid UI Server Connect        

Purpose

To remove zeroes before or after a string based on parameters passed.

User Interface

Log into SAP and on the SAP Easy Access Screen. You will find the below screen:


 

Enter the value and click on either the ‘Remove Zeroes Left’ or ‘Remove Zeroes Right’ pushbuttons.


 

Liquid UI Script

//SAPLSMTR_NAVIGATION.E0100.sjs

// Function to remove zeroes padded to the source based on the direction specified
function unPadZeroes(source,direction) {
    var output = "";
    var sourceLength = 0;
    var sourceOriginalLength = 0;
    source = source.toString();

    if(source) {
       sourceOriginalLength = source.length;    
       sourceLength = source.length;
    }
    
    switch (direction){
        case "LEFT":
            for (var loop = 0; loop < sourceOriginalLength; loop++) {            
                if(source[0]=='0'){
                    source = source.substring(1,sourceLength);
                    sourceLength = source.length;
                } else {
                    break;    
                }
            }
            break;
        case "RIGHT":
            for (var loop = 0; loop < sourceOriginalLength; loop++) {            
                if(source[sourceLength-1]=='0'){
                    source = source.substring(0,sourceLength-1);
                    sourceLength = source.length;
                } else {
                    break;    
                }
            }
            break;
    }
    return source;
}

// Function to remove zeroes to the left of the source
function removeZeroesLeft(){
    z_temp = unPadZeroes(z_value,"LEFT");
    set('V[z_unpadded_value]','&V[z_temp]');
    return;
}

// Function to remove zeroes to the right of the source
function removeZeroesRight(){
    z_temp = unPadZeroes(z_value,"RIGHT");
    set('V[z_unpadded_value]','&V[z_temp]');
    return;
}

// User Interface
clearscreen();
inputfield([1,0], "Enter Value", [1,16], {"size":10, "name":"z_value"});
inputfield([2,0], "New Value", [2,16], {"size":10, "name":"z_unpadded_value", "readonly":true});
pushbutton([4,0], "Remove Zeroes Left", {"process":removeZeroesLeft, "size":[1,18]});
pushbutton([4,20], "Remove Zeroes Right", {"process":removeZeroesRight, "size":[1,18]});