cancel
Showing results for 
Search instead for 
Did you mean: 

Regarding modifying Sync BO

Former Member
0 Kudos

Hi,

I want to modify the contact syncbo data on the mobile device using the following code. One of the field is weight.

private static final SyncBoDescriptorFacade DESC_FACADE =

SmartSyncRuntime.getInstance().getSyncBoDescriptorFacade();

private static final SyncBoDescriptor SYNC_BO_DESC =

DESC_FACADE.getSyncBoDescriptor(SYNC_BO_NAME);

private static final RowDescriptor ROW_DESC =

SYNC_BO_DESC.getRowDescriptor("TOP");

private static final FieldDescriptor FIELD_DESC_WEIGHT =

ROW_DESC.getFieldDescriptor("WEIGHT");

row.setFieldValue(FIELD_DESC_WEIGHT,weight);

The documentation says that setFieldValue function is deprecated. I am finding any set function in the member variables of the com.sap.ip.me.api.smartsync.row interface.

How do I modify the data in the syncbo.

Is there any other api that I need to use to change the syncbo data.

Regards

Raja Sekhar

Accepted Solutions (0)

Answers (10)

Answers (10)

Former Member
0 Kudos

Hi,

Please excuse my ignorance, but the Field.setValue method is also deprecated.

Field f = row.getField(getFieldDescriptor("PARTNER_KEY"));

f.setValue("test");

What have I done wrong?

Kind regards

Former Member
0 Kudos

Hi,

I am unable to modify sync bo data on the MI client end.

In the xml file of my application, the syncbo details are as follows

<SyncBO id="Z_CONTACT" version="1" type="timedTwoWay" allowCreate="true" allowModify="true" allowDelete="true" reqDirectSync="true">

- <TopStructure name="TOP">

- <Field name="SYNC_KEY" type="N" length="10" decimalLength="0" signed="false" isKey="true" isIndex="true">

<Input type="create">false</Input>

<Input type="modify">false</Input>

</Field>

-

While the values of the fields are as follows

<Input type="create">false</Input>

<Input type="modify">false</Input>

For example

<Field name="MANDT" type="C" length="3" decimalLength="0" signed="false" isKey="false" isIndex="false">

<Input type="create">false</Input>

<Input type="modify">false</Input>

</Field>

<Field name="PERSNUMBER" type="N" length="10" decimalLength="0" signed="false" isKey="false" isIndex="false">

<Input type="create">false</Input>

<Input type="modify">false</Input>

</Field>

- <Field name="FIRST_NAME" type="C" length="40" decimalLength="0" signed="false" isKey="false" isIndex="false">

<Input type="create">false</Input>

<Input type="modify">false</Input>

</Field>

- <Field name="LAST_NAME" type="C" length="40" decimalLength="0" signed="false" isKey="false" isIndex="false">

<Input type="create">false</Input>

<Input type="modify">false</Input>

</Field>

- <Field name="PROFESSION" type="C" length="40" decimalLength="0" signed="false" isKey="false" isIndex="false">

<Input type="create">false</Input>

<Input type="modify">false</Input>

</Field>

- <Field name="SEX" type="C" length="1" decimalLength="0" signed="false" isKey="false" isIndex="false">

<Input type="create">false</Input>

<Input type="modify">false</Input>

</Field>

- <Field name="BIRTHDAY" type="D" length="8" decimalLength="0" signed="false" isKey="false" isIndex="false">

<Input type="create">false</Input>

<Input type="modify">false</Input>

</Field>

- <Field name="WEIGHT" type="P" length="6" decimalLength="2" signed="false" isKey="false" isIndex="false">

<Input type="create">false</Input>

<Input type="modify">false</Input>

</Field>

- <Field name="HEIGHT" type="P" length="6" decimalLength="2" signed="false" isKey="false" isIndex="false">

<Input type="create">false</Input>

<Input type="modify">false</Input>

Does it mean that the fields cannot be modified at the MI client end. I have created a Tu01 sync bo.

Regards

Raja Sekhar

Former Member
0 Kudos

Hi Kishore,

I appreciate your prompt replies.

I am getting the ModificationNotAllowedException . I have created a Timed Two way Sync. Does that not give the client permission to change the BO data on the client side.

Regards

Raja Sekhar

kishorg
Advisor
Advisor
0 Kudos

Hi Raja,

hope u have selected CHANGE BAPI Wrapper also while creating the S01 Sync BO.

You mush have to select this change bapi wrapper also while creating the sync bo.

u just check the meRepMeta.xml file for the particular

particular sync bo..

if u have the provision to change the sync bo instance , then u can see like this..

<SyncBO id=<Sync Bo Name> version="<version>" type="twoWay" allowCreate="true" <b>allowModify="true"</b> allowDelete="false">

otherwise <b>allowModify="false"</b> .

If u have selected the MODIFY Bapi Wrapper , then while meta data export, in meRepMeta.xml file it will automatically like allowModify="true".

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

i havent tried this....below

just change that to allowModify="true" in meRepMeta.xml file and try once again ..

but in this way we can only change this in the client end . this cant change data in back end , if u have not selected the CHANGE Bapi Wrapper for this Sync Bo.(this im sure).i think this can cause error in back end . exactly dont know..

hope u got it..

Regards

Kishor Gopinathan

Former Member
0 Kudos

Hi Kishore,

I have used your code.

I am still facing issues

There are few points that I want to clarify.

In the code sample that u have given, The fields are being modified using setHeaderFieldValue(). After the sync bo fields are set, dont we need to call the replacesyncbo function before committing the transaction

The code snippet is as below

sb = dataFacade.getSyncBo(sbd,key);

SyncBo copyBO = sb.createUnlinkedCopy();

SmartSyncTransactionManager transactionManager;

transactionManager = dataFacade.getSmartSyncTransactionManager();

transactionManager.beginTransaction();

setHeaderFieldValue(copyBO,"PERSNUMBER","9866321467");

setHeaderFieldValue(copyBO,"FIRSTNAME","RajaSekhar");

setHeaderFieldValue(copyBO,"LASTNAME","Varigonda");

setHeaderFieldValue(copyBO,"PROFESSION","Technical Specialist");

setHeaderFieldValue(copyBO,"SEX","MALE");

setHeaderFieldValue(copyBO,"BIRTHDAY","1977-09-28");

setHeaderFieldValue(copyBO,"HEIGHT","165");

setHeaderFieldValue(copyBO,"WEIGHT","75");

dataFacade.replaceSyncBo(copyBO);

// Commit the transaction

transactionManager.commit();

Let me know if I am correct.

Also any help as to how I can debug in NWDS

Regards

Raja Sekhar

kishorg
Advisor
Advisor
0 Kudos

Hi Raja ,

for modifying one sync bo instance , there is no need to use createUnlinkedCopy()..

just use like this..

<b>sb = dataFacade.getSyncBo(sbd,key);

SmartSyncTransactionManager transactionManager;

transactionManager = dataFacade.getSmartSyncTransactionManager();

transactionManager.beginTransaction();

setHeaderFieldValue(sb,"PERSNUMBER","9866321467");

setHeaderFieldValue(sb,"FIRSTNAME","RajaSekhar");

setHeaderFieldValue(sb,"LASTNAME","Varigonda");

setHeaderFieldValue(sb,"PROFESSION","Technical Specialist");

setHeaderFieldValue(sb,"SEX","MALE");

setHeaderFieldValue(sb,"BIRTHDAY","1977-09-28");

setHeaderFieldValue(sb,"HEIGHT","165");

setHeaderFieldValue(sb,"WEIGHT","75");

// Commit the transaction

transactionManager.commit();</b>

setHeaderFieldValue - can be used to set value in new sync bo instance , or modify the instance.

But one main think here have to consider is , if you have created one Sync Bo instance , not synchronized with back end and u have modified that, then thats just like a creation .So during sync this will call Create Bapi Wrapper.

But after synchronization , is u are modifying that instance , then it is a modification(will call MODIFY Wrapper in back end during synchronization). u must have the right to modify this instance in the client side.

hope u got it.

u can debug MI Applications in NWDS.

refer this blog written by Arun

/people/arunkumar.ravi/blog/2006/02/22/execute-debug-your-mi-code-from-nwds

let me know , if u have doubts

Regards

Kishor Gopinathan

Former Member
0 Kudos

Hi,

I dont have any doubts on the importance of upgrading SAP WebAS. Currently I am getting it done.

I have a query regarding the persistance of the changes done to the syncbo.

To change the syncbo

1. Begin a transaction using Transaction manager.

2. Get the syncbo which we would like to modify/create

3. Change the fields of the syncbo.

4. Commit the transaction

Do the four steps suffice to store the changes done to sync bo to persist in the File I/O.

or Should I use persistance api's from persistance packages like

com.sap.ip.me.api.persist.app.

I am asking this because the changes I have made to the syncbo are not persisting.

Regards

Raja Sekhar

kishorg
Advisor
Advisor
0 Kudos

Hi Raja,

you are right .

u have to follow those steps , that u have mentioned in your last reply..

u can use sample codes that i have already written in my some forums. as some null pointer exceptions are not handled in standard code templates..

If u want to change the data in smart sync instance , then u have to use SmartSync API.

Regards

Kishor Gopinathan

Former Member
0 Kudos

Hi,

Kishore, thanks for the reply.

I have NWDS 14. Can I use to create an application from an xml file which was created from SAP Web AS SP9.

Will there be any compatability issues.

Regarding the syncbo, I am able to see that the syncbo is updated as I am displaying after modification. But the issue is if Iam running the app again, the changes are not persisting. Should I use any api so that the changes made to syncbo persist.

Regards

Raja Sekhar

kishorg
Advisor
Advisor
0 Kudos

Hi Raja,

u can use the same meRepMeta.xml file to create application in ur new version of Studio.

here the prerequisites...

u need MI client which is compatible with your developer studio.

if you are upgrading your client , then u have to upgrade ur server also..

thats all..

let me know if u have doubts.

Regards

Kishor Gopinathan

Former Member
0 Kudos

Hi,

Kishore and Abhijit, Thanks for your reply.

I have created a timed two way sync bo using the MEREP_CONTACT_GETLIST,MEREP_CONTACT_GETDETAIL,MEREP_CONTACT_CREATE,MEREP_CONTACT_MODIFY,MEREP_CONTACT_DELETE bapi wrappers.

While Enabling the syncbo, I selected the push capability. I guessed that it might be required for a two way sync bo. Is my guess right.

I mapped the following fields, persnumber,firstname,lastname.

On creating an application using the xml file, bointerface called ZContact,ZContactManager and boimplementation deriving from bointerface called ZContactImpl,ZContactManagerImpl got created. The ZContact bointerface contain only getfunctions. I added the set functions in ZContact and implemented them in ZContactImpl. An example for the setfunction code is as follows

public void setLastName(String lName) {

// TODO Auto-generated method stub

if (lName != null)

{

lastName = lName;\

}

}

Here lastName is the member variable of ZContactImpl.

In the controller file where the details are displayed,

I wrote a function which executes the following code

public Forward onSubmitChanges(Forwards forwards) {

try

{

ZContact item = getZContactCustom().getSelectedZContact();

ZContactManager cntManager = new ZContactManagerImpl();

item.setPersnumber("9866321467");

item.setFirstName("RajaSekhar");

item.setLastName("Varigonda");

item.setSex("Male");

cntManager.updateZContact(item);

ZContact item1 = getZContactCustom().getSelectedZContact();

} catch(BOException e)

{

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

}

return forwards.findForward("default");

}

The updateZContact function in ZContactManagerImpl is given below

public void updateZContact(ZContact parent) throws BOException {

try {

// make copy of the sync bo to the persistence

Row row = ((RowBO) parent).getRow();

SyncBo syncBO = row.getSyncBo();

SyncBo copyBO = syncBO.createUnlinkedCopy();

// map the row to the bo implementation

Row rowCopy = copyBO.getTopRow();

((RowBO) parent).setRow(rowCopy);

((WritableBO) parent).write();

dataFacade.replaceSyncBo(copyBO);

} catch (Exception e) {

throw new BOException("Failed updating ZContact" + e.toString());

}

}

The write function in ZContactImpl is given below

public void write() throws BOException {

// write to data access object

Field field;

try {

if (persnumber != null)

{

field = row.getField(FIELD_DESC_PERSNUMBER);

field.setValue(persnumber);

}

if(firstName != null)

{

field = row.getField(FIELD_DESC_FIRST_NAME);

field.setValue(firstName);

}

if(lastName != null)

{

field = row.getField(FIELD_DESC_LAST_NAME);

field.setValue(lastName);

}

} catch (Exception e) {

throw new BOException("Failed writing to Row: " + e.toString());

}

}

Please let me know if the code has any problems. I am using the framework generated by the application. The code doesnt seem to work as the data in the backend hasnt changed.

Regards

Raja Sekhar

kishorg
Advisor
Advisor
0 Kudos

Hi Raja,

right now u r using the SP 9 version of NWDS for MI Application development.

thats why u r facing this problem. Applications in SP 09 is not generic, to migrate it into other versions it is too difficult. atleast use the SP 11 version of Studio.

application developments in sp11 is entirely different and generic one.

Regards

Kishor Gopinathan

kishorg
Advisor
Advisor
0 Kudos

Hi Raja ,,

use this code

For modifying a particular Sync Bo instance ,

for example modifying the header ,

first u have to find ou the particular Sync Bo Instance.

for this u need sync key of that particular sync bo instance ..

anyway if you are going for modification , then u will have the

synckey for that instance .

using this sync key ,

u can find out the sync bo instance in this way..

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

SyncBo sb = null;

try {

sb = dataFacade.getSyncBo(sbd,<syncKey>);

} catch (PersistenceException pex) {

}

so we have the particular sync bo instance..

SmartSyncTransactionManager transactionManager;

transactionManager = dataFacade.getSmartSyncTransactionManager();

if (!transactionManager.isTransactionStarted())

transactionManager.beginTransaction();

// then use the setHeaderFieldValue method in the SmartSyncDB Access.

setHeaderFieldValue(sb,<header field Name>,<value>);

//Commit the transaction

transactionManager.commit();

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

// Method to set the value in header .. in this some exceptions are also handled.. u can use this method

public boolean setHeaderFieldValue(

SyncBo sb,

String headerFieldName,

Object value) {

SyncBoDescriptor sbd = sb.getSyncBoDescriptor();

RowDescriptor trd = sbd.getTopRowDescriptor();

FieldDescriptor fd = trd.getFieldDescriptor(headerFieldName);

if (fd != null) {

BasisFieldType bft = fd.getFieldType();

Row header = sb.getTopRow();

try {

// Integer operator

if (bft == BasisFieldType.N) {

NumericField nf = header.getNumericField(fd);

if (nf != null) {

BigInteger ii = new BigInteger(value.toString());

nf.setValue(ii);

return true;

} else {

return false;

}

}

// Character operator

if (bft == BasisFieldType.C) {

CharacterField cf = header.getCharacterField(fd);

if (cf != null) {

cf.setValue(value.toString());

return true;

} else {

return false;

}

}

// Decimal operator

if (bft == BasisFieldType.P) {

DecimalField df = header.getDecimalField(fd);

if (df != null) {

BigDecimal bd = new BigDecimal(value.toString());

df.setValue(bd);

return true;

} else {

return false;

}

}

// Similar operation for time and date operator fields

if (bft == BasisFieldType.D) {

DateField df = header.getDateField(fd);

if (df != null) {

if (value.toString().equals("0")) {

Date dat = Date.valueOf("0000-00-00");

df.setValue(dat);

} else if (!value.toString().equals("")) {

Date dat = Date.valueOf(value.toString());

df.setValue(dat);

} else {

Calendar cal = Calendar.getInstance();

java.sql.Date bd =

new java.sql.Date(cal.getTime().getTime());

df.setValue(bd);

}

return true;

} else {

return false;

}

}

// Similar operation for time and date operator fields

} catch (SmartSyncException ex) {

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

} catch (PersistenceException e) {

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

}

}

return false;

}

let me know , if u have doubts..

Regards

Kishor Gopinathan

kishorg
Advisor
Advisor
0 Kudos

Hi Raja,

i have written some sample code templates in these forums..

just go throught these forums.

let me know , if u have doubts..

Regards

Kishor Gopinathan

Former Member
0 Kudos

Hello Raja,

You can use following code.

private static final FieldDescriptor FIELD_DESC_WEIGHT =

ROW_DESC.getFieldDescriptor("WEIGHT");

<b>Field weightField = row.getField(FIELD_DESC_WEIGHT);

weightField.setValue(weight);</b>

I think this will solve your problem.