Liquid UI - WS Reference Library

Increment counter using appendfile()


Prerequisites


Runs On

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


Purpose

To use appendfile command for incrementing counter in a file and add content.


User Interface

Open the SAP Easy Access Screen and click on the ‘Execute’ toolbar pushbutton to run the below script:



Liquid UI Script

//SAPLSMTR_NAVIGATION.E0100.sjs

function testFunction() {
strFileName = 'counter.txt';
appendToCounterFile(strFileName);
} pushbutton([TOOLBAR],'Execute','?',{'process':testFunction});

// Function is called to remove blank spaces
String.prototype.trim = function() {
return this.replace(/^\s+|\s+$/g,"");
}

// Function is called to validate if the variable holds blank or null value
function isBlank(jvar){
if(typeof jvar == undefined || jvar == null || jvar == "" || jvar == void 0)
return true;
else
return jvar.toString().trim() == '';
}

// Function which takes as parameter the file and appends 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);
}