on 09-06-2007 3:54 PM
My custom controller is giving me fits.
I have a structure (Empl_Pernr) in my model that needs to be part of the input before calling a second BAPI. The source of this input is the output of another BAPI - thus a structure. The structure that is input is found in wdContext.node<NODENAME> contains 5 distinct entries. When I run the following code the abstract list created is 5 long but only contains the LAST element in the node I was "unloading".
....
AbstractList emplList = new Zhr_Empl_Pernr.Zhr_Empl_Pernr_List();
Zhr_Empl_Pernr emplItem = new Zhr_Empl_Pernr();
for(int i = 0; i < wdContext.node<NODENAME>().size(); i++)
{
emplItem.setLastName(wdContext.node<NODENAME>().getOrg_OutElementAt(i).getLastName());
emplItem.setPersNo(wdContext.node<NODENAME>().getOrg_OutElementAt(i).getPersNo());
emplList.add(i,emplItem);
}
inputMangHours.setEmpl_Pernr(emplList);
....
INPUT
Last name PersNo
Last1 02600174
Last2 02600176
Last3 02600265
Last4 02600266
Last5 02600268
OUTPUT
Last name PersNo
Last5 02600268
Last5 02600268
Last5 02600268
Last5 02600268
Last5 02600268
What did I miss?
Diane,
You are not creating the object inside the loop. You are just changing the same object again and again. Because of object references its updating all previous entries. Simple to say you are adding same element 5 times.
Change the code this way...
AbstractList emplList = new Zhr_Empl_Pernr.Zhr_Empl_Pernr_List();
Zhr_Empl_Pernr = null;
for(int i = 0; i < wdContext.node<NODENAME>().size(); i++)
{
emplItem = new Zhr_Empl_Pernr();
emplItem.setLastName(wdContext.node<NODENAME>().getOrg_OutElementAt(i).getLastName());
emplItem.setPersNo(wdContext.node<NODENAME>().getOrg_OutElementAt(i).getPersNo());
emplList.add(i,emplItem);
}
Regards
Abhilash
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
101 | |
13 | |
13 | |
11 | |
11 | |
7 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.