Skip to Content

Chalange: where is the bug?

Hi everybody,

in the below code there is bug. At least for the release 700 P22. The code is so short and simple, that, I believe, it can be interesting exercise for you to test your in-brain debuggers! So here you are with the challenge. There will be no prices, just a winner. I'm going to post a hint in a week.

FUNCTION CALCULATE_DATE.*"----------------------------------------------------------------------*"Lokale Schnittstelle:*"       IMPORTING*"             DAYS DEFAULT '0'*"             MONTHS DEFAULT '0'*"             START_DATE DEFAULT SY-DATUM*"       EXPORTING*"             RESULT_DATE*"----------------------------------------------------------------------  DATA: NO_MONTHS TYPE I,        NO_YEARS TYPE I,        DATE_D TYPE D.  DATE_D = START_DATE.  NO_MONTHS = DATE_D+4(2) + MONTHS.  NO_YEARS =  NO_MONTHS DIV 12.  NO_MONTHS = NO_MONTHS MOD 12.  NO_YEARS = DATE_D+0(4) + NO_YEARS.  IF NO_MONTHS = 0.    NO_YEARS  = NO_YEARS - 1.    NO_MONTHS = 12.  ENDIF.  DATE_D+0(4) = NO_YEARS.  UNPACK NO_MONTHS TO DATE_D+4(2).  DATE_D = DATE_D + DAYS.  RESULT_DATE = DATE_D.ENDFUNCTION.
Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

2 Answers

  • Best Answer
    Posted on Nov 29, 2013 at 09:54 AM

    As @Jürgen L notified me, there is already a correct answer on SCN : http://scn.sap.com/thread/1870005

    So I apologize for the double posting. A moderator can eventually remove the above post :-)

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Nov 29, 2013 at 09:40 AM

    The data defenition of DATE_D TYPE D is wrong.

    It should be as SY-DATUM only.

    Because, when the START_DATE is given as 29.11.2013, then, (which is 20131129)...

    then the DATE_D is stored as 29.11.20.

    This is the problem,

    So further calculations are wrong

    The output is not a valid date

    Regards,

    Venkat

    Add a comment
    10|10000 characters needed characters exceeded

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.