cancel
Showing results for 
Search instead for 
Did you mean: 

Lookup table id from Main table Field ID

Former Member
0 Kudos

Hi,

I have created a progam to update the records in main table.

But, in the case of Lookup fields, I have to pass the Lookup table's record id into the main table.

In order to achieve this, I have to find out the Lookup Table id.

Can any one , please let me know how to retrieve the lookup table record id, by giving Main table lookup field id as the input.

Thanks,

Priya.

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi Priya,

I am attaching the sample code.Sure this will help you

GetRepositorySchemaCommand getRepSchemaCmd = new GetRepositorySchemaCommand(connection);

getRepSchemaCmd.setSession(sessionId);

try

{

getRepSchemaCmd.execute();

}

catch(CommandException e)

{

System.out.println(e.getLocalizedMessage());

}

RepositorySchema repSchema = getRepSchemaCmd.getRepositorySchema();

TableId lookupTableId = new TableId("Countries"); //Countries is the code of the lookup table

ResultDefinition rd = new ResultDefinition(lookupTableId);

//Select all records

Search search = new com.sap.mdm.search.Search(lookupTableId);

//Get fields

GetFieldListCommand getFieldListCommand = new GetFieldListCommand(connection);

getFieldListCommand.setSession(sessionCommand.getUserSession());

getFieldListCommand.setTableId(lookupTableId);

try

{

getFieldListCommand.execute();

}

catch (CommandException e)

{

System.out.println(e);

}

FieldProperties[] lookupFields = getFieldListCommand.getFields();

//Add fields to records to retrieve

rd.addSelectField(repSchema.getFieldId("Countries","Name"));

rd.addSelectField(repSchema.getFieldId("Countries","Code"));

//Retrieve the records

RetrieveLimitedRecordsCommand retriveLimRecCommand = new RetrieveLimitedRecordsCommand(connection);

retriveLimRecCommand.setSession(sessionId);

retriveLimRecCommand.setResultDefinition(rd);

retriveLimRecCommand.setSearch(search);

try

{ retriveLimRecCommand.execute();

}

catch (CommandException e)

{

e.printStackTrace();

}

System.out.println("Record count is " + retriveLimRecCommand.getRecords().getCount()+"\n");

Record[] records = retriveLimRecCommand.getRecords().getRecords();

System.out.print(records[3].getFieldValue(repSchema.getFieldId("Countries","Code"))+" ");

I am using System.out.print you can pass this value while modifying the main table field.

Hope this will help you...

Please let me know if any further help is required.

Regards,

Jitesh Talreja

Former Member
0 Kudos

Hi,

Thanks for the reply....

In your case, you know the Lookup Table Name(Code), so, you have retrieved the table id.

But my case is like, I know, there is a field in Main table of type Lookup Flat.

I know the field Id of that field in the main table.

Now, with this information how will I retrieve, which is the Lookup table that is liked to the main table field., ie the name of the lookup table, linked to the main table field.

Thanks,

Priya.

Former Member
0 Kudos

Hi Priya,

There is a class known as LookupFieldProperties (int fieldid)

which consists of the method getLookupTableId() which returns the object of class TableId .Now you can use this TableId in the above code to retrieve the records from the lookup table.

Regards,

Jitesh Talreja

Former Member
0 Kudos

HI,

I have tried this also, but it did not work

int intfieldId = fieldProp[t].getId().getIdValue();

LookupFieldProperties lookupProp = new LookupFieldProperties(intfieldId);

I got an error as

Exception in thread "main" java.lang.UnsupportedOperationException

at com.sap.mdm.schema.fields.LookupFieldProperties.<init>(LookupFieldProperties.java:22)

at programs.ModifyRecord.main(ModifyRecord.java:102)

Thanks,

Priya.

Former Member
0 Kudos

Hi Priya,

int intfieldId = fieldProp[t].getId().getIdValue();

LookupFieldProperties lookupProp = new LookupFieldProperties(intfieldId);

LookupFieldProperties (int type)

parameter should specify the type of lookup like Flat,Qualified,Hierarchy etc not the field id.

So instead of passing fieldid try passing field type.

E.g.LookupFieldProperties lfp=new LookupFieldProperties(fieldProp[t].getType())

Regards,

Jitesh Talreja

Former Member
0 Kudos

Hi,

I tried passing the table typr, but still my issue is not solved, i am getting null in the output.

int intfieldId = fieldProp[t].getType();

LookupFieldProperties lookupProp = new LookupFieldProperties(intfieldId);

Thanks,

Priya.

Former Member
0 Kudos

This functionlaity is not present in the new MDM Java API's, so MDM4J jar files should be used to get this done.

Thanks,

Priya.

nitin_mahajan2
Contributor
0 Kudos

How?

Former Member
0 Kudos

Hi,

You can get this through MAM Java API's itself, MDM4J is not required.

LookupFieldProperties lookupFieldSer = (LookupFieldProperties) lookupFieldProp;

Table Id lookupTable = lookupFieldSer.getLookupTableId();

lookupFieldProp -


> Lookup Field Properties in Main Table.

lookupTable -


> Lookup table id.

Thanks,

Priya.

nitin_mahajan2
Contributor
0 Kudos

Yea i managed to work on that after a few hours of head banging with the API's. Just checked your reply, Thanks any ways.

Answers (1)

Answers (1)

Former Member
0 Kudos

Hi Priya,

I think, by applying a drill down search in Data Manager on the look up table field, u ll be able to get the look up table record id.

Thanks and Regards,

shreya.

Edited by: Shreya Landge on Apr 3, 2008 12:08 PM

Former Member
0 Kudos

Hi,

Before doing the search for record id, i need to retrieve the Lookup table Id.

How to retrieve the Lookup Table ID, by giving Main table field id as input.

Thanks,

Priya.

Former Member
0 Kudos

Hi Priya,

In MDM according to me, there is no look up table id. Yes, there is System id, Global id etc .... But Look up tables are associated with names only. I really doubt if any Id remains assoicated with them.

TNR

Shreya.

Former Member
0 Kudos

Hi,

I think you did not understand me.

I forgot to tell you, I am using Java API's to do this.

So, while using Java API, every Record, every Table and every field is associated with with an id.

so now, my concern, is to find the lookup table name or atleast the lookup table id, when main table field id is given as the input.

Thanks,

Priya.