on 10-20-2005 6:17 AM
Hi All,
I have an application where the data from R/3 server is displayed on the table.
The different columns are:
1. Date 2. Volume 3. Price
the Volume is corresponding to the date mentioned. which is in past/or future.
I have to read the difference between current date and the column date in days. and multiply that with a price factor( to be read from the server ) and add it up with price on current day( to be read from server) and display it under the column "price".
there can be many rows with many different dates and different corresponding price factors.
Can some one tell me how to go about this.
Thanks in advance
Srikant
Hi Srikant,
for(int counter = 0; counter< wdContext.nodeOutput_Contract_Qty().size(); counter ++)
{
nodeElement = wdContext.createTableNodeElement();
scheduleElement = wdContext.nodeZs_Wcontract_Quantity_Input().nodeOutput_Contract_Qty().nodeLi_Schedule_Lines().getLi_Schedule_LinesElementAt(counter);
fixedFactorElement = wdContext.nodeZs_Wcontract_Quantity_Input().nodeOutput_Contract_Qty().nodeLi_Fixed_Factor().getLi_Fixed_FactorElementAt(counter);
priceElement = wdContext.nodeZs_Wcontract_Quantity_Input().nodeOutput_Contract_Qty().nodeLi_Post_Id_Price().getLi_Post_Id_PriceElementAt(counter);
.
.
.
In these codes, the counter is for 'Output_Contract_Qty', when creating the elements you are using the counter for the child nodes, which is wrong. Can you paste your entire oupt node structure here, with the details of the data to be shown?
Best Regards,
Nibu.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Nibu,
Following is the structure :
Context
|_Zs_WContract_Quantity
|_Li_Fixed_factor
|_Li_Schedule_Lines
|_Li_Price_Id_Factor
|_TableNode
|_cmpDate
|_cmpPrice
The structure is as above
Still can't figure out how I solve this.
Can you please educate me how do you select size of the loop in general?
Thanks in advance
Srikant
Hi Srikant,
Can you please provide the structure in a hierarchical manner, showing which is a node, which is an attribute and what attribute is inside what node? Also, please elaborate on the logic to be followed to generate the display data.
Regarding the size() of a node, I'll try to explain whatever little I know :
int n=wdContext.nodeOutput_Contract_Qty().size();
<b>for(int i = 0; i<n; i++)
{</b>
This loop does 'n' iterations, where n is the size of the 'Output_Contract_Qty' node. So inside this loop, you can access any element of 'Output_Contract_Qty' node, by the statement
wdContext.nodeOutput_Contract_Qty().getOutput_Contract_QtyElementAt(i);
where 0 <= i <n.
In your case, 'Li_Fixed_factor' might be a node inside 'Output_Contract_Qty' node. Though you can know the size of the parent node, you get no idea about the size of the child node from the value 'n'. And the childnode may have 'm' elements of it's own. So if it is a non-singleton node, each of the 'n' parent node elements will have 'm' child node elements of it's own.
And each set of elements of the child node will be bound to an element of the parent node. So you can access these elements only through a code like :
wdContext..nodeOutput_Contract_Qty().getOutput_Contract_QtyElementAt(i); nodeLi_Fixed_Factor().getLi_Fixed_FactorElementAt(j);
where 0<=i<n and 0<=j<m.
Hope this helps,
Best Regards,
Nibu.
Hi Nibu,
I got what you mean by size of node
The logic of Application is to read the date listed under the ScheduleLines Node. N then difference of days is calcualted. and then we get the data of price factor from the Fixed Factor and multiply it with days difference. and add wiht current price which we getting from the Price Id
The no. of child elements in Node Fixed Factor '9' where only meaning ful thing is fixed factor
similarly in Schedulelines it is '14' only imp one being the date thing
and for price_ID it is '12' and the price is only imp
I hope the structure is clear
Thanks in advance
Srikant
Hi Nibu
Thanks for making me understand how the node's size to be taken.
The problem is not yet solved as its still giving the same error of IndexOutOfBounds.
I've to get the data from the node elements within each of the inner nodes and and then go with the logic. But I'm unable to as my for loop is giving me error ..
Can you suggest me a way in it??
Its bit urgent !!!
Thanks in Advance
Srikant
Hi Srikant,
I am not very sure about your requirement, anyway giving a guess about the way to do the same:
create a value node say 'table_node' with these three attributes - date,volume and price.
Now let the ouput node from RFC (let's call it 'RFC_output') have attributes
- RFC_date
- RFC_price_factor
- RFC_current_price
- RFC_Volume
Now after executring the RFC, do your manipulations like:
IPrivate<View_name>.ITable_nodeElement elmt;
IPrivate<View_name>.IRFC_ouputElement rfc_elmt;
for(int i=0;i<wdContext.nodeRFC_output().size();i++)
{
elmt = wdContext.createTable_nodeElement();
rfc_elmt = wdContext.nodeRFC_output().getRFC_outputElementAt(i);
elmt.setDate(rfc_elmt.getRFC_date());
elmt.setVolume(rfc_elmt.getRFC_volume());
// calculate the difference in days using
Date current_date = new Date(System.currentTimeMillis());
long from = current_date.getTime();
long to = rfc_elmt.getRFC_date().getTime();
int diffrence_days = Math.round(((from-to)/(10006060*24)));
Now calculate the price based on this difference and rfc_elmt.getRFC_price(), let the calculated price be 'cal_price'.
elmt.setprice(cal_price);
wdContext.nodeTable_node().addElement(elmt);
}
I feel I can provide you a better answer if you paste your RFC output node structure here. Also specify the exact data that you want to display in the table and their data type and what data are to be shown directly from the RFC output without any manipulation.
Hope this helps,
Best Regards,
Nibu.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Nibu,
Well thanks for the help, at least i got a direction from where I was stuck.
Well i did the following code. before that the price factor is coming from node -> fixed_factor, the current price is coming from node -> Sche and date is from node -> schedule lines..
accordingly my code in the execution method is as follows:
public void executeZs_Wcontract_Quantity_Input( )
{
//@@begin executeZs_Wcontract_Quantity_Input()
try
{
wdContext.nodeZs_Wcontract_Quantity_Input().currentZs_Wcontract_Quantity_InputElement().modelObject().execute();
wdContext.nodeOutput_Contract_Qty().invalidate();
/***********************Manipulation Code************************************/
IPublicPreBuyPricesComp.ITableNodeElement nodeElement;
IPublicPreBuyPricesComp.ILi_Schedule_LinesElement scheduleElement;
IPublicPreBuyPricesComp.ILi_Fixed_FactorElement fixedFactorElement;
IPublicPreBuyPricesComp.ILi_Post_Id_PriceElement priceElement;
for(int counter = 0; counter< wdContext.nodeOutput_Contract_Qty().size(); counter ++)
{
nodeElement = wdContext.createTableNodeElement();
scheduleElement = wdContext.nodeZs_Wcontract_Quantity_Input().nodeOutput_Contract_Qty().nodeLi_Schedule_Lines().getLi_Schedule_LinesElementAt(counter);
fixedFactorElement = wdContext.nodeZs_Wcontract_Quantity_Input().nodeOutput_Contract_Qty().nodeLi_Fixed_Factor().getLi_Fixed_FactorElementAt(counter);
priceElement = wdContext.nodeZs_Wcontract_Quantity_Input().nodeOutput_Contract_Qty().nodeLi_Post_Id_Price().getLi_Post_Id_PriceElementAt(counter);
nodeElement.setCmpDate(scheduleElement.getSchddt());
//Calculation of difference in dates
Date current_date = new Date(System.currentTimeMillis());
long currentDate = current_date.getTime();
long givenDate = scheduleElement.getSchddt().getTime();
int daysDifference = Math.round(((givenDate-currentDate)/(1000*60*60*24)));
double daysDiff = daysDifference;
double factor = fixedFactorElement.getFixfactor().doubleValue();
double Price = priceElement.getPrice().doubleValue();
//Calculation of price
double price = Price + ( daysDiff * factor );
nodeElement.setCmpPrice(price);
wdContext.nodeTableNode().addElement(nodeElement);
}
}
catch(WDRFCException ex)
{
ex.printStackTrace();
}
//@@end
}
after deploying
I'm getting following error.
The initial exception that caused the request to fail, was:
java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
at java.util.ArrayList.RangeCheck(ArrayList.java:507)
at java.util.ArrayList.get(ArrayList.java:324)
at com.sap.aii.proxy.framework.core.JcoBaseList.get(JcoBaseList.java:268)
at com.sap.aii.proxy.framework.core.AbstractList.get(AbstractList.java:230)
at com.sap.tc.webdynpro.modelimpl.dynamicrfc.DynamicRFCList.get(DynamicRFCList.java:281)
... 41 more
Thanks in advance
Srikant
P.S. thanks u been of gr8 help.
Hi to All(& Nibu)
I have written functions:
1. Executing the The Bapi
2. finding the difference the between dates in days.
3. finding the price
The following are the codes for them:
public void executeZs_Wcontract_Quantity_Input( )
{
//@@begin executeZs_Wcontract_Quantity_Input()
try
{
wdContext.nodeZs_Wcontract_Quantity_Input().currentZs_Wcontract_Quantity_InputElement().modelObject().execute();
wdContext.nodeOutput_Contract_Qty().invalidate();
}
catch(WDRFCException ex)
{
ex.printStackTrace();
}
//@@end
}
public int daysDifference( java.lang.String startDate, java.lang.String finishDate )
{
//@@begin daysDifference()
try
{
SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
Date beginDate = dateFormat.parse(startDate);
Date endDate = dateFormat.parse(finishDate);
GregorianCalendar calStart = new GregorianCalendar();
calStart.setTime(beginDate);
GregorianCalendar calEnd = new GregorianCalendar();
calEnd.setTime(endDate);
//if the dates belong to same year
if (calStart.get(Calendar.YEAR) == calEnd.get(Calendar.YEAR))
{
return calEnd.get(Calendar.DAY_OF_YEAR) - calStart.get(Calendar.DAY_OF_YEAR);
}
else if ((calEnd.get(Calendar.YEAR) - calStart.get(Calendar.YEAR)) == 1)
{
int daysEndYear = calEnd.get(Calendar.DAY_OF_YEAR);
int daysStartYear = calStart.getActualMaximum(Calendar.DAY_OF_YEAR) - calStart.get(Calendar.DAY_OF_YEAR);
return daysEndYear + daysStartYear;
}
else
{
int startYear = calStart.get(Calendar.YEAR);
int endYear = calEnd.get(Calendar.YEAR);
GregorianCalendar cal = new GregorianCalendar();
int days = 0;
for (int i = startYear + 1; i < endYear; i++)
{
cal.set(Calendar.YEAR, i);
days += cal.getActualMaximum(Calendar.DAY_OF_YEAR);
}
days += calEnd.get(Calendar.DAY_OF_YEAR);
days += (calStart.getActualMaximum(Calendar.DAY_OF_YEAR) - calStart.get(Calendar.DAY_OF_YEAR));
return days;
}
}
catch (Exception e)
{
return -1;
}
//@@end
}
public void calFixedPrice( )
{
//@@begin calFixedPrice()
int max = wdContext.nodeZs_Wcontract_Quantity_Input().nodeOutput_Contract_Qty().size();
//wdContext.currentContextElement().setCFlag("Srikant");
for (int fixedCounter = 0; fixedCounter<max; fixedCounter++)
{
Date presentDate = Calendar.getInstance().getTime();
Date givenDate = wdContext.nodeZs_Wcontract_Quantity_Input().nodeOutput_Contract_Qty().nodeLi_Schedule_Lines().getLi_Schedule_LinesElementAt(fixedCounter).getSchddt();
//Conversion of the Dates in String
String PresentDate = presentDate.toString();
String GivenDate = givenDate.toString();
//Calculation of no. of days
int numDays = daysDifference(PresentDate,GivenDate);
double Days = numDays;
//Getting the Values of Current Price for the Day and Fixed Price Factor based on that
double quotedPrice = (wdContext.nodeZs_Wcontract_Quantity_Input().nodeOutput_Contract_Qty().nodeLi_Post_Id_Price().getLi_Post_Id_PriceElementAt(fixedCounter).getPrice().doubleValue());
double fixedPriceFactor = (wdContext.nodeZs_Wcontract_Quantity_Input().nodeOutput_Contract_Qty().nodeLi_Fixed_Factor().getLi_Fixed_FactorElementAt(fixedCounter).getFixfactor().doubleValue());
//wdContext.currentContextElement().setCTest(fixedPriceFactor);
//Calcualtion of Fixed Price
double FixedPrice = (quotedPrice + (fixedPriceFactor * Days));
}
//@@end
I'm not able find out where to use these methods and how to call them
Please help me on this, its urgent
Thanks in advance
Srikant
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Srikanth,
I think you can use CalculatedAttributes for this.
Please refer to the tutorial in SDN for this.
Regards, Anilkumar
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
79 | |
9 | |
9 | |
7 | |
7 | |
6 | |
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.