cancel
Showing results for 
Search instead for 
Did you mean: 

display only selected data from model output in a table

Former Member
0 Kudos

Hi Experts,

After my BAPI execute,it is returning output in a table and I need to separate the table data based on one parameter(type, which returns success or error).and display all the success in one table and errors in a separate table in the view.How will Go ahead with this.

Please find my code:

if(wdContext.nodeMaterial_Table_Out().size()!=0){

for(int i=0;i<wdContext.nodeMaterial_Table_Out().size();i++){

if(wdContext.nodeMaterial_Table_Out().getMaterial_Table_OutElementAt(i).getType().equalsIgnoreCase("S")){

wdComponentAPI.getMessageManager().reportSuccess("Came here in 2nd BAPI Output");

//Here I need to set it to the success table

}

else{

wdComponentAPI.getMessageManager().reportSuccess("Error here"+wdContext.nodeMaterial_Table_Out().getMaterial_Table_OutElementAt(i).getMaterial());

responseFromBAPI.put(wdContext.nodeMaterial_Table_Out().getMaterial_Table_OutElementAt(i).getMaterial(),wdContext.nodeMaterial_Table_Out().getMaterial_Table_OutElementAt(i).getMessage());

//here I need to set it to the error table, How will I do that?

}

}

}

}

My model output node is:

Z_BAPI

--Output(output node)

-


Table_Output(Bapi returns output in a table)

-


Material(Value Attribute)

-


Type(Value Attribute)

I need to display material and type in the two tables.

Please provide me valuable suggestions/code..

Thanks

Anjana.

Accepted Solutions (1)

Accepted Solutions (1)

former_member751941
Active Contributor
0 Kudos

Hi Anjana,

Take value nodes

ErrorNode

|----Material(Value Attribute)

|----Type(Value Attribute)

SuccessNode

|----Material(Value Attribute)

|----Type(Value Attribute)

Create View layout using the ValueNode.

Then write the code

if(wdContext.nodeTable_Output().size()> 0){

for(int i=0;i<wdContext.nodeTable_Output().size();i++){

if(wdContext.nodeTable_Output().getTable_OutputElementAt(i).getType().equalsIgnoreCase("S")){

IPrivate<Component Name>View.ISuccessNodeElement succElm = wdContext.createSuccessNodeElement();

succElm.setMaterial(wdContext.nodeTable_Output().getTable_OutputElementAt(i).getMaterial());

succElm.setType(wdContext.nodeTable_Output().getTable_OutputElementAt(i).getType());

wdContext.nodeSuccessNode().addElement(succElm);

}

else{

IPrivate<Component Name>View.IErrorNodeElement errElm = wdContext.createErrorNodeElement();

errElm.setMaterial(wdContext.nodeTable_Output().getTable_OutputElementAt(i).getMaterial());

errElm.setType(wdContext.nodeTable_Output().getTable_OutputElementAt(i).getType());

wdContext.nodeErrorNode().addElement(errElm);

}

}

else

{

wdComponentAPI.getMessageManager().reportException("Data not Found.",true);

}

Regards,

Mithu

Answers (2)

Answers (2)

Former Member
0 Kudos

Hi Manoj and Mithu,

Thanks a lot for ur responses. The code was really userful!

Have awarded points...

I am able to generate the success table. But for the error table, sorry for not mentioning one thing before: I am calling one bapi before calling the Z_BAPI. I have "success" and "error" messages from that bapi too. and then based on the "success" ones I am calling the second BAPI. Here, I am storing the "errors" in a hashmap because later I need to combile this 'errors' with the 'errors' from the second bapi and bind it to the error node.

HashMap responseFromBAPI = new HashMap();

if(wdContext.nodeMaterial_Variant_Res().size() != 0){

for(int i=0;i<wdContext.nodeMaterial_Variant_Res().size(); i++){

if(wdContext.nodeMaterial_Variant_Res().getMaterial_Variant_ResElementAt(i).getType().equalsIgnoreCase("S")){

//call another bapi

//create obj of the strucutue and set values

IMaterial_Variant_ResElement row2 = wdContext.nodeMaterial_Variant_Res().getMaterial_Variant_ResElementAt(i);

Zmmweb_St_Material_Variant mvObject2 = new Zmmweb_St_Material_Variant();

mvObject2.setCountry(row2.getCountry());

mvObject2.setCustomer_Code(row2.getCustomer_Code());

mvObject2.setLanguage(row2.getLanguage());

mvObject2.setPrice_Zone(row2.getPrice_Zone());

mvObject2.setVersion(row2.getVersion());

createInput.addMaterial_Table(mvObject2);

// main node obj.add(strucute obj)

wdComponentAPI.getMessageManager().reportSuccess("Came here"+wdContext.nodeMaterial_Variant_Res().getMaterial_Variant_ResElementAt(i).getMaterial());

}

else{

wdComponentAPI.getMessageManager().reportSuccess("Error here"+wdContext.nodeMaterial_Variant_Res().getMaterial_Variant_ResElementAt(i).getMaterial());

responseFromBAPI.put(wdContext.nodeMaterial_Variant_Res().getMaterial_Variant_ResElementAt(i).getMaterial(),wdContext.nodeMaterial_Variant_Res().getMaterial_Variant_ResElementAt(i).getMessage());

}

}

// call comp controller method...

wdThis.wdGetDISTitleCreateAndMaintainController().Z_Mmweb_Material_Create_Input();

if(wdContext.nodeMaterial_Table_Out().size()!=0){

for(int i=0;i<wdContext.nodeMaterial_Table_Out().size();i++){

if(wdContext.nodeMaterial_Table_Out().getMaterial_Table_OutElementAt(i).getType().equalsIgnoreCase("S")){

wdComponentAPI.getMessageManager().reportSuccess("Came here in 2nd BAPI Output");

IPrivateCreateVariant.ISuccessNodeElement succElm = wdContext.createSuccessNodeElement();

succElm.setMaterial(wdContext.nodeMaterial_Table_Out().getMaterial_Table_OutElementAt(i).getMaterial());

succElm.setMessage(wdContext.nodeMaterial_Table_Out().getMaterial_Table_OutElementAt(i).getMessage());

wdContext.nodeSuccessNode().addElement(succElm);

}

else{

wdComponentAPI.getMessageManager().reportSuccess("Error here"+wdContext.nodeMaterial_Table_Out().getMaterial_Table_OutElementAt(i).getMaterial());

responseFromBAPI.put(wdContext.nodeMaterial_Table_Out().getMaterial_Table_OutElementAt(i).getMaterial(),wdContext.nodeMaterial_Table_Out().getMaterial_Table_OutElementAt(i).getMessage());

}

}

}

Right now I have taken both the errors to the same hashmap -'responseFromBAPI'. Will that overwrite my first 'error' objects?

How will I combine both these errors and display in one table binded to 'ErrorNode'

Please help me in figuring out this.

Thanks

Anjana.

Former Member
0 Kudos

Hi,

It is clear from your code that while populating the hashmap you are using different key values as your attribute values at both the places. Hence, it will not overwrite the previous values.

Hence the same hashmap you can use to show the errors.

thanks & regards,

Manoj

Former Member
0 Kudos

Hi,

How can I take the data from the hashmap and populate it in the error node?

Thanks

Anjana

Former Member
0 Kudos

Hi,

You can convert hashmap to List in a loop using:

List list = new ArrayList();

list.add(map.values());

Then bind to your node:

wdContext.node<node name>().bind(list);

Else you can use the List directly instead of hashmap.

thanks & regards,

Manoj

Former Member
0 Kudos

Hi,

Your approach is correct. For this you need to create two nodes of same structure as of your output node, one for success and another for error table.

Then in if case, create the element of successNode and set its attributes and then add it to the node. In this way the successNode consist of all the success. This node you can map as dataSource of your success table.

Similarly you can, populate the errorNode in your else part and bind it to the dataSource of your error table.

The code which you can use:

IPrivate<View name>.ISuccessElement success = wdContext.createSuccessElement();

success.setMaterial(<current index material>);

success.setType(<current index type>);

wdContext.nodeSuccess().bind(success);

Similarly for error case you can populate the erroeNode.

thanks & regards,

Manoj

Edited by: Manoj Kumar on Dec 17, 2007 11:22 AM