cancel
Showing results for 
Search instead for 
Did you mean: 

Search for maintable records with numeric attribute values via Java API

Former Member
0 Kudos

Hello Experts,

I have a requirement to search for maintable records with numeric attribute values (EQUALS, GRATER THAN, LESS THAN).

I create at first my Search object:

Search mainSearch = new Search(MainTableId);

afterwards I try to create SearchItem with:

AttributeSearchDimension searchDim = new AttributeSearchDimension( taxFieldId , attributeId );
MeasurementValue measValue = new MeasurementValue(equalsDb, unitId);
MeasurementSearchConstraint searchConstr = new MeasurementSearchConstraint(measValue,MeasurementSearchConstraint.EQUALS);					
searchItem = new SearchParameter ( searchDim , searchConstr );
mainSearch.addSearchItem( searchItem );

than I create an RetrieveLimitedRecordsCommand:

RetrieveLimitedRecordsCommand retrLimRecCom = null;
		try {
			retrLimRecCom = new RetrieveLimitedRecordsCommand ( this.userSessionContext );
		} catch (SessionException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		} catch (ConnectionException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
		retrLimRecCom.setSession( this.session );
		retrLimRecCom.setSearch( mainSearch );
		retrLimRecCom.setResultDefinition( this.resDef );

after executing the command:

		try {
			retrLimRecCom.execute();
		} catch (CommandException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

I get an error message:

com.sap.mdm.commands.CommandException: com.sap.mdm.internal.protocol.manual.ServerException: Server error (0xffaa2009)
	at com.sap.mdm.data.commands.AbstractRetrieveLimitedRecordsCommand.execute(AbstractRetrieveLimitedRecordsCommand.java:180)
	at com.sap.mdm.data.commands.RetrieveLimitedRecordsCommand.execute(RetrieveLimitedRecordsCommand.java:173)

According to MDM Java API I can use MeasurementSearchConstraint with AttributeSearchDimension.

Can anyone give me a hint, why doesn't it work?

Thanks,

Nico

Accepted Solutions (0)

Answers (2)

Answers (2)

Former Member
0 Kudos

Hi RajaSekhar,

thank you for your answer. It was very helpful. It works with my code properly. I changed only one thing. In my code I created AttributeId only with the integer value and now I use your code for creating attribute:

AttributeId attributeId=new AttributeId(attrId,AttributeId.NOMINAL_RATING);

And it works! Many thanks!

Regards

Nico

Former Member
0 Kudos

Nico,

I have the same requirements. Can you please post your code... I have a record that has some values and now i want to pull similar records if there are any??

Thanks in Advance for your help

Former Member
0 Kudos

Nico,

I guess you are following appropriate approach except minor changes needed;

As you are trying to get mainTable Records based on attribute values, you need to pass Taxonomy FieldID and AttributeID to AttributeSearchDimension and search for Numeric Attribute Values, convert the values into MDMValues , pass the value to PickListSearchConstraint as follows;

MeasurementSearchConstraint might not be suitable for the above requirement , but you can use PickListSearchConstraint();

look at the following example;

Example:-

public void addAttributesValuesToSearch(Search search,Attribute attributes[],FieldId taxFieldId)

{

SearchDimension dim;

SearchConstraint cons;

if(attribute.getType()==AttributeType.NUMERIC.getId() && attribute.getNumericValues().length>0)

{

AttributeId attributeId=new AttributeId(attribute.getId(),AttributeId.NOMINAL_RATING);

dim=new AttributeSearchDimension(taxFieldId,attributeId);

NumericAttributeValue[] numericAttributeValue=attribute.getNumericValues();

MdmValue[] mdmValue=new MdmValue[numericAttributeValue.length];

for(int m=0;m<numericAttributeValue.length;m++)

{

MeasurementValue measurementValue=new MeasurementValue(numericAttributeValue[m].getValue(),new UnitId(numericAttributeValue[m].getUnitId()));

mdmValue[m]=measurementValue;

}

cons=new PickListSearchConstraint(mdmValue);

if(mdmValue.length>0)search.addSearchItem(dim,cons);

}

}

if you still face the problem , let me know;

Regards

RajaSekhar K