cancel
Showing results for 
Search instead for 
Did you mean: 

How to get values from R/3 dynamically into dropdownlist of my WD appl

Former Member
0 Kudos

Hi all,

Can any one plz send a PDF/blogs that talks abt <b>accessing data from R/3 (ofcourse by executing a Bapi in WebDynpro appl) into dropdown list or objectvaluehelp of my WD appl.</b>

All helpful answers are highly rewarded.

regards,

Ganesh

Accepted Solutions (1)

Accepted Solutions (1)

sridhar_k2
Active Contributor
0 Kudos

Hi,

Create a context Variable in your View with empcode.

empCode - whichever you want to see in the DropDownListByKey.

IContextElement contextElement = wdContext.currentContextElement();

IWDNodeInfo nodeInfo = wdContext.getNodeInfo();

IWDAttributeInfo dateAttributeInfo = nodeInfo.getAttribute(contextElement.empCode);

IModifiableSimpleValueSet dropValueSet = dateAttributeInfo.getModifiableSimpleType().getSVServices().getModifiableSimpleValueSet();

String empCodeTxt=null;

//Gives the Size of the List, which is coming from Model

int nodeLength = wdContext.node<BAPIList>().size();

for (int i = 0; i < nodeLength; i++) {

// Gives the Value, Which you want to show in Drop Down List Box.. Change it according to your need.

empCodeTxt=String.valueOf(((IPrivate<viewname>.I<BAPIList>Element)(wdContext.node<BAPIList>().getElementAt(i))).get<Parameter>());

dropValueSet.put(empCodeTxt, empCodeTxt);

}

Regards,

Sridhar

Former Member
0 Kudos

Hi Sridhar,

Where the code you mentioned shud be placed, is it in wdInit() or where?

Thanks a lot

regards,

Ganesh

Former Member
0 Kudos

Hi,

You should place in doModifyView()

Regards,

Saravanan K

Former Member
0 Kudos

Hi Sridhar,

Where shud I write the code mentioned by you.

Thanks a lot.

regards,

Ganesh

sridhar_k2
Active Contributor
0 Kudos

Hi Ganesh,

You can keep that code any where in your program. Just before accessing that drop down . Good to keep in the wdInit().

Regards,

Sridhar

Former Member
0 Kudos

Hi Sridhar,

In my appl, when a number is selected from dropdown list the corresponding elements have to be bpopulated. The Bapi does the work of extracting the elements when I select some material number from dropdown list.The dropdown list has to be populated with values from backend.

For this I have created a SimpleType under LocalDictionary called <b>matnum</b>. Then in Context of custom controller I created a value attribute called <b>matnum</b> and kept its type as matnr (which is of type model attribute.)

In the wdInit() method of my Custom controller the code is:

IContextElement conElement=wdContext.currentContextElement();

IWDNodeInfo nodeInfo=wdContext.getNodeInfo();

IWDAttributeInfo matAttrInfo=nodeInfo.getAttribute(conElement.MATNUM);

IModifiableSimpleValueSet dropValueSet=matAttrInfo.getModifiableSimpleType().getSVServices().getModifiableSimpleValueSet();

String matnum=null;

int nodeLength=wdContext.nodeY_Ep_MatGD_Input().size();

for(int i=0;i<nodeLength;i++)

{

matnum=String.valueOf(((IPrivateMaterialgdCompView.IY_Ep_MatGD_InputElement)

(wdContext.nodeY_Ep_MatGD_Input().getElementAt(i))).getMatnr());

dropValueSet.put(matnum,matnum);

}

Y_Ep_Demo_Material_Get_Data_Input input=new Y_Ep_Demo_Material_Get_Data_Input();

wdContext.nodeY_Ep_MatGD_Input().bind(input);

*********and in excuteY_Ep() method of Custom controller:

try{

wdContext.currentY_Ep_MatGD_InputElement().modelObject().execute();

} catch(Exception ex){

ex.printStackTrace();

}

and in my View I have defined a button when I select and press the button the elements have to be populated.

wdThis.wdGetMaterialgd_CustController().executeY_Ep();

When I run this appl, the dropdown list is empty. Please suggest me.

Thanks in advance

Former Member
0 Kudos

Hi Ganesh,

The value attribute matnum that you have created - is it bound to the selectedKey property of the DropDownByKey?

In that case its type should be the type created in local dictionary, i.e. matnum in your case. It shouldn't be of model attribute type.

Regards,

Satyajit.

Former Member
0 Kudos

Hi satyajit,

I have given what you said, but still, the list is empty and all fields are disabled. Is my code correct?Please suggest me.

Thanks in advance

Former Member
0 Kudos

Hi,

Is this attribute mapped to your DropDown? Do you have a mapping from the Custom Controller to the view?

Regards,

Satyajit.

Former Member
0 Kudos

Hi

Yes it is mapped to Dropdown and I have mapped Custom controller to the view, I don't where I went wrong. Am I following correct procedure, or can you guide me what are the development steps. So, that I can check my implementation once.

Thnaks&regards,

Ganesh

Former Member
0 Kudos

Hi

This is the code in WdInit() of my CustomController:

IContextElement conElement=wdContext.currentContextElement();

IWDNodeInfo nodeInfo=wdContext.getNodeInfo();

IWDAttributeInfo matAttrInfo=nodeInfo.getAttribute("matnum");

IModifiableSimpleValueSet dropValueSet=matAttrInfo.getModifiableSimpleType().getSVServices().getModifiableSimpleValueSet();

String matnum=null;

int nodeLength=wdContext.nodeY_Ep_MatGD_Input().size();

for(int i=0;i<nodeLength;i++)

{

matnum=String.valueOf(((IPrivateMaterialgdCompView.IY_Ep_MatGD_InputElement)

(wdContext.nodeY_Ep_MatGD_Input().getElementAt(i))).getMatnr());

dropValueSet.put(matnum,"matnum");

}

Y_Ep_Demo_Material_Get_Data_Input input=new Y_Ep_Demo_Material_Get_Data_Input();

wdContext.nodeY_Ep_MatGD_Input().bind(input);

I have created a Valuenode in Customcontroller and a ValueAttribute under that.

I have created a Simpletype matnum and bound this to matnum of SimpleType under Context->MatNode->properties of CustomeController.

This is the code in my onActionGetlist() of my View:

wdThis.wdGetMaterialgd_CustController().executeY_Ep();

and this is the cede of executeY_Ep() of CustomController:

try{

wdContext.currentY_Ep_MatGD_InputElement().modelObject().execute();

}

catch(Exception ex){

ex.printStackTrace();

}

When I ran the appl, I am getting NullPointer Exception:

java.lang.NullPointerException

at com.sap.demo.materialgd.Materialgd_Cust.wdDoInit(Materialgd_Cust.java:107)

at com.sap.demo.materialgd.wdp.InternalMaterialgd_Cust.wdDoInit(InternalMaterialgd_Cust.java:138)

at com.sap.tc.webdynpro.progmodel.generation.DelegatingCustomController.doInit(DelegatingCustomController.java:73)

at com.sap.tc.webdynpro.progmodel.controller.Controller.initController(Controller.java:215)

Thanks in advance

Former Member
0 Kudos

Hi,

I guess you are trying to fetch the list of materials from the back-end, after executing a BAPI. If that's the case then why are you trying to populate the list using the model input nodes? Shouldn't you be using the output node instead?

Regards,

Satyajit.

Former Member
0 Kudos

Hi satyahit,

In my appl, when i choose one material number and after pressing getlist button, the elements shud be populated. When I enter Material number and execute my Bapi by giving SE37 in my backend side, I get list of elements. This is how it works, am trying to implement the same in my appl.

So if I use Outputnode will it work. My input model node consists of materialnumber and my ouput model node consists of list of other elements.

Thanks a lot in advance.

regards,

Ganesh

Former Member
0 Kudos

Hi,

Where are these material numbers coming from? Are you selecting a material number from a dropdown? If yes, then once a material is selected from a the dropdown, you are taking that and executing a BAPI, right?

In the stacktrace that you posted(nullpointer exception), which is line 107?

Regards,

Satyajit.

Former Member
0 Kudos

Hi Satyajit,

>>In the stacktrace that you posted(nullpointer exception), which is line 107?

What does it mean?

Yes once a material is selected from dropdown list and when i press getlist button, the elements have to be populated. I have another Bapi for getting the values into dropdown.

Thanks&regards,

Ganesh

Former Member
0 Kudos

Hi,

This is the stacktrace that you posted:

<i>java.lang.NullPointerException

at com.sap.demo.materialgd.Materialgd_Cust.wdDoInit(Materialgd_Cust.java:107)

at com.sap.demo.materialgd.wdp.InternalMaterialgd_Cust.wdDoInit(InternalMaterialgd_Cust.java:138)

at com.sap.tc.webdynpro.progmodel.generation.DelegatingCustomController.doInit(DelegatingCustomController.java:73)

at com.sap.tc.webdynpro.progmodel.controller.Controller.initController(Controller.java:215)</i>

What I am asking is. in your wdDoInit() method, which is line 107?

Which is the BAPI that you are using to get the list of materials? I'll try and post the exact code once you have told me that.

Regards,

Satyajit.

sridhar_k2
Active Contributor
0 Kudos

Hi Ganesh,

Can you please check this line of code. Whether it is giving null or not?

int nodeLength=wdContext.nodeY_Ep_MatGD_Input().size();

In your code it is giving error at line number 107. Where is that? you can get your line number by (Ctrl + L - 107) NWDS.

Regards,

Sridhar

Former Member
0 Kudos

Hi

This is that line

IWDAttributeInfo matAttrInfo=nodeInfo.getAttribute("matnum");

regards,

Ganesh

sridhar_k2
Active Contributor
0 Kudos

Hi Ganesh,

It seems, it is not able to find "matnum" from your context variable.

What is your context variable which you are binding to the drop down list box? Give that variable to this code.

IWDAttributeInfo matAttrInfo=nodeInfo.getAttribute("Your Context Variable.);

Try this one.

Regards,

Sridhar

Former Member
0 Kudos

Hi Sridhar,

This is the cide in wdInit() method of custController:

Y_Ep_Demo_Material_Get_Data_Input input=new Y_Ep_Demo_Material_Get_Data_Input();

wdContext.nodeMatgdIP().bind(input);

//ICon

IWDAttributeInfo aInfo= wdContext.getNodeInfo().getAttribute("Matnr");

if(aInfo!=null){

IModifiableSimpleValueSet valSet=aInfo.getModifiableSimpleType().getSVServices().getModifiableSimpleValueSet();

valSet.put(Matnr,"Matnr");

}

I have created a siompletype in LocalDictionaries with name matnum. Then I created a model attribute called Matnr that was bound to my Bapi(Model attribute).

But I am getting redmark (underlined error for key here Matnr)indicating that it cannot be resolved.

Help me.

Thanks a lot in advance

sridhar_k2
Active Contributor
0 Kudos

Hi Ganesh,

If you are getting data from BAPI, is there any need to have a simple Type.

Create a Value Attribute and assign it to Drop Down List Box. and place your context variable here.

IWDAttributeInfo matAttrInfo=nodeInfo.getAttribute("Your Context value Attribute ");

Hope it solves your problem.

Regards,

Sridhar

Former Member
0 Kudos

Hi Sridhar,

I am using DropDownByIndex for getting values from R/3 into my dropdown list for displaying a list of Material Numbers.

In my wdInit() method of CustController

IWDAttributeInfo aInfo=wdContext.getNodeInfo().getAttribute("Matnr");

if(aInfo!=null){

IModifiableSimpleValueSet valSet=aInfo.getModifiableSimpleType().getSVServices().getModifiableSimpleValueSet();

<b>valSet.put(Matnr,"Matnr");</b> }

I am getting error mark in the first value Matnr cannot be resolved.

Let me explain what I did:

I created a Node and Node attribute in my View and kept its type as Model attrubute like Matnr. Then in CustController I created a Model Node and mapped the attributre of ModelNode to that of Bapis Model attribute.

In View->properties of DropDownByIndex->texts to Context attribue (of my View). The list is empty.

Where I did wrong. Please suggest me.

Thanks a lot for all your inputs. I will definitely reward maximum points.

Thanks a lot

Former Member
0 Kudos

Hi,

The BAPI used: Bapi_Material_Getlist. Let's say the model that you have created is called FetchListOfMaterials.

Your custom controller context:

-Root

--Bapi_Material_Getlist_Input (model node)

---Materialshortdescsel

---Matnrselection

---Output

-


Mtnrlist

---Plantselection

--Maxrows

--MaterialNumberList (value node)

---Material

Create a method in your Custom Controller, say selectListOfMaterials().

I am keeping it simple here, just selecting for plant 0001.

Now in your view, the context looks like:

-Root

--MaterialNumberList (value node, mapped to your Custom Controller)

---Material.

Create a DropDown and bind its texts property to MaterialNumberList.Material.

In the wdDoInit() of your view:


wdThis.wdGetBackEndCustomControllerController().selectListOfMaterials();

The method selectListOfMaterials():


FetchListOfMaterials getModel = (FetchListOfMaterials)com.sap.tc.webdynpro.progmodel.model.api.WDModelFactory.getModelInstance(FetchListOfMaterials.class,WDModelScopeType.TASK_SCOPE);
Bapi_Material_Getlist_Input input = new Bapi_Material_Getlist_Input();
    	
Bapimatram matNumberSel = new Bapimatram();
matNumberSel.setOption("CP");
matNumberSel.setSign("I");
matNumberSel.setMatnr_Low("*");
    	
input.addMatnrselection(matNumberSel);
    	
Bapimatras matDescSel = new Bapimatras();
matDescSel.setDescr_Low("Z*");
matDescSel.setOption("CP");
matDescSel.setSign("I");
    	
input.addMaterialshortdescsel(matDescSel);
    	
Bapimatraw plntSel = new Bapimatraw();
plntSel.setPlant_Low("0001");
plntSel.setOption("EQ");
plntSel.setSign("I");
		
input.addPlantselection(plntSel);
		
input.setMaxrows(10);
		
wdContext.nodeBapi_Material_Getlist_Input().bind(input);
		
try {
	input.execute();
} catch (WDDynamicRFCExecuteException e) {
// TODO Auto-generated catch block
	e.printStackTrace();
} 
		
		
IWDNodeElement elemSrc;
IWDNodeElement elemDest;
		
wdContext.nodeMaterialNumberList().invalidate();
for(int i = 0; i < wdContext.nodeMatnrlist().size(); i++){
elemSrc 	= wdContext.nodeMatnrlist().getElementAt(i);
elemDest 	= wdContext.nodeMaterialNumberList().createElement();
			
WDCopyService.copyCorresponding(elemSrc,elemDest);
			
wdContext.nodeMaterialNumberList().addElement(elemDest);
}

This is the basic scenario. This should get your Materials into the dropdown. Check if you have done this much.

Regards,

Satyajit.

sridhar_k2
Active Contributor
0 Kudos

Hi Ganesh,

valSet.put(Matnr,"Matnr");

First Element is Key , the Element is Value (which you can see in DD). You can give both with the same value.

Where you are getting this Material Number(Matnr) from BAPI? Pass that one to your value Set (valSet).

String Matnr=String.valueOf("get your Material number from BAPI - code");

and Set that value to value set.

valSet.put(Matnr,Matnr);

Regards,

Sridhar

Former Member
0 Kudos

Hi Sridhar,

Thanks for all your guidence. I am getting error at this line:the error is NullPointerException.

IWDAttributeInfo aInfo = wdContext.getNodeInfo().getAttribute("Matnr");

<b>ModifiableSimpleValueSet vSet=aInfo.getModifiableSimpleType().getSVServices().getModifiableSimpleValueSet();</b>

String matnum=null;

int nLen=wdContext.nodeY_Ep_Input().size();

for(int i=0;i<nLen;i++){

matnum=String.valueOf(((IPrivateSD_InsertCompView.IContextElement)(wdContext.nodeY_Ep_Input().getElementAt(i))).getAttributeAsText("matnum"));

valSet.put(matnum,"Matnr");

}

Please suggest me.

Thanks a lot

sridhar_k2
Active Contributor
0 Kudos

Hi Ganesh,

Can you please tell me which line you are getting Null Pointer Exception? I guess it after this line.

IWDAttributeInfo aInfo = wdContext.getNodeInfo().getAttribute("Matnr");

Regards,

Sridhar

Answers (2)

Answers (2)

Former Member
0 Kudos

Hi Ganesh,

The following Blog is helpful in executing a RFC from WD.

/people/perumal.kanthan/blog/2005/03/09/handling-structuretable-transactions-using-bapis-in-web-dynpro-part-ii

Before that you have to configure JCo Destinations, the following pdf will help you.

https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/docs/library/uuid/526bd490-0201-0010-038e-d3f...

Thanks and regards

RK

Former Member
0 Kudos

Hi RadhKrishna,

The following link is not working.

/people/perumal.kanthan/blog/2005/03/09/handling-structuretable-transactions-using-bapis-in-web-dynpro-part-ii

Plesae send me if can access that blog as a PDF.

Thanks a lot

regards,

Ganesh

Former Member
0 Kudos

Hi,

Create one Node using the following code. Inside the DoInit() method

Step 1:

IWDNodeInfo multiplenode = multipleinfo.addChild("MultiNode" , null, true, false, true, true, false, true, null, null, null);

multiplenode.addAttribute("roles", "ddic:com.sap.dictionary.string");

Step 2:

Assign values for Dropdown

IWDNode node1 = wdContext.nodeNodeA().getChildNode("MultiNode", IWDNode.NO_SELECTION);

IWDNodeElement elem1;

for(int s=0;s<5;s++){

elem1 = node1.createElement();

elem1.setAttributeValue("roles","Value"+s);

node1.addElement(elem1);

}

Step 3:

Inside Domodifyview create IWDDropDownByIndex UI Element and Bind it.

IWDDropDownByIndex dropDownList = (IWDDropDownByIndex)view.createElement(IWDDropDownByIndex.class, "drop");

IWDAttributeInfo info = wdContext.getNodeInfo().getChild("NodeA").getChild("MultiNode").getAttribute("roles");

dropDownList.bindTexts(info);

dropDownList.setWidth("100");

Finally add this Dropdown into container. Like this you can create more Dropdown and add action to the dropdown as dynamically.

Kind Regards,

S.Saravanan.

Message was edited by: Saravanan S

Former Member
0 Kudos

Hi

But Iam using DropDownByKey and not by DropDownByIndex,

can you let me know how to create that code accordingly.

>>Step 3:

>>Inside Domodifyview create IWDDropDownByIndex UI >>Element and Bind it.

>>IWDDropDownByIndex dropDownList = (IWDDropDownByIndex)>>view.createElement(IWDDropDownByIndex.class, "drop");

>>IWDAttributeInfo info = wdContext.getNodeInfo().getChild("NodeA").getChild("MultiNode").getAttribute("roles");

dropDownList.bindTexts(info);

dropDownList.setWidth("100");