on 06-26-2009 10:14 AM
Hi all,
I have a requirement to read my MDM main table using MDM Java APIs. In that main table there is a qualified look up flat table (MultiValue). Kindly give me sample code to do the same.
Regards,
Yogesh Bhatia.
Hello Yogesh,
Below are Steps to achieve the same:
Step 1: Fetch the tableId.
Step 2: Retrieve the field Ids of all the fields using:
int numOfFields = schema.getTableSchema(tableId).getFields().length;
/** Create an array to hold the field ids*/
FieldId fields[] = new FieldId[numOfFields];
/** Store the properties of each field in an array of <b>FieldProperties</b>*/
FieldProperties[] fieldProperties =
schema.getTableSchema(tableId).getFields();
for (int i = 0; i < numOfFields; i++) {
/** Store the field Properties into the array */
fields<i> = fieldProperties<i>.getId();
}
Step 3: Define ResultSet and use RetrieveLimitedRecordsCommand command to get all the records:
TableId tableId = getTableId(tableName);
FieldId fields[] = getAllFieldIdsOfTable(tableName);
/*Defining ResultSetDefinition/
ResultDefinition resultDef = new ResultDefinition(tableId);
resultDef.setSelectFields(fields);
Search search = new Search(tableId);
int j=1;
int pageIndx = 0;
RecordResultSet recordSet = null;
TableSchema tableSchema = null;
RetrieveLimitedRecordsCommand limitedRecordsCommand =
new RetrieveLimitedRecordsCommand(simpleConnection);
limitedRecordsCommand.setSearch(search);
limitedRecordsCommand.setSession(userSession);
limitedRecordsCommand.setPageIndex(pageIndx);
limitedRecordsCommand.setResultDefinition(resultDef);
limitedRecordsCommand.execute();
recordSet = limitedRecordsCommand.getRecords();
tableSchema = recordSet.getRecordMetadata();
if (recordSet.getCount() > 0) {
for (int i = 0; i < recordSet.getCount(); i++) {
recordsArr.add(new MdmRecord(recordSet.getRecord(i), tableSchema));
}
}
Iterator itr = recordsArr.iterator();
records = new MdmRecord[recordsArr.size()];
while(itr.hasNext()){
records[cnt] = (MdmRecord)itr.next();
cnt++;
}
records will give you all the records.
Step 4: Use
FieldProperties[] fields=tableSchema.getFields();
MdmValue mdmValue = mdmRecord.getFieldValue(fields[index].getId());
mdmValue will be the recordId of the look up field and using recordId we can easily get the record.
I think it will solve your problem
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Yogesh,
Though I don't have sample code , I would suggest you to explore the mdm api QualifiedLookupValue .
To get a documentation about the api use the below link
https://help.sap.com/javadocs/MDM/SP06/index.html
Regards
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
93 | |
11 | |
10 | |
9 | |
9 | |
7 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.