Plant Stock details for a given date

At present we are using MB52 for latest stock position of a plant. Is there any code for getting stock details for earlier date.
As we are facing lot of problems while audits....

Hi
Please check the following link
Re: No stock showing in Inventory on date stock report
Cheers
Chandra

Similar Messages

  • How to query a item stock quantity for a given date

    Hi there,
    I need to query the stock quantity of an item for a given date. For example, i want to know how many pieces of A i have on stock at the 20th of march 2009.
    I know there is a report, but i need the value for a subquery.
    Regards Steffen

    Sorry Gordon,
    Your query is not wrong, far from me to insult your work. It does indeed make full sense if the business process allows the item description to change.
    If not, we can avoid a "inner join"  = smaller, cleaner and (theoritically) faster query
    Here is your code with the little review:
    SELECT T0.ItemCode, T0.Dscription, sum(T0.InQty - T0.OutQty) as 'On Hand'
    FROM DBO.OINM T0
    WHERE T0.DocDate <= '[%0]' and T0.ItemCode = '[%1]'
    GROUP BY T0.ItemCode, T0.Dscription
    Cheers
    tested on 2007 SP00 PL46

  • Function module for getting stock details for a given period or date range

    Hi experts,
         Any function module available for getting stock details batch, plant, storage location, and period wise. <<removed_by_moderator>>
    Thanks in advance
    M Prasanna
    Edited by: Vijay Babu Dudla on Apr 28, 2009 7:23 AM

    Hi,
    Try with this FM:
    BAPI_MATERIAL_AVAILABILITY .
    Go through this link for more details:
    ABAP Development
    by
    Prasad gvk.

  • How to get the Change Document Header details for a given date

    Hi All,
    Can anyone help me on this Change Document Header details(CDHDR).
    Better way to pull the information of Change Document Header details(CDHDR). No Index is maintained for the tables.
    So please suggest better Optimising techniques to get the Change Document Header details(CDHDR).
    Using this Function module : CHANGEDOCUMENT_READ_HEADERS how to import the DATE_OF_CHANGE.
    Thanks in advance
    Regards
    Chakri

    HI,
    Go through the documenattion of the FM u can get the details.. and also where used list
    Regards,
    Nagaraj

  • Hi experts . how can we know the stock details for a perticular plant?

    hi experts . how can we know the stock details for a perticular plant

    check this code
    REPORT  YSG_MATSTK_REP    LINE-SIZE 220
                              LINE-COUNT 50(5).
    *&                       DATA DECLARATION                              *
    TABLES: MARA,              "GENERAL MASTER DATA
            MARC,              "PLANT DATA FOR MATERIAL
            MARD,              "STORAGE LOCATION DATA FOR MATERIAL
            MBEW,              "MATERIAL VALUATION
            MVKE,              "SALES DATA FOR MATERIAL
            MAKT.              "MATERIAL DESCRIPTION
    DATA: BEGIN OF I_MARA OCCURS 0,
               MATNR LIKE MARA-MATNR,"MATERIAL NUMBER
               MBRSH LIKE MARA-MBRSH,"INDUSTRY SECTOR
               MEINS LIKE MARA-MEINS,"BASE UNIT OF MEASURE
          END OF I_MARA.
    DATA: BEGIN OF I_MARC OCCURS 0,
              MATNR LIKE MARC-MATNR,"MATERIAL NUMBER
              WERKS LIKE MARC-WERKS,"PLANT
              LVORM LIKE MARC-LVORM,"FLAG MATERIAL FOR DELETION AT PLANT
                                    "LEVEL
              PSTAT LIKE MARC-PSTAT,"MAINTENANCE STATUS
              DISPO LIKE MARC-DISPO,"MRP CONTROLLER
          END OF I_MARC.
    DATA: BEGIN OF I_MAKT OCCURS 0,
               MATNR LIKE MAKT-MATNR,"MATERIAL NUMBER
               MAKTX LIKE MAKT-MAKTX,"MATERIAL DESCRIPTION
          END OF I_MAKT.
    DATA: BEGIN OF I_MVKE OCCURS 0,
               MATNR LIKE MVKE-MATNR,"MATERIAL NUMBER
               VKORG LIKE MVKE-VKORG,"SALES ORGANIZATION
               VTWEG LIKE MVKE-VTWEG,"DISTRIBUTION CHANNEL
          END OF I_MVKE.
    DATA: BEGIN OF I_MARD OCCURS 0,
               MATNR LIKE MARD-MATNR,"MATERIAL NUMBER
               LGORT LIKE MARD-LGORT,"STORAGE LOCATION
               LABST LIKE MARD-LABST,"VALUATED STOCK WITH UNRESTRICTED USE
          END OF I_MARD.
    DATA: BEGIN OF I_OUT OCCURS 0,
            MATNR LIKE MARC-MATNR,
            WERKS LIKE MARC-WERKS,
            LVORM LIKE MARC-LVORM,
            PSTAT LIKE MARC-PSTAT,
            DISPO LIKE MARC-DISPO,
            MBRSH LIKE MARA-MBRSH,
            MEINS LIKE MARA-MEINS,
            MAKTX LIKE MAKT-MAKTX,
            VKORG LIKE MVKE-VKORG,
            VTWEG LIKE MVKE-VTWEG,
            LGORT LIKE MARD-LGORT,
            LABST LIKE MARD-LABST,
          END OF I_OUT.
    DATA : TOT TYPE I. " TOT - TOTAL TO PRINT STOCK
    *&                   S E L E C T I O N - S C R E E N                   *
    SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-100.
    SELECT-OPTIONS: S_MATNR FOR MARA-MATNR OBLIGATORY.
    PARAMETERS: P_WERKS LIKE MARC-WERKS OBLIGATORY.
    SELECT-OPTIONS: S_LGORT FOR MARD-LGORT,
                    S_DISPO FOR MARC-DISPO.
    SELECTION-SCREEN END OF BLOCK B1.
    *&                  I N I T I A L I Z A T I O N                      *
    INITIALIZATION.
      S_MATNR-SIGN = 'I'.
      S_MATNR-OPTION = 'EQ'.
      S_MATNR-LOW = 'M-14'.
      S_MATNR-HIGH = 'M-18'.
      P_WERKS = '3000'.
      S_LGORT-SIGN = 'I'.
      S_LGORT-OPTION = 'EQ'.
      S_LGORT-LOW = '0001'.
      S_LGORT-HIGH = '0004'.
      S_DISPO-SIGN = 'I'.
      S_DISPO-OPTION = 'EQ'.
      S_DISPO-LOW = '001'.
      S_DISPO-HIGH = '002'.
      APPEND S_DISPO.
      APPEND S_LGORT.
      APPEND S_MATNR.
      CLEAR S_DISPO.
      CLEAR S_LGORT.
      CLEAR S_MATNR.
    *&             S T A R T - O F - S E L E C T I O N                     *
    START-OF-SELECTION.
      SELECT MATNR WERKS LVORM DISPO FROM MARC
      INTO CORRESPONDING FIELDS OF TABLE I_MARC
                          WHERE WERKS EQ P_WERKS
                          AND MATNR IN S_MATNR
                          AND DISPO IN S_DISPO
                          AND WERKS = P_WERKS.
      IF I_MARC[] IS INITIAL.
        WRITE:/ 'NO MATCHING DATA AVAILABLE FROM MARC'.
        EXIT.
      ENDIF.
      SELECT MATNR LGORT LABST FROM MARD INTO TABLE  I_MARD
                          FOR ALL ENTRIES IN I_MARC
                          WHERE MATNR = I_MARC-MATNR
                          AND WERKS EQ P_WERKS
                          AND LGORT IN S_LGORT.
      IF I_MARD[] IS INITIAL.
        WRITE:/ 'NO MATCHING DATA AVAILABLE FROM MARD'.
        EXIT.
      ENDIF.
      SELECT MATNR VKORG VTWEG FROM MVKE INTO TABLE I_MVKE
                          FOR ALL ENTRIES IN I_MARC
                          WHERE MATNR = I_MARC-MATNR.
    IF I_MVKE[] IS INITIAL.
        WRITE:/ 'NO MATCHING DATA AVAILABLE FROM MVKE'.
        EXIT.
      ENDIF.
      LOOP AT I_MARC.
        MOVE-CORRESPONDING I_MARC TO I_OUT.
        CLEAR MARC.
        SELECT SINGLE MATNR MBRSH MEINS FROM MARA
                         INTO CORRESPONDING FIELDS OF MARA
                         WHERE MATNR = I_OUT-MATNR.
        IF SY-SUBRC = 0.
          MOVE: MARA-MBRSH TO I_OUT-MBRSH,
                MARA-MEINS TO I_OUT-MEINS.
        ELSE.
          CONTINUE.
        ENDIF.
        SELECT SINGLE MATNR MAKTX FROM MAKT
                        INTO  CORRESPONDING FIELDS OF MAKT
                        WHERE  MATNR = I_OUT-MATNR.
        IF SY-SUBRC = 0.
          MOVE: MAKT-MAKTX TO I_OUT-MAKTX.
        ELSE.
          CONTINUE.
        ENDIF.
        LOOP AT I_MARD WHERE MATNR = I_MARC-MATNR.
          MOVE: I_MARD-LABST TO I_OUT-LABST,
                I_MARD-LGORT TO I_OUT-LGORT.
          APPEND I_OUT.
        ENDLOOP.
        LOOP AT I_MVKE WHERE MATNR = I_MARC-MATNR.
          MOVE: I_MVKE-VKORG TO I_OUT-VKORG,
                I_MVKE-VTWEG TO I_OUT-VTWEG.
          APPEND I_OUT.
        ENDLOOP.
        CLEAR I_OUT.
      ENDLOOP.
    CALL FUNCTION 'GUI_DOWNLOAD'
      EXPORTING
        FILENAME = 'C:\matstk.TXT'
       FILETYPE                        = 'ASC'
      TABLES
        DATA_TAB                        = I_OUT.
    *&                  T O P - O F - P A G E                              *
    TOP-OF-PAGE.
      WRITE:/ 'DATE:' ,SY-DATUM.
    *&                  E N D - O F - P A G E                              *
    END-OF-PAGE.
      WRITE: / SY-ULINE,
             /100 'PAGNO: ',SY-PAGNO,
             SY-ULINE.
    *&        E N D -- O F --  S E L E C T I O N                           *
    END-OF-SELECTION.
      LOOP AT I_OUT.
        AT FIRST.
          WRITE :/ 'MATERIAL EXTRACTION REPORT',
                   SY-ULINE.
        ENDAT.
        WRITE:/    SY-VLINE,
                   I_OUT-MATNR,SY-VLINE,
                   I_OUT-MEINS,SY-VLINE,
                   I_OUT-WERKS,SY-VLINE,
                   I_OUT-LVORM,SY-VLINE,
                   I_OUT-PSTAT,SY-VLINE,
                   I_OUT-DISPO,SY-VLINE,
                   I_OUT-MBRSH,SY-VLINE,
                   I_OUT-MAKTX,SY-VLINE,
                   I_OUT-VKORG,SY-VLINE,
                   I_OUT-VTWEG,SY-VLINE,
                   I_OUT-LGORT,SY-VLINE,
                   I_OUT-LABST,SY-VLINE.
        TOT = TOT + I_OUT-LABST.
        AT NEW MATNR.
          WRITE : 'NEW RECORD',
                   SY-VLINE.
        ENDAT.
        AT END OF LABST.
          WRITE : 'STOCK = ',
                   TOT,
                   SY-VLINE,
                   SY-ULINE.
        ENDAT.
        AT LAST.
          FORMAT COLOR 7 INTENSIFIED OFF.
          WRITE : /159 'TOTAL STOCK = ',
                     TOT.
        ENDAT.
      ENDLOOP.
        WRITE : /159 'TOTAL STOCK = ',
                     TOT.
    regards,
    srinivas
    <b>*reward for useful answers*</b>

  • Block stock calculation from mseg table for any given date.

    I am calculating stock from mseg table for any given date. Not just month end stock or current stock. It could be back date also. It is tallying also with MB5B stock report of that date. Now I have to bifurcate that stock into unrestricted stock, quality stock and block stock.
    I have checked INSMK and ZUSTD field in mseg table, but could not concluded. Should I check movement type wise? Block/ Quality stock could be transferred into unrestricted stock also. That also I have to take care.
    Can anyone clearly explain how the stock type posting takes place in mseg table when goods receipt as block / quality stock and when the same goods transferred in unrestricted stock, what are the reference indication.

    DATA : LIST_TAB TYPE TABLE OF ABAPLIST.
    DATA: BEGIN OF VLIST OCCURS 0,
          FIELD1(5)  TYPE C,
          FIELD2(19) TYPE C,
          FIELD3(16) TYPE C,
          FIELD4(17) TYPE C,
          FIELD5(25) TYPE C,
          FIELD6(24) TYPE C,
          FIELD7(25) TYPE C,
          FIELD8(25) TYPE C,
          END OF VLIST.
    TYPES : BEGIN OF ITAB,
           MATNR(18) TYPE C,
           WERKS(5) TYPE C,
           END_MENGE(20) TYPE C,
           END OF ITAB.
    DATA : ITAB TYPE STANDARD TABLE OF ITAB WITH HEADER LINE,
            WA_TAB TYPE ITAB.
    ----submit command to run mb5b in the background and -
    ----push the data into an internal table -
    " Calling MB5B for displaying the Closing Stock
    SUBMIT RM07MLBD USING SELECTION-SCREEN  '1000'
                    WITH DATUM BETWEEN S_DATE-LOW AND S_DATE-HIGH
                    WITH MATNR IN S_MATNR WITH WERKS IN S_WERKS
                    WITH BWART-LOW = '601' EXPORTING LIST TO  MEMORY
                    AND RETURN.
    CALL FUNCTION 'LIST_FROM_MEMORY'
      TABLES
        LISTOBJECT = LIST_TAB
      EXCEPTIONS
        NOT_FOUND  = 1
        OTHERS     = 2.
    CALL FUNCTION 'LIST_TO_ASCI'
      EXPORTING
        LIST_INDEX         = -1
      TABLES
        LISTASCI           = VLIST
        LISTOBJECT         = LIST_TAB
      EXCEPTIONS
        EMPTY_LIST         = 1
        LIST_INDEX_INVALID = 2
        OTHERS             = 3.
    LOOP AT VLIST WHERE FIELD1 CS '|'.
    CHECK SY-TABIX GE 4.
    MOVE :  VLIST-FIELD1+1(4) TO ITAB-WERKS,
            VLIST-FIELD2+1(18) TO ITAB-MATNR,
            VLIST-FIELD8 TO ITAB-END_MENGE.
    APPEND ITAB.
    ENDLOOP.
    This is the program to call MB5B and the standard program and use the following settings for the closing stock opening stock and block stock

  • How to get start date of the period for a given date from cube

    I have a situation where i need to find the start day of the period for a given date. is there a way to know that. i want to use that in my report. i enter the date from my report(i have date parameter), depends on the date, i want to display the start day
    of the period. how can i write expression for that in my report?
    ram

    Hi ramprasad74,
    According to your description, you are using Analysis Services as a data source for the report, the cube has hierarchy: Fyear, FQuarter, FPeriod, fweek, Fdate. You want to add a date parameter to the report, after you changed value of the parameter, the
    report will return the first day of FPeriod.
    To achieve your goal, we need to add a parameter to the report, then use the parameter in mdx query. For detail information, please refer to the following steps:
    In the Report Data pane, right-click on a dataset created from a SQL Server Analysis Services data source type, and then click Query. The MDX query designer opens in Design mode.
    On the toolbar, click Design to toggle to Query mode.
    On the MDX query designer toolbar, click Query Parameters symbol. The Query Parameters dialog box opens.
    In the Parameter column, click <Enter Parameter>, and then type the name of a parameter.
    In the Dimension column, choose a value from the drop-down list.
    In the Hierarchy column, choose a value from the drop-down list.
    In the Default column, from the drop-down list, select a single value.
    Click OK. 
    In query designer dialog box, type the mdx query like below:
    with member [Measures].[FirstChild]
    as
    [Date].[Fiscal].currentmember.parent.firstchild.name
    select {[Measures].[FirstChild]} on 0,
    [Date].[Fiscal].[Date].members on 1
    from
    ( SELECT ( STRTOSET(@ParameterName, CONSTRAINED) ) on 0
    from
    [Cube]
    Here are relevant threads you can reference:
    https://social.msdn.microsoft.com/forums/sqlserver/en-US/c7146ac3-40ea-4d53-b321-c707aebbd405/how-to-pass-date-parameter-to-mdx-query
    https://social.msdn.microsoft.com/forums/sqlserver/en-US/fd12a865-bc90-4a65-af42-ce38a8cfa29b/pass-date-time-parameter-to-mdx-query-ssrs
    If you have any more questions, please feel free to ask.
    Thanks,
    Wendy Fu
    If you have any feedback on our support, please click
    here.

  • Name of users of a particular Tcode for a given date range

    Hi experts,
    I am making an alv where inputs will be
    1> T_code(as parameter)
    2> Date Range(as Select options)
    I have to display the following fields:::
    1> User name
    2> Frequency of use the Tcode for the given Date range.
    Please give me the tables where I can get the relation of those fields.
    N.B. I know the transaction AL08 and SM04.But it won't solve my purpose.
    Thanx in advance,
    Sourav

    >
    SOURAV PAUL wrote:
    > Hi experts,
    > I am making an alv where inputs will be
    > 1> T_code(as parameter)
    > 2> Date Range(as Select options)
    by creating the report As per your this requirement you need not to create any Bulk on your SAP.Just use STAD/STAT transaction they are availabe for this purpose.
    and more you may track by security log audit by SM20 get these details.
    i'm worried about tables which sre storing these details.

  • How to get the date of first day of a week for a given date

    Hi gurus
    can any one say me how to get the date of first day(date of Sunday) of a week for a given date in a BW transformations. For example for 02/23/2012 in source i need to get 02/19/2012(Sunday`s date) date in the result. I can get that start date of a week using  BWSO_DATE_GET_FIRST_WEEKDAY function module. But this function module retrieves me the  start date as weeks monday(02/20/2012) date. But i need sundays(02/19/2012) date as the start date. So it would be really great if anyone sends me the solution.
    Thanks
    Rav

    Hi,
    The simplest way would be to subtract 1 from the date date which you are already getting in transformation routine, but instead of doing that subtraction manually which might need bit of errort, you can simply use another FM to subtract 1 from given date.
    RP_CALC_DATE_IN_INTERVAL
    Regards,
    Durgesh.

  • Table name for shipping details for the given purchase order

    Hi,
    Table name for shipping details for the given purchase order
    regards,
    vijay

    Had anybody seen that this question was raised 5 years ago?
    And the question was about where are the shipping details of a purchase order stored.
    The discussion owner hat marked the the discussion a year ago as solved, but did not mark any correct answer and did not tell himself what the solution was.
    The correct answer was given by Amitkumar yesterday, it is EKPV
    I am locking the discussion to avoid that even more wrong answers are added to this particualr question

  • [HELP] Error: "JDBC theme based FOI support is disabled for the given data"

    Hi all,
    I have already set up MapViewer version 10.1.3.3 on BISE1 10g OC4J server. I am current using JDK 1.6. I create a mvdemo/mvdemo user for demo data.
    The MapViewer demo is running fine with some demo without CHART. But give this error with some maps that have CHART like: "Dynamic theme, BI data and Pie chart style", "Dynamic theme and dynamic Bar chart style". The error is:
    ----------ERROR------------
    Cannot process the FOI response from MapViewer server. Server message is: <?xml version=\"1.0\" encoding=\"UTF-8\" ?> <oms_error> MAPVIEWER-06009: Error processing an FOI request.\nRoot cause:FOIServlet:MAPVIEWER-06016: JDBC theme based FOI support is disabled for the given data source. [mvdemo]</oms_error>.
    ----------END ERROR------
    I searched many threads on this forum, some point me to have this allow_jdbc_theme_based_foi="true" in mapViewerConfig.xml and restart MapViewer.
    <map_data_source name="mvdemo"
    jdbc_host="localhost"
    jdbc_sid="bise1db"
    jdbc_port="1521"
    jdbc_user="mvdemo"
    jdbc_password="mvdemo"
    jdbc_mode="thin"
    number_of_mappers="3"
    allow_jdbc_theme_based_foi="true"
    />
    Error Images: [http://i264.photobucket.com/albums/ii176/necrombi/misc/jdbcerror.png|http://i264.photobucket.com/albums/ii176/necrombi/misc/jdbcerror.png]
    I have this configuration, but no luck. Could anyone show me how to resolve this problem?
    Rgds,
    Dung Nguyen

    Oop, i managed to have this prob resolved!
    My prob may come from this I use both scott and mvdemo schema for keeping demo data (import demo data).
    Steps i made to resolve my prob are:
    1) Undeploy MapViewer from Application Server Control (http://localhost:9704/em in my case)
    2) Drop user mvdemo
    3) Download mapviewer kit from Oracle Fusion Middleware MapViewer & Map Builder Version 11.1.1.2
    4) Deploy MapViewer again
    5) Recreate mvdemo and import demo data
    6) Run mcsdefinition.sql, mvdemo.sql with mvdemo user (granted dba already)
    7) Edit mapViewerConfig.xml
    <map_data_source name="mvdemo"
    jdbc_host="dungnguyen-pc"
    jdbc_sid="bise1db"
    jdbc_port="1521"
    jdbc_user="mvdemo"
    jdbc_password="!mvdemo"
    jdbc_mode="thin"
    number_of_mappers="3"
    allow_jdbc_theme_based_foi="true"
    />
    Save & Restart MapViewer
    And now, all demos run fine. Hope this helpful for who meet prob like my case.

  • Print MULTIPLE sales order for a given date

    Hi Gurus,
    My requirement is to print sales order for a given date like the one given below.
    VL71  - Output from Outbound Deliveries
    VL74  - Output from Handling
    VF31  - Output from Billing
    VOK4- Output Determination: Inventory mgmt.
    Is there any T.code for printng multiple sales order instead one-by-one printing using VA02/VA03?
    Please hlep me in this regard.
    Regards,
    Anbu

    Hi anbu,
    This is very much possible to mass printing for sales orders.
    Goto SE38 T.Code.
    Enter the program name as "RSNAST00".
    Press Execute or F8
    Select output application as "V1" which is sales.
    Enter your object key here.
    Enter your output type.
    Select the transaction medium as "1".
    Tick "send again".
    Press on Execute or "f8".
    Regards,
    Krishna.

  • Find the 'DAY' for a given 'DATE'

    Hi Folks,
    I need a help regarding finding the day for a given date.
    My requirement is that..,
             If I enter a date using 'parameters', it should write the 'day' for the corresponding date.
    To be more specific.....,
    if I enter date as ' 07/15/2008 ' it should return me  the day as 'Tuesday'.
    Regards,
    Naveen G

    HI,
    FM LIST WITH RESPECT TO DAY, WEEK, AND MONTH.
    CALCULATE_DATE : Calculates the future date based on the input .
    DATE_TO_DAY : Returns the Day for the entered date.
    DATE_COMPUTE_DAY : Returns weekday for a date
    DATE_GET_WEEK : Returns week for a date
    RP_CALC_DATE_IN_INTERVAL : Add days / months to a date
    MONTHS_BETWEEN_TWO_DATES : To get the number of months between the two dates.
    END_OF_MONTH_DETERMINE_2 : Determines the End of a Month.
    HR_HK_DIFF_BT_2_DATES : Find the difference between two dates in years, months and days.
    FIMA_DAYS_AND_MONTHS_AND_YEARS : Find the difference between two dates in years, months and days.
    MONTH_NAMES_GET : Get the names of the month
    WEEK_GET_FIRST_DAY : Get the first day of the week
    HRGPBS_HESA_DATE_FORMAT : Format the date in dd/mm/yyyy format
    SD_CALC_DURATION_FROM_DATETIME : Find the difference between two date/time and report the difference in hours
    L_MC_TIME_DIFFERENCE : Find the time difference between two date/time
    HR_99S_INTERVAL_BETWEEN_DATES : Difference between two dates in days, weeks, months
    LAST_DAY_OF_MONTHS : Returns the last day of the month
    DATE_CHECK_PLAUSIBILITY :Check for the invalid date.
    Reward points if useful,
    siri

  • Find 3rd friday of the month for a given date

    how to find out 3rd friday of the month for a given date? I can always pass the first day of the month as input
    eg, input date is 01-JAN-09. need to get the 3rd friday 16-JAN-09 (Jan has 5 fridays 02, 09, 16,23,30)
    input date : 01-feb-09, need to get 20-feb-09
    Edited by: user520824 on Apr 1, 2009 12:30 PM

    NLS independent solution:
    SELECT  DT,
            TO_CHAR(DT,'FMDay') day,
            CASE
              WHEN TRUNC(TRUNC(DT,'MM') + 7,'IW') - 3 < TRUNC(DT,'MM') THEN TRUNC(TRUNC(DT,'MM') + 7,'IW') + 18
              ELSE TRUNC(TRUNC(DT,'MM') + 7,'IW') + 11
            END THIRD_FRIDAY_OF_THE_MONTH
      FROM  (
             SELECT  TO_DATE(LEVEL || '/2009','MM/YYYY') DT
               FROM  DUAL
               CONNECT BY LEVEL < 13
    DT        DAY       THIRD_FRI
    01-JAN-09 Thursday  16-JAN-09
    01-FEB-09 Sunday    20-FEB-09
    01-MAR-09 Sunday    20-MAR-09
    01-APR-09 Wednesday 17-APR-09
    01-MAY-09 Friday    15-MAY-09
    01-JUN-09 Monday    19-JUN-09
    01-JUL-09 Wednesday 17-JUL-09
    01-AUG-09 Saturday  21-AUG-09
    01-SEP-09 Tuesday   18-SEP-09
    01-OCT-09 Thursday  16-OCT-09
    01-NOV-09 Sunday    20-NOV-09
    DT        DAY       THIRD_FRI
    01-DEC-09 Tuesday   18-DEC-09
    12 rows selected.
    SQL> SY.

  • Getting the week number for a given date

    Oracle Database 11g Enterprise Edition Release 11.1.0.7.0 - 64bit Production
    PL/SQL Release 11.1.0.7.0 - Production
    CORE     11.1.0.7.0     Production
    TNS for 64-bit Windows: Version 11.1.0.7.0 - Production
    NLSRTL Version 11.1.0.7.0 - Production
    Hello all.
    I am currently migrating our product from SQL SERVER to ORACLE and have the following issue.
    Basically I'm just trying to get the year week number for a given date but I'm having trouble with Oracle as it seems to think that the weeks run from Thursday to Thursday?. I presume this is something to do with the fact that the first day of the year was Thursday?
    e.g.
    SQL SERVER:
    select DATEPART(wk, '2009-10-24') as Sat -- 43 - correct
    select DATEPART(wk, '2009-10-25') as Sun -- 44 - correct
    select DATEPART(wk, '2009-10-26') as Mon -- 44 - correct
    select DATEPART(wk, '2009-10-27') as Tue -- 44 - correct
    select DATEPART(wk, '2009-10-28') as Wed -- 44 - correct
    select DATEPART(wk, '2009-10-29') as Thu -- 44 - correct
    select DATEPART(wk, '2009-10-30') as Fri -- 44 - correct
    select DATEPART(wk, '2009-10-31') as Sat -- 44 - correct
    select DATEPART(wk, '2009-11-1') as Sun -- 45 - correct
    select DATEPART(wk, '2009-11-2') as Mon -- 45 - correct
    select DATEPART(wk, '2009-11-3') as Tue -- 45 - correct
    select DATEPART(wk, '2009-11-4') as Wed -- 45 - correct
    select DATEPART(wk, '2009-11-5') as Thu -- 45 - correct
    ORACLE:
    SELECT to_char(to_date('24-OCT-2009'), 'ww') as Sat from dual; -- 43 correct
    SELECT to_char(to_date('25-OCT-2009'), 'ww') as Sun from dual; -- 43 incorrect - should be 44
    SELECT to_char(to_date('26-OCT-2009'), 'ww') as Mon from dual; -- 43 incorrect - should be 44
    SELECT to_char(to_date('27-OCT-2009'), 'ww') as Tue from dual; -- 43 incorrect - should be 44
    SELECT to_char(to_date('28-OCT-2009'), 'ww') as Wed from dual; -- 43 incorrect - should be 44
    SELECT to_char(to_date('29-OCT-2009'), 'ww') as Thu from dual; -- 44 correct
    SELECT to_char(to_date('30-OCT-2009'), 'ww') as Fri from dual; -- 44 correct
    SELECT to_char(to_date('31-OCT-2009'), 'ww') as Sat from dual; -- 44 correct
    SELECT to_char(to_date('1-NOV-2009'), 'ww') as Sun from dual; -- 44 incorrect - should be 45
    SELECT to_char(to_date('2-NOV-2009'), 'ww') as Mon from dual; -- 44 incorrect - should be 45
    SELECT to_char(to_date('3-NOV-2009'), 'ww') as Tue from dual; -- 44 incorrect - should be 45
    SELECT to_char(to_date('4-NOV-2009'), 'ww') as Wed from dual; -- 44 incorrect - should be 45
    SELECT to_char(to_date('5-NOV-2009'), 'ww') as Thu from dual; -- 45 correct
    Now I don't want to get into a discussion with regard to locales etc.
    In my world (and is seems SQL SERVER's) the first day of the week is Sunday and the last Saturday.
    Is there some NLS_? setting or something that I'm missing?
    thanks for any help on this.
    Andy

    This is what you need.
    SELECT ceil(( 7+(trunc(to_date('25-OCT-2009'),'d')-trunc(to_date('25-OCT-2009'),'Y')) )/7) FROM dual
    HTH!!!
    --tested all these statements.
    Works as you wish!!
    SELECT ceil(( 7+(trunc(to_date('24-OCT-2009'),'d')-trunc(to_date('24-OCT-2009'),'Y')) )/7) as Sat from dual;
    SELECT ceil(( 7+(trunc(to_date('25-OCT-2009'),'d')-trunc(to_date('25-OCT-2009'),'Y')) )/7) as Sun from dual;
    SELECT ceil(( 7+(trunc(to_date('26-OCT-2009'),'d')-trunc(to_date('26-OCT-2009'),'Y')) )/7) as Mon from dual;
    SELECT ceil(( 7+(trunc(to_date('27-OCT-2009'),'d')-trunc(to_date('27-OCT-2009'),'Y')) )/7) as Tue from dual;
    SELECT ceil(( 7+(trunc(to_date('28-OCT-2009'),'d')-trunc(to_date('28-OCT-2009'),'Y')) )/7) as Wed from dual;
    SELECT ceil(( 7+(trunc(to_date('29-OCT-2009'),'d')-trunc(to_date('29-OCT-2009'),'Y')) )/7) as Thu from dual;
    SELECT ceil(( 7+(trunc(to_date('30-OCT-2009'),'d')-trunc(to_date('30-OCT-2009'),'Y')) )/7) as Fri from dual;
    SELECT ceil(( 7+(trunc(to_date('01-NOV-2009'),'d')-trunc(to_date('01-NOV-2009'),'Y')) )/7) as Sat from dual;
    SELECT ceil(( 7+(trunc(to_date('02-NOV-2009'),'d')-trunc(to_date('02-NOV-2009'),'Y')) )/7) as Sun from dual;
    SELECT ceil(( 7+(trunc(to_date('03-NOV-2009'),'d')-trunc(to_date('03-NOV-2009'),'Y')) )/7) as Mon from dual;
    SELECT ceil(( 7+(trunc(to_date('04-NOV-2009'),'d')-trunc(to_date('04-NOV-2009'),'Y')) )/7) as Tue from dual;
    SELECT ceil(( 7+(trunc(to_date('05-NOV-2009'),'d')-trunc(to_date('05-NOV-2009'),'Y')) )/7) as Wed from dual;
    SELECT ceil(( 7+(trunc(to_date('06-NOV-2009'),'d')-trunc(to_date('06-NOV-2009'),'Y')) )/7) as Thu from dual;
    Cheers!!!
    Bhushan
    Edited by: Buga on Oct 29, 2009 10:46 AM

Maybe you are looking for