cancel
Showing results for 
Search instead for 
Did you mean: 

Re Order of the entries im MeIterator

Former Member
0 Kudos

Hi,

I have to get the item records of a syncBo.I used the following code.

RowDescriptor rd;

RowCollection rc = syncbo.getRows(rd);

MeIterator ri = rc.iterator();

the records are populated into the Meiterator.But following the above way the order of entries populated into the iterator is changing each time.

what is the order in which the entries are populated for an MeIterator?.Is it not in some order(ascending or descending ) of synckey of the item records?

How to get the entries in the order of a particular field of the item??

Thanks in advance..

Accepted Solutions (1)

Accepted Solutions (1)

kishorg
Advisor
Advisor
0 Kudos

Hi Veera,

<<

How to get the entries in the order of a particular field of the item??

>>

You can create conditions to query data from persistence with respect to one SyncBO. You can also create SortOrder and can apply this SortOrder on that condition before doing query from the persistence, so that u would get the desired data.

Go through this forum also..

use this code template to code..

For Header

*************************************************

//Here return is MeIterator

SyncBoDescriptor sbd = descriptorFacade.getSyncBoDescriptor(<SyncBoName>);

MeIterator iteratorSyncBos = null;

Condition cond1 = null;

Condition cond2 = null;

Condition[] condArray = {};

Condition condNet = null;

SmartSyncQueryFactory queryFactory =

SmartSyncRuntime.getInstance().getQueryFactory();

RowDescriptor rd = sbd.getTopRowDescriptor();

FieldDescriptor fd1 = rd.getFieldDescriptor("<Field1 from Header>");

//Customer Code

FieldDescriptor fd2 = rd.getFieldDescriptor("<Field2 from Header>");

cond1 =

queryFactory.createCondition(

fd1,

<RelationalOperatorType.EQUALS>,

<Value of this field>);

cond2 =

queryFactory.createCondition(

fd2,

<RelationalOperatorType.EQUALS>,

<Value of this field>);

condArray = { cond1,cond2 };

condNet =

queryFactory.createCondition(

condArray,

<LogicalOperatorType.OR>);

// Based on the value of the boolean variable of this method, we can decide whether to sort the data in the ascending order(true) or descending order(false).

<b>SortOrder sort1 = queryFactory.createSortOrder(fd1, true);</b>

SortOrder sort2 = queryFactory.createSortOrder(fd2, true);

SortOrder[] sortArray = { sort1, sort2 };

SortOrder sortNet = queryFactory.createSortOrder(sortArray);

Query syncBoQuery =

queryFactory.createQuery(

sbd,

condNet,

sortNet,

start,

count);

iteratorSyncBos = dataFacade.getSyncBos(syncBoQuery).iterator();

loop through this ..

**************************************************

For Item

****************************************************

// Here Return parameter is Row[]

SyncBoDescriptor sbd = descriptorFacade.getSyncBoDescriptor(<SyncBoName>);

MeIterator iteratorSyncBos = null;

Condition cond1 = null;

Condition cond2 = null;

Condition[] condArray = {};

Condition condNet = null;

SmartSyncQueryFactory queryFactory =

SmartSyncRuntime.getInstance().getQueryFactory();

RowDescriptor rd = sbd.getRowDescriptor(<itemName>); // particular item name.. Here we can use "TOP" for Header

FieldDescriptor fd1 = rd.getFieldDescriptor("<Field1 from Header>");

//Customer Code

FieldDescriptor fd2 = rd.getFieldDescriptor("<Field2 from Header>");

cond1 =

queryFactory.createCondition(

fd1,

<RelationalOperatorType.EQUALS>,

<Value of this field>);

cond2 =

queryFactory.createCondition(

fd2,

<RelationalOperatorType.EQUALS>,

<Value of this field>);

condArray = { cond1,cond2 };

condNet =

queryFactory.createCondition(

condArray,

<LogicalOperatorType.OR>);

SortOrder sort1 = queryFactory.createSortOrder(fd1, true);

SortOrder sort2 = queryFactory.createSortOrder(fd2, true);

SortOrder[] sortArray = { sort1, sort2 };

SortOrder sortNet = queryFactory.createSortOrder(sortArray);

Query syncBoQuery =

queryFactory.createQuery(

rd,

condNet,

sortNet,

start,

count);

RowList rc = dataFacade.getRows(syncBoQuery);

Row[] arrayRows = null;

MeIterator ri = rc.iterator();

int i = 0;

while (ri.hasNext()) {

ri.next();

i++;

}

ri = rc.iterator();

arrayRows = new Row;

//start filling the array now

i = 0;

while (ri.hasNext()) {

arrayRows = (Row) ri.next();

i++;

}

return arrayRows;

*********************************************************

Here in this method ..

just look here

//Here sbd for header itself.

queryFactory.createQuery(sbd,condNet,sortNet,start,count);

//Here rd for items

queryFactory.createQuery

(rd,condNet,sortNet,start,count);

here

//For top Row -- means header

RowDescriptor topRow = sbd.getTopRowDescriptor();

//for item rows..

RowDescriptor rd = sbd.getRowDescriptor(<itemName>);

for Header , in place of <itemName> , u can use "TOP"..

can put "TOP" in place of "010" ,"020"...

refer these links also..

https://www.sdn.sap.com/irj/go/km/docs/library/mobile/mobile%20infrastructure/mobile%20development%2...

https://www.sdn.sap.com/irj/go/km/docs/library/mobile/mobile%20infrastructure/mobile%20development%2...

https://www.sdn.sap.com/irj/go/km/docs/library/mobile/mobile%20infrastructure/mobile%20development%2...

Regards

Kishor Gopinathan

Former Member
0 Kudos

Hi Kishor,

Thank you very much for your detailed description and code samples.Now I am able to get the iterator values populated in the correct order.

Thanks for your constant support and help.

Answers (0)