cancel
Showing results for 
Search instead for 
Did you mean: 

Java coding for ADD, DELETE & CHANGE functionality in Smart Sync Appln

Former Member
0 Kudos

Hello Everybody,

I have developed a smartsync appln with all the five types of bapi wrappes.

I want to enable the application to insert, delete or modify records fom the client.

We need to insert a lot of java code in the already auto generated java code in NWDS.

Can anyone help me as to how to go about it.

I am using sp13 Patch 00.

Thanks and Regards,

Saurabh

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi Saurabh,

Here is the sample Java code for ADD,MODIFY,DELETE functionality...its our code which we have developed for our small MI application.....Kindly go through it and u will surely find this helpful and based on this u can expand ur requirements and develop still furthur code.

<b>Add Header</b>

public void createRow(String syncboName, HashMap datas){

SyncBoDescriptor syncBoDescriptor = descriptorFacade.getSyncBoDescriptor(syncboName);

try{

SyncBo syncBo = dataFacade.createEmptySyncBo(syncBoDescriptor);// create syncBo instance

Row row = syncBo.getTopRow();

RowDescriptor rowDescriptor = row.getRowDescriptor();

FieldDescriptorIterator fieldDescriptorIterator = rowDescriptor.getAllFieldDescriptors();

System.out.println("RowCountBefore" + syncBo.getRows().length);

while (fieldDescriptorIterator.hasNext()) {

FieldDescriptor fieldDescriptor =

(FieldDescriptor) fieldDescriptorIterator

.next();

Field field = row.getField(fieldDescriptor);

if(datas.containsKey(fieldDescriptor.getFieldName())) {

if(fieldDescriptor.getFieldType().getClientRepresentation() == java.sql.Date.class){

row.modifyFieldValue(fieldDescriptor, Date.valueOf((String)datas.get(fieldDescriptor.getFieldName())));

}else if(fieldDescriptor.getFieldType().getClientRepresentation() == Calendar.class){

simpleTimeFormat.parse((String)datas.get(fieldDescriptor.getFieldName()));

Calendar cal = simpleTimeFormat.getCalendar();

row.modifyFieldValue(fieldDescriptor, cal);

}else{

row.modifyFieldValue(fieldDescriptor, datas.get(fieldDescriptor.getFieldName()));

}

}

}//END_WHILE

dataFacade.insertSyncBo(syncBo);

}catch(Exception e){

System.err.println(e.toString());

}

}

<b>Modify Header</b>

public void modifyRow(String synboName, String syncKey, HashMap datas) {

SyncBoDescriptor syncBoDescriptor =

descriptorFacade.getSyncBoDescriptor(synboName);

try {

MeIterator meIterator2 =

dataFacade

.getRows(syncBoDescriptor.getTopRowDescriptor())

.iterator();

while (meIterator2.hasNext()) {

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

if(row.getSyncKey().equals(syncKey)) {

RowDescriptor rowDescriptor =

row.getRowDescriptor();

FieldDescriptorIterator fieldDescriptorIterator =

rowDescriptor.getAllFieldDescriptors();

while (fieldDescriptorIterator.hasNext()) {

FieldDescriptor fieldDescriptor =

(FieldDescriptor) fieldDescriptorIterator

.next();

Field field = row.getField(fieldDescriptor);

if(datas.containsKey(fieldDescriptor.getFieldName())) {

if(fieldDescriptor.getFieldType().getClientRepresentation() == java.sql.Date.class){

row.modifyFieldValue(fieldDescriptor, Date.valueOf((String)datas.get(fieldDescriptor.getFieldName())));

}else if(fieldDescriptor.getFieldType().getClientRepresentation() == Calendar.class){

simpleTimeFormat.parse((String)datas.get(fieldDescriptor.getFieldName()));

Calendar cal = simpleTimeFormat.getCalendar();

row.modifyFieldValue(fieldDescriptor, cal);

}else {

row.modifyFieldValue(fieldDescriptor, datas.get(fieldDescriptor.getFieldName()));

}// end of else loop

}// end of if loop

}//END_WHILE

row.getSyncBo().modifyRow(row);

}

}//END_WHILE

} catch (Exception e) {

System.err.println(e.toString());

}

}

<b>Delete Header</b>

public void deleteRow(String synboName, String syncKey) {

SyncBoDescriptor syncBoDescriptor =descriptorFacade.getSyncBoDescriptor(synboName);

//JLog.print("SyncBoDescriptor : " + syncBoDescriptor);

try {

MeIterator meIterator2 =dataFacade.getRows(syncBoDescriptor.getTopRowDescriptor()).iterator();

System.out.println("RowCountBeforeDelete:" + meIterator2.elementCount());

while (meIterator2.hasNext()) {

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

if(row.getSyncKey().equals(syncKey)) {

dataFacade.deleteSyncBo(row.getSyncBo());

}

}

} catch (Exception e) {

//JLog.print(e.toString());

}

}

Hope this is helpful to some extent.

Cheers,

Karthick

Former Member
0 Kudos

Hey Karthick,

thanks a lot for this great help.

I could understand most of it. I just have a few queries :-

1. I have never used HashMap. can you tell me with the help of your example what is it that you pass in this hashmap object.

2. Also tell me how do you create this HashMap instance.

3. Is that these three methods are all what you need to enable these functionalities or there are some others also required.

4. Which is the class wherein you can include this code. Where did you do it for your application.

5. Lastly can you just use this code and insert it in the auto generated java code. Or do you even need to write that.

Thanks & Regards,

Saurabh.

Former Member
0 Kudos

Hi Saurabh,

1) Hash map is the collection to hold key-value and data....

For ex: when we give a sync key it gives all the value related to that synckey.

2) HashMap map = new HashMap( );

3) May be you can try for child items also.

4) SyncboDataAccess

5) Yeah we can use it in autogenerated java code......just change/pass the parameters accordingly..

Hope its helpful

Cheers,

Karthick

Former Member
0 Kudos

Hi Karthick,

Do you mean that for a particular synckey the hashmap will give you the data related to that entire row that of all the fields

I got it as to how to create the Hashmap.

Can you tell me as to when you pass this HashMap obj to the add and modify functions what does it contain.

The creation statement of the hashmap u just sent creates an empty Hashmap right. so will it not have to contain something more when it is passed to these functions.

Also do you call these methods directly from the servlet class when the add or modify event is fired.

Kindly continue helping.

Thanks & Regards,

Saurabh.

Former Member
0 Kudos

Hi Saurabh,

Hope the following is useful to some extent.

1) Create JSP in JSP folder

2) JSP-->Decleared in constants

3) Once the JSP pages are created....click on create button..for this events should be coded in Servlets

4) Once the data is created ..we need to save it..dsata to be saved locally..so we press save button...[ Smart DB access]

5) TCP(Table content provider) is used to connect with Servlets and Smart DB access

These are the very basic steps to implement ADD,DELETE,MODIFY functionalities using Smart synchronization(once the skelten is created using Netweaver developer studio).

To implement these we need to have good Java knowledge.

Cheers,

karthick

Answers (3)

Answers (3)

Former Member
0 Kudos

Hi Saurabh!

Just to add a little to what karthick was saying, Its not that you have to plug the code in the classes given Smart Sync Framework. You can create your own classes following the MVC pattern and use the APIs' given by MI. You will get a better understanding of the flow if you study the contoller , SmartsyncDB access and TablecontentProvider classes given by the framework.

View ( Input forms for ADD and Modify) can be easily handled using Jsp.

Thanks

Best Regards

Mohan.

Former Member
0 Kudos

Hello Karthick & Mohan,

Thnaks a lot for your interest in solving my query.

I have used the std classes in the generated code i.e. controller, tablecontentProvider, SmartSyncDbAccess and the functions add & modify provided in them.

I have been able to complete the functionality for ADD & now currently working on the modify and the delete part.

You both are right that the input forms can easily be handled by JSP.

However i would want to know from Karthick of his approach of using HashMap.

I still dont know that wen you pass the HashMap to the respective functions(add,modify...) what does it contain.

Again thanks lot for your efforts.

In the cuorse of further developing this application if i encounter any difficulties i will post them on the same link. I hope to get similar response from yourside.

And also once i am done with adding all the functionalities i shall also post some useful insights into developing such an appln.

Best Regards,

Saurabh

Former Member
0 Kudos

hi saurabh.

NWDS comes with the MDK which can get the documentation for the Javadoc API

of MI client as well as sample codes on how to use the APIs especially SmartSync

codes which you are looking for. in your NWDS go to

Help -> SAP Web AS Documentation -> SAP Web AS Technologies

Choose [SAP Mobile Development Kit] from the contents menu.

regards

jo

Former Member
0 Kudos

Hi Jo,

Thanks a lot for replying. I went thru the path you told me.

But there no literature under SAP Mobile Development Kit(MDK) -> Mobile Application Development.

There is a lot of info on Peripheral Input/Output Services under the same link. But this is not what i am looking for.

I have gone thru the smart Sync Inventory example in MDK. The problem that i am facing is that after i generate the syncBo and then provide the metaxml file to the NWDS, it generates the java code for that application.

Now this auto generated code has functionality only for display of header and item records. It does not have functionality as well as the GUI for Add, Delete and Modify functions.

When i try to analyze this auto generated code to that of the Inventory code there are a lot of differences in the two.

This is where i am stuck. i am not able to figure out what all methods and classes need to be added to make the code capable of doing these 3 functions also.

Kindly Help.

Thanks & Regards,

Saurabh.

Former Member
0 Kudos

Hello,

What code do you want to add to sync bos?

Julien.