Calculating a Leap Year with a FOX Formula

Hi to everybody.
Is it posible to calculate a leap year using BPS in BW 3.5 with a FOX formula?
The code i need to write is something like this:
if ((year % 4 == 0) AND ((year % 100 != 0) OR (year % 400 == 0)) then
  it is a leap year;
else
  it isn´t a leap year;
endif;
The problem i have is that my variable year is an standard type 0CALYEAR and I cannot do i.e.
Year MOD 4, and save this value to an integer because 0CALYEAR and INTEGER are different types of variables.
Any idea?
Thanks in advance!
Edited by: Ivan Lopez on Jan 15, 2008 5:24 PM
Edited by: Ivan Lopez on Jan 15, 2008 5:24 PM

Hi,
Eventhough variable is on the characteristic 0CALYEAR, you can assign the variable value to an integer in FOX.
Declare a local variable of type integer.
DATA YEAR TYPE I.
YEAR = VARV(variable).
Now you can do MOD operations on YEAR.
Regards,
Bindu

Similar Messages

  • Bug or error when handling leap years with WDS/DS

    Hi all,
    I discovered a difference in outcome with Build and Debug (without screens) and Build and Debug with Web Determinations or Determinations Server when calculating days within leap years.
    I use the function DayDifferenceInclusive to calculate the amount of days in an insurance period.
    the amount of days of the insurance period = DayDifferenceInclusive(the start date of the insurance, the end date of the insurance)
    With the regression tester or Build and Debug (without screens) I get the following outcome for the following input:
    *93 = DayDifferenceInclusive(02-29-2008, 05-31-2008)*
    When we use Web Determinations or Determinations Server we get the value of *92* for the exact same input data when it should be 93.
    Is this a bug in the java code? How can we fix this or is there a work around for it?
    We're in the middle of System Integration Testing for a huge project so help is much appreciated!
    Best regards,
    Niels Roest

    Niels,
    thanks for that - and it looks like in the Netherlands daylight savings started on the 30th of March 2008, which as far as I know is the trigger for this error.
    I have reproduced the issue against 10.1 using the period 01 October 2010 to 30 October 2010, which contains the date that daylight saving started in Australia.
    As for ways to work around the issue, I can offer 3:
    * wait for 10.2 - it's in beta at the moment (though given your opening comments, this might not be an option for you)
    * set your server locale to one that doesn't have DST
    * work around the issue in rules:
    Firstly, the issue is that the shipping version fails because it doesn't take into account that one of the days is shorter than the standard 24 hours.
    The trick is to replace the DayDifference function with the HourDifference function and round to the nearest number of days.
    So given a rule that looks like:
    the result = DayDifference(date one, date two)
    it can be rewritten as:
    The result = round(HourDifference(date one at 00:00:00, date two at 00:00:00) / 24, 0)
    * the whole "at 00:00:00" is necessary because HourDifference works on datetimes, not dates.
    Sorry for the hassle.
    Regards
    Andrew

  • Type error while calling function module with in FOX formula

    Hi,
    I am getting following error while calling function module from FOX Formula:
    "Types of parameter DAY_IN () and variable J_CALDAY(D) are inconsistent"
    Following is the code:
    DATA    I_CALDAY       TYPE  0CALDAY.
    DATA    N_CALDAY       TYPE  0CALDAY.
    DATA    KYF              TYPE KEYFIGURE_NAME.
    FOREACH   I_CALDAY, KYF.
       CALL FUNCTION SLS_MISC_GET_LAST_DAY_OF_MONTH
          EXPORTING
             DAY_IN  =  I_CALDAY
          IMPORTING
             LAST_DAY_OF_MONTH = N_CALDAY.
        {KYF, N_CALDAY}  =  {KYF, L_CALDAY}.
    ENDFOR.
    Import parameter DAY_IN is of type sy-datum (that inturn is data element SYDATUM of data type DATS - same as 0CALDAY). Not sure why error is being thrown. Any idea? Thanks.
    Edited by: SAP_BOY on Dec 4, 2009 5:26 PM

    Hi,
    I think It will not identify ,though you have  (data element SYDATUM of data type DATS - same as 0CALDAY).Check it out by assigning it through a variable of type D.
    Data I_CALDAY TYPE D.
    Hope it may work out.
    Regards,
    Indu

  • Calculation of interest amount with two variables formula

    Hello everyone,
    Iu2019m facing a problem with the way that TRM calculate the interest amount for money market transaction when I have a formula with two variable, e.g. reference interest rate u201CXu201D multiplied by 0,98.
    Some contracts explicitly say that to obtain the u201Cdaily interest rateu201D of the contract firstly the u201Cdaily interest rateu201D of the reference interest rate must be calculated and then apply a index or factor (e.g. 0,98). In the other hand some contracts says that it should be done the other way around. Iu2019ve noticed that TRM calculate the interest amount using the first way.
    Is there any way to set which the way the interest amount should be calculates?
    Has anyone faced similar problem?
    The examples below illustrate the difference in the two ways to calculate interest amount.
    Considering the following money market transaction:
    1. Borrowing structure:
    1.1. amount: USD 1.000.000,00
    1.2. flow type: 1105 u201CBorrowing/Increaseu201D
    2. Term (only one day to simplify the example)
    2.1. Start date: 30.01.2011
    2.2. End data:   31.01.2011
    3. Interest structure:
    3.1. Interest form: VARIABLE ( formula = Z1 * 0,98), where u201CZ1u201D is a reference interest rate
    3.2. condition type: 1200 u201CNominal interestu201D
    3.3. Interest calculation method: ActW/252
    Considering that Z1u2019s annual interest rate in 30.01.2011 is 11,66%, TRM would perform the following calculation:
    1. Contract annual interest rate (%) = Z1*0,98 = 11,66 *0,98 = 11,42680000%
    2. Convert from u201CContract annual interest rate (%)u201D  to number = 1,11426800
    3. u201CContract daily interest rateu201D = 1,11426800 ^(1/252) = 1,00042945
    4. Convert from u201Cnumberu201D to Day interest rate (%)  = 0,04294481%
    5. Interest amount = u201CContract daily interest rateu201D * Borrowed amount = 0,04294481% * 10.000.000,00 = 4.294,48
    In the other hand, some contracts say that the interest rate should be calculated in the following way:
    1. Annual interest rate (%) = 11,66  = 11,66000000%
    2. Convert from u201CAnnual interest rate (%)u201D  to number = 1,11660000
    3. Daily interest rate = 1,11660000 ^(1/252) = 1,00043775
    4. Convert from u201Cnumberu201D to Daily interest rate (%)  = 0,04377480%
    5. Calculate u201CContract daily interest rateu201D = 0,04377480% * 0,98 = 0,04289930%
    5. Interest amount = u201CContract daily interest rate (%)u201D  * Borrowed amount = 0,04289930% * 10.000.000,00 = 4.289,93
    With this simple scenario  we end up with a USD 4,55 difference for a single day, but for big contracts of hundred millions and for several years the difference is quite  huge.
    Thanks in advance ..
    Giuliano

    Hi,
    with Product Category 550 you can have both scenarios:
    for the 1st case you can use a formular (e.g. EONIA * 0,98)
    => interest for 1 day: 462,70 EUR
    for the 2nd case you can use the field Variable Interest Rate (EONIA) + field Payment Rate (98)
    => interest for 1 day: 453,44 EUR
    Is this, what you are looking for?
    Regards,
    Lorenz

  • Fox formula - Copy variable value to a characteristic in IP

    Hi All,
    I have to copy the value of a variable to a characteristic in Fox formula in IP. In this scenario I am forecasting data using copy function. Whenever new data is copied I need to save it as a new version. So in the fox formula I have mentioned only 'version' as the field to be changed. I get the value of version automatically from a function module. In BPS I think it is possible but I am using IP.
    Example.
    Copied data
    Customer Material Version Year Qty
    c1            m1          0           2012  10
    c2            m2          0           2012  20
    c3            m3          0           2012   15
    This is the reference data got as a result of copy function. In the code I get the version computed from a function module in variable fm_version.
    I wrote the logic like this.
    data lv_version type version.
    foreach lv_version.
    {0quant_b, lv_version} = {0quant_b, fm_version}
    endfor.
    When it is execute it is showing error as records changed and deleted.
    Is it the correct method or is there any other workaround.
    I would realyt appreciate your time and effort.
    Thanking you,
    Jerry Jerome

    Hello,
    You can use either standard copy function or fox formula.
    So here I need to make the version as 1 since it is forecasted for the first time. I am trying to do it with a fox formula. In the fox formula I am trying to change the characteristic value of version from 0 to 1.
    You can not change the characteristic value of version from 0 to 1. The copy function or fox formula will copy the key figures from version 0 to 1.
    For example:
    The transaction data contains data like -
    customer     material            year     version    qty
    c1                 m1            2012     0           10
    c2                 m2            2012     0            5
    After copy you will get both version like this
    customer     material            year     version    qty
    c1                 m1            2012        0        10
    c2                 m2            2012        0         5
    c1                 m1            2012        1        10
    c2                 m2            2012        1         5
    Thanks.
    With regards,
    Anand Kumar

  • How to implement this planning function using Fox formula

    Hello,
    I am new to Fox.
    I want to implement this complex logic in a planning function
    i have A (Kf X from infoprovider Z_A), B (Kf Y from infoprovider Z_B) & moreover there is one more condition,
    If current FISCPER > variable value of FISCPER
    KF Z = KF Z1 (from Cube C1)
    Else KF Z = KF Z2 (from Cube C2).
    for a particular calender week,
    X =   ( Y * Z ) / (summation of (Y * Z)  for each week of the whole year)
    I know it is complex.
    but i have to implement this in a planning function.
    The aggreagtion level is built on a multiprovider having A, B , C1 & C2.
    Can someone help me out with the FOX formula for this? or is there any better way to do this.
    Thanks john

    Hi Gerardo,
    Thanks for that.
    I have tried something similiar to it
    DATA CHA_CALWEEK TYPE 0CALWEEK.
    DATA CHA_COMP_CODE TYPE 0COMP_CODE.
    DATA CHA_FISCPER TYPE 0FISCPER.
    DATA VAR_PERIOD  TYPE 0FISCPER.
    DATA SUM_YEAR TYPE F.
    DATA TEMP_D TYPE F.
    DATA SUM_WEEK TYPE F.
    CURRENCY IS LOCAL CURRENCY. FOR DATA SELECTION TO BE RIGHT, NECESSARY TO DERIVE FROM CC.
    DATA UN_LOC_CURRCY TYPE 0LOC_CURRCY.
    UN_LOC_CURRCY = VARV(Z_U_I100).
    CHA_COMP_CODE = VARV(Z_U_I100).
    To Calculate the D
    VAR_PERIOD = VARV(Z_U_I010).
    SUM_YEAR = 0.
    TEMP_D =0.
    IF CHA_FISCPER > VAR_PERIOD.
    TEMP_D = {ZSA_BUD2X,CHA_COMP_CODE,CHA_FISCPER,YBUDG_01X,CHA_CALWEEK}.
    FOREACH CHA_CALWEEK.
    SUM_YEAR = SUM_YEAR + TEMP_D * {ZCREENTSV,CHA_COMP_CODE,CHA_FISCPER,ZIP_RREF1} .
    ENDFOR.
    ELSE.
    TEMP_D = ({ZSAEXCUSV,CHA_COMP_CODE,CHA_FISCPER,YRT_C02X} - {ZCREENTSV,CHA_COMP_CODE,CHA_FISCPER,YRT_C02X}).
    FOREACH CHA_CALWEEK.
    SUM_YEAR = SUM_YEAR + TEMP_D * {ZIP_INDEX,CHA_COMP_CODE,CHA_FISCPER,ZIP_RREF1}) .
    ENDFOR.
    ENDIF.
    But i am getting a syntax error
    Formula error: } expected
      Syntax error in row 21, column 20
    i have marke line21 in bold. above.
    I feel it is correct, still wonder why i am getting this error.
    can you pls help ?

  • Error Control on Fox Formula

    Hello everybody
    I have a problem with a Fox formula. When i chek my formula i have the error
    "RFCCheckScreenNecessary: Exception condition "INPUT_NOT_LEGAL" raised., error key: RFC_ERROR_SYSTEM_FAILURE "
    This Formula Use 12 Formula Variables ZVPOIDSx.
    My Formula work Fine when i use only 2 Formula Variables ZVPOIDSx. (ZVPOIDS1 et ZVPOIDS2). The control is OK and the results ar Ok
    But when i use 3 (or +) variable it s not ok
    Extract of my Formula
    DATA ZPOIDS1 TYPE I.
    DATA ZPOIDS2 TYPE I.
    DATA ZPOIDS3 TYPE I.
    DATA ZPOIDS4 TYPE I.
    DATA ZPOIDS5 TYPE I.
    DATA ZPOIDS6 TYPE I.
    DATA ZPOIDS7 TYPE I.
    DATA ZPOIDS8 TYPE I.
    DATA ZPOIDS9 TYPE I.
    DATA ZPOIDS10 TYPE I.
    DATA ZPOIDS11 TYPE I.
    DATA ZPOIDS12 TYPE I.
    DATA ZPOIDSTOT TYPE I.
    ZPOIDS1 = VARV(ZVPOIDS1).
    ZPOIDS2 = VARV(ZVPOIDS2).
    ZPOIDS3 = VARV(ZVPOIDS3).
    ZPOIDS4 = VARV(ZVPOIDS4).
    ZPOIDS5 = VARV(ZVPOIDS5).
    ZPOIDS6 = VARV(ZVPOIDS6).
    ZPOIDS7 = VARV(ZVPOIDS7).
    ZPOIDS8 = VARV(ZVPOIDS8).
    ZPOIDS9 = VARV(ZVPOIDS9).
    ZPOIDS10 = VARV(ZVPOIDS10).
    ZPOIDS11 = VARV(ZVPOIDS11).
    ZPOIDS12 = VARV(ZVPOIDS12).
    *ZPOIDSTOT is the sum of all ZPOIDSx
    ZPOIDSTOT = ZPOIDS1 + ZPOIDS2 + ZPOIDS3 + ZPOIDS4 +  ZPOIDS5  + ZPOIDS6  + ZPOIDS7  + ZPOIDS8  + ZPOIDS9  + ZPOIDS10  + ZPOIDS11  + ZPOIDS12.
    *{ 0AMOUNT, 013 } is the Budget for all the year
    { 0AMOUNT, 001 } = { 0AMOUNT, 013 }*  (ZPOIDS1 /ZPOIDSTOT).
    { 0AMOUNT, 002 } = { 0AMOUNT, 013 }*  (ZPOIDS2 /ZPOIDSTOT).
    { 0AMOUNT, 003 } = { 0AMOUNT, 013 }*  (ZPOIDS3 /ZPOIDSTOT).
    { 0AMOUNT, 004 } = { 0AMOUNT, 013 }*  (ZPOIDS4 /ZPOIDSTOT).
    { 0AMOUNT, 005 } = { 0AMOUNT, 013 }*  (ZPOIDS5 /ZPOIDSTOT).
    { 0AMOUNT, 006 } = { 0AMOUNT, 013 }*  (ZPOIDS6 /ZPOIDSTOT).
    { 0AMOUNT, 007 } = { 0AMOUNT, 013 }*  (ZPOIDS7 /ZPOIDSTOT).
    { 0AMOUNT, 008 } = { 0AMOUNT, 013 }*  (ZPOIDS8 /ZPOIDSTOT).
    { 0AMOUNT, 009 } = { 0AMOUNT, 013 }*  (ZPOIDS9 /ZPOIDSTOT).
    { 0AMOUNT, 010 } = { 0AMOUNT, 013 }*  (ZPOIDS10 /ZPOIDSTOT).
    { 0AMOUNT, 011 } = { 0AMOUNT, 013 }*  (ZPOIDS11 /ZPOIDSTOT).
    { 0AMOUNT, 012 } = { 0AMOUNT, 013 }*  (ZPOIDS12 /ZPOIDSTOT).
    Thanks for your help

    Hi,
    I hope the note will work. But still I would test the following:
    DATA ZPOIDS1 TYPE I.
    DATA ZPOIDS2 TYPE I.
    DATA ZPOIDS3 TYPE I.
    DATA ZPOIDS4 TYPE I.
    DATA ZPOIDS5 TYPE I.
    DATA ZPOIDS6 TYPE I.
    DATA ZPOIDS7 TYPE I.
    DATA ZPOIDS8 TYPE I.
    DATA ZPOIDS9 TYPE I.
    DATA ZPOIDS10 TYPE I.
    DATA ZPOIDS11 TYPE I.
    DATA ZPOIDS12 TYPE I.
    DATA ZPOIDSTOT TYPE I.
    ZPOIDS1 = VARV(ZVPOIDS1).
    ZPOIDS2 = VARV(ZVPOIDS2).
    ZPOIDS3 = VARV(ZVPOIDS2).
    ZPOIDS4 = VARV(ZVPOIDS2).
    ZPOIDS5 = VARV(ZVPOIDS2).
    ZPOIDS6 = VARV(ZVPOIDS2).
    ZPOIDS7 = VARV(ZVPOIDS2).
    ZPOIDS8 = VARV(ZVPOIDS2).
    ZPOIDS9 = VARV(ZVPOIDS2).
    ZPOIDS10 = VARV(ZVPOIDS2).
    ZPOIDS11 = VARV(ZVPOIDS2).
    ZPOIDS12 = VARV(ZVPOIDS2).
    If this works, the problem is within variable ZVPOIDS3 - ZVPOIDS12.
    Also note that the latest SP is 14, so if you are still in development I would recommend to install SP13 and 14!
    D

  • Select  timestamp interval on leap year

    Hello,
    i tried to select a timestamp interval on leap year with following action
    select to_timestamp_tz('20000301 +0100','yyyymmdd tzhtzm')+INTERVAL '-3' YEAR from dual;
    The result is an error: ORA-01839: date not valid for month specified
    the year 2000 is a leap year.
    There is the same result with 36 months.
    Oracle Version 10.1.0.4
    What is wrong on it. Is there a workaround?
    Thanks and Greetings
    Silke Viet

    since you are moving 3 years into the past, the year 1997 is not a leap year, that seems to cause it to throw that error:
    SQL> select to_timestamp_tz('20000301 +0000','yyyymmdd tzhtzm') + INTERVAL '-3' YEAR from dual;
    TO_TIMESTAMP_TZ('20000301+0000','YYYYMMDDTZHTZM')+INTERVAL'-3'YEAR
    01-mar-1997 00:00:00.000000 +0000
    1 row selected.
    SQL> select to_timestamp_tz('20000301 -0100','yyyymmdd tzhtzm') + INTERVAL '-3' YEAR from dual;
    TO_TIMESTAMP_TZ('20000301-0100','YYYYMMDDTZHTZM')+INTERVAL'-3'YEAR
    01-mar-1997 00:00:00.000000 -0100
    1 row selected.
    SQL> select to_timestamp_tz('20000301 +0100','yyyymmdd tzhtzm') + INTERVAL '-3' YEAR from dual;
    select to_timestamp_tz('20000301 +0100','yyyymmdd tzhtzm') + INTERVAL '-3' YEAR from dual
    ERROR at line 1:
    ORA-01839: date not valid for month specified
    SQL>

  • ICal and Leap Year

    I had set up a yearly recurring event for a birthday notification for Feb 29 (Leap Year) with a Alarm notification 6 days in advance of the day so I could be sure to send out a card in time, etc. etc. However, because there is no Feb 29 in calendar year 2010 it appears that the Alarm notification isn't working. Is this a bug or did I possibly do something wrong?

    Yes, I noticed this the other day but didn't make a connection with the US holidays. Odd quirk.

  • How to realize special scenario with FOX formula - FOREACH, variables

    Hello,
    we want to use the integrated planning for the following thing within the portal:
    A salesman should add manual values (planned turnover) for his top 10 customers. The rest of his yearly budget should be distributed automatically and equally to the rest of his customers.
    I thought a lot about it and arrived at the conclusion that:
    - we have somehow to put the salesman number into a variable maybe also the year for which the planning should be done -- Which possibilities are given to do this?
    - We need an additional flag that tells if this customer has to be planned / was planned manually.
    After the manual planning a planning function (FOX formula) has to be executed in order to
    1. get the budget that was already planned manually
        use of FOREACH in combination with an IF clause
        -- Which kind of FOREACH do I have to use?
    2. calculated total budget - manual planned budget = budget that has to be distributed
        after FOREACH
    3. count on how many customers the distribution has to be done and calculate the
        turnover per customer (rest budget / counted customers)
        use of another FOREACH loop which counts every value that hasn't got the flag set
    4. distribute the remaining budget on the customers that weren't planned manually
        -- Can it be done with something like turnover=value that should be assigned ?
    Maybe it's simple to realize this scenario but I'm a absolute "newbie" on that theme.
    Thanks
    Bettina

    Hi,
    I have been following this thread for quite long, here's my take on this
    1. Please create all the master data like sales man, customers in BI. for the key customers  add an attribute to key customer which can be a single character field.
    2. Add Sales man as an attribute to customer master and maintain values for each customer.
    3. Create an exit variable for customer number, this should read value from the sales man variable and populate all the key customers.
    4. Create an agg level with the above 2 and the required time characteristic. There will be 3 variables on the input ready query a. sales man number b. key customer exit variable c. some time period variable.
    5. Create a planning function of type generate combination for the agg level created in the above step. Add this function to the work book or the web template.
    6. Now salesman will be able to go in and create his budget for the key customers.
    Annual budget entry
    1. Create an agg level without customer, add salesman and time characteristics.
    2. create a query which will allow to enter data (yearly budget) for the salesman.
    Allocation to non key customers
    1. Create an agg level that should create the missing combinations sales man and non key customers. If designed properly the first agg level can also be used for this function.
    2. Create a fox function which with foreach loop for customer and sales man if the amount is 0 add 1 to counter, also read the value wtih customer as blank (yearly budget), lastly if the amount is not blank sum up the amount. This will help in getting the balance amount.
    3. get balance figure as total - allocated. One more foreach loop same as above if the amount is blank then amount = balance / counter.
    Tried to answer
    thanks

  • Predicate boolean method...calculating whether or not a year is a Leap year

    I'm trying to get pointed in the right direction for this program. I am attempting to write a program that calculates whether or not an inputted year by the user is a valid leap year or not, however I'm having problems figuring out the method for this calculation.
    A predicate method boolean seems to be the right way, but I can't figure out exactly how. Here's what I've brainstormed thus far:
    Leap Year Conditions:
    1. Is divisible by 4.
    2. Is NOT divisible by 100.
    3. Is divisible by 4.
    public class Year
              public boolean isLeapYear()
    }What confuses me is how to satisfy these conditions. Here is what I want to fill those '...' with. Excuse the tacky language coming up, but it's the only way I can express my thinking here:
    return ((inputted year) / 4) && (inputted year / 400) && !((inputted year) / 100)
    If the year is undivisible by any of these values then it could end up being a technical decimal (which means the inputtted year is not a leap year). But of course java would still calculate it anyway depending on how I defined the type.
    Should I try to implement a condition that if the variable returned by any of these calculations (except for 100) is a float point then the year is not a leap year? How would I do this?
    I'm really not sure where to go on this one. If anyone could point me in the right direction and give me a good start I would appreciate it. Thank you.
    Message was edited by:
    fairtex
    Message was edited by:
    fairtex

    http://en.wikipedia.org/wiki/Leap_year
    They have some leap year algorithms on there.

  • Handling weeks in Planning with leap years

    How are people handling weeks-based forecasting in Planning?
    I have a Planning app that has 53 time periods with an extra week in August to handle the leap year (thus the 53). There are dynamically calculated months, quarters, and the always-loved YearTotal in Time as well.
    This works fine in a leap year, but is kludgy otherwise as it includes an additional month in August – this skews form spreads.
    And it gets even uglier when calculating/data viewing year over year forms as the start week for September should vary across leap and non-leap years.
    It occurred to me that I could create a custom dimension called “Weeks” with all 53 weeks and then use a nested dimension strategy that combined a 12 months Time dimension and the relevant weeks (some hard coding there on forms). I could then use the form column/row suppression to show/hide weeks by month.
    The upsides:
    1)     Smaller block size, as Weeks would go sparse and Time would get reduced from 53 to 12 members.
    2)     True week/month relationships in reporting/forms through prepopulated data and suppression.
    3)     True 4-4-5 spreads to months (although an algorithm to spread to the separate Weeks would have to exist, but that is irrespecitive of the 4-4-5 spread). NB -- 445, etc., concepts don't work in a Planning app with weeks.
    I see a few downsides to this:
    1)     The possibility of entering data by week into the wrong month <-- Form construction could mitigate this.
    2)     Block creation issues in calcs as there is another sparse dimension to take care of.
    3)     Many more blocks <-- How about 53 of them?
    Any thoughts on this approach? I’m not scared of the calcs although I appreciate it’s a little more complicated. I don’t think it breaks the Scenario dimension’s opening/closing of periods. I guess I’m trying to see if there are any hidden issues with this approach and if anyone has figured out a better way to do this.
    Thanks,
    Cameron Lackpour

    The Calendar Component does take account of the leap year.
    If you look at the code, it has
    if ((month == FEBRUARY) && (isLeapYear(year))) numCells++;Not sure what went wrong. I'll take a look at it.
    - Winston

  • How to do a date validation with leap years

    I'm doing a date validation program in my Java class, and well it's pretty hard (for me that is). I have to be able to type in a date, have it say whether it's a leap year or not, and print out the number of days in the month. It seems pretty straight forward, but I get confused on trying to do the 'if else' statements and even the simplest things like getting the day prompting to work. >< The years I'm doing only goes through 1000 to 1999, so that's why those numbers are there. The program isn't complete, so if anyone could help show me what I'm doing wrong in the areas I'm working on then I'd appreciate it...and I'm still kind of in the basics of Java so if you do hint me with some code then I'd appreciate it if it was stuff that's not too advanced so yea.
    // Dates.java
    // Determine whether a 2nd-millenium date entered by the user
    // is valid
    import java.util.Scanner;
    public class Dates
    public static void main(String[] args)
    int month, day, year; //date read in from user
    int daysInMonth; //number of days in month read in
    boolean monthValid, yearValid, dayValid; //true if input from user is valid
    boolean leapYear; //true if user's year is a leap year
    Scanner scan = new Scanner(System.in);
    //Get integer month, day, and year from user
    System.out.print("Type in the month: " );
              month = scan.nextInt();
    System.out.print("Type in the day: " );
              day = scan.nextInt();
    System.out.print("Type in the year: " );
              year = scan.nextInt();
    //Check to see if month is valid
    if (month >= 1)
    month = month;
    else
    if (month <= 12)
    month = month;
    else;
    //Check to see if year is valid
    if (year >= 1000)
    year = year;
    else
    if (year <= 1999)
    year = year;
    else;
    //Determine whether it's a leap year
    //Determine number of days in month
    if (year == 1 || 3 || 5 || 7 || 8 || 10 || 12)
         System.out.println (Number of days in month is 31);
         else (year == 4 || 6 || 9 || 11)
         System.out.println (Number of days in month is 30);
    //User number of days in month to check to see if day is valid
    //Determine whether date is valid and print appropriate message
    // Dates.java
    // Determine whether a 2nd-millenium date entered by the user
    // is valid
    import java.util.Scanner;
    public class Dates
    public static void main(String[] args)
    int month, day, year; //date read in from user
    int daysInMonth; //number of days in month read in
    boolean monthValid, yearValid, dayValid; //true if input from user is valid
    boolean leapYear; //true if user's year is a leap year
    Scanner scan = new Scanner(System.in);
    //Get integer month, day, and year from user
    System.out.print("Type in the month: " );
              month = scan.nextInt();
    System.out.print("Type in the day: " );
              day = scan.nextInt();
    System.out.print("Type in the year: " );
              year = scan.nextInt();
    //Check to see if month is valid
    if (month >= 1)
    month = month;
    else
    if (month <= 12)
    month = month;
    else;
    //Check to see if year is valid
    if (year >= 1000)
    year = year;
    else
    if (year <= 1999)
    year = year;
    else;
    //Determine whether it's a leap year
    //Determine number of days in month
    if (year == 1 || 3 || 5 || 7 || 8 || 10 || 12)
         System.out.println (Number of days in month is 31);
         else (year == 4 || 6 || 9 || 11)
         System.out.println (Number of days in month is 30);
    //User number of days in month to check to see if day is valid
    //Determine whether date is valid and print appropriate message
    }

    Here are some helpfull hints for you:
    1. Your code is really hard to read, there are two main reasons for this. First, your indentation sucks. Second, you seem to be fascinated with saving two (ok four if you count the shift key) keypresses to avoid using { and }.
    2. Not using the brackets (you know { and } which you like to avoid) also is causing your code to do some stuff you don't realize or want to happen, or at least it would be if your code compiled.
    3. If statements require arguements, "year == 1" is an arguement, "3" is not an arguement. Each operator like the or operator ("||") is essentially a new if and requires a complete arguement. So the following code peice:
    if (year == 1 || 3 || 5 || 7 || 8 || 10 || 12)Literally translates to if year equals 1 or if 3 or if 5 or if 7 or if 8 or if 10 or if 12. Doesn't make much sense in english, and it doesn't make much sense in Java either.
    4. I am pretty sure "year" is not the variable you want in the code snippet above (the one used in hint 3), especially considering years 1, 3, 5, 7, 8, 10, and 12 are not between 1000 and 1999. You need to be really carefull not make these kind of mistakes when coding, because they are by far the hardest to track down and fix later since they don't really throw up any flags or anything at compile or run time. Take your time and think thuroughly about each line of code while coding it, it will save you tons of time in the long run.
    5. What exactly do you expect statements like "month = month;" to do? That translates as make month equal to month. Do you go to the bank and say " I have exactly $3.56 in my pocket, so I would like to deposite all $3.56 and then withdraw $3.56 and put it back in my pocket"? How do you think the teller would look at you? Teller would probably do it, but the teller would feel like he/she wasted time with you and that you are not really right in the head. Java feels the same way when you make it do the same thing, and you love to do it.
    6. Code like the following is all wrong, and for more reasons than pointed out in hint 5.
    if (month >= 1)
    month = month;
    else
    if (month <= 12)
    month = month;
    else;Let's say someone put 13 in as the month. It passes the first check because 13 is greater than or equal to 1. so month which is 13, now gets set to 13 (gee that was effective). Now we hit the else and things get confusing because you didn't use brackets or proper indentation (hint 1) so we don't know what your real intent was. Did you mean else do nothing, and the next if statement is then executed, or did you mean to just run the next if statement if the else condition was met? Fortunatly it doesn't matter here because the next if statement is failed anyways since 13 is not less than or equal to 12.
    So, we leave this code with month ebing 13, wait when did we add a 13th month to the calendar? Are you using the Jewish calendar? Could be, except even if I put 1234567 as the month your code would except it as valid, and I know no calendar with that many months. Try writing this in english first and translating it to jave, like i would probably say "if the month is greater than or equal to 1 and less than or equal to 12 then the month is valid." Course now what do you do if it is invalid? Hmm, maybe I would actually say "while the month is less than 1 or greater than 12 ask the user for the month" until they get it right.
    There are a few other problems, but most of them are probably things you haven't learned yet, and they are not show stoppers so we will let them fly. You already have a lot of work to do to make this better. But I do have one more really really big usefull hint for you:
    Never, ever, under any circumstances, should you ever ask in any way or even hint at asking for someone else to provide code solutions to your problems. So "so if you do hint me with some code then I'd appreciate it if it was stuff that's not too advanced " was a very bad thing to do, but fortunatly for you you followed it with proof you were trying to write the code yourself. Had the code you provided not been so full of problems it was obvious a beginner wrote it, you would probably have gotten much less cordial responses. I would seriously consider avoiding any implication of wanting code, at least until you become a regular poster here and people know you are not just looking to get your homework done for you.
    Hope some of this helps.
    JSG

  • Problem with Nested loop in Fox-Formula

    Dear Experts,
    Let s share the scenario :
    MaterialGroups with following Keys for Example AAAA, BBBB, CCCC..., Materialgroups are selected in the 1st input ready query, which is assigned to DataProvider DP_1 in a  webtemplate.
    every Materialgroup has several Materials, for instance:
    Materialgroup AAAA has following Materials: AAAA10, AAAA11, AAAA12, AAAA13...
    Materials are  selected in a second  input ready Query, which is assigned to a second DataProvider DP_2 in the Same Webtemplate as the query 1.
    Both Materialgroup and Material are based on the same Aggreagtion level and same real time cube.
    I want to copy the input values for every  MaterialGroup ( 1st query, DP_1) only to it s own Materials (2cond Query, DP_2).
    To resolve this Issue i wrote the following Fox Formula code with a nested loop, however it does not work properly. when I m debugging the code, i could release that the second Loop was ignored.but wehn i replace the second loop (nested loop) with a fixed value it s seems to work properly
    DATA MG1 TYPE MATG.<------ MaterialGroup
    DATA MT1 TYPE MAT.<----
    Material
    DATA S1 TYPE STRING.
    DATA S2 TYPE STRING.
    DATA S3 TYPE STRING
    DATA K TYPE F.
    DATA Z TYPE F.
    FOREACH MG1.
    To check Materialgroup in debugger
    S1= MG1.
    BREAK-POINT.
    K = {KEYfIG, #, MG1}.
    BREAK-POINT.
    FOREACH  MT1.   <----- if i set MT1 to a fixed value like AAAA11 then S3 get the wished value namely AAAA
    S2 = MT1.
    BREAK-POINT.
    S3 =  SUBSTR (MT1, 0, 4).  
    BREAK-POINT.
    IF S1 = S3.
    {KEYFIG, MT1, #} = K.
    following Statement is only used To check in debugger if Material has become the same Materialgroup value
    Z = {KEYFIG, MT1, #}.
    BREAK-POINT.
    ENDIF.
    ENDFOR.
    ENDFOR.
    Thakns for any help
    Frank
    Edited by: FRYYYBM on Mar 17, 2011 10:54 PM
    Edited by: FRYYYBM on Mar 17, 2011 11:06 PM

    Hi,
    Please try this way.
    DATA MG1 TYPE MATG.<------ MaterialGroup
    DATA MT1 TYPE MAT.<----
    Material
    DATA S1 TYPE STRING.
    DATA S2 TYPE STRING.
    DATA S3 TYPE STRING
    DATA K TYPE F.
    DATA Z TYPE F.
    FOREACH MT1.
    FOREACH MG1.
    To check Materialgroup in debugger
    S1= MG1.
    BREAK-POINT.
    K = {KEYfIG, #, MG1}.
    BREAK-POINT.
    FOREACH MT1. <----- if i set MT1 to a fixed value like AAAA11 then S3 get the wished value namely AAAA
    S2 = MT1.
    BREAK-POINT.
    S3 = SUBSTR (MT1, 0, 4).
    BREAK-POINT.
    IF S1 = S3.
    {KEYFIG, MT1, #} = K.
    following Statement is only used To check in debugger if Material has become the same Materialgroup value
    Z = {KEYFIG, MT1, #}.
    BREAK-POINT.
    ENDIF.
    ENDFOR.
    ENDFOR.
    ENDFOR.
    Thanks.
    With regards,
    Anand Kumar

  • Problem with leap years in Calendar demo

    I've just looked at the Calendar demo component:
    http://developers.sun.com/prodtech/javatools/jscreator/reference/codesamples/samplecomps/calendar.html
    There is a little bug : it doesn't seem to manage leap years.
    Go to february 2008, and you won't the the 29th of February 2008 in the calendar.
    Please try to correct this bug quickly. It is a bad idea to let people get source code with bugs as a a demo.
    Thanks
    Thibaut REGNIER
    See TastePhone, my Open Source app made whith Java Studio Creator:
    http://www.club-java.com/TastePhone/J2ME/MIDP_mobile.jsp

    The Calendar Component does take account of the leap year.
    If you look at the code, it has
    if ((month == FEBRUARY) && (isLeapYear(year))) numCells++;Not sure what went wrong. I'll take a look at it.
    - Winston

Maybe you are looking for

  • How to search file in application server using pattern

    Hi all, I want to search file in application server. Suppose there is file named abc20090808.dat. Is there is any function module to search the file? it should return back the file names starting with abc, if the import parameter is abc* Regards, Nik

  • Problem with forum

    Greetings I had been away from the discussion boards for a while, and when i tried to log in got a "This ID has been suspended for security reasons' error. I figured I might be using the wrong username or password (hey, it's been a while) so I chose

  • Can we rename the Apply button to RUN or GO in BI Publisher 11g?

    Hi , We have a requirement to rename the Apply button to RUN or GO. ( after selecting the parameters , we have to click the Apply button) Can this be achieved? Thanks Ashish

  • Solaris volume manager ; finding free space

    Hello Is there a way to find out the space available in a metadevice for creating new soft partions? I am looking for the equivalent of the following vxvm commands vxdg free vxassist maxsize Thanks in advance

  • How to invalidate session after some time

    How can I assign null value to session if user does not interact with the jsp page uptill M minutes. (Here M is variable, say after 5 minutes)