on 02-16-2012 5:08 AM
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.
Hi,
Please update your findings and close the thread
Regards
Goutham Kanithi
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
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
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.
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
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
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
Regrds
Goutham Kanithi
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
Regrds
Goutham Kanithi
@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.
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
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
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
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
This blog touches the topic and gives useful pointers :
Thanks,
Ravi
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
80 | |
9 | |
9 | |
7 | |
7 | |
6 | |
6 | |
6 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.