Skip to Content
author's profile photo Former Member
Former Member

Display of data on as columns in a table

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

Add a comment
10|10000 characters needed characters exceeded

Related questions

4 Answers

  • Best Answer
    author's profile photo Former Member
    Former Member
    Posted on Oct 20, 2005 at 10:17 AM

    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.

    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member Former Member

      Hi Srikant,

      But how do you relate the elements in the different node?

      For an element of 'ScheduleLines Node' how do you select a corresponding element from 'FixedFactor' element, because the former node has 14 node elements & the latter has just '9' ???

      Best Regards,

      Nibu.

  • author's profile photo Former Member
    Former Member
    Posted on Oct 20, 2005 at 05:38 AM
    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Oct 20, 2005 at 06:27 AM

    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

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Oct 20, 2005 at 06:39 AM

    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.

    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member

      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.

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.