Function Module - Calculate Previous Week

Hi Guys,
I am looking to create a variable on Fiscal Period/Year, that automatically populates the variable with the previous week (current week minus 1), when the user runs the query.
I have heard there is a Function Module available - can anyone help?
Thanks
Scott
Message was edited by:
        Scott Sweeney

Hi,
use the following code:
DATA: l_curr_week LIKE SCAL-WEEK.
DATA: l_prev_week LIKE SCAL-WEEK.
DATA: l_day TYPE DATS.
CALL FUNCTION 'DATE_GET_WEEK'
  EXPORTING
    date               = SY-DATUM
IMPORTING
   WEEK               = l_curr_week.
CALL FUNCTION 'WEEK_GET_FIRST_DAY'
  EXPORTING
    week               = l_curr_week
IMPORTING
   DATE               = l_day.
SUBTRACT 1 FROM l_day.
CALL FUNCTION 'DATE_GET_WEEK'
  EXPORTING
    date               = l_day
IMPORTING
   WEEK               = l_prev_week.
hope this helps...
Olivier.

Similar Messages

  • Function Module - Calculate 5 weeks lookup based on -7 increments from the Key Date

    Hi Guys,
    I am looking to create a variable on Fiscal Period/Year, that automatically populates the variable with the previous 5 weeks based on -7 increments from the key date , when the user runs the query .
    For Example: If key date is 03/11/2014 need to get previous 5 weeks 03/04/2014, 02/25/2014, 02/18/2014, 02/11/2014, 02/04/2014. mm/dd/yyyy.
    Is there any Function Module available/ please provide the logic code - can anyone help?
    Thanks,
    Suresh Narayan

    Hi suresh,
    Please once try with this approach,
    Create a variable with variable represents :  multiple input value, Processing type : customer exit ; variable is ready for input.
    and write the below code :
    if i_step = 1.
    data : fdate type d ,
            wa1 like line of e_t_range,
           n1 type i.
    n1 = 1.
    if n1 <= 5.
    wa1-opt = 'EQ'.
    wa1-sign = 'I'.
    wa1-low = fdate.
    append wa1 to e_t_range.
    fdate = fdate - 7.
    endif.
    endif.
    Hope you got it,

  • Date Function to get Previous week

    Is there a date function to get
    Let us say today is 23rd of Jun 2009
    I want a date function to get previous Thursday 18 Jun 2009
    and another function which get 7 days before which is Friday 12 Jun 2009.
    FYI: For the current week, I was able to use:
    select next_day(case to_char(sysdate,'Day') when 'Thursday' then trunc(sysdate-1) else trunc(sysdate) end, 'Thursday')
    from dual;
    select next_day(trunc(sysdate-7), 'Friday') from dual;
    I want something similar to that.
    Thanks

    No, not separate functions, but you can tweak next_day to get what you want:
    select trunc(sysdate) today,
           next_day(trunc(sysdate)-1, 'THURSDAY')-7 last_thursday,
           next_day(trunc(sysdate)-1, 'FRIDAY')-14 prev_2nd_friday
    from   dual;
    TODAY     LAST_THUR PREV_2ND_
    23-JUN-09 18-JUN-09 12-JUN-09

  • Is there any function module? Fiscal week no problem

    Hi friends,
    I want how to get physical week for given date.
    Ie for 01-04-2009 week no is 1.
    Is there any function module?
    Pls suggest
    Regards
    Moosa

    Hi,
    Use the below code.
    DATA: v_ersda TYPE sy-datum VALUE '20090618'.
    DATA: v_month(2) TYPE c,
          v_week(2) TYPE c,
          v_full_week LIKE scal-week.
    MOVE v_ersda+4(2) TO v_month.
    CALL FUNCTION 'DATE_GET_WEEK'
      EXPORTING
        date         = v_ersda
      IMPORTING
        week         = v_full_week
      EXCEPTIONS
        date_invalid = 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.
    MOVE v_full_week+4(2) TO v_week.
    WRITE:/5 'Month = ', v_month.
    WRITE:/5 'Week = ', v_week.
    Regards,
    Kumar Bandanadham

  • What is function module get previous date by enteing no of days

    FM should take : 7 days
    and should return : 4.12.2007
    as output.
    Thanx,
    Naveen

    Hi,
    Apart from function module, you can write as follows.
    data : date1 type datum,
           date2 type datum.
    date1 = sy-datum.
    date2 = date1 - 7 .
    write date2.

  • Function module SD_SCHEDULING: delivery date calculation factory calendar

    Hi,
    When I create or change a sales order, system calculates the delivery time and date (ETDAT) using transit duration and factory calendar. Currently factory calendar says that transportation leaves every Monday, Wednesday and Friday. Unfortunately, function module SD_SCHEDULING calculates the delivery date using factory calendar dates, i.e. <b>NOT</b> using working dates.
    Function module reads the factory calendar from table TVRO (Routes) and field SPFBK (Factory calendar key) in subroutine GET_CUSTOMIZING, and saves factory calendar id in CS_SCHEDDU-TRANSIT_FC. The calculation itself is done later in function module DATE_CONVERT_TO_FACTORYDATE.
    For example, if transit duration is 3 working days, function module calculates the delivery date using Monday (first day), Wednesday (second day) and Friday (third day). Thus, the result is Friday, which is wrong. Result should be of course Wednesday (Monday first day, Tuesday second day and Wednesday third day).
    I'd like to use working days instead of calendar days. I am planning to recalculate the delivery date in some user exit, but before I start coding, I'd like to hear your opinion: <i>Is it possible to use working days instead of calendar days when calculating delivery date?</i> (I believe it must be, since my case is very normal). If it is, I assume that this can be achieved with IMG, but how and where?
    I am using SAP R/3 Enterprise.
    Regards,
    Jarmo Tuominen

    Hi jarmo,
    1. DATE_CHECK_WORKINGDAY
       Probably this FM may be useful to u.
    2.
    CALL FUNCTION 'DATE_CHECK_WORKINGDAY'
            EXPORTING
              date                       = d
              factory_calendar_id        = '01'
              message_type               = 'I'
            EXCEPTIONS
              date_after_range           = 1
              date_before_range          = 2
              date_invalid               = 3
              date_no_workingday         = 4
              factory_calendar_not_found = 5
              message_type_invalid       = 6
              OTHERS                     = 7.
    regards,
    amit m.

  • WWI issue: function module with symbol doesn't work in conditional output

    Hi,
    I have created a function module to be used in combination with a symbol that represents the quantity of a composition item in a composition. In some cases a average quantity is not filled and the function module calculates the quantity based on the lower and upper limit of the composition item. This function works perfectly if managed in customising with a symbol or called with a symbol in WWI. When displaying the result of the symbol in a WWI word template it shows the expected value.
    However when I use the symbol with a function module (or the customised symbol with function module) in a conditional output expression, the value it represents in the expression is always equal to zero. It seems that a symbol value that is calculated using a functional module is not calculated properly when used in a conditional output expression. Setting a break in the functional module always shows the correct value, but the value as I already told, is not seen by the conditional output expression. Within the expression the value is always equal to zero.
    Does anyone know if this is a known issue in WWI? Is there any solution to handle this problem? I hope anyone can help.
    Thanks,
    Paul

    Dear Paul,
    only some add on high level ideas:
    if you look at:
    Example: Layout of an Abridged Material Safety Data Sheet - Basic Data and Tools (EHS-BD) - SAP Library
    you find the standard example of SAP for master and slave group:
    2  <11BRG003 (M,SAP_EHS_1012_004;*)> ¶
    3  <03EHS_L_TEXT(CED
      -SDB-01.002)> ¤
    <03EHS_L_TEXT(CED-
    SDB-02-07)> ¤
    <03EHS_L_TEXT(CED-
    SDB-02-05)> ¤
    4  <11BRG002 (S:POS;*)> ¿
    5 <01GESTRIDENT(I:NAM,
    6  IUPAC,;*)> <11ERG002>¤
    7
    8
    9
    <11BRG002 (S:POS; *)> ¿
    <01G1023001R2(C;*)
    ><11ERG002>¤
    <11BRG002 (S:POS;*)> ¿
    <01GESTVPRECL>
    <01GESTVCOMPL(N:" ZZ9,9")>
    <01GESTVCOMPE>
    <11ERG002> ¤
    10  <11ERG003>¶
    The "issue" is that you need to analyse by "line" of POS group; or precisely: it is easy to print lower, upper and average value if it exists.
    In conditional output this example is shown in SAP help:
    <15BIF001(AND:01G1013005VA GE 1)><01G1013005VA(;*/TL)[D:Value]>
    <15CIF001><03EHS_L_TEXT(CUST-100000000000031)[D:Density is less than 1]>
    <15EIF001>
    I believe you need a "clever" nesting together with your customer symbol
    E.g. you need first "test" the contents of the three values and decide about result
    The easiest way could be to use a "table" structure as above.
    Just use column header "lower"; "average"; "upper" value. Then you need to ask your self in which situation what need to printed.
    If you use the table structure and you print just what is there and leave simply lower / upper limit "field" empty if it does not exists (what is bad with this?) you need only this "conditional" output topic done for average value. You could check for: if value > 0.0001 then print the value (as then there is a value); if not use the report symbol in which you calculate something. In my opinion it is worth to try it.
    It is known that you can check "numeric values by using conditional output. I belive tis cintional one des work as well with the "composition" values (lwoer, upper, average),
    May be this approach might help.
    The "stack" examples which are discussed in SAP help and in the links shown are related to "characteristic" values of classes and not for composition ones.
    C.B.
    PS: If this really works you can clearly extend your solution. E.g. if lower value is empty may be print "0", If upper valus is empty may be print "100" etc. (or prepare a further costumer symbol calculating something).

  • 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

  • Need a Function Module for Week Calculation

    Dear Experts,
      I want a function module which calculate the week number.
      Suppose for date 04.05.2010
      week is 19...........
       i want to fetch through function module.
    i have already tried function module like GET_WEEK_INFO_BASED_ON_DATE & DATE_GET_WEEK
      throgh both function module output is come out is 18.
      but i need 19.
      when i pass 02.01.2010
    then it giving 53 week of 2009.
    plz. help me as soon as possible.
    Thanks,

    Jan 2 2010 was indeed 53rd week of 2009, so SAP FMs are returning right value. I would strongly recommend to consult your functional consultant before assuming Jan1 2010 as week 1 of 2010.
    [quote from wikipedia|http://en.wikipedia.org/wiki/ISO_8601#Week_dates]
    'If 1 January is on a Monday, Tuesday, Wednesday or Thursday, it is in week 01. If 1 January is on a Friday, Saturday or Sunday, it is in week 52 or 53 of the previous year (there is no week 00). 28 December is always in the last week of its year.'
    Regards,
    Pawan.
    Edited by: Pawan Kesari on May 4, 2010 4:56 PM

  • Function module to calculate Estimate delivery lead time

    Hi Experts,
    It's ugrent.
    In APO System,
    I need a function module to calculate the estimated delivery lead time, The estimate delivery lead time is the time in weeks between the current date and the estimated delivery date. This is rounded up to the next integer value.
    Thanks in advance,
    Regards
    Adil

    Hi Vishal,
    I've declared two variables
    DATA: LDATE(20),
               LTIME(20).
    CALL FUNCTION 'GET_SYSTEM_TIME_REMOTE'
    IMPORTING
      K_DATE        =
      K_TIME         =
       L_DATE         = LDATE
       L_TIME          = LTIME
    AND IN THE FORM HEADER I'VE GIVEN IT AS,
    WA_HEADER-TYP  = 'S'.
    WA_HEADER-INFO = ': Date'.
    WA_HEADER-KEY  = LDATE.
    APPEND WA_HEADER TO IT_HEADER.
    WA_HEADER-TYP  = 'S'.
    WA_HEADER-INFO = ': Time'.
    WA_HEADER-KEY  = LTIME.
    APPEND WA_HEADER TO IT_HEADER.
    STILL IM NOT GETTING WAT ELSE IS REQUIRED ?

  • Require a function module to calculate sum of the quantity based on GRNDATE

    hi friends,
    I need to calculate the sum of the quantity based on GRN DATE and invoice date.
    the invoice date given in select-options should be captured by program and from the previous day it need to retrieve the GRN dates and corresponding quantities and i need to do the summation of all these quantities can anybody tell any function module.
    Thanks in advance.

    Try function MD_CONVERT_MATERIAL_UNIT
    the table of UOM's is MARM.
    Doug

  • Function Module to Calculate Due Date from Payment Terms?

    I'm writing an aged debtor report as the SAP standard one isn't quite right for our requirements.  Is there a function module that will calculate the payment due date if I give it the payment terms and the base line date?
    I did a search in SE37 but couldn't see one which fitted my requirements (I was searching on CALCDUEDATE and variantions of).
    Any suggestions welcome, thanks.
    Gill

    Hi,
    Use the FM FI_TERMS_OF_PAYMENT_PROPOSE for calculating the Payment due date
    call function 'FI_TERMS_OF_PAYMENT_PROPOSE'
      exporting
        i_bldat         = gv_bldat
        i_budat         = gv_budat
        i_cpudt         = sy-datum
        i_zfbdt         = gv_zfbdt
        i_zterm         = gv_terms_paym
        i_bukrs         = gv_comp_code
      importing
        e_zbd1t         = gv_zbd1t
        e_zbd1p         = gv_zbd1p
        e_zbd2t         = gv_zbd2t
        e_zbd3t         = gv_zbd3t.
    Regards,
    Dwaraka.S

  • Function Module to calculate Open Contract Quantity

    Hi All,
    Is there a function module to calculate Open Contract Quantity?
    Thanks.

    Hi Ravi,
    Thanks for the reply.
    For this FM, i need to pass the Sales Doc Number. Is there an FM where i can pass the contract number?
    Best regards,
    Sindy

  • Any function module for getting fiscal year week numbers

    can any one provide me function module for getting fiscal year week numbers ? if no function module please let me know work around.
    Thanks!
    Lakshmikandh

    hi,
    Use FM <b>'DATE_GET_WEEK'</b>...
    parameter D1 LIKE SCAL-DATE.
    Data w like scal-week.
    CALL FUNCTION <b>'DATE_GET_WEEK'</b>
    EXPORTING
    date = D1
    IMPORTING
    WEEK = W
    EXCEPTIONS
    DATE_INVALID = 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.
    write W+4(2).
    Regards,
    Santosh

  • Function module for getting starting day of a week form current data

    Hi ,
    Is there any function module that gives starting day of week when we give a particular date
    eg: today date is 19-12-2007
    if i give this date as input i should get 16-12-2007 because this is starting day of this week .

    Hi,
    Use FM  GET_WEEK_INFO_BASED_ON_DATE
    You will get the first day of the week in export parameter MONDAY
    Lokesh

Maybe you are looking for

  • How to manage more than one iTunes library?

    I want to transfer some media from my lap to an ext drive to create more space. I want one iTunes library on the ext drive for some media and keep the main library on my laptop. I created a new iTunes library on my external drive and added one artist

  • Multiple Text Boxes on 1 Slide...

    There have been a lot of threads about this, but I've been unable to find an answer to the specific situation a colleague is facing. We are simulating a mainframe system where the user enters multiple values, then presses enter.  The client wants the

  • BLOB with RTF with Arabic strings

    ORACLE 10.1.0.5.0. NLS_CHARACTERSET: AL32UTF8 NLS_LANGUAGE: ITALIAN We have a table with a BLOB colum. In that column, we have a rich text format file and it can contain text in different languages (Arabic, chinese, italian, vietnamese, french, spani

  • Lightroom after PS Photography Program purchase

    I have a downloaded trial version of LR5 but after I purchased the PS Photography Program, how do I get the full version of the program? 

  • Automatic music transfer bombs out

    I have an original iPod and everything has always worked great. Just recently when I connected to my computer and the iPod started to auto sync it stops part way through and freezes. I get the following error "The drive is not ready for use; Please c