Author Topic: Copying Data from Textbox to Table Cell using Copytext with Line option  (Read 4666 times)

Sai Siddhartha

  • GuiXT Forum
  • Newbie
  • *
  • Posts: 47
    • View Profile
Purpose:
Using copytext command with line option data from textbox is copied into table cells.

In the following example, We are using variables to specify the line numbers to be copied.
These variable are trimmed to remove whitespace and place the value into an array.
A 'set' command is used to move these values into the table.

Example uses 'All items' table from 'VA01' transaction to set values from textbox.

Liquid UI Code
//////////////////////////////////////// SAPMV45A.E0101.sjs /////////////////////////////////////

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 (loop = 1; loop <lastIndex; loop++){ 
      // copytext with line option and variable as line number
      copytext({"fromtext":"z_copytext", "tostring":"z_str", "line":loop}); 
      if (isBlank(z_str) || z_str=='undefined'){   
         break;         // exits loop
      } 
      arMaterial.push(z_str.trim());  // adding values to array
      lastIndex++;
   }

   relrow=1;
   absrow=1;
   row_max=0;
   materialvalue="";
   onscreen 'SAPMV45A.4001'
      set("F[Sold- To Party]","1460");      // default sold- to party value
      gettableattribute("T[All items]", {"firstvisiblerow":"FVisRow", "lastvisiblerow":"LVisRow", "lastrow":"LastRow"});
      new_screen: //scroll the table to the absolute row              
      enter('/ScrollToLine=&V[absrow]', {"table":"T[All items]"});   

   onscreen 'SAPMV45A.4001'
      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) {                                                 
         goto new_screen;                               
      }                                                                                                             
      set("cell[All items,Material,&V[relrow]]", arMaterial[row_max]);                               
      set("cell[All items,Order Quantity,&V[relrow]]", 1); // default value '1' is added
      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();                                               
      onerror              // error handling                                                 
      enter("/nva01");

   onscreen 'SAPLSPO2.0300'                                               
      enter("=OPT1");   
 
   onscreen 'SAPMV45A.4001'                               
      row_max++;                               
      absrow=absrow+1;                               
      relrow++;                               
      goto new_row;               
      end_of_table:;       
      enter('/ScrollToLine=1', {"table":"T[All items]"});
}   

After executing function you can see values added to All items table of VA01 second screen.

See attachment for more information and screenshots