Prerequisites
- Products: Liquid UI WS, Liquid UI Server or Local DLL, Client Software
- Commands: pushbutton(), set(), del(), onscreen(), enter(), box(), textbox(), message(), setcursor()
Purpose
You will learn how to copy text content to SAP text editor screen to handle particular SAP long text control which can't use "copytext" command. We will walk you through the following steps:
- Add a function to trim blank spaces in a string
- Add a function to check string value is blank
- Add a function to split the string value
- Add a function to check the long text is blank
- Add a function to update the text in the SAP text editor
- Add a groupbox
- Add a textbox
- Add a pushbutton
- Display the text in an SAP text editor
//Create this file inside your script folder for customizing SAP Easy Access screen: grid_functions.sjs
//Now let's start adding the content to the above file
- Add a function to trim the string values.
//Function to trim string String.prototype.trim = function() { return this.replace(/^\s+|\s+$/g,""); }
- Add a function to check the string value entered in the inputfield is blank.
//Function to check if the string blank function isBlank(jvar) { println(jvar); if (jvar=="undefined" || jvar== void 0 || jvar.toString().trim()=="" || jvar==null) { return true; } else { return false; } }
- Add a function to split a string into an array of values
//Function to split a string into an array with specified char size function splitText(longText, charSize){ charSize = parseInt(charSize); var textArray = longText.split('\n'); var resultArray = [], matchedArray = []; var new_line_content = "", remained_line_content = "", cur_line = ""; for(var iCount=0; iCount<textArray.length; iCount++){ new_line_content = textArray[iCount].replace(/\t+/g," ").trim(); //Text editor doesn't support Tab content do{ remained_line_content = ""; if(new_line_content.length > charSize){ cur_line = new_line_content.substring(0,charSize); matchedArray = cur_line.match(/((\S*\s+\S*)+\s)|(\S*)/g); remained_line_content = new_line_content.substring(matchedArray[0].length, new_line_content.length) new_line_content = matchedArray[0]; } resultArray.push(new_line_content); new_line_content = remained_line_content; } while(new_line_content.length > 0) } return resultArray; }
- Add a function to check the long text specified in the textbox is blank.
//Function to check if longtext is blank function isTextBoxBlank(longText) { var bTextExist = true; var arrText = longText.split('\n'); for(var iCount=0; iCount<arrText.length; iCount++) { if(!isBlank(arrText[iCount].trim())) { bTextExist = false; break; } } return bTextExist; }
Note: The generic functions can be all put in one script file and load once in esession.sjs file - Add a function to copy the text entered in the textbox and paste the text in an SAP text editor.
//Function to copy text content to SAP text editor screen function va01SaveText(param){ var z_va0x_find_text_counter = param.l_seq; //Copy passed sequence parameter onscreen "SAPMV45A.4001" if(isBlank(z_va01_term_of_delivery_text.trim())){ //Skip copy text if textbox is blank goto SKIP_COPY_TEXT; } var start_line=1; //Set initial values var blank_line=0; enter('/Menu=3,2,11'); //Go to Header Data-> Text tab onmessage //Error handling if(_message.substring(0,2) == "E:"){ message(_message); enter('?'); goto FUNC_END; } else enter(); onscreen 'SAPMV45A.4002' enter('=TP_FIRST'); //Go to first option in the list RECHECK_FIND_TEXT:; onscreen 'SAPMV45A.4002' if(z_va0x_find_text_counter > 0){ //According to sequence value z_va0x_find_text_counter--; enter('=TP_NEXT'); //Go to next text in the list goto RECHECK_FIND_TEXT; } else{ enter('=TP_DETAIL'); //Go to text editor } onscreen 'SAPLSTXX.2102' enter('/Menu=3,3'); //Change editor onscreen 'SAPLSTXX.1100' enter("/Menu=1,7"); //Cancel existing content onscreen 'SAPLSPO1.0100' enter("=YES"); //Select "yes" in the popup onscreen 'SAPLSTXX.1100' setcursor('cell[TABLE,3,'+(start_line+2)+']'); var tmp_next_line = ""; enter(); NEXT_LINE:; onscreen 'SAPLSTXX.1100' //Copy each line from textbox to a temp string copytext({"fromtext":"z_va01_term_of_delivery_text", "tostring":"tmp_line", "line":start_line}); //Remove "indent" in the string if it's not empty if(!isBlank(tmp_line)){ tmp_line = tmp_line.replace(/\t+/g," ").trim(); }else{ tmp_line = ""; } //Merge the temp next line with current line if(!isBlank(tmp_next_line)){ tmp_line = tmp_next_line + " " + tmp_line; } if(!isBlank(tmp_line)){ if(tmp_line.length > 72){ //If length of current line exceed 72 characters tmp_chk_text = tmp_line.substring(0,72); tmp_last_space = tmp_chk_text.lastIndexOf(" "); tmp_next_line = tmp_line.substring(tmp_last_space, tmp_line.length); tmp_line = tmp_line.substring(0,tmp_last_space); } else { tmp_next_line = ""; tmp_line = tmp_line.trim(); } set('cell[TABLE,3,'+(start_line+2)+']',tmp_line); blank_line = 0; start_line++; setcursor('cell[TABLE,3,'+(start_line+2)+']'); enter(); goto NEXT_LINE; } else { if(blank_line < 2){ //If count of continue blank line is less than 2 set('cell[TABLE,3,'+(start_line+2)+']',""); blank_line++; start_line++; setcursor('cell[TABLE,3,'+(start_line+2)+']'); enter(); goto NEXT_LINE; } } enter('/11'); //Save after change onscreen "SAPMV45A.4001" SKIP_COPY_TEXT:; enter("?"); FUNC_END:; }
- Navigate to Change Sales Order screen and enter the Order value. Click the continue button as shown below:
- Add a groupbox to collate related screen elements.
//Creates a group box based on the specified coordinates with a title as Term of Delivery box([0,87], [5,125], "Term of Delivery");
- Add a textbox inside the groupbox as shown below:
//Creates a textbox with a technical name as z_va01_term_of_delivery_text textbox([1,89], [5,119], {"name":"z_va01_term_of_delivery_text"});
- Add a pushbutton to execute va01SaveText process on click.
//Creates a pushbutton with an icon included in the title and executes a process with parameters specified
pushbutton([4,122], "@2L\\QSave Text@", "?", {"process":va01SaveText, "size":[1,2], "using":{"l_seq":6}});
- Enter the long text in the textbox and click on the save button as shown below:
- You will see the text entered in the textbox is displayed in the SAP text editor screen as shown below:
This article is part of the Javascript functions tutorial.