Is there a completely reliable method of adding months to a date in ABAP?

Does anyone know of a completely reliable and consistent ABAP function module that can be used to add months to a date.  One that will always get the correct last day of the month when requested to add 1 month to the last day of the previous month.  Something as reliable as using the ADD_MONTHS function in Oracle SQL.  I don't want to use any of the specific 'get last day of the month' function modules since the start date may not necessarily be the last day of a month.
In the past I have trusted the following.  Now they have betrayed me. 
MONTHS_PLUS_DETERMINE  
Correctly provides 28.02.09 when adding 1 months to 31.01.09.
Incorrectly gives me 28.03.09 instead of 31.03.09 when adding 1 month to 28.02.09
RP_CALC_DATE_IN_INTERVAL and RP_CALC_DATE_IN_INTERVAL_SG
Both incorrectly give me 01.03.09 when asked to add 1 month to 31.01.09.
Both incorrectly give me 28.03.09 when asked to add 1 month to 28.02.09.
We're on ECC6.

>
Suhas Saha wrote:
> Hello Christine,
>
> Did you check the method ADD_MONTHS_TO_DATE of the class CL_HRPAD_DATE_COMPUTATIONS ?
>
>
> *     Adds No. of Months to Date
>       TRY.
>           CALL METHOD cl_hrpad_date_computations=>add_months_to_date
>             EXPORTING
>               start_date = sy-datum
>               months     = l_v_month
>             RECEIVING
>               date       = l_v_date.
>         CATCH cx_hrpa_violated_postcondition .
>       ENDTRY.
>
>
> I dont have any idea how ADD_MONTHS function in Oracle SQL works, though ):
>
> Hope this helps.
>
> BR,
> Suhas
That also sometimes works.....but adding 1 month to 28.02.2009 gives me 28.03.2009 and adding 1 month to 29.02.2008 gives me 29.03.2008.
This is how to use ADD_MONTHS in Oracle SQL - a bit naughty since you have to use native SQL to do it but it ALWAYS seems to work.  I pass a date, month number and + or - into the function module.
* For use with class based exception CX_SY_OPEN_SQL_DB.
DATA:
  ex_check_os       TYPE REF TO cx_sy_open_sql_db,
  ex_check_rs       TYPE REF TO cx_sy_native_sql_error,
  ex_result(200)    TYPE C,
  ex_text           TYPE STRING,
  lv_new_date       TYPE datum,
  lv_old_date       TYPE datum,
  lv_months         TYPE I.
  lv_old_date = iv_date.
  lv_months = iv_months.
  IF iv_sign = '-'.
     lv_months = lv_months * -1.
  ENDIF.
  TRY.
    EXEC SQL.
      SELECT to_char(add_months(to_date(:lv_old_date,'YYYYMMDD'),:lv_months),'YYYYMMDD')
      INTO :lv_new_date
      FROM sys.dual a
    ENDEXEC.
    CATCH cx_sy_native_sql_error INTO ex_check_rs.
    ex_text = ex_check_rs->get_text( ).
    ev_error_message = ex_text.
    ev_return = 4.
  ENDTRY.
  ev_return = 0.
  ev_date = lv_new_date.

Similar Messages

  • (Almost) Completely Reliable Method of Building AUR Pkgs with Clang

    The concise wiki directions to add `export CC=clang\nexport CXX=clang++` to makepkg.conf fails to address the unfortunate plethora of pkgbuilds that include GCC specific build options or otherwise prevent this from working.
    Since, at this point, there are very few sources that actually will not build with clang and appropriate options; there has to be a way to "help" pkgbuilds adapt to clang/clang++. My suspicion is that some sort of standard regex replacements of incompatible options should help many of the simpler cases; but I am far from actual knowledge on this point.
    Has anyone gotten a `makepkg.conf` + ??? setup to work reasonably well?

    Welcome to the forums.
    Please edit your post.
    When posting configs, code or command output, please use [ code ] tags https://bbs.archlinux.org/help.php#bbcode
    like this
    It makes the code more readable and - in case of longer listings - more convenient to scroll through.

  • Adding months to a date

    I`m setting up ranges for searching a database. I plan to use
    a combobox for choosing 'year', 'month', 'week' as ranges from a
    given date. I have one datefield for the start date, and want
    another one to reflect the date of the range limit.
    In other words, I want to select '1 month', '2 months' etc.
    from a combobox and calculate the end date.
    Anyone ?

    "toft" <[email protected]> wrote in message
    news:gnaor6$hgf$[email protected]..
    > I`m setting up ranges for searching a database. I plan
    to use a combobox
    > for
    > choosing 'year', 'month', 'week' as ranges from a given
    date. I have one
    > datefield for the start date, and want another one to
    reflect the date of
    > the
    > range limit.
    >
    > In other words, I want to select '1 month', '2 months'
    etc. from a
    > combobox
    > and calculate the end date.
    http://flexdiary.blogspot.com/2008/05/working-with-dates-in-as3.html

  • Is there a reliable method for detecting that a query is too large?

    I am writing some code (that uses OCI) to properly detect when a query string is too long for OCI and/or the Oracle database server. I can't find any specific error code information in the docs, so I just started firing off large queries to see what would happen.
    The queries I am sending are >2MB in size, up to 16MB. If the queries are above ~10MB, I get the error "ORA-03113 'End-of-file on communications channel'" after a fairly short amount of time (i.e. not enough for a timeout to expire). If the queries are below ~10MB, but above ~2.5MB, it either just sits there and does not do anything (for more than 15 hours). So watching for ORA-03113 when executing large queries does not seem like a very reliable method for detecting the queries that are too large.
    Does anyone know of a reliable way of detecting that a query is too large for the OCI client and/or the Oracle database server?
    I am using version 10.2.0.1 for both the OCI client and the Oracle database server, but I'm getting similar errors for combinations of 10.2.0.1 and 9.2.0.7 for both the OCI client and the Oracle database server.
    These large queries need to be handled properly (i.e. distinguished from some generic failure) because the server handles requests from users, which could be programs that generate SQL queries (and have constructed huge ones in the past).
    Thanks for any information!

    The ORA-03113 means that the Oracle server process has died trying to satisfy your request. In almost all cases it is strictly correct to call that a bug, and we shouldn't easily forgive the server process when it happens. But in the case of multimegabyte statements my anger and disapointment turns to sympathy, for in my heart I can't bring myself to blame it. Can you?

  • Time Machine is EXTREMELY SLOW. What is the best way to make a complete, reliable copy of the hard drive before i erase the disk?

    I was given an older iMac (from 2010) on the condition i first create a complete, reliable copy of everything on her hard drive and then wipe it clean.  Is Time Machine the best way to do this so that she can use this data when she needs it?  I started Time Machine but it is so slow, at this rate it will take at least 10 days to do the first backup.  I'm already on the 3rd day now at about 2.5 GB per day.  Is there a better way that is reliable?  perhaps some kind of disc copy? This iMac has 4gb memory,processor: 3.06 gHz Intel core i3, model iMac11,2, 1 processor, 2 cores.  thank you

    Choices.
    Clone  - Carbon Copy Cloner          (Often recommended as it has more features than some others)
    Clone – Data Backup
    Clone – Deja Vu
    Clone  - SuperDuper
    Clone - Synk
    Clone Software – 6 Applications Tested
    Time Machine Versus Clones and Archives
    Commonly Used Backup Methods

  • My iPad camera photos will wirelessly sync with my iMac and iCLoud photo stream, but the videos do not, is USB connection the only way to transfer videos or is there also a wireless method?

    My iPad camera photos will wirelessly sync with my iMac and iCLoud photo stream, but the videos do not, is USB connection the only way to transfer videos or is there also a wireless method?

    Videos are not included with the Photo Stream. Photo Stream is for photos only.
    There is not a wireless method for importing videos from the iPad's Camera Roll.

  • I have numerous music movie clips that I have not purchased through iTunes, can I stream these "home" movies to apple TV? And if this is not possible, is there another complete program available that I can purchase to have my music movie clips stream to a

    I have numerous music movie clips that I have not purchased through iTunes, Is it possible to stream these "home" movies using iTunes to apple TV?
    And if iTunes will not allow it, is there another complete program available that I can purchase to have my music movie clips stream to a TV and/or another computer?
    Any help would be appreciated. Thanks

    Thanks, Winston C, I've actually tried everything you suggested. I'm thinking now that the Home Sharing problem likely is related to Bonjour--I've seen several people mention this with similar (but not identical) problems. The solution that seems to work for some people is to uninstall and reinstall Bonjour. Frankly, I don't want to go through the trouble given that the iOS 7 release is imminent.
    One thing that I haven't tried is resetting the ATV to factory settings. I'll give that whirl.
    Thanks for your advice!

  • When i connect my iphone to my imac itunes opens but my itunes is not there.  My wife has recently added herself to the computer

    When i connect my iphone to my imac, itunes opens but my itunes is not there.  My wife has recently added herself to the computer
    and her itunes appears but i cannot find my itunes?

    Not really! Anyhow, what do you want to achieve. The only things you can access in your iPad outside of using iTunes are photos and videos. [Locate the iPad as any other external device through Windows Eplorer or Finder and dig through the folders.]
    You are fortunate that iTunes opens when you connect the iPad since many other users have difficulty in achieving this. It is from there that you can manage what you want synced to the iPad.

  • Is there a complete outstanding buglist ?

    Hi everyone,
    Is there a complete outstanding iAS buglist somewhere in iPlanet site?
    (Apart from SP3 release notes, on what it is fixed, coz I am looking for
    outstanding bugs so that I should be aware of :p )
    Thanks!
    Mark Andrews

    As per my knowledge all subledger entries link will be stored in the below tables provided if you complete the accounting. can you check are you accounting any transactions in projects ?
    Below is the output from our instance.
    select distinct SOURCE_DISTRIBUTION_TYPE from XLA.XLA_DISTRIBUTION_LINKS
    SOURCE_DISTRIBUTION_TYPE
    DEPRN
    AP_INV_DIST
    AR_DISTRIBUTIONS_ALL
    TRX
    PO_DISTRIBUTIONS_ALL
    WIP_TRANSACTION_ACCOUNTS
    AP_PMT_DIST
    AP_PREPAY
    XLA_MANUAL
    RA_CUST_TRX_LINE_GL_DIST_ALL
    PO_REQ_DISTRIBUTIONS_ALL
    MTL_TRANSACTION_ACCOUNTS
    RCV_RECEIVING_SUB_LEDGER

  • I want to change my account payment method to none and I do not have a credit card yet.Plus, iTunes gave a message saying that I need to review my account and when I go there,the none payment method is hidden.

    I want to change my account payment method to none and I do not have a credit card yet.Plus, iTunes gave a message saying that I need to review my account and when I go there,the none payment method is hidden.

    Assuming that you want help and that you aren't just copying-and-pasting that thread's title and posting a link to it, then have you tried the steps on the post that I linked to in my first reply on that thread ?
    If you don't get the 'none' option when trying those instructions then you will need to enter credit card details before you will be able to use the account - when you've entered credit card details you should get the 'none' option and be able to remove your card details.
    Or you can create a new account, and follow, exactly, the steps on this page when creating it' : http://support.apple.com/kb/HT2534

  • Is there anyway to view ALL 'things' added to my Macbook pro in chronological order?

    Is there anyway to view ALL 'things' added to my Macbook Pro in chronological order?

    From the Finder menu select View>Show View Options. Then check the Date Created box only.

  • Is there a Function or Method to automaticaly generate passwords?

    hi there,
    is there a Function or Method which generates passwords?

    Check the below sample code paste and check in SE38
    data lv_genpassword type char08.
    CALL FUNCTION 'RSEC_GENERATE_PASSWORD'
    EXPORTING
       ALPHABET                   = '0123456789ABCDEFGHIJKNPQRSTUVXYZ'
       ALPHABET_LENGTH            = 36
       OUTPUT_LENGTH              = 8
    IMPORTING
       OUTPUT                     = lv_genpassword
    EXCEPTIONS
       SOME_ERROR                 = 1
       OTHERS                     = 2
    IF sy-subrc <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
             WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    else.
       write lv_genpassword.
    ENDIF.
    Kanagaraja L
    Edited by: Kanagaraja  Lokanathan on Sep 3, 2009 2:36 PM

  • Simple and reliable method to preform an OCR on a pdf? [SOLVED]

    I have Acrobat at work which does a wonderful job preforming an OCR (optical character recognition) on scanned pdf files so that one can do keyword searching within the pdf.  I have spent the past hour following-up various guides on the 'net at large which do not work for me.  Can someone recommend a simple and reliable method to accomplish this?
    Last edited by graysky (2014-03-30 13:50:34)

    I can second OCRFeeder. It can use different OCR engines, and the application doesn't hide the complexity of the options that these engines accept, so with a little fine tuning you should get reasonable results. For Latin text, that is. For non-Latin or mixed scripts, all  FOSS engines are essentially useless (I've tried long and hard to get Japanese OCR to work).
    To be honest, I myself only use Acrobat now because it's the only thing that produces consistently excellent results. For example, text selection will often not work smoothly  because the FOSS tools don't group the text objects properly into lines or paragraphs.

  • I have an iMac 27" which is 4  years old and probably overdue for a clean-up. Is there any good reliable software out there that would help? Has anyone had any experience of 'Mackeeper'?

    I have an iMac 27" which is 4  years old and probably overdue for a clean-up. Is there any good reliable software out there that would help?
    Has anyone had any experience of 'Mackeeper'?

    Check how many applications are starting when you log in, I found that if there was a lot of activity at login Finder did not display the icons on the desktop correctly, again like you it did not occur at every login, just occasionally.
    For Safari have you tried resetting Safari, if that does not help you could disable plugins and extensions one at a time. You may find one of those is causing the problem.

  • Netbeans 6.0 - code completion of method parameters

    I just updated to NetBeans 6.0 and I find the code completion of method parameters very annoying and counter productive.
    It inserts the parameters as keywords when choosing a method from the list after pressing CTRL+SPACE.
    How can I switch this off?
    I searched the options and also the forum but didn't find a solution.

    I know that pressing space or whatever replaces the selected parameter. For a method with a single parameter is not a big problem but this is a poor workaround if a method has more parameters, like eg
    public static String formatDate(Date myDate, String myFormat)
    When typing
    Str.form<CTRL+SPACE,choose method, ENTER>
    it looks like
    Str.formatDate(myDate, errorMessage)
    Although myDate is selected and I can overwrite it, I have to proceed to the next parameter with CTRL+M instead of simply typing a comma. This is very annoying if a method has more parameters and as this annoyance occurs approx. every 5 lines that accumulates.

Maybe you are looking for

  • Creating a cartoon from regular image

    Okay, I am trying my hands at vector graphics and there is something that I found that I really want to learn to do. I would like to know how to take a regular image and make it look like a type of cartoon. Here are two example of what I am looking t

  • Your Music Saved Albums library disappearing

    Recently I've been using the "saved album" section found under the Your Music tab but have had all the albums I saved disappear even the albums that were ticked for offline play. I press the save album button which would save the album under the "sav

  • Problems listing locked accounts

    Hi! I'm having some problems listing locked accounts. They usual receipe is "log in to the SSO self-service console (oiddas) - choose Directory, then Users, there it will be some unlock-options etc." However, I don't have that option within the Users

  • Serious Bug: Crimson \ JSTL

    Hi, I have been experiencing problems whilst attempting to use the JSTL Standard Tag Library with the Apache Crimson XML Parser in the classpath. I have tried running the JSTL JSP page without Crimson in the classpath and it works fine. However when

  • How to getParameter() from more than one pages

    I have two jsp pages which using "next" link together. on second page action it call servlet which has getParameter() for getting user input. It only gets the second page's value not the first page's. how can I fix this problem? Thanks, j