Function module to subtract a number of months from a date

I have a field, FISCPER, in the format YYYY/MMM(2007004) and I need to subtract 12 months off of it to get 2006004.  I tried to just subtreact 12 but it gave me the actual value when you subtract the 2.

Hi,
Check the following example:
FM to Get the Day for a Particular Date
FM or any other means by which we can get the DAY for a particular date?
Yes, DATE_COMPUTE_DAY
Sample code:
  clear: hold_day_of_week.
  CALL FUNCTION 'DATE_COMPUTE_DAY'
       EXPORTING
            DATE = workdate
       IMPORTING
            DAY  = day_of_week_num
       EXCEPTIONS
            OTHERS  = 8.
  CASE day_of_week_num.
    WHEN 1.
      hold_day_of_week = 'Monday'.
    WHEN 2.
      hold_day_of_week = 'Tuesday'.
    WHEN 3.
      hold_day_of_week = 'Wednesday'.
    WHEN 4.
      hold_day_of_week = 'Thursday'.
    WHEN 5.
      hold_day_of_week = 'Friday'.
    WHEN 6.
      hold_day_of_week = 'Saturday'.
    WHEN 7.
      hold_day_of_week = 'Sunday'.
    WHEN OTHERS.
      hold_day_of_week = 'invalid'.
  ENDCASE.
or 
You can use  DATE_COMPUTE_DAY to get the day number of the week (for example, today gives 5)
then use WEEKDAY_GET which returns an itab with seven entries (one for each day of the week.)
You enter in this itab and get the field langt to get the day name.

Similar Messages

  • Function module which could calculate the previous month's start date.....

    hi,
    I want a function module which could calculate the previous month's start date and end date...
    Say todays date is  like 29.05.2007(start date) it should return
    01.04.2007 and 30.04.2007...
    IS there any FM for this ... or how to go about this scenario ???
    thanks in advance
    samm

    See the below Logic :
    DATA :g_date(2) TYPE n,           " Date
          g_month(2) TYPE n,          " Month
          g_year(4) TYPE n ,          " Year
          g_bill_low(10) TYPE n,       " From date
          g_bill_high(10) TYPE n,      " To date
          g_month1(2) TYPE n,         " Month
          g_year1(4) TYPE n,          " Year
          g_date1(2) TYPE n,          " Date
          g_year2(4) TYPE n,          " Year
          g_datum LIKE sy-datum.      " System date
    RANGES : r_bdate  FOR vbrk-fkdat.             " Billing date
      g_datum = p_date + 10.
      g_month = g_datum+4(2).
      g_year = g_datum+0(4).
      IF g_month = 1.
        g_year = g_year - 1.
        g_month = 12.
        g_date = 1.
      ELSE.
        g_month = g_month - 1.
        g_date = 1.
      ENDIF.
    Passing the date to billing date-low
      CONCATENATE  g_year g_month g_date  INTO g_bill_low.
      r_bdate-low = g_bill_low.
      r_bdate-sign = 'I'.
      r_bdate-option = 'BT'.
      g_month1 = g_datum+4(2).
      g_year1 = g_datum+0(4).
      IF g_month1 = 1.
        g_year1 = g_year1 - 1.
        g_month1 = 12.
      ELSE.
        g_month1 = g_month1 - 1.
      ENDIF.
      CASE g_month1.
        WHEN 1.g_date1 = '31'.
        WHEN 3.g_date1 = '31'.
        WHEN 4.g_date1 = '30'.
        WHEN 5.g_date1 =  '31'.
        WHEN 6.g_date1 = '30'.
        WHEN 7.g_date1 = '31'.
        WHEN 8.g_date1 = '31'.
        WHEN 9.g_date1 = '30'.
        WHEN 10.g_date1 = '31'.
        WHEN 11.g_date1 = '30'.
        WHEN 12.g_date1 = '31'.
      ENDCASE.
      g_year2 = g_year1.
      IF g_month1 = 2.
        g_year2 = g_year2 MOD 4 .
        IF g_year2 = 0.
          g_date1 = 29.
        ELSE.
          g_date1 = 28.
        ENDIF.
      ENDIF.
    Passing the date to billing date-high
      CONCATENATE  g_year1  g_month1  g_date1 INTO g_bill_high.
      r_bdate-high = g_bill_high.
      APPEND r_bdate.
    Reward Points if it is helpful
    Thanks
    Seshu

  • Function module to retrieve day of the week from a date.

    Hi Experts,
    i am looking for a function module to retrieve the day of the week from a specific date. For example, the date is 20070820. The day of this date is 'Monday'.
    Please let me know how do i get the result i.e. 'Monday'.
    thanks a lot for ur timely help.
    Best regards,
    Aksh

    DATE_COMPUTE_DAY
         Returns a number indicating what day of the week the date falls on. Monday is returned as a 1, Tuesday as 2, etc.
    DATE_IN_FUTURE
         Returns a number indicating what day of the week the date falls on. Monday is returned as a 1, Tuesday as 2, etc.
    DAY_ATTRIBUTES_GET
         Return useful information about a day. Will tell you the day of the week as a word (Tuesday), the day of the week (2 would be Tuedsay), whether the day is a holiday, and more
    regards,
    srinivas

  • Any1 aware of a function module to convert a number in exponential form

    any1 aware of a function module to convert a number in exponential form to normal form...
    eg... a no. like 8.00000000000004E-01 
                     8.88888888888884E-01
    and
    a no. like 1.50000000000000E+00 
               9.44444444444442E-01

    I think you can just move from type F to type p.
    p =  f .
    Regards,
    Rich Heilman

  • Function Module to get pernr number based on first name and last name

    Hi All,
    What is the Function Module to get pernr number based on first name and last name.
    Could you please help me.
    T@R.
    Vidya

    hi Vidya,
    you can get perner from PA0002 based on firs name and last name.
    use select query and get perner.

  • Function Module to determine the number of pages in a pdf file

    Hi All,
    Is there any standard function module to determine the number of pages in a pdf file?
    Thanks,
    Sai

    Hi unk2,
    There's no functionality in the Acrobat.com online services to do a character count. But, you could use ExportPDF to convert your PDF file to Word format, and then do your character count in Word.
    Please let us know if you need additional assistance.
    Best,
    Sara

  • Function module for assigning BP Number to the Postion ID in org model

    Hi Experts,
    Is there any function module for assigning BP Number to the Postion ID in organizational model.
    The requirement is:
    1)There are some employees which are reporting to a Manager who has a position ID.
    2) Each of these employees should be assigned to the given position ID.
    This can be done by First Locate the BP Record in SAP via the Vantive Person ID  and retrieve the SAP BP Number.
    <b>Then assign the SAP BP Number found to the Position ID.</b>
    My question is <b>Is there any function module for assigning BP Number to the Postion ID .</b>
    Looking forward for reply.
    Thanks & Regards,
    Renju.

    Hi,
       Org. management uses API classe objects with static methods as APIs. You may be able to achieve this using
    CL_CRM_ORGMAN_SERVICES->MAPPING_ORGUNIT_TO_BP
    Reward if helpful!
    Regards,
    Sudipta.

  • Is there any Function Module to create SERIAL NUMBER

    Hi All,
         I need to create "SERIAL NUMBER" by passing "Material & Equipment Category ('S' -Always) ".
    Plz Advise me , is there any Function Module to Create  "Serial Number ".
    Thanks in Advance.
    Vyshu.

    hi,
    check this function module
    'NUMBER_GET_NEXT
    Search with  NUMBER_GET_NEXT keyword
    Thanks & REgards

  • Function module for GL account open items at a key date

    Is there a function module for "GL account open items at a key date" similar to following for customer and vendor accounts?
    BAPI_AR_ACC_GETOPENITEMS Customer account open items at a key date
    BAPI_AP_ACC_GETOPENITEMS Vendor account open items at a key date
    If not, please suggest any alternatives. I am looking to capture the output of FBL3N (GL account line item display) in a program.
    Thank you in advance.
    Prasanna Pujari

    hi,
    please go through the below link i think it will help u.
    http://sapfunctional.com/FI/GL/Balance.
    Regard
    Abhishek Tripathi

  • Derive Number of months from variable entry

    I have a requirement to calculate the average sales qty using the number of months entered in the variable entry and not the actual number of months the product was sold. For example Variable cal month entered as the range 01/2009 - 03/2009. The average needs to be calculated with the 3 month range even if sales only occurred in months 01 and 02. I understand I need to create a formula variable type customer exit, but I need assistance in creating the formula that would count the number of months from the variable entry.
    Any help would be appreciated.
    Craig

    Hi,
    Yes you can replace the variable and use if the code has been declared in such a way. Use i_t_var_range instead of It_var_range. This is a table which should been defined in your existing code.
    I have modified the code. Hope this helps
    WHEN 'FORMULAVARIABLE'.
    IF I_step = 2.
    CLEAR l_s_var_range.
    LOOP AT l_t_var_range INTO l_s_var_range WHERE vnam = 'MONTH_VARIABLE'.
    CLEAR l_s_range.
    l_s_range-low = l_s_var_range-high4(2) - l_s_var_range-low4(2) + 1
    IF l_s_range-low < 0.
    l_s_range-low = l_s_range-low + 12
    endif.
    l_s_range-sign = 'I'.
    l_s_range-opt = 'EQ'.
    APPEND l_s_range TO e_t_range.
    CLEAR l_s_range.
    ENDLOOP.
    endif.
    Regards
    Akhan

  • Subtracting months from current date

    how to subtract months from current date in mysql

    You are in an Oracle forum, so the Oracle answer is: use add_months(sysdate,-2) to subtract two months from the current date.
    Regards,
    Rob.

  • How to get name of the month from current date.

    Hi,
       How to get the name of the month from current date.
    Thanks,
    Senthil

    Sethil,
    Use your date(let us say Date1) instead of sy-datum.
    CALL FUNCTION 'MONTH_NAMES_GET'
    EXPORTING
    LANGUAGE = SY-LANGU
    IMPORTING
    RETURN_CODE =
    TABLES
    MONTH_NAMES = itab_month
    EXCEPTIONS
    MONTH_NAMES_NOT_FOUND = 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.
    ENDIF.
    READ TABLE itab_month
    WITH KEY MNR = date1+4(2).
    itab_month-LTX will contain the value you are looking for
    Good luck
    Raghava

  • How to calculate number of days from a date field

    Dear BW Experts.
    I have a field 'Create Date' in the BEx query. Now we need to create a variable which should give the number of days from the date of running the query (sy-datum) to the Create Date.
    This will help the users to get records which are say, 30 days old (Sy-datum - create date = 30) or 10 days old etc.
    Could you suggest as to how to create this variable.
    Thanks,
    Sai

    Hi,
    Step 1: Create variable on "Create Date" with User entry processing type
    Step 2: Create a restricted KF for Sales & restrict it on "Create Date" to get "Sales on day"
    Step 3: Manipulate  the values of "Create Date" on which you could restrict  "Sales" again and again to get other values
    Step 4: Create one variable (ZPUTMNTH) for u201CMonth to Dateu201D with processing by u201CCustomer Exitu201D. This variable was created  on u201CDateu201D characteristics.
    Step 5 : Goto C-mod t-code and use EXIT_SAPLRRS0_001
    to calculate "month to date" user input is "Calday" Key Date
    WHEN 'ZPUTMNTH'.
    IF I_STEP = 2. "after the popup
    LOOP AT I_T_VAR_RANGE INTO LOC_VAR_RANGE
    WHERE VNAM = 'ZPDATE'.
    CLEAR L_S_RANGE.
    L_S_RANGE-LOW = LOC_VAR_RANGE-LOW(6). "low value, e.g.YYYYMM (200606) part of key date (20060625)
    L_S_RANGE-LOW+6(2) = '01'. u201C low value e..g. YYYYMM01 (20060601)
    L_S_RANGE-HIGH = LOC_VAR_RANGE-LOW. "high value = input
    L_S_RANGE-SIGN = 'I'.
    L_S_RANGE-OPT = 'BT'.
    APPEND L_S_RANGE TO E_T_RANGE.
    EXIT.
    ENDLOOP.
    ENDIF.
    Assign if helps.....
    Regards,
    Suman

  • URL in lieu PH consumed within 3 months from the date of PH

    Hi friends
    I achieved Unrecorded leave in lieu of PH,through writing PCR but i am having another doubt..This URL in lieu of PH has to be consumed within 3 months from the date of public holiday,how to achieve this??any suggestions from u friends???
    Thanks&best regds
    Shaila

    I have asked a moderator to provide assistance, they will post an invite on this thread.
    They are the only BT employees on this forum, and are a UK based team of people, who take personal ownership of your problem.
    Once you get a reply, make sure that you are logged into the forum, then click on their name, you will see a screen like this. Click on the link as shown below.
    Please do not send them a personal message, as they cannot deal with service issues that way.
    For your own security, do not post any personal details, on this forum. That includes any tracking number you are give.
    They will respond either by phone or e-mail, when its your turn in the queue.
    Please use the tracked e-mail, to reply, not via the forum. Thanks
    This is the form you should see when you click on the link. If you do not see this form, then you have selected the wrong link.
    When you submit the form, you will receive an enquiry number, so please keep a note of it
    There are some useful help pages here, for BT Broadband customers only, on my personal website.
    BT Broadband customers - help with broadband, WiFi, networking, e-mail and phones.

  • Get the month from a date column with the calculated column

    I am trying to get the month from a date field with the help of calculated column. However I get this syntax error whenever I want to submit the formula:
    Error 
    The formula contains a syntax error or is not supported. 
    the default language of our site is German and [datum, von] is a date field.

    Hi,
    I have created two columns
    Current MM-YY
    Calculated (calculation based on other columns)
    Today
    Date and Time
    Current MM-YY is calculated value with formula as
    =TEXT(Today,"mmmm")
    But the output shows as December instead of May.
    I have tried =TEXT([Datum, von];"mmmm") but no help.
    I am trying to populated the column automatically with current month..ex: if its May the field should show May, next month it should show June an so on.
    Any kind help is grateful.
    Regards,
    Pradeep

Maybe you are looking for

  • Issuance of material without availability of required qty. as on that date

    I had done GRN of 100 qty. with posting date 15.11.09. Now I am trying to book consumption of that material with posting date 01.11.09 and systme allows to do. As per MB5B, as on date stock on 01.11.09 is zero before booking of consumption and after

  • User defined function using xsql

    Hello, We defined the java function in xslt. When we tried to declare the namespace, it is giving the error "http://www.oracle.com/...." expected. Is it a bug. If not what is the correct syntax to denfined the userdefined namespace and functions. tha

  • Cisco ISE 1.2 to 1.3 Upgrade Failed - Old Certificates in Cert Store, but can't remove

    Hello guys, My attempt an upgrade bombed out pretty quick due to an expired certificate in the certificate store. However, these certs are disabled because I've never been able to delete them due to the below error as I can not find what they would b

  • InDesign CS6 crashing at startup after upgrade

    Hello all, Yesterday, we upgraded a few of our iMacs (10.7.4) with the MasterCollection CS6 from CS5.5. Everything launches with no problems EXCEPT for InDesign CS6. The splash screen comes up and quits when it says "Starting up service registry". Wh

  • Dynamically add custom MXML components in Actionscript

    As there's no constructor for custom MXML components, how to dynamically add it as a child using ActionScript? I'm looking for some alternative to avoid the need to rewrite the entire existent component in ActionScript just to add it this feature (a