You can use variables to specify line numbers to be copied. In the following example, we will use a variable and a trim function to remove whitespace. We will then place the value into an array, from whence we can use the set command to move it into the All items table.
textbox([7,82], [11,113],{ "name":"z_copytext","textfont":"Arial","textheight":"12", "textweight":"5"}); pushbutton([TOOLBAR], "Screen Copy",{ "process":copy_test});
function isBlank(jvar) { if (typeof jvar == 'string'){ jvar = jvar.trim(); } return(jvar == null || jvar=="" || jvar == void 0); }
String.prototype.trim = function() { return this.replace(/^\s+|\s+$/g,""); }
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]"}); }
The text will be copied to the All items table.