on 12-27-2007 7:43 AM
Dear all,i have this following codes
a = Long.parseLong(wdContext.currentContextElement().getMat_doc_frm());
b = Long.parseLong(wdContext.currentContextElement().getMat_doc_to());
c = b-a + 1;
Zbapi_Goodsmvt_Getdetail_Input stockitem = new Zbapi_Goodsmvt_Getdetail_Input();
Zdocnum docnum = new Zdocnum();
for(int x = 1; x <= c; x++){
docnum.setMat_Doc(String.valueOf(a));
docnum.setDoc_Year(wdContext.currentContextElement().getYear());
stockitem.addZdocnum(docnum);
wdComponentAPI.getMessageManager().reportSuccess(docnum.getMat_Doc());
wdComponentAPI.getMessageManager().reportSuccess(docnum.getDoc_Year());
a = a+1;
}
wdContext.nodeZbapi_Goodsmvt_Getdetail_Input().bind(stockitem);
IWDMessageManager manager = wdComponentAPI.getMessageManager();
try {
wdContext.currentZbapi_Goodsmvt_Getdetail_InputElement().modelObject().execute();
} catch (WDDynamicRFCExecuteException ce) {
manager.reportException(ce.getMessage(), false);
}
let said i key in the doc_num_frm as 5000002567 and doc_num_to as 5000002568,it seems that the stockitem.addZdocnum(docnum); only captur the last number which is 5000002568 for 2 times...it shd be 5000002567 and 5000002568..but now the data inside the stockitem for zdocnum is both oso 5000002568.. any idea why lead to this? thanks
Dear Joan,
Zdocnum docnum = new Zdocnum();
Write the above line of code within the for loop instead of outside as follows :
for(int x = 1; x <= c; x++){
Zdocnum docnum = new Zdocnum();
docnum.setMat_Doc(String.valueOf(a));
docnum.setDoc_Year(wdContext.currentContextElement().getYear());
stockitem.addZdocnum(docnum);
wdComponentAPI.getMessageManager().reportSuccess(docnum.getMat_Doc());
wdComponentAPI.getMessageManager().reportSuccess(docnum.getDoc_Year());
a = a+1;
}
What is going wrong is you are creating a reference of type ZDocnum, instantiating it, setting its values and adding it to the input list.
Next time when you set its values you are using the same reference without changing the instance it points to.
So a new element gets added no doubt but the values of the first element also get changed.
If you create a new instance every time you add an element to the list ,then this won't happen.
Try this and check.
Regards,
Mayuresh
PS : xxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Edited by: Armin Reichert on Jan 1, 2008 3:50 PM
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
Your execute statement is outside the for loop, so it will be executed with the last value assigned to the Mat Doc.
for(int x = 1; x <= c; x++){
docnum.setMat_Doc(String.valueOf(a));
docnum.setDoc_Year(wdContext.currentContextElement().getYear());
stockitem.addZdocnum(docnum);
wdComponentAPI.getMessageManager().reportSuccess(docnum.getMat_Doc());
wdComponentAPI.getMessageManager().reportSuccess(docnum.getDoc_Year());
IWDMessageManager manager = wdComponentAPI.getMessageManager();
wdContext.nodeZbapi_Goodsmvt_Getdetail_Input().bind(stockitem);
try {
wdContext.currentZbapi_Goodsmvt_Getdetail_InputElement().modelObject().execute();
} catch (WDDynamicRFCExecuteException ce) {
manager.reportException(ce.getMessage(), false);
}
a = a+1;
}
Regards
Ayyapparaj
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
93 | |
10 | |
10 | |
9 | |
9 | |
7 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.