cancel
Showing results for 
Search instead for 
Did you mean: 

Insert 2 Row (related on the same TopRow) in a syncbo

Former Member
0 Kudos

hello,

i need to insert in my syncBo more than 1 Row structure.

this example working if i want insert 1 row related to 1 toprow structure:

<i> public void insertNewSyncBo() {

SyncBo newCustomerOrder = this.syncBoDataFacade.createEmptySyncBo(this.customerOrderD);

Row customerOrderHead = newCustomerOrder.getTopRow();

customerOrderHead.setFieldValue(this.customerNumberD, "987");

customerOrderHead.setFieldValue(this.orderValueD, new FixedDecimal("1234,25"));

customerOrderHead.setFieldValue(this.salesRegion, "Walldorf");

<b>// add 1 Row</b>

Row customerOrderItem = newCustomerOrder.createEmptyRow(customerOrderItemD);

customerOrderItem.setFieldValue(this.productNumberD, new Integer(1241294));

customerOrderItem.setQuantity(this.productNumberD, new Integer(3));

<b>//if i need insert another Row in this bo?</b>

//insert Bo locally

this.syncBoDataFacade.insertSyncBo(newCustomerOrder);

}</i>

Accepted Solutions (0)

Answers (2)

Answers (2)

Former Member
0 Kudos

> <i> public void insertNewSyncBo() {

> SyncBo newCustomerOrder =

> der =

> this.syncBoDataFacade.createEmptySyncBo(this.customerO

> rderD);

>

> Row customerOrderHead =

> ead = newCustomerOrder.getTopRow();

>

>

>

>

> customerOrderHead.setFieldValue(this.customerNumberD,

> "987");

>

> customerOrderHead.setFieldValue(this.orderValueD,

> ueD, new FixedDecimal("1234,25"));

>

> customerOrderHead.setFieldValue(this.salesRegion,

> ion, "Walldorf");

>

> <b>// add 1 Row</b>

> Row customerOrderItem =

> tem =

> newCustomerOrder.createEmptyRow(customerOrderItemD);

>

>

>

>

> customerOrderItem.setFieldValue(this.productNumberD,

> , new Integer(1241294));

>

>

> customerOrderItem.setQuantity(this.productNumberD,

> rD, new Integer(3));

>

> <b>//if i need insert another Row in this bo?</b>

at this point i need to add in my syncbo another Row object .

i need to use these methods:

createInitialCopy()

createUnlinkedCopy()

?

>

> //insert Bo locally

>

>

>

>

> this.syncBoDataFacade.insertSyncBo(newCustomerOrder);

>

> }</i>

kishorg
Advisor
Advisor
0 Kudos

Hi Elina ,

u can use,,,

in this way...

SyncBo unlinkedCopy = existingSyncBo.createUnlinkedCopy();

Row newRow = unlinkedCopy.createEmptyRow(rowDesc);

//Set some values to the new row

//Insert the row into the syncbo

unlinkedCopy.insertRow(newRow);

//Commit the txn

refer this link also..

http://media.sdn.sap.com/public/html/submitted_docs/MI/MDK_2.5/content/javadoc/com/sap/ip/me/api/sma...

Regards

Kishor Gopinathan

Former Member
0 Kudos

if i want insert 2 child Row in the same syncbo?

SyncBo unlinkedCopy = existingSyncBo.createUnlinkedCopy();

Row newRow1 = unlinkedCopy.createEmptyRow(rowDesc);

Row newRow2 = unlinkedCopy.createEmptyRow(rowDesc);

//Set some values to the new row

//Insert the row into the syncbo

unlinkedCopy.insertRow(newRow1);

unlinkedCopy.insertRow(newRow2);

//Commit the txn

kishorg
Advisor
Advisor
0 Kudos

HI Elina

u can try in this way also...

SyncBo unlinkedCopy = existingSyncBo.createUnlinkedCopy();

Row newRow1 = unlinkedCopy.createEmptyRow(rowDesc);

<b> Row newRow2 = newRow1.createInitialCopy();</b>

ur code will work perfectly..

refer this also...

http://media.sdn.sap.com/public/html/submitted_docs/MI/MDK_2.5/content/javadoc/com/sap/ip/me/api/sma...

Regards

Kishor Gopinathan

Former Member
0 Kudos

hello eliana,

looking in your code, at the point where you are asking what

to use, createUnlinkedCopy or createInitialCopy; note

that you can only use

SyncBo.createInitialCopy or Row.createInitialCopy

coz your SyncBo as well as Row instances at that point are

still NOT inserted in the repository. you can only use

createUnlinkedCopy from objects that are already inserted

in the local repository.

use insertSyncBo or insertRow method when inserting the

initial copies, and replaceSyncBo or replaceRow when replacing

the existing object that is already in the local repository with that of your unlinked copies.

regards

jo

Former Member
0 Kudos

Hi Jo,

can explain me?

i have this code but when i read the values of fields of the Row the result is NULL.

my code:

+ /* MODIFIED VERSION OF ADDROW IN DB.

WE TRY TO ADD ONE SYNC BO WITH ONE TOP STRUCTURE AND A CERTAIN NUMBER OF

CHILD STRUCUTRE INSTANCES, BUT THE CHILD FIELDS ARE INSERTED NULL

*/

public String addRowInDB(String syBName, Vector HeaderFieldNames, Vector ChildFieldNames, Vector HeaderValues, Vector ChildValues, String Structure)

throws SmartSyncException, PersistenceException

{

String ToReturn = "";

String syncBoName = syBName;

SyncBoDescriptor sbd = descriptorFacade.getSyncBoDescriptor(syBName);

System.out.println("descriptor: " + syBName);

SmartSyncTransactionManager transactionManager;

String[] IdeaMalsana = new String[] {"010", "020", "030", "040", "050", "060"};

transactionManager = dataFacade.getSmartSyncTransactionManager();

// here we insert the header values and all is ok with that

try

{

// Create new syncbo

SyncBo newsyncBo = dataFacade.createEmptySyncBo(sbd);

// A transaction manager is valid for one action starting with beginTransaction and ending with commit/rollback

// In this example we commit (save) every row we add - no rollback.

for (int i = 0; i < HeaderFieldNames.size(); i++) {

System.out.println("header: "+ HeaderFieldNames.elementAt(i).toString() + ": " + HeaderValues.elementAt(i));

if (HeaderValues.elementAt(i) != null) {

System.out.println(

setHeaderFieldValue(

newsyncBo,

HeaderFieldNames.elementAt(i).toString(),

HeaderValues.elementAt(i).toString()));

}

else

ToReturn = "Tipo dati non supportato nel campo.";

}

int ElementCounter = 0;

// HERE WE TRY TO INSERT CHILD STRUCTURES, CYCLING ON A VACTOR

// THAT GOES THROUGH ALL CHILD FIELD NAMES

RowDescriptor rd = null;

for(int count=0;count<ChildValues.size();count++)

{

try

{

rd = sbd.getRowDescriptor("010");

Row r010Row = newsyncBo.createEmptyRow(rd).createInitialCopy();

FieldDescriptor r010MovDesc = rd.getFieldDescriptor(ChildFieldNames.elementAt(ElementCounter).toString());

System.out.println("CAMPO CORRENTE: " + r010MovDesc.getFieldName());

System.out.println("----

-


: " + count);

BasisFieldType bft = r010MovDesc.getFieldType();

System.out.println(ChildFieldNames.elementAt(ElementCounter).toString() + ": " + ChildValues.elementAt(count));

if(bft == BasisFieldType.C)

{

System.out.print("tipo dati carattere ");

System.out.println("adding: " + ChildValues.elementAt(count));

r010Row.modifyFieldValue(r010MovDesc, (String) ChildValues.elementAt(count));

//Campo.setValue((String) ChildValues.elementAt(c));

}

else if(bft == BasisFieldType.P)

{

System.out.print("tipo dati P - bigdecimal ");

BigDecimal bd = new BigDecimal((String) ChildValues.elementAt(count));

System.out.println("adding: " + ChildValues.elementAt(count));

r010Row.modifyFieldValue(r010MovDesc, bd);

//Campo.setValue(bd);

}

else if(bft == BasisFieldType.N)

{

System.out.print("tipo dati N - biginteger ");

BigInteger bi = new BigInteger((String) ChildValues.elementAt(count));

System.out.println("adding: " + ChildValues.elementAt(count));

r010Row.modifyFieldValue(r010MovDesc, bi);

//Campo.setValue(bi);

}

else

{

ToReturn = "Tipo dati non riconosciuto.";

return ToReturn;

}

ElementCounter ++;

if(ElementCounter >= ChildFieldNames.size())

{

System.out.println("insertrow");

transactionManager.beginTransaction();

newsyncBo.insertRow(r010Row);

FieldDescriptor fd1 = rd.getFieldDescriptor("KTEXT1");

System.out.println("prima di aggiungere: " + r010Row.getFieldValue(fd1));

//System.out.println(newsyncBo.getRows());

ElementCounter = 0;

}

}

catch(NumberFormatException nf)

{

//transactionManager.rollback();

nf.printStackTrace();

ToReturn = "Formato dati non valido in uno o più campi.";

return ToReturn;

}

catch(NullPointerException npe)

{

//transactionManager.rollback();

npe.printStackTrace();

ToReturn = "Impossibile inserire uno o più campi.";

return ToReturn;

}

catch(Exception e)

{

//transactionManager.rollback();

e.printStackTrace();

ToReturn = "Impossibile processare la richiesta: " + e.getMessage();

return ToReturn;

}

}

//transactionManager.beginTransaction();

transactionManager.beginTransaction();

RowCollection rc = newsyncBo.getRows(rd);

System.out.println("Ho questi items: " + rc.iterator().elementCount());

dataFacade.insertSyncBo(newsyncBo);

transactionManager.commit();

ToReturn = "OK";

}

/*catch(PersistenceException pe)

{

pe.printStackTrace();

//transactionManager.rollback();

ToReturn = "Problema sul set di dati locali: " + pe.getReason();

}*/

catch(NumberFormatException nf)

{

nf.printStackTrace();

//transactionManager.rollback();

ToReturn = "Problema sul formato di uno o più campi";

}

catch(NullPointerException npe)

{

npe.printStackTrace();

//transactionManager.rollback();

ToReturn = "Uno o più campi risultano non valorizzati o non congruenti.";

}

catch(Exception e)

{

e.printStackTrace();

//transactionManager.rollback();

ToReturn = e.getMessage();

}

return ToReturn;

}+

Former Member
0 Kudos

excuse me,

i have posted my entirely java method.

my problem is :

i dont'have understood why

in my syncbo i can't insert more than 1 Row obj.

in my local persistence these Rows are null.

Former Member
0 Kudos

Hi,

I understand that my previous posts were not so clear as I’m trying different solutions at the same time, so I decided to explain in words how I’m trying to proceed:

1 – I create a new syncbo from datafacade (createemptysyncbo) using the proper sync bo descriptor

2 – I call recursively the method: setheaderfieldvalues to evaluate and set the header fields and everything goes well

3 – I loop through any element of a proper vector that I initialized to contain child field values, and, for each row I create a new row using rowdescriptor of the “010” child structure.

4 – I initialize the field descriptor starting from another vector of child field names

5 – I determine the type of any field and call the “modifyfieldvalue” for each type

6 – I begin a new transaction using transactionmanager

7 – I insert the row in sync bo, calling “insertrow” from the sync bo object

8 – I commit the transaction, each of these steps are obviously executed more times depending on the loop

9 – I begin a new transaction and call datafacade.insertsyncbo and then I commit

The main problem is that the header values of the sync bo just created are properly set, but NOT the child ones, witch are completely NULL..

How shoud I proceed ? .. where is my mistake ?

Former Member
0 Kudos

hello eliana,

you are using the modifyFieldValue method.

this method will only assign the value temporarily into the

Row instance and will not write it into the persistence

object unless you call the method SyncBo.modifyRow(Row);

Row newRow = parentBo.createEmptyRow(RowDescriptor);

newRow.modifyFieldValue(fieldDescriptor0, value0);

newRow.modifyFieldValue(fieldDescriptor1, value1);

newRow.modifyFieldValue(fieldDescriptor2, value2);

<b>parentBo.modifyRow(newRow);</b> //IMPORTANT

this will solve your problem.

regards

jo

Former Member
0 Kudos

hi jo,

my problem isn't insert FIELD value in a Row.

my problem is : insert many Row in a sync bo,

and these rows are related to rowdescriptor "010":

i try to insert multiple Row in a same child 010 of a sync bo.

is it possible?

kishorg
Advisor
Advisor
0 Kudos

Hi Elina,,

use this code template

This is one sample code ...

RowDescriptor itemRow = sbd.getRowDescriptor("010");

Row item = null;

String[] arrayItemfields = getItemFieldNames(syncBoName, "010");

for (int itemCount = 0; itemCount < itemRows.size(); itemCount++) {

item = newsyncBo.createEmptyRow(itemRow);

Vector itemLine = (Vector) itemRows.elementAt(itemCount);

String[] itemLineValues = new String[5];

for (int itemLineValCnt = 0;

itemLineValCnt < 5;

itemLineValCnt++) {

itemLineValues[itemLineValCnt] =

itemLine.elementAt(itemLineValCnt).toString();

}

for (int iCount = 0; iCount < collectItemFields.length; iCount++) {

FieldDescriptor fd =

itemRow.getFieldDescriptor(collectItemFields[iCount]);

if (fd != null) {

setFieldValue(fd, item, itemLineValues[iCount]);

}

}

newsyncBo.insertRow(item);

}

dataFacade.insertSyncBo(newsyncBo);

//Commit the transaction

transactionManager.commit();

Regards

Kishor Gopinathan

Former Member
0 Kudos

> for (int itemCount = 0; itemCount < itemRows.size(); itemCount++) {

sorry kishor, the Vector itemRows what contains?

kishorg
Advisor
Advisor
0 Kudos

Hi Elina,

Suppose u have to add 5 010 item rows to your one SyncBo instance .. then

Then u can pass one vector with 5 elements ,which contain the data for 5 010 item...

here in that sample code .. thats i mentioned..

<b>Vector itemRows = <You have to pass this vector ></b>

then ....

loop through this vector...

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

SmartSyncTransactionManager transactionManager;

// Create new syncbo

SyncBo newsyncBo = dataFacade.createEmptySyncBo(sbd);

RowDescriptor itemRow = sbd.getRowDescriptor("010");

Row item = null;

for (int c=0;c<itemRows.size();c++)

{

<b>item = newsyncBo.createEmptyRow(itemRow);</b>

Vector itemRowV = (Vector) itemRows.elementAt(c);

// suppose in ur one row u have 5 fields .. then for getting the values of this individual fileds .. u have to loop through this vector again...

//for storing the values of a particular row

// for easy..

<b>String[] itemLineValues = new String[itemRowV.size()+1];</b>

for(int j=0;j<itemRowV.size();j++)

{

itemLineValues[itemLineValCnt] =

itemRowV.elementAt(itemLineValCnt).toString();

}

String [] fieldNames = getItemFieldNames(syncBoName, "010") // I have mentioned this method in one forum .. for you..

for (int iCount = 0; iCount < fieldNames.length; iCount++) {

FieldDescriptor fd =

itemRow.getFieldDescriptor(fieldNames[iCount]);

if (fd != null) {

setFieldValue(fd, item, itemLineValues[iCount]);

}

}

newsyncBo.insertRow(item);

}

dataFacade.insertSyncBo(newsyncBo);

//Commit the transaction

transactionManager.commit();

}

Regards

Kishor Gopinathan

Former Member
0 Kudos

hello kishor,

the only difference actually of my code is:

in my SP13 the method setFieldValue()

has only 2 parameter, your method 3.

kishorg
Advisor
Advisor
0 Kudos

Hi Elina ,

Is it working properly or not ?.

I think from our standard code in SmartSynDBAccess , we have only one method to set values in the header object.

But i have given sample code for setting values in the item in my last forum..(for u).

Let me know..

Regards

Kishor Gopinathan

kishorg
Advisor
Advisor
0 Kudos

Hi Elina,

can u explain it clearly...

Regards

Kishor Gopinathan