cancel
Showing results for 
Search instead for 
Did you mean: 

Retrieve Records based on Tuple Fields

Former Member
0 Kudos

Hello,

I am creating Webdynpro Java Application using MDM Java APIs and want to retrieve the Records from the Repository based on a Tuple Field in the Main table. Assuming the Main Table is M, which has a Tuple T and T has a tuplefield in it as TF. How can I do the same ?.

I am following the link : http://forums.sdn.sap.com/thread.jspa?threadID=1710567

but it's not exactly clear as to how to retrieve the records based on the TupleField.

Any help would be highly Appreciated.

Accepted Solutions (1)

Accepted Solutions (1)

former_member209780
Active Participant
0 Kudos

Hi,

Please update your findings and close the thread

Regards

Goutham Kanithi

Former Member
0 Kudos

Hello Goutham,

Here are my findings when I tried the first segment of code:

Got the error as : Field with ID 'F981_120988' does not exist in the table <Table Name> (T1) '

and with Second segment of code:

Displayed the Contents of Short Description Field of the Main Table.

Looking forward to your reply.

Thanks

former_member209780
Active Participant
0 Kudos

Hi,

As the error mentioned field ID does not exist in the table, check if you assigned the tuple as a field to the main table. Also I see that the field IDs shown in the error are different in your initial posts and the above post.

When you create a tuple, you have to assign a code for it and when you assign this tuple as a field to the main table, you give another code.

Try with both of these codes in <Tuple Field Code>

If this one also doesn't work, enter a lookup field code and check with the below code whether atleast lookups are working fine

FieldId f1 = RepositorySchema().getFieldId("<Main Table>","<Lookup Field Code>");

RecordResultSet recResultSet = rlc.getRecords( ) ;

Record rec = recResultSet.getRecord(0);

String lookupdf = rec.getLookupDisplayValue(f1);

Regards

Goutham Kanithi

Former Member
0 Kudos

Thanks for the reply. The field Id in the last post was different since I was trying to work with a different Tuple Field in the same main table . If I use the Old Tuple Field from which I want to to get the data ,I still get the error as below:

Field with ID 'F965_120970' does not exist in the table <Main Table> (T1).

And where can I find the code when the tuple is created and the code when you assign this tuple as a field in the Main table?

Pls help.

former_member209780
Active Participant
0 Kudos

Hi,

There are lot of things you have to consider, here are few

1. Whether you are using single valued tuple or multivalued tuple.

2. After creating a tuple, did you create a tuple field in the main table referencing to the tuple you created.

3. Which code you are using to retrive the tuple field Id (it should be the field code in Main table, not the tuple code)

Also please check the two things I mentioned in my previous post, lookup and tuple field codes

Hope this works

Regards

Goutham Kanithi

Former Member
0 Kudos

Hi,

Go to MDM Console:

Do a verify repository,if there are errors/warnings take a backup of the repository.

Do a repair.Load the repository with update indices.

Rerun your code and check if the error persists.

Pls revert.

Thanks,

Ravi

Former Member
0 Kudos

Hello Goutham,

1) The tuple I am trying to Reference is Multi-Value.

2) Tuple Field does exist in the Main Table as when I get the fields for the Table using FieldProperties ,it does print the Tuple Field.

3) I am using the Tuple Field Code in the Main Table as the Field Code exists for Other Fields in the same Main Table.

Looking forward to your reply.

Thanks

former_member209780
Active Participant
0 Kudos

Hi,

I recommend you to create a single valued tuple initially and try the previous code. If it works then you can go for Multivalued

If you are using a multivalued tuple, below is the code

FieldId f1 = RepositorySchema().getFieldId("<Main Table>","<Tuple Field Code>");

RecordResultSet recResultSet = rlc.getRecords( ) ;

Record rec = recResultSet.getRecord(0);

MultiTupleValue myTuple = (MultiTupleValue)rec.getFieldValue(f1);

TupleValue reqTuple = (TupleValue) myTuple.getValue(0);

String tupdf = reqTuple.getDisplayValue();

For further information, refer page number 11, in the below link

http://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/9039f92b-714b-2c10-d49f-a0cdf4e27...

Regrds

Goutham Kanithi

former_member209780
Active Participant
0 Kudos

Hi,

I recommend you to create a single valued tuple initially and try the previous code. If it works then you can go for Multivalued

If you are using a multivalued tuple, below is the code

FieldId f1 = RepositorySchema().getFieldId("<Main Table>","<Tuple Field Code>");

RecordResultSet recResultSet = rlc.getRecords( ) ;

Record rec = recResultSet.getRecord(0);

MultiTupleValue myTuple = (MultiTupleValue)rec.getFieldValue(f1);

TupleValue reqTuple = (TupleValue) myTuple.getValue(0);

String tupdf = reqTuple.getDisplayValue();

For further information, refer page number 11, in the below link

http://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/9039f92b-714b-2c10-d49f-a0cdf4e27...

Regrds

Goutham Kanithi

Former Member
0 Kudos

Hi,

Pls update if you have run a verify on your repository.

Thanks,

Ravi

Former Member
0 Kudos

@Goutham,

I am not sure if the MDM Team would change it to Single Value Tuple. I used the code you suggested for MultiTuple Value ,and

still I got the same error.

@Ravi,

We ran a Verify Repository,there was one non-fatal error which got fixed. After that I ran my code and still

got the same error.

Pls help.

Former Member
0 Kudos

Hi,

Thanks for the update.I hope you did run a "Repair" after you did "Verify".

Pls confirm.

Thanks,

Ravi

Former Member
0 Kudos

Yes. The Repair was done for the Repository

It's very strange as when I get the FieldCodes using the following code:

String[] fieldcodes = grepsch.getRepositorySchema().getFieldCodes("<TableCode>");

for(int f=0;f<fieldcodes.length;f++)

{

<messagemanager>.reportSuccess(fieldcodes[f].toString());

}

It prints <FieldCode> as one of Field Codes which I am using in the statement :

FieldId f1 = grepsch.getRepositorySchema().getFieldId("<TableCode>","<FieldCode>");

Edited by: PortalPerson on Feb 25, 2012 5:39 AM

Former Member
0 Kudos

Hello,

I noticed that the same error is occuring even if I am trying to access the FieldValue of a Non-Tuple Field through the Record

Pls help.

Former Member
0 Kudos

Any ideas. Please Help.

former_member209780
Active Participant
0 Kudos

Hi,

Check for your read/write access.

1) As you mentioned same error appears for lookup fields also, I think it is better to set some value in the lookup field and retrive it. just to test and find the fault

I am not sure about his code, as I didn't check due unavailabilty of IDE now. but still u can try it

FieldId f1 = RepositorySchema().getFieldId("<Main Table>","<Lookup Field Code>");

RecordResultSet recResultSet = rlc.getRecords( ) ;

Record rec = recResultSet.getRecord(0);

Record lookupRecords[] = rec.findLookupRecords(f1) ;

Record lookupRec = lookupRecords[0] ;

lookupRec.setFieldValue(f1, new StringValue("Test Lookup Value") );

RecordResultSet recResultSet = rlc.getRecords( ) ;

Record rec = recResultSet.getRecord(0);

Record lookupRecords[] = rec.findLookupRecords(f1) ;

Record lookupRec = lookupRecords[0] ;

String str = lookupRec.getFieldValue(f1).toString( ) ;

Print the string and check for the value.

2) If execution is not successful, check for the value in MDM and let me know your findings.

Try to put the value in a text field and retrive it

FieldId f1 = RepositorySchema().getFieldId("<Main Table>","<Text Field Code>");

RecordResultSet recResultSet = rlc.getRecords( ) ;

Record rec = recResultSet.getRecord(0);

rec.setFieldValue(f1, new StringValue("Test Text Value") );

RecordResultSet recResultSet = rlc.getRecords( ) ;

Record rec = recResultSet.getRecord(0);

String str = rec.getFieldValue(f1).toString( ) ;

Print the string and check for the value.

Regards

Goutham Kanithi

Former Member
0 Kudos

Hello,

When I try the first section of Code , I get the same error at the following line of code:

Record lookupRecords[] = rec.findLookupRecords(f1) ;

And with the 2nd section of code ,ie. If I first set the Field value and then retrieve/print the String value , it works fine.

Thanks

former_member209780
Active Participant
0 Kudos

Hi Rohit,

You have to add the field you want to retrive, to result set definition. As shown below

                                TableId mainTableId = schema.getTableId(“Products”);

                                ResultDefinitionEx resDef = new ResultDefinitionEx(“Products”, context);

                                resDef.addSelectField(“field_code”);

                                resDef.setLoadAttributes(true);

                                Search search = new Search(mainTableId);

                                RetrieveLimitedRecordsCommand command = new RetrieveLimitedRecordsCommand(

                                                                context);

                                command.setResultDefinition(resDef);

                                command.setSearch(search);

                                command.setSession(ses);

                                try {

                                                command.execute();

                                } catch (Exception e) {

                                                e.printStackTrace();

                                }

                                RecordResultSet recordResultSet = command.getRecords();

                                Record[] records = recordResultSet.getRecords();

follow the below link. you can directly execute the code from the below link.

Regards

Goutham Kanithi

Answers (6)

Answers (6)

former_member209780
Active Participant
0 Kudos

Hi,

try the below code

FieldId f1 = RepositorySchema().getFieldId("<Main Table>","<Tuple Field Code>");

RecordResultSet recResultSet = rlc.getRecords( ) ;

Record rec = recResultSet.getRecord(0);

String tupdf = rec.getTupleDisplayValue(f1);

Print the string tupdf and see if it works. If this didn't work:

FieldId f1 = RepositorySchema().getFieldId("<Main Table>","<Tuple Field Code>");

RecordResultSet recResultSet = rlc.getRecords( ) ;

Record rec = recResultSet.getRecord(0);

String df = rec.getDisplayValue();

Print the string df, view that record in datamanager and check whether tuple display field value exists for that record

Regards

Goutham Kanithi

former_member209780
Active Participant
0 Kudos

Hi,

Looks like records from the resultset are not populated in the record array. Just try with any other lookup field Id and check whether the value is retrived or not.

Instead of rlc.getRecords().getRecords(), rlc.getRecords() is sufficient I think.

Also check whether tuple value is assigned or not, for the index of records which you are giving (records[0])

Regards

Goutham Kanithi

Former Member
0 Kudos

Thanks for the reply.

I tried with another Tuple Field and it gives the same error.

rlc.getRecords() gives the RecordResultSet that's why I do rlc.getRecords().getRecords() to get the Record Array.

And I checked the Tuple Value for the record records[0] and there exists a value for it.

Pls help.

former_member209780
Active Participant
0 Kudos

Hi,

Looks like records from the resultset are not populated in the record array. Just try with any other lookup field Id and check whether the value is retrived or not.

Instead of rlc.getRecords().getRecords(), rlc.getRecords() is sufficient I think.

Also check whether tuple value is assigned or not, for the index of records which you are giving (records[0])

Regards

Goutham Kanithi

Former Member
0 Kudos

Hi,

This blog touches the topic and gives useful pointers :

http://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/9039f92b-714b-2c10-d49f-a0cdf4e27...

Thanks,

Ravi

Former Member
0 Kudos

Thanks for the replies.

I read the links and using the following code:

FieldId f1 = RepositorySchema().getFieldId("<Main Table>","<Tuple Field Code>");

Used the RetrieveLimitedRecordsCommand command to retrieve the Records from the Main Table which are coming fine as :

Record[] records = rlc.getRecords().getRecords(); // where rlc is the Object for RetrieveLimitedRecordsCommand

Then when I try to retrieve the TupleValue as below:

TupleValue tv = (TupleValue)records[0].getFieldValue(f1);

It throws an Exception At Runtime as :

java.lang.IllegalArgumentException: Field with ID 'F965_120970' was not populated or does not exist in repository for table 'T1' .

Please help with the same.

former_member209780
Active Participant
0 Kudos

Hi,

Below link has all the information and code samples on working with tuples using Java API.

http://help.sap.com/saphelp_nwmdm71/helpdata/en/f9/ff1d5f39c048eaa6e1eb7012004c32/frameset.htm

Retrieving Records with Search :

http://help.sap.com/saphelp_nwmdm71/helpdata/en/c7/a301320f534b4cb7b2d24df01ef31b/frameset.htm

Regards

Goutham Kanithi

Former Member
0 Kudos

Hello,

You may use the JAVA Help site for MDM JAVA APIs http://help.sap.com/javadocs

This link provides documentation on how to use various classes and their attributes.

With sample code

Regards,

Abhishek