Liquid UI - Documentation - 19.14 Increment counter using appendfile()

19.14 Increment counter using appendfile()


Prerequisites

Purpose

This article guides you through creating a file in SAP and incrementing the counter using the appendfile command. To demonstrate this with a scenario, we’ll guide you through the following steps.

  1. Delete the image container on the SAP Easy Access screen
  2. Add a push button to add content to a file
  3. Add a function to append values to a file
  4. Check the file for new content


User Interface

//Create this file inside your script folder for customizing the SAP Easy Access Screen, SAPLSMTR_NAVIGATION.E0100.sjs

//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 del().
     
    //Deletes the Image container on the screen
    del("X[IMAGE_CONTAINER]");
     
     
  2. Add a toolbar push button Execute to initiate the testfunction process:
     
    // Creates a toolbar push button labeled Execute  
    pushbutton([TOOLBAR],'Execute','?',{'process':testFunction});
    
     
     
  3. Add a function to declare a variable and invoke another function, passing the strFileName parameter.
     
    // Function to invoke another function
    function testFunction() {
        strFileName = 'counter.txt';
        appendToCounterFile(strFileName);
    }
    
     
  4. Add a function to remove blank spaces.
     
    // Function to remove blank spaces
    String.prototype.trim = function() {
        return this.replace(/^\s+|\s+$/g,"");
    }
    
     
  5. Add a function to validate blank spaces in the string.
     
    // Function to validate whether the variable holds a blank space or null value
    function isBlank(jvar){
        if(typeof jvar == undefined || jvar == null || jvar == "" || jvar == void 0)
            return true;
        else
            return jvar.toString().trim() == '';
    }
    
  6. Add a function to create a text file named counter.txt, increment the counter value, and append it to the file.
     
    
    // Function that takes a file as a parameter and appends data to it
    function appendToCounterFile(fileName) {
    	var lastCounter = 0;
        var z_counter = '';
    	var strBlank = '';
        openfile(fileName,{"delimiter":","});
        NEXT_LINE_READ:;
        readfile(fileName,{"z_counter":true});
        if(isBlank(z_counter)) {
    		 goto END_OF_FILE;   
    		 }
    		 lastCounter = parseInt(z_counter);
    		 var z_counter = '';
    		 goto NEXT_LINE_READ;    
    		 END_OF_FILE:;   
    		 closefile(fileName);
    		 openfile(fileName,{"append":true, "delimiter":","});
    		 lastCounter++;    
    		 appendfile(fileName,{"lastCounter":true});
    		 closefile(fileName);
    		 }
    		 
     

SAP Process

  1. Refresh the SAP Easy Access screen and click the Execute push button to increment the last value and append it to the file.
     
     

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