cancel
Showing results for 
Search instead for 
Did you mean: 

How can obtain a row from an attribute

Former Member
0 Kudos

Hi, i´m doing a smart project and i need only one row, how can obtain it?

The row i want obtain it from an attribute.

Thanks,

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Sorry, i hven´t the sync Key... how can obtain a row, with an attribute that it isn´t the sync key.

Thanks,

Former Member
0 Kudos

Hi Victor,

well, if you do not have the sync key, two possible ways:

A.) Create a query - look int the MDK, this example is really good

B) You have the list of BOs. The listengs above give you the list of BOs if you want them. Make an iteration over that list and do a simple IF.... then.... statement. This is the easiest way to develop it!

Regards,

Oliver

Former Member
0 Kudos

mmmm, if i use an iterator... how can acced the differents attributes in the iterator... For example, i have a row with this:

ID Desc Number

1 Food 10 --> my row

In the iterator, how can do: if (row.id == 1)...

Thanks,

Former Member
0 Kudos

Finally i do it with this method:

public Vector getFile(MeIterator syncBos, int fromIndex, int count, String id) {

// We want usually all items in the MEIterator because the SmartSync API already delivered

// the correct part of items we want to display.

// the fromIndex and count variable are only there in case we need a single entry.

Vector retVec = new Vector();

int i = 0;

if (syncBos != null) {

syncBos.reset();

// Fill table header with Field Names of Top Row

while (syncBos.hasNext()) {

/* SyncBo sb = (SyncBo) syncBos.next();

if (i >= fromIndex) {

Vector rowData = new Vector();

for (int col = 0; col < getColumns(); col++) {

rowData.addElement(getHeaderFieldValue(sb, tableHeaderNames[col]));

}

retVec.addElement(rowData);

} */

Row row = (Row) syncBos.next();

if (i >= fromIndex) {

Vector rowData = new Vector();

if ((getHeaderFieldValue(row, tableHeaderNames[1])).equals(id)) {

for (int col = 0; col < getColumns(); col++) {

rowData.addElement(getHeaderFieldValue(row, tableHeaderNames[col]));

}

retVec.addElement(rowData);

}

}

i++;

// return when count has been reached, when count is greater 0.

// if count less 0 we get all records.

if (count > 0) {

if (i >= (fromIndex + count))

return retVec;

}

}

}

return retVec;

}

Thanks,

Answers (3)

Answers (3)

Former Member
0 Kudos

Solve it

Former Member
0 Kudos

Hi Victor,

you can either use the KEY of the row and access it directly as written above.

Or get the complete list and iteate through it - mentioned above as well.

Or you write a Query and select this item with the Query. This is explained in the MDK and really easy - well, a few lines of code are necessary.

The question is here: what information do you have about the row? While you have the key, number 1 is the simplest option.

If you can not really select it with a query, then option two is the best one, even it is a little time consuming on a PDA - but as long as the dataset is not too big it should be ok.

Hope this helps you to come a step forward.

Regard,s

Oliver

Former Member
0 Kudos

I don´t understand... I have the key and i have the method getSyncBoInstance, and this method for obtain the SyncBO, but i don´t know how can obtain the row...

public void getDataArrayFila(String id) {

RowCollection[] rows = (dbAccess.getSyncBoInstance(currentSync, id)).getRows();

MeIterator ri = rows.iterator();

return;

}

I can´t use MeIterator ri = rows.iterator(); because is a Collection...

Thanks,

Message was edited by:

Victor Capi

rajan_venkatachalam
Participant
0 Kudos

Hi Victor,

I dont understand why you cant create an iterator from row collection, are you getting any exception for that.You can use iteraror in the Row collection to get row entities.

Thanks,

Rajan

Former Member
0 Kudos

Yes, appear an exception:

"Cannot invoke iterator() on the array type RowCollection[]"

Thanks,

Former Member
0 Kudos

Hi Victor,

this I do not understand. You say you have the key - but you want to go via the iteration?

Well, if you really have the key, I think this is your code:

SyncBo sb = dataFacade.getSyncBo(sbd, syncKey);

Or is it: you have the TOP row already with its key and now you want to get all the items for that SyncBO?

Regards,

Oliver

rajan_venkatachalam
Participant
0 Kudos

Hi Victor,

You should not create an array type for RowCollection , the syntax should look like this

 RowCollection rows = (dbAccess.getSyncBoInstance(currentSync, id)).getRows();
    MeIterator ri = rows.iterator(); 

Hope this helps

Thanks and Regards,

Rajan

Former Member
0 Kudos

Oliver has reason, this shoul be my code...

SyncBo sb = dataFacade.getSyncBo(sbd, syncKey);

But, how can obtain the row from a syncbo

rajan_venkatachalam
Participant
0 Kudos

Okay then you can use this code to get the row entities,

RowCollection rc = sb.getRows();

MeIterator ri = rc.iterator(); 

If you have the SyncKey then you can get the particual row with this method

Row row = rc.get(syncKey);

Regards,

Rajan

Message was edited by:

Rajan Venkatachalam

Former Member
0 Kudos

Exception: Type mismatch: cannot convert from RowCollection[] to RowCollection

rajan_venkatachalam
Participant
0 Kudos

Hi victor,

Can you please paste the method again after the changes that you did and tell me wheather the exception occurs in this method.

Regards,

Rajan

Former Member
0 Kudos

public SyncBo getSyncBoInstance(String syncBoName, String syncKey) {

SyncBoDescriptor sbd = descriptorFacade.getSyncBoDescriptor(syncBoName);

try {

SyncBo sb = dataFacade.getSyncBo(sbd, syncKey);

return sb;

} catch (PersistenceException pex) {

System.out.println(pex.getMessage());

return null;

}

}

public void getDataArrayFila(String id) {

RowCollection rc = dbAccess.getSyncBoInstance(currentSync, id).getRows();

Row row = rc.get(id);

}

Exception in rc --> Type mismatch: cannot convert from RowCollection[] to RwoCollection.

rajan_venkatachalam
Participant
0 Kudos

Hi Victor,

can you try this in getDataArrayFile method


SyncBo sc =  dbAccess.getSyncBoInstance(currentSync, id);

RowCollection rc = sc.getRows();

Row row = rc.get(id);

Regards,

Rajan

Former Member
0 Kudos

No, the same exception...

rajan_venkatachalam
Participant
0 Kudos

Hi Victor,

Okay can you please add the try and catch block in this method getDataArrayFila(String id) like this


try {
     SyncBo sc =  dbAccess.getSyncBoInstance(currentSync, id);
 
RowCollection rc = sc.getRows();
 
Row row = rc.get(id);

} catch (PersistenceException pex) {
System.out.println(pex.getMessage());
return null;
} 

Regards,

Rajan

Former Member
0 Kudos

No, appear the same error... in rc

Former Member
0 Kudos

The method for obatin a RowCollection is getRows(RowDescriptor arg0); but i don´t know what is RowDescriptor...

Thanks,

rajan_venkatachalam
Participant
0 Kudos

Hi Victor,

Yes thats right,i forgot the argument.

A RowDescriptor instance describes the metadata definition for a Row object. It provides access to the following:

*Row name; ("TOP" represents the top row)

*FieldDescriptor of the key field

*Specific FieldDescriptor instance belonging to this RowDescriptor instance

*All FieldDescriptor instances belonging to this RowDescriptor

*All RelationDescriptor instances which are relating to this RowDescriptor

*SyncBoDescriptor instance which this RowDescriptor is member of

You can obtain RowDescriptor from the SyncBoDescriptior as per the last point mentioned above.


SyncBoDescriptor sbd = descriptorFacade.getSyncBoDescriptor(syncBoName);

RowDescriptor rd = sbd.getTopRowDescriptor(); 

You can pass this argument in the getRows() method to obtaing RowCollection.

Thanks and Regards,

Rajan

Former Member
0 Kudos

Hi, finally i write:

public void getDataArrayFila(String id) {

try {

SyncBo sc = dbAccess.getSyncBoInstance(currentSync, id);

SyncBoDescriptor sbd = dbAccess.getSyncBoDescriptor(currentSync, id);

RowDescriptor rd = sbd.getTopRowDescriptor();

RowCollection rc = sc.getRows(rd);

Row row = rc.get(id);

} catch (PersistenceException pex) {

System.out.println(pex.getMessage());

}

}

I think that work, but... how can show this row... and the attributes.

Thanks,

Message was edited by:

Victor Capi

Message was edited by:

Victor Capi

Former Member
0 Kudos

The previous method is called:

public void loadBeanFila(String id) {

// Set headerpanel

// The left side displays the MI icon, that canbe clicked to go back to the MI home page

<b>tableViewDefinition.setHeaderPanelEntryLeft("<a href=\"http://127.0.0.1:4444/me\" > <img src=\"mimes/milogo.gif\" alt=\"MI Home\" ></a>");</b>

// The right side displays the text MDK

<b>tableViewDefinition.setHeaderPanelEntryRight("MDK");</b>

// Setup Commands for this example. Commands are displayed on the top of the centerpage.

// In this example we use add, delete, filter and list all commands.

<b>setCommands();</b>

// Set footerpanel

// The left side displays the application name

<b>tableViewDefinition.setFooterPanelEntryLeft(current_filter_string);</b>

// The right side displays the type of the example

<b>tableViewDefinition.setFooterPanelEntryRight(currentPageFooter);</b>

// set commands for application - the commands have been set in the initialize method already

<b>tableViewDefinition.setCommandLine(commandLine)</b>;

// set title of the center window

<b>tableViewDefinition.setCenterPageTitle(pageTitle);</b>

// Generate table header

<b>setTableHeader();</b>

// Generate data and set Vector in bean

<b>dataHandler.getDataArrayFila(id);</b>

// The following variables are necessary for the navigation

<b>dataHandler.setTableRows(MAX_TABLE_ROWS);</b>

<b>dataHandler.setTableColumns(dataHandler.getColumns());</b>

d<b>ataHandler.setRowsInDataset(dataHandler.getRowsInDataset());</b>

<b>dataHandler.setCurrentIndex(start_index);</b>

}

Thanks,

Message was edited by:

Victor Capi

Former Member
0 Kudos

Sorry, i can´t write the method other form...

Message was edited by:

Victor Capi

rajan_venkatachalam
Participant
0 Kudos

Hi Victor,

I am not sure how far this info is going to help you ,however you can consider

public SyncBo getSyncBoInstance(String syncBoName, String syncKey) {
		SyncBoDescriptor sbd = descriptorFacade.getSyncBoDescriptor(syncBoName);
		try {
			SyncBo sb = dataFacade.getSyncBo(sbd, syncKey);
			return sb;
		} catch (PersistenceException pex) {
			System.out.println(pex.getMessage());
			return null;
		}
	}
 

Based on the SyncBo value from the previous code snippet , you can obtain the rowCollection thru this method.

public RowCollection[] getRows()
                        throws PersistenceException 

Ex:

sb.getRows()

Once you obtain the RowCollection for the particular syncBo,you can iterate thru rowCollection to get the row entities.

//To get the iterator of the Row entities in this RowCollection.

MeIterator it = rowList.iterator();

I would suggest you to go through the <a href="https://help.sap.com/javadocs/NW04/current/me/index.html">API</a> Doc which is clearly explained about all the methods which would be useful for you to do all sort of operation.

Thanks and Regards,

Rajan