In this article, you will learn how to copy line numbers using variables. We will use a variable and trim function to eliminate extra spaces or whitespace. The resulting value will then be stored in an array, which can be easily transferred to the "All Items" table using the set command.
To demonstrate coping line numbers using variables, we will use the Create Sales Order: Initial Screen (VA01) and walk you through the following steps:
- Add a toolbar push button to copy the line numbers.
- Add a textbox to enter the number
- Add isBlank function
- Add a trim function
- Add a function to perform the copy operation
User Interface
//Create this file inside your script folder for customizing the Create Sales Order: Initial Screen, SAPMV45A.E0101.sjs
//Now, let's add the Liquid UI script to the above file and save it.
Customization
- Add a toolbar push button labeled Screen Copy.
//Create a toolbar push button labeled Screen Copy to execute the process copy_test pushbutton([TOOLBAR], "Screen Copy",{ "process":copy_test});
- Add a textbox to enter the values.
//Creates a textbox textbox([7,82], [11,113],{ "name":"z_copytext","textfont":"Arial","textheight":"12", "textweight":"5"});
- Add a isBlank function.
//Adds an isBlank function function isBlank(jvar) { if (typeof jvar == 'string'){ jvar = jvar.trim(); } return(jvar == null || jvar=="" || jvar == void 0); }
- Add a trim function to remove whitespace.
String.prototype.trim = function() { return this.replace(/^\s+|\s+$/g,""); }
- Add a function to perform the copy operation.
function copy_test(){ var z_str = ""; var arMaterial = []; var lastIndex = 2; for (var loop = 1; loop <lastIndex; loop++){ copytext({"fromtext":"z_copytext", "tostring":"z_str", "line":loop}); if (isBlank(z_str)){ break; } arMaterial.push(z_str.trim()); lastIndex++; } relrow=1; absrow=1; row_max=0; materialvalue=""; gettableattribute("T[All items]", {"firstvisiblerow":"FVisRow", "lastvisiblerow":"LVisRow", "lastrow":"LastRow"}); new_screen: enter('/ScrollToLine=&V[absrow]', {"table":"T[All items]"}); //scroll the table to the absolute row onscreen '*' println("Inside 2nd Screen Block"); gettableattribute("T[All items]", {"firstvisiblerow":"FVisRow", "lastvisiblerow":"LVisRow", "lastrow":"LastRow"}); println("After get table attribute"); relrow=1; new_row: if (row_max == arMaterial.length){ goto end_of_table; } if(absrow>LVisRow) { <!-- end of screen? --> goto new_screen; } //set("cell[All items,Material,&V[relrow]]", "&V[materialvalue]"); set("cell[All items,Material,&V[relrow]]", arMaterial[row_max]); set("cell[All items,Order Quantity,&V[relrow]]", 1); set("V[tmp1]", "&cell[All items,Material,&V[relrow]]"); set("V[tmp2]", "&cell[All items,Order Quantity,&V[relrow]]"); println('**********tmp1 and tmp2 = ' + tmp1 + ' & ' + tmp2); enter(); onmessage if (_message){ //.... error handling } onscreen 'SAPLATP4.0500' next_stock_item:; onscreen 'SAPLATP4.0500' goto next_stock_item; onscreen 'SAPMV45A.4001' row_max++; absrow=absrow+1; relrow++; goto new_row; end_of_table:; enter('/ScrollToLine=1', {"table":"T[All items]"}); }
SAP Process
- Refresh the Create Sales Order: Initial Screen. Enter the material number in the textbox in a single line, and enter the Order Type as OR.
- Click on Screen Copy to initiate the copy operation. The text will be copied to the All Items table, as shown below.