cancel
Showing results for 
Search instead for 
Did you mean: 

Personas Table Parsing issue

Former Member
0 Kudos

Hi Experts

We are facing one issue on screen personas while table parsing to capture data selected row from the table.

We are tried using given example on SCN

Link: http://wiki.scn.sap.com/wiki/display/Img/SAP+Screen+Personas+3.0+and+Tables

Used below code:

// Define Objects

var objAdditDataBtn = session.findById("wnd[0]/tbar[1]/btn[30]"),

objMainDataBtn = session.findById("wnd[0]/tbar[1]/btn[27]"),

objAdditTable = session.findById("wnd[0]/usr/tabsTABSPR1/tabpZU01/ssubTABFRA1:SAPLMGMM:2110/subSUB2:SAPLMGD1:8000/tblSAPLMGD1TC_KTXT"),

objInfo = session.findById("wnd[0]/usr/textEditPersonas_4");

// Define Functions

// Parse data from table object to an array function

parseTable(srcTable) {   

var totalColNum = srcTable.columns.length,       

totalRowNum = srcTable.rowCount,       

resTable = new Array();   

for (var curColNum=1; curColNum<=totalColNum; curColNum++) {       

var curCol = srcTable.getColumnId(curColNum);       

resTable[curColNum] = new Array();       

resTable[curColNum][0] = curCol;       

for (var curRowNum = 0; curRowNum<totalRowNum; curRowNum++) {           

resTable[curColNum][curRowNum+1] = srcTable.getCellValue

(curRowNum, curCol); }     }     return resTable; }

// Table data formatting function

formatTableData(srcTable) {   

var resArr = [];   

for (var i = 1; i < srcTable.length; i++) {       

for (var j = 1; j < srcTable[i].length; j++) {           

var val = srcTable[i][j].replace(/\_/g,"");           

if(val) {               

resArr[j] = (resArr[j]) ? resArr[j] + " " + val : val;         

  }    

  } 

  }   

return resArr.join("\n");

}

// Parse the table and display the results

  • objAdditDataBtn.press();

var jsAdditTable = parseTable(objAdditTable),   

copyData = formatTableData(jsAdditTable);

  • objMainDataBtn.press();
  • objInfo.text = copyData;

only modified screen ID’s

we are getting below error

Unexpected token {

I removed some code given only

parseTable(srcTable) {   

}

For above code also I am getting same error

Please advise how to solve the issue.

Accepted Solutions (0)

Answers (1)

Answers (1)

Former Member
0 Kudos

I think part of the problem is that your function definitions are missing the "function" keyword. So rather than:

formatTableData(srcTable) {   
  var resArr = [];   
  for (var i = 1; i < srcTable.length; i++) {       
    for (var j = 1; j < srcTable[i].length; j++) {           
      var val = srcTable[i][j].replace(/\_/g,"");           
        if(val) {               
          resArr[j] = (resArr[j]) ? resArr[j] + " " + val : val;         
        }    
      } 
  }   
  return resArr.join("\n");
}

you should have:

function formatTableData(srcTable) {   
  var resArr = [];   
  for (var i = 1; i < srcTable.length; i++) {       
    for (var j = 1; j < srcTable[i].length; j++) {           
      var val = srcTable[i][j].replace(/\_/g,"");           
        if(val) {               
          resArr[j] = (resArr[j]) ? resArr[j] + " " + val : val;         
        }    
      } 
  }   
  return resArr.join("\n");
}

But also look at the code in this Wiki page to see how to copy data from a table: Copying Table data into a variable - SAP Imagineering - SCN Wiki. I'm not sure your parseTable function will work correctly.

Steve.

Former Member
0 Kudos

Thanks steve for quick replay.

above problem was solved.

My exact requirement is I have a flat file I tried upload data and after some modification to data

I have displayed the same in the ALV, now user clicked on any row   we have to select the particular row need to capture the row.

In this case when I use object picker to select the ALV it is showing as a shell not like table.

Please advise in this case.

Former Member
0 Kudos

That is correct. The object ID will say it is a "shell" but look at the type in the object inspector and it will be a TableView or GridView, like this:

You can use the "onSelect" event of a grid or table to trigger a script. That script will be passed a "source" parameter that references the table, from which you can get the selected row number and then call getCellValue, like this:


var row = parseInt(source.selectedRows);

var value = source.getCellValue(row, "CCOL");

(substitute the appropriate column name, obviously )

Does that make sense?

Steve.