Liquid UI - Documentation - 23.13 Unpad Zeroes from String

23.13 Unpad Zeroes from String


Prerequisites

Purpose

You will learn how to remove the padded values from a string value entered in an input field. It is used to remove characters from the beginning or end of the string. To demonstrate this process, we are considering the SAP Easy Access screen as an example, and guide you through the following steps:

  1. Delete the image container on the SAP Easy Access screen.
  2. Add an input field where the user can enter the value and a non-editable input field to display the value with padded zeroes removed from either the left or right.
  3. Add two push buttons that execute the corresponding function and remove zeroes from the user-entered value.
  4. Add a function to remove the padded values from a source.
  5. Add a function to remove the padded values from the left.
  6. Add a function to remove the padded values from the right.

User Interface

//Create the file SAPLSMTR_NAVIGATION.E0100.sjs inside your scripts folder for customizing the SAP Easy Access screen 
//Now, let's add the Liquid UI script to the above file and save it

Customization

  1. Delete the image container on the SAP Easy Access screen using the del command.
     
    //Deletes the image container on the SAP screen
    del("X[IMAGE_CONTAINER]");
    
     
     
  2. Add an input field labeled Enter Value for users to enter a value, and a non-editable field labeled New Value to display the value with padded zeroes removed from either the left or right side.
     
    //Creates an input field where the user can enter the values 
    inputfield([1,0], "Enter Value", [1,16], {"size":10, "name":"z_value"});  
    //Creates an non-editable input field to display the value
    inputfield([2,0], "New Value", [2,16], {"size":10, "name":"z_unpadded_value", "readonly":true});
    
     
     
  3. Add two push buttons, labeled Remove Zeroes Left and Remove Zeroes Right, which execute the corresponding function upon click to remove zeroes from the user-entered value.
     
    //Creates a push button with a label as Remove Zeroes Left and executes the removeZeroesLeft function on click
    pushbutton([4,0], "Remove Zeroes Left", {"process":removeZeroesLeft, "size":[1,18]});  
    //Creates a push button with a label as Remove Zeroes Right and executes the removeZeroesRight function on click
    pushbutton([4,20], "Remove Zeroes Right", {"process":removeZeroesRight, "size":[1,18]});  
    
     
     
  4. Add the unPadZeroes function to remove zeroes padded to the source based on the direction specified.
     
    //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;
    }
    
     
  5. Add the removeZeroesLeft function to remove zeroes padded on the left of the field value.
     
    //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; 
    		}   
    
     
  6. Add the removeZeroesRight function to remove zeroes padded on the right of the field value.
     
    //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;  
    		}    
    
     

SAP Process

  1. Refresh the SAP screen and enter the value into the Enter Value input field. Clicking on the Remove Zerores Left push button removes the zeroes padded to the value entered and displays the value in the New Value input field.
     
     
  2. Similarly, clicking on the Remove Zeroes Right push button removes zeroes padded to the right and displays the value in the New Value input field.
     
     


Next Steps

Return values from new session
Learn how to return values from one session to another session.

10 min.

This article is part of the Invoking functions tutorial.


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