cancel
Showing results for 
Search instead for 
Did you mean: 

Need to implement Comma Separated Search

Former Member
0 Kudos

Hi friends,

I am trying to create an application using the MDM.java API. The requirement is I have to implement comma separated search on one of the fields. Now the question is how to do that.

FYI

I am preparing a search criteria as

public void addSearchCriteria(

FreeFormTableParameter fftp,

String fieldname,

String value,

int searchTypeSign) {

if (value != null) {

FreeFormParameterField searchField =

fftp.GetFields().New(fieldname, searchTypeSign);

searchField.GetFreeForm().NewString(value, searchTypeSign);

}

Accepted Solutions (0)

Answers (2)

Answers (2)

Former Member
0 Kudos

Thank You friends. I got it done after some modifications.

Former Member
0 Kudos

Hi,

What do you mean by "comma-separated search"? Are you trying to search a field for one or more values? Please explain exactly your scenario.

Walter

Former Member
0 Kudos

Thanks Walter for your question. You are correct in this. I am trying to search a material from the back end for more than one values. The input to be given by the user will be AAAAA,BBBB.

The search results should return corresponding results for both of them.

Former Member
0 Kudos

CORRECTION : I am trying to search a field for one or more VALUES and not A MATERIAL

Former Member
0 Kudos

Hi Avik

Based on what i have understood from thread, The following code gets me the records based on the Alphabets using STARTSWITH Search constraint.

I hope this helps.


String[] alphabetsArray ={"A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"};
		RetrieveLimitedRecordsCommand retrieveLimitedRecordsCommand = null;	
		RetrieveRecordsByIdCommand objRecordsByIDCommand = null;
		Record[] taxoSubClassRecs = null;		
		String subClassCode = null;  
		//Compose the search
		//Create constraint and dimension for key word search			  
		FieldSearchDimension classificationSearchDim = new FieldSearchDimension(fields[0]); //  put the fieldID

		for(int k = 0; k <alphabetsArray.length;k++ )
		{
			TextSearchConstraint classificationSearchConstraint = new TextSearchConstraint(alphabetsArray[k],TextSearchConstraint.STARTS_WITH); // You have options of STARTSWITH/EQUALS/etc
			//Create the search and add the key word constraint
			com.sap.mdm.search.Search search = new com.sap.mdm.search.Search(mainTableId);
			search.addSearchItem(classificationSearchDim, classificationSearchConstraint);

			//Instantiate search command
			retrieveLimitedRecordsCommand = new RetrieveLimitedRecordsCommand(repository.getConnection());
			retrieveLimitedRecordsCommand.setSession(repository.getAuthenticatedUserSession().getSession());
			//Supply the result definitions and the search as argument to the command.
			retrieveLimitedRecordsCommand.setResultDefinition(rd);
			retrieveLimitedRecordsCommand.setSearch(search);

			//Execute the command and print the number of records found
						
			try 
			{
				retrieveLimitedRecordsCommand.execute();
				System.out.println("Number of records found for Alphabet: " +alphabetsArray[k]+ "=" + retrieveLimitedRecordsCommand.getRecords().getCount());

				
			} 
			catch (CommandException e) 
			{
				e.printStackTrace();
			} 		
			taxoSubClassRecs = retrieveLimitedRecordsCommand.getRecords().getRecords();

Cheers

Former Member
0 Kudos

Hi Navneet,

You have not understood my question.

I am trying to search a table in MDM and the search string that is passed is in the format "String1,String2". With reference to blog /people/andreas.seifried/blog/2006/03/26/performing-free-form-searches-with-mdm-java-api

I have tried the following.

+

public void addSearchCriteriaWithComma(

FreeFormTableParameter fftp,

String fieldname,

String value,

int searchTypeSign) {

if (value != null) {

FreeFormParameterField searchField =

fftp.GetFields().New(

fieldname,

FreeFormParameterField.SEARCH_OPERATOR_OR);

StringTokenizer valueToken = new StringTokenizer(value,",");

// StringTokenizer valueToken = new StringTokenizer("7000318,7000324", ",");

while (valueToken.hasMoreTokens()) {

value = valueToken.nextElement().toString();

searchField.GetFreeForm().NewString(value, searchTypeSign);

}

}

}

+

But this doesn't seem to work.The StringTokenizer should take the values and pass it to the searchField for Searching.

Please help.