Forecast tuning in demantra

Hello All,
We are analyzing client data and found about 2/3 of the item location combinations in mdp matrix are too young to generate the forecast.
what else can be looked at to analyze the data.
Regards

Hello Kirit,
Please check whther your max_sales_date, last_date_backup on sys_params table is set according to the clients history data.
For eg if you are on a dev instance and your instance is as old as Sept 2009 and your max_sales_date is set as Feb 2010 then this will make most of your item location combination young.
So set the dates approroriately.
Update prop_changes on mdp_matrix to 1 and then execute proport.
Also check your dying time and mature age parameter.
Best Regards
Thomas

Similar Messages

  • Forecasting Models in Demantra

    Hi All,
    Does any one tried with only enabling certain models in Demantra. In business modeler, I enabled only regression in model library and ran the engine. I compared with demantra forecast with all the models checked. There is no change in demantra forecast. Is it the expected behaviour. Inspite of user input, demantra goes only by the recommendation from baysean model?
    Thanks
    Ramkri

    Hi
    Plz check the following
    Demantra - Reciveing flat line forecast (Naive)
    Forecast Engine forecasting 2.5 to 3 times more than expected
    Statistical Forecast - generates the same forecast qty for all periods
    Demantra: Very good historical fit -> Bad forecast
    forecast tuning in demantra
    Hope it will help
    Tks
    MJ

  • Multiple Forecast Streams in Demantra

    Hey,
    I've noticed release note for 7.2 includes the following enhancement:
    "You may want to create statistical forecasts from multiple demand streams.
    You can generate a forecast from any data stream, for example, booking history and shipment history. Each data stream has a unique engine profile and version."
    I haven't been able to find much documentation about this option.
    Has anyone implemented a solution using that ? Know any HOW-TO documents available?
    I'm thinking of using it for forecasting - item sales, and item returns from customers.
    How should SALES_DATA be loaded for that scenario? How should engine be run?
    Thanks alot for any reply,
    Aaron

    Hi All,
    Forecasting with multiple demand stream means that you can generate multiple forecasts based on different demand stream. By demand stream, i mean the historical data stream on which you want to generate the forecast.
    There can be situations where you may require to generate forecast for different purpose.Like Aaron mentioned, you may want to generate a forecast based on the order/booking history and/or you may want to generate a forecast based on the returns history. For this purpose you need to create different engine profiles.Engine profile is nothing but a set of engine parameters with specific values. Oracle Demantra provides some predefined profiles for different purposes, and you can define additional engine profiles, as needed. When you run the Analytical Engine, you specify the engine profile to use.
    Now coming to the HOW-TO part:
    1) The quantity_form (system parameter) contains an expression that is used by the engine to retrieve and aggregate demand stream data from the SALES_DATA table. Make sure that the quantity_form expression for a specific engine profile points to database columns containing the historical demand stream desired for the profile. Meaning, if you want to generate a forecast based on booking history then the quantity_form should point to the booking history stream in the sales_data table. Likewise for returns history, point the quantity_form to returns history stream in sales_data table.
    2) Create a series to view the forecast generated by the engine profile.
    3) The newly created engine profiles gets added to the list of engine profiles in the system parameters.You can select the required engine profile and generate the forecast.
    4) View, Edit or compare the forecast created in step 4 by creating a worksheet with all the forecast generated.
    I hope this brings more clarity to the queries/replies posted earlier.
    Regards,
    Shekhar
    Edited by: Shekhar on Feb 18, 2009 10:02 AM

  • Demantra forecast disappears intermittently from ASCP.

    Demantra forecast disappears intermittently from ASCP. Need to run Upload local forecast workflow again and then the plan run to view the forecast again, Can anyone tell why is this happening?
    However the forecast entries are not disappearing from the Denorm table.
    Thanks
    Somanath

    if the data is available in denorm table, then some planning program is causing this issue. demantra worflow or forecast publish from demantra works fine.

  • Lead time information in Demantra

    Hi
    For a POC, We need to get lead time data from ERP(R12) to Demantra. Can I use Lead time as one of the attributes in data model? is there any other better way to represent the same in Demantra?
    What are the inputs for forecast generation in Demantra (Other than Historical series, Causal factors and engine/non engine parametes)
    Thanks
    DNP

    Mismatch of forecast values having similar history on 7.2.0.2 VS 6.2.6
    Hi,
    check the following
    Hope it will help you
    Demantra - history period to be considered for forecast ???
    Forecast generation horizon
    Demantra Forecast clarification
    System Parameter
    Demantra - sytem parameter - max_fore_sales_date
    Thanks
    MJ

  • Can Demantra Forecast at a National level?

    Good afternoon Forum,
    I posted a thread about a month ago and am back again to hear some more good advice and information. I work in a business group which supplies spare parts nationally through regional distribution centers for a large industrial equipment installed base. Despite me being against this, our management has decided to use Demantra to forecast parts usage at the National level and then force down to the regional distribution centers to take a percentage of parts based on past percentage of the total, rather than roll up the individual regional forecasts to create a total.
    My question is can Demantra be set to do this? What would it take? Besides being less accurate at a regional level, what other drawbacks are there?
    Thanks in advance for any assistance you can provide.
    Best regards,
    ABoyNamedJoe

    Hi Maggie,
    To solve the proble, I think the best way is to create something like dummy entity, which is usually called adjustment entity as Alwin mentions.
    Please remember not making any child entity of the adjustment entity.  Otherwise, the adjustment entity won't be base-level member anymore, and you can not post data.
    Hope it helps.
    Atsushi

  • Can demantra(7.2) forecast at hourly level??

    I have a requirement where the forecast needs to be done at hourly level .
    Can it be done in demantra ?
    As per implementation guide for demantra 7.2 , it seems it can be done. Implementation guide says :
    "The base time unit is specified during configuration to a length that is appropriate for
    your planning cycle. Oracle provides three sizes of base time unit (day, week, or month)
    and *can support hourly time units if needed*."
    Please let me know, if you know the details of such setup
    Regards

    Hi,
    I think i was not able to explain the question well . I know that the forecast cycle can be run each hour.
    My question is : can the forecast be generated at hourly bucket ?
    can we give history in terms of hourly bucket and get the forecast in hourly bucket too?
    The time level aggrgation may look like : - hour -> day -> week -> month
    As per data model, there seems to be only three time bucket option is there i.e. day , week and month.
    But as per implementation guide , we can also forecast in hourly bucket. if it can be done , can some body let me know what the extra step required .
    Regards

  • Forecasting the need of spare parts in Demantra

    Hello everyone,
    I would really appreciate if anyone who's had dealt with the following issue help us,
    The thing is - we want to forecast 3 different kind of items:
    1. Main items we sell - for examples - machines.
    2. Accessories for machines we sell. A certian accessory can be used with several type of machines. (Cables, Batteries etc.)
    3. Spare parts we need to keep in stock in order to provide repair services for our customers.
    Each machine we sell has a different set of spare parts used when repairing.
    The forecast for machines is a typical demantra model forecast.(sales forecast by the book).
    My question is regarding the forecast for the spare parts we need for repairs.
    We know that demand for a certain spare part is influenced by how many machines which use that part were sold to customers.
    Also - it depends how common is the use of that part when fixing those machines that need service.
    (some parts get broken more frequently etc).
    Also since we provide fixed price insurance for customers, they dont "see" spare parts price as a factor.
    (they dont naturally "buy" the parts).
    How can demantra tie the forecast for the spare part to sales history of machines? Can demantra forecast service ?(which behaves alot different than sales). It is obvious that forecasting demand for spare parts with looking only at each part's history will not provide best forecast results.
    Any insights anyone?
    I'm pretty sure most implementations faced that issue - regarding the forecast of parts for service -
    Would appreciate any reply,
    Thanks alot,
    Aaron.
    Edited by: user10894682 on 07:30 05/02/2009

    Hi Aaron,
    Per my understanding,you sell machines as well as their accessories.So forecasting for them is by the book where you would be using the demand for machine as well as for accessories..
    As far as the service parts' forecasting is concerned, Oracle has a seperate module for Service & Spare parts planning based on Demantra's forecasting engine.
    Spare Parts Planning(SPP) has the following features:
    1. Forecast accurately with built in Demantra's Forecasting engine
    2. Replenish spares based on Single plan model
    3. Distribute spares using SPP's plan
    4. One single UI to carry out all 3 above processes for improved productivity
    5. Forecasting based on Shipments, Spares Usage, and Returns
    6. Plan based on Service parts failure rates calculations
    7. Integrated with various APS modules like Demantra DM, CP, IO, and ASCP.
    From demantra's perspective you may try out the following:
    Since you provide fixed price insurance for customers,you would definitely be keeping track of the service provided like what spare was replaced and probably how many of the same spare have been replaced for a particular customer over a period of time. Also as per the insurance you must have specified that a particular spare would be replaced only x number of times within a span of say 6 months or 12 months.
    You may utilize these information to classify the spares based on the frequency of use viz. very frequent, medium frequent and less frequent and associate some factor to it.You can club this information as well as the spare parts demand coming out of the BOM (bill of material) of the machine along with each part's history and come up with a forecast that can be more relied upon.
    I hope this helps.
    Regards,
    Shekhar

  • ASCP Plan Is Not Able To Read Global Forecast For Options Published By Demantra

    ASCP plan is not able to read global forecast for options published by Demantra
    ASCP plan is not able to read global forecast for options published by Demantra. Only Model Forecast is being read into ASCP plan. 
    1) We are publishing global forecast from Demantra at CTO/Zone/Week level and it is getting published properly to ASCP denorm table. 
    2)There is no forecast explosion being done in ascp (plan option explode forecast is not checked) 
    3)The sourcing rule is set at zone level for the model saying source from an organization (org code 11) 
    4) The profile: msc:-Organization containing generic BOM for global forecasting is set to 22 which is a reference org 
    5) Now when we run the plan the model forecast goes to org 11  but the option forecasts do not go properly 
    6) We have just one line created for the option (production forecast) with a wrong quantity
    7) Demantra has forecasts for both Model and options

    Looking at the error message "The Network Adapter could not establish the connection" , It appears hostname and port may be incorrect. Review the targets.xml under E:\oracle\product\10.2.0\db_1\SAP_solman_SDB\emd and
    emoms.properties under E:\oracle\product\10.2.0\db_1\SAP_solman_SDB\config folder to make sure host ( sap_solman) and port (1527) are correct.
    As far as setting the environment variables goes, you can go to control panel -> system -> advanced -> environment variables and set the ORACLE_HOME and ORACLE_SID
    -Ramesh

  • Demantra Forecast clarification

    hi everyone,
    a small clarification. supposing forecast has been generated for the entire list of items during the analytical engine run once.
    now when i am running the engine again, i want to retain the forecast generated previously during the last run for some items.
    is there a way to do this.
    also how do i find out if a particular run of the engine(run previously) has been in dp or pe mode.
    regards,
    karthi sankar!

    Hey there,
    For your requirement, cleary what you need to use is the LOB functionality (Line of Business).
    In this functionality, you set the engine to run on a subset of your data.
    You define which data by setting system parameters - engine - shell - Integration1LOBLevel: Defines the Table name by which you segment your data.
    and - engine - shell - Integration1LOBPopulation - to define the members to be included.
    Segmentation can be done by any level in your model.
    Example: Say you have a level called Item Type. Then - Level = Item Type.
    And to find the Population - you need to query the table Demantra created for this level (t_ep_Xxx) and note the id's for the members you want to include in the engine run.
    There is an LOB workflow that you need to run.
    First stage - looks at those system parameters and for all other members update prediction_status to '96' which means no forecast.
    Then engine is run only on that population combinations only.
    Then there's a stage that copies all other combination previous forecast, because it mustnt be changed, it also copies back the correct predication_status before it was run over by 96.
    You can read more in the Implementation guide, although I have to say documentation is not that detailed.
    Hope this helps,
    Aaron

  • The three members in Demantra level Forecast System Status represent what?

    There are three members in Demantra level Forecast System Status. Good For Forecast, Young Address, and Dead Address. What do each of these mean and how does it work?

    Hi,
    98 (Young) — Sales for this combination are too new to be used for prediction.
    99 (Dead) — Sales for this combination are not recent enough to be used for prediction.
    1 (Live or Active)—Neither young nor dead.
    Tks
    MJ

  • Demantra - history period to be considered for forecast ???

    In the current system I have 5 years of history sales data - but for my forecast I need to consider data only for the last 3 years.
    Are "history length" and "start date" are the only parameters which decide the history length or is there any other parameter also considered in deciding the length of history to be considered for forecast generation.
    Appreciate your response.
    thx and rgds,
    Pankaj

    Hi,
    Check whether the following parameters fulfill your requirement.
    StartAverage
    AverageHorizon
    PromotionStartDate
    last_date
    Tks
    M J

  • How to install Demantra on 64-bit machine so that all components work?!!

    I'm using 64-bit windows 7. I first installed Oracle DB 10.2.0.4 x64, then Demantra 7.3 x64. Some component of Demantra didn't work, wouldn't open giving me the following error "Can't connect to database Oracle library OCI.dll or ORA803.dll couldn't be loaded". Only then I read official installation notes for Demantra which say:
    You can run Oracle Demantra on either a 32-bit or 64-bit Oracle database. However, the Oracle Demantra Installer and these applications run in 32-bit mode, so you must use the 32-bit Oracle database client to install Oracle Demantra and use these applications:
    * Business Modeler
    * Member Management
    * Chaining Management
    * Oracle Demantra forecasting engine
    How do I "use the 32-bit Oracle database client to install Oracle Demantra"? Give me a bit more detailed answer if you can, as I'm not an expert. Thank you.

    Hi Milind,
    Unfortunately, I don't have Oracle SID and access to metalink. We're about to get into contractual agreement, but it's still in the workings. My original problem was solved by way of using virtual machine (32 XP) on top of Windows 7 64. However there are other issues standing in the way of our training. Do you know whether 7.3.0.1 has seeded demo data? (7.2 had it, and 7.3.0 didn't). Desperately need to a big nice rich dataset for 7.3. Any help greatly appreciated.
    Yuriy

  • Could anyone please tell me how to tuning my program?

    I have already executed the program with SE30.
    I think that the program has some problem SQL in form
    "GET_BACK_ORDER       (Fetch VBAP, Net % = <b>26.2</b>)" and
    "GET_PENDING_ORDER (Fetch AUFK,  Net % = <b>25.7</b>)"
    but I can not find the data that I want from others table and I don't know how to tuning both form.
    Source code for Review of Sales Forecast
    REPORT  ZLPPRP26
            LINE-SIZE 573
            NO STANDARD PAGE HEADING.
      T A B L E S                                                        *
    TABLES: pbed,      "Independent Requirements Data
            pbim.      "Independent Requirements for Material
    TABLES: afko,      "Order header data PP orders
            aufk,      "Order master data
            t399x,     "Plant/order type
            tj02t,     "Text Status for check status of Process Order
            s003,      "Sale Order
            vbep,      "Sales Document: Schedule Line Data (QTY)
            vbap,      "Sales Document: Item Data (Material)
            vbup,      "Sales Document: Item Status
            mchb,      "Stock
            mcha,      "Stock description
            mara.      "General Material Data
    *................................ Include ISO declarations
    INCLUDE zstprpi1.
      T Y P E S                                                          *
    TYPES: boolean(1).
    TYPE-POOLS : slis.
      W O R K I N G   S T O R A G E   D A T A                            *
    DATA: BEGIN OF wa_pbim,
            matnr  LIKE  pbim-matnr,     " MATERIAL NO.
            werks  LIKE  pbim-werks,     " PLANT.
            bedae  LIKE  pbim-bedae,     " REQUIREMENT TYPE.
            versb  LIKE  pbim-versb,     " VERSION.
            pbdnr  LIKE  pbim-pbdnr,     " REQUIREMENT PLAN NO.
            bdzei  LIKE  pbim-bdzei,     " INQ REQUIREMENT POINTER.
            vervs  LIKE  pbim-vervs,     " STATUS ACTIVE-INACTIVE.
          END OF wa_pbim.
    DATA: BEGIN OF wa_pbed,
            pdatu  LIKE  pbed-pdatu,     " FINISH DATE
            bdzei  LIKE  pbed-bdzei,     " INQ REQUIREMENT POINTER.
            aenam  LIKE  pbed-aenam,     " NAME OF PERSON CHANGE.
            laeda  LIKE  pbed-laeda,     " DATE CHANGE.
            meins  LIKE  pbed-meins,     " UM.
            plnmg  LIKE  pbed-plnmg,     " PLAN QTY.
            entlu  LIKE  pbed-entlu,     " PERIOD INDICATOR
            perxx  LIKE  pbed-perxx,     " PLANNING PERIOD
          END OF wa_pbed.
    DATA: BEGIN OF wa_marc,     
            matnr  LIKE  marc-matnr,      " MAT CODE
            werks  LIKE  marc-werks,      " PLANT
            maabc  LIKE  marc-maabc,     " Class
            dismm  LIKE  marc-dismm,     " MRP Type
            dispo  LIKE  marc-dispo,     " MRP Controller
            eisbe  LIKE  marc-eisbe,     " Safety Stock
            bstfe  LIKE  marc-bstfe,     " Fix
            bstmi  LIKE  marc-bstmi,     " Min
            bstma  LIKE  marc-bstma,     " Max
          END OF wa_marc.
    DATA : BEGIN OF wa_mchb,
            matnr  LIKE  mchb-matnr,     " Mat Code
            werks  LIKE  mchb-werks,     " Plant
            clabs  LIKE  mchb-clabs,      " UR
            cinsm  LIKE  mchb-cinsm,      " QI
            cspem  LIKE  mchb-cspem,      " BL
            lgort  LIKE  mchb-lgort,     " Storage Location
            charg  LIKE  mchb-charg,     " Batch
          END OF wa_mchb.
    DATA : BEGIN OF wa_all_material,     " **MAIN OF PROGRAM**
            matnr  LIKE  mara-matnr,     " Mat Code
            werks  LIKE  marc-werks,      " Plant
            maabc  LIKE  marc-maabc,     " Class
            dismm  LIKE  marc-dismm,     " MRP Type
            dispo  LIKE  marc-dispo,     " MRP Controller
            meins  LIKE  mara-meins,     " UoM
            mseht  LIKE  t006a-mseht,    " UoM Text
            maktx  LIKE  makt-maktx,     " Mat Description
          END OF wa_all_material.
    DATA: BEGIN OF wa_ind_req,
            matnr  LIKE  pbim-matnr,     " MATERIAL NO.
            werks  LIKE  pbim-werks,     " PLANT.
            bedae  LIKE  pbim-bedae,     " REQUIREMENT TYPE.
            versb  LIKE  pbim-versb,     " VERSION.
            pbdnr  LIKE  pbim-pbdnr,     " REQUIREMENT PLAN NO.
            bdzei  LIKE  pbim-bdzei,     " INQ REQUIREMENT POINTER.
            vervs  LIKE  pbim-vervs,     " STATUS ACTIVE-INACTIVE.
            pdatu  LIKE  pbed-pdatu,     " FINISH DATE &#3585;&#3619;&#3603;&#3637; DAY Period
            aenam  LIKE  pbed-aenam,     " NAME OF PERSON CHANGE.
            laeda  LIKE  pbed-laeda,     " DATE CHANGE.
            plnmg  LIKE  pbed-plnmg,     " PLAN QTY.
            entli  LIKE  pbed-entli,     " Date type (1day, 2week, 3month)
            perxx  LIKE  pbed-perxx,     " PLANNING PERIOD
          END OF wa_ind_req.
    DATA: BEGIN OF wa_ind_req1,
            matnr  LIKE  pbim-matnr,     " MATERIAL NO.
           meins  LIKE  pbed-meins,     " UM. [Tiwa 31072006]
            plnmg  LIKE  pbed-plnmg,     " PLAN QTY.
            entli  LIKE  pbed-entli,     " Date type (1day, 2week, 3month)
            perxx  LIKE  pbed-perxx,     " PLANNING PERIOD
            pdatu  LIKE  pbed-pdatu,     " FINISH DATE &#3585;&#3619;&#3603;&#3637; DAY Period
          END OF wa_ind_req1.
    DATA: BEGIN OF wa_ind_rep,
            matnr  LIKE  pbim-matnr,     " MATERIAL NO.
            cw4    LIKE  pbed-plnmg,     " PLAN QTY of week from user
            nw1    LIKE  pbed-plnmg,     " PLAN QTY next month week1
            nw2    LIKE  pbed-plnmg,     " PLAN QTY next month week2
            nw3    LIKE  pbed-plnmg,     " PLAN QTY next month week3
            nw4    LIKE  pbed-plnmg,     " PLAN QTY next month week4
            nw5    LIKE  pbed-plnmg,     " PLAN QTY next month week5
            mxx    LIKE  pbed-plnmg,     " PLAN QTY next month(Period Month)
            ntotal LIKE  pbed-plnmg,     "
          END OF wa_ind_rep.
    DATA: BEGIN OF wa_sales_hist,
            spbup    LIKE  s003-spbup,      " Period to analyze
            vkorg    LIKE  s003-vkorg,      " Sales Organization(Plant)
            matnr    LIKE  s003-matnr,      " Mat Code
            aemenge  LIKE  s003-aemenge, " incoming orders Qty
            ummenge  LIKE  s003-ummenge, " Billing Qty
            ssour    LIKE  s003-ssour,   " for key
            vrsio    LIKE  s003-vrsio,   " for key
            spmon    LIKE  s003-spmon,   " for key
            sptag    LIKE  s003-sptag,   " for key
            spwoc    LIKE  s003-spwoc,   " for key
            vtweg    LIKE  s003-vtweg,   " for key
            spart    LIKE  s003-spart,   " for key
            bzirk    LIKE  s003-bzirk,   " for key
            kunnr    LIKE  s003-kunnr,   " for key
          END OF wa_sales_hist.
    DATA: BEGIN OF wa_sales_report,
            matnr    LIKE  s003-matnr,      " Mat Code
            m_3      LIKE  s003-aemenge, " incoming orders Qty m-3
            m_2      LIKE  s003-aemenge, " incoming orders Qty m-2
            m_1      LIKE  s003-aemenge, " incoming orders Qty m-1
            m_0      LIKE  s003-aemenge, " incoming orders Qty m-0
            estim    TYPE  P DECIMALS 3,
            avg_sale TYPE  P DECIMALS 3,
          END OF wa_sales_report.
    DATA: BEGIN OF wa_back_order,
            matnr    LIKE  vbap-matnr,     " Mat Code
            wmeng    LIKE  vbep-wmeng,     " Order quantity
            bmeng    LIKE  vbep-bmeng,     " Confirmed quantity
           vrkme    LIKE  vbep-vrkme,     " Sales unit [Tiwa 31072006]
          END OF wa_back_order.
    DATA: BEGIN OF wa_backord_rep,
            matnr    LIKE  vbap-matnr,     " Mat Code
            back     LIKE  vbep-wmeng,     " Order quantity
          END OF wa_backord_rep.
    DATA: BEGIN OF wa_pending_order,
            objnr    LIKE  jest-objnr,  " Object
            matnr    LIKE  afpo-matnr,  " Material
            psmng    LIKE  afpo-psmng,  " Order Item QTY
            wemng    LIKE  afpo-wemng,  " GR QTY
            amein    LIKE  afpo-amein,  " UoM for Inhouse Prod
          END OF wa_pending_order.
    DATA: BEGIN OF wa_pending_rep,
            matnr    LIKE  afpo-matnr,  " Material
            psmng    LIKE  afpo-psmng,  " Order Item QTY
          END OF wa_pending_rep.
    DATA: BEGIN OF wa_batch_safety,
            matnr    LIKE  marc-matnr,  " Mat Code
            eisbe    LIKE  marc-eisbe,     " Safety Stock
            bstfe    LIKE  marc-bstfe,     " Fix
            bstmi    LIKE  marc-bstmi,     " Min
            bstma    LIKE  marc-bstma,     " Max
          END OF wa_batch_safety.
    DATA: BEGIN OF wa_vbep,
            vbeln    LIKE  vbep-vbeln,  "Sales Document
            posnr    LIKE  vbep-posnr,  "Sales Document Item
            wmeng    LIKE  vbep-wmeng,  "Order quantity in sales units
            bmeng    LIKE  vbep-bmeng,  "Confirmed quantity
          END OF wa_vbep.
    DATA: BEGIN OF wa_vbap,
            vbeln    LIKE  vbap-vbeln,    "Sales Document
            posnr    LIKE  vbap-posnr,    "Sales Document Item
            matnr    LIKE  vbap-matnr,    "Material Code
            kwmeng   LIKE  vbap-kwmeng,   "Order Qty.
            kbmeng   LIKE  vbap-kbmeng,   "Comfirmed Qty.
            klmeng   LIKE  vbap-klmeng,   "Back Order.
          END OF wa_vbap.
    DATA: BEGIN OF wa_vbup,
            vbeln    LIKE  vbup-vbeln,  "Sales Document
            posnr    LIKE  vbup-posnr,  "Sales Document Item
          END OF wa_vbup.
    DATA: BEGIN OF wa_vbfa,
            VBELV    LIKE  vbfa-VBELV,   "Preceding SO
            POSNV    LIKE  vbfa-POSNV,   "Preceding item of an SD document
            VBTYP_N  LIKE  vbfa-VBTYP_N, "Document category J = D/O
            RFMNG    LIKE  vbfa-RFMNG,   "QTY in D/O
            MATNR    LIKE  vbfa-MATNR,   "Material
            VBELN    LIKE  vbfa-VBELN,   "Subsequent SD Doc.
            POSNN    LIKE  vbfa-POSNN,   "Subsequent item of an SD document
          END OF wa_vbfa.
    DATA:  matclss  LIKE  marc-maabc,      " SLECTION OPTION
           mrpcont  LIKE  marc-dispo,      " SLECTION OPTION
           p_week   LIKE  scal-week,       " Apply from parameter P_WEEK
           p_week4  LIKE  scal-week VALUE 999999, "add in 270706
           tmpweek  LIKE  scal-week,       " return of FORM date_2_week
           tmpdate  LIKE  scal-date,       " return of FORM week_get_1st_day
           tmp_next_week  LIKE  scal-week, " return of FORM next_week.
           yyyymm_nextmonth(6) TYPE C,
           firstdate_of_week_of_monthend LIKE  scal-date, "1st&#3586;&#3629;&#3591;week&#3626;&#3640;&#3604;&#3607;&#3657;&#3634;&#3618;
           all_mat_found  TYPE I VALUE 1.  " Use in FORM read_all_material
    DATA : next_month      LIKE  scal-date,
           next_next_month LIKE  scal-date,
           next_month_w1   LIKE  scal-week,
           next_month_w2   LIKE  scal-week,
           next_month_w3   LIKE  scal-week,
           next_month_w4   LIKE  scal-week,
           next_month_w5   LIKE  scal-week,
           next_next_month_w1  LIKE  scal-week,
           next_next_month_w2  LIKE  scal-week,
           next_next_month_w3  LIKE  scal-week,
           next_next_month_w4  LIKE  scal-week,
           next_next_month_w5  LIKE  scal-week.
    DATA : prev_month  LIKE  scal-date,  "GLOBAL
           prev_month0(6)  TYPE  C,      "Current Month
           prev_month1(6)  TYPE  C,
           prev_month2(6)  TYPE  C,
           prev_month3(6)  TYPE  C.
    DATA : date1_in_currweek4_1  LIKE scal-date  VALUE 99999999,  "MON
           date2_in_currweek4_1  LIKE scal-date  VALUE 99999999,  "TUE
           date3_in_currweek4_1  LIKE scal-date  VALUE 99999999,  "WED
           date4_in_currweek4_1  LIKE scal-date  VALUE 99999999,  "THU
           date5_in_currweek4_1  LIKE scal-date  VALUE 99999999,  "FRI
           date6_in_currweek4_1  LIKE scal-date  VALUE 99999999,  "SAT
           date7_in_currweek4_1  LIKE scal-date  VALUE 99999999.  "SUN
    DATA : date1_in_currweek4  LIKE scal-date,  "MON
           date2_in_currweek4  LIKE scal-date,  "TUE
           date3_in_currweek4  LIKE scal-date,  "WED
           date4_in_currweek4  LIKE scal-date,  "THU
           date5_in_currweek4  LIKE scal-date,  "FRI
           date6_in_currweek4  LIKE scal-date,  "SAT
           date7_in_currweek4  LIKE scal-date.  "SUN
    DATA : date1_in_nextmonth_week1  LIKE scal-date,  "MON
           date2_in_nextmonth_week1  LIKE scal-date,  "TUE
           date3_in_nextmonth_week1  LIKE scal-date,  "WED
           date4_in_nextmonth_week1  LIKE scal-date,  "THU
           date5_in_nextmonth_week1  LIKE scal-date,  "FRI
           date6_in_nextmonth_week1  LIKE scal-date,  "SAT
           date7_in_nextmonth_week1  LIKE scal-date.  "SUN
    DATA : date1_in_nextmonth_week2  LIKE scal-date,  "MON
           date2_in_nextmonth_week2  LIKE scal-date,  "TUE
           date3_in_nextmonth_week2  LIKE scal-date,  "WED
           date4_in_nextmonth_week2  LIKE scal-date,  "THU
           date5_in_nextmonth_week2  LIKE scal-date,  "FRI
           date6_in_nextmonth_week2  LIKE scal-date,  "SAT
           date7_in_nextmonth_week2  LIKE scal-date.  "SUN
    DATA : date1_in_nextmonth_week3  LIKE scal-date,  "MON
           date2_in_nextmonth_week3  LIKE scal-date,  "TUE
           date3_in_nextmonth_week3  LIKE scal-date,  "WED
           date4_in_nextmonth_week3  LIKE scal-date,  "THU
           date5_in_nextmonth_week3  LIKE scal-date,  "FRI
           date6_in_nextmonth_week3  LIKE scal-date,  "SAT
           date7_in_nextmonth_week3  LIKE scal-date.  "SUN
    DATA : date1_in_nextmonth_week4  LIKE scal-date VALUE 99999999,  "MON
           date2_in_nextmonth_week4  LIKE scal-date VALUE 99999999,  "TUE
           date3_in_nextmonth_week4  LIKE scal-date VALUE 99999999,  "WED
           date4_in_nextmonth_week4  LIKE scal-date VALUE 99999999,  "THU
           date5_in_nextmonth_week4  LIKE scal-date VALUE 99999999,  "FRI
           date6_in_nextmonth_week4  LIKE scal-date VALUE 99999999,  "SAT
           date7_in_nextmonth_week4  LIKE scal-date VALUE 99999999.  "SUN
    DATA : date1_in_nextmonth_week5  LIKE scal-date VALUE 99999999,  "MON
           date2_in_nextmonth_week5  LIKE scal-date VALUE 99999999,  "TUE
           date3_in_nextmonth_week5  LIKE scal-date VALUE 99999999,  "WED
           date4_in_nextmonth_week5  LIKE scal-date VALUE 99999999,  "THU
           date5_in_nextmonth_week5  LIKE scal-date VALUE 99999999,  "FRI
           date6_in_nextmonth_week5  LIKE scal-date VALUE 99999999,  "SAT
           date7_in_nextmonth_week5  LIKE scal-date VALUE 99999999.  "SUN
    DATA : t_fieldcat   TYPE  slis_t_fieldcat_alv.
      I N T E R N A L   T A B L E S                                      *
    DATA: it_pbim           LIKE wa_pbim          OCCURS 0 WITH HEADER LINE,
          it_pbed           LIKE wa_pbed          OCCURS 0 WITH HEADER LINE,
          it_stock          LIKE wa_mchb          OCCURS 0 WITH HEADER LINE,
          it_stock_rep      LIKE wa_mchb          OCCURS 0 WITH HEADER LINE,
          it_ind_req        LIKE wa_ind_req       OCCURS 0 WITH HEADER LINE,
          it_ind_req1       LIKE wa_ind_req1      OCCURS 0 WITH HEADER LINE,
          it_ind_rep        LIKE wa_ind_rep       OCCURS 0 WITH HEADER LINE,
          it_tmp_sales_hist LIKE wa_sales_hist    OCCURS 0 WITH HEADER LINE,
          it_sales_hist     LIKE wa_sales_hist    OCCURS 0 WITH HEADER LINE,
          it_back_order     LIKE wa_back_order    OCCURS 0 WITH HEADER LINE,
          it_pending_order  LIKE wa_pending_order OCCURS 0 WITH HEADER LINE,
          it_sales_report   LIKE wa_sales_report  OCCURS 0 WITH HEADER LINE,
          it_backord_rep    LIKE wa_backord_rep   OCCURS 0 WITH HEADER LINE,
          it_batch_safety   LIKE wa_batch_safety  OCCURS 0 WITH HEADER LINE,
          it_pending_rep    LIKE wa_pending_rep   OCCURS 0 WITH HEADER LINE,
          it_all_material   LIKE wa_all_material  OCCURS 0 WITH HEADER LINE,
          t_vbap            LIKE wa_vbap          OCCURS 0 WITH HEADER LINE,
          t_vbep            LIKE wa_vbep          OCCURS 0 WITH HEADER LINE,
          t_vbfa            LIKE wa_vbfa          OCCURS 0 WITH HEADER LINE,
          t_vbup            LIKE wa_vbup          OCCURS 0 WITH HEADER LINE.
      R A N G E S                                                        *
    RANGES: r_month    FOR  pbed-pdatu,
            r_matnr    FOR  pbim-matnr.
      S E L E C T - O P T I O N S   A N D   P A R A M E T E R S          *
    SELECTION-SCREEN: BEGIN OF BLOCK bk1 WITH FRAME TITLE text-007.
      PARAMETERS:     p_werks  LIKE pbim-werks OBLIGATORY. "DEFAULT '1100'.
      SELECT-OPTIONS: s_matnr  FOR  mara-matnr.
      SELECT-OPTIONS: s_matc   FOR  matclss.
      SELECT-OPTIONS: s_mrpc   FOR  mrpcont OBLIGATORY.
      PARAMETERS :    p_month  LIKE s003-spbup OBLIGATORY.
    SELECTION-SCREEN : END OF BLOCK bk1.
      M A C R O   C O M M A N D   D E F I N I T I O N                    *
    DEFINE m%print_right.
      write at sy-linsz ''.
    END-OF-DEFINITION.
      MAIN PROGRAM                                                       *
    START-OF-SELECTION.
      PERFORM date_2_week USING sy-datum.  "return to tmpweek
      PERFORM get_last_week_of_month.
      PERFORM process_get_month_for_sales.
      PERFORM get_week_next_month.
      PERFORM get_week_next_next_month.
      PERFORM get_date_in_currweek4.
      PERFORM get_date_in_week_in_nextmonth.
      PERFORM read_all_material.
      IF all_mat_found EQ 1.        "Found some of material
        PERFORM read_stock.
        PERFORM read_pbim_pbed_data.
        PERFORM get_sales_history.
        PERFORM get_back_order.
        PERFORM get_pending_order.
        PERFORM print_report.
      ENDIF.
    *&      Form  read_pbim_pbed_data
    FORM read_pbim_pbed_data.
      yyyymm_nextmonth = next_month+0(6).
      SELECT pbimmatnr pbimwerks pbim~bedae
             pbimversb pbimpbdnr pbimbdzei pbimvervs
             pbedpdatu pbedaenam pbed~laeda
             pbedplnmg pbedentli pbed~perxx
      INTO TABLE it_ind_req
      FROM pbim
      INNER JOIN pbed
            ON pbimbdzei = pbedbdzei
      FOR ALL ENTRIES IN it_all_material
      WHERE pbim~vervs = 'X'  AND      "Active Version
            pbim~werks = p_werks AND
            pbim~matnr EQ it_all_material-matnr AND
            ( ( pbedperxx = next_month_w1 AND pbedentli = 2 ) OR
              ( pbedperxx = next_month_w2 AND pbedentli = 2 ) OR
              ( pbedperxx = next_month_w3 AND pbedentli = 2 ) OR
              ( pbedperxx = next_month_w4 AND pbedentli = 2 ) OR
              ( pbedperxx = next_month_w5 AND pbedentli = 2 ) OR
              ( pbedperxx = p_week        AND pbedentli = 2 ) OR
              ( pbedperxx = p_week4       AND pbedentli = 2 ) OR "27072006
              ( pbed~pdatu between date1_in_currweek4 AND
                                   date7_in_currweek4 ) OR
              ( pbed~pdatu between date1_in_currweek4_1 AND   "add 27072006
                                   date7_in_currweek4_1 ) OR  "add 27072006
              ( pbed~pdatu between date1_in_nextmonth_week1 AND
                                   date7_in_nextmonth_week1 ) OR
              ( pbed~pdatu between date1_in_nextmonth_week2 AND
                                   date7_in_nextmonth_week2 ) OR
              ( pbed~pdatu between date1_in_nextmonth_week3 AND
                                   date7_in_nextmonth_week3 ) OR
              ( pbed~pdatu between date1_in_nextmonth_week4 AND
                                   date7_in_nextmonth_week4 ) OR
              ( pbed~pdatu between date1_in_nextmonth_week5 AND
                                   date7_in_nextmonth_week5 ) OR
              ( pbedperxx = yyyymm_nextmonth AND pbedentli = 3 ) ).
      LOOP AT it_ind_req.
        wa_ind_req1-matnr = it_ind_req-matnr.
        wa_ind_req1-plnmg = it_ind_req-plnmg.
        wa_ind_req1-entli = it_ind_req-entli.
        wa_ind_req1-perxx = it_ind_req-perxx.
        wa_ind_req1-pdatu = it_ind_req-pdatu.
        COLLECT wa_ind_req1 INTO it_ind_req1.
      ENDLOOP.
      PERFORM get_ind_rep.
      PERFORM get_batch_safe.
    ENDFORM.
    *&      Form  get_batch_safe
    FORM get_batch_safe.
      DATA: wl_marc LIKE marc,
            safety  LIKE marc-eisbe VALUE 0,
            fix     LIKE marc-eisbe VALUE 0,
            min     LIKE marc-eisbe VALUE 0,
            max     LIKE marc-eisbe VALUE 0.
      LOOP AT it_all_material.
        CLEAR : wl_marc, safety, fix, min, max.
        SELECT SINGLE * FROM marc INTO wl_marc
        WHERE  matnr = it_all_material-matnr AND
               werks = p_werks.
        IF sy-subrc EQ 0.
          safety = wl_marc-eisbe.  " Safety Stock
          fix    = wl_marc-bstfe.  " Fix
          min    = wl_marc-bstmi.  " Min
          max    = wl_marc-bstma.  " Max
        ENDIF.
        it_batch_safety-matnr = it_all_material-matnr.
        it_batch_safety-eisbe = safety.  " Safety Stock
        it_batch_safety-bstfe = fix.     " Fix
        it_batch_safety-bstmi = min.     " Min
        it_batch_safety-bstma = max.     " Max
        APPEND it_batch_safety.
      ENDLOOP.
    ENDFORM.
    *&      Form  get_ind_rep
    FORM get_ind_rep.
      DATA: cw4     TYPE  P VALUE 0 DECIMALS 3,
            nw1     TYPE  P VALUE 0 DECIMALS 3,
            nw2     TYPE  P VALUE 0 DECIMALS 3,
            nw3     TYPE  P VALUE 0 DECIMALS 3,
            nw4     TYPE  P VALUE 0 DECIMALS 3,
            nw5     TYPE  P VALUE 0 DECIMALS 3,
            mxx     TYPE  P VALUE 0 DECIMALS 3, "Add in 12/07/2006 by Tiwa
            ntotal  TYPE  P VALUE 0 DECIMALS 3.
      LOOP AT it_all_material.
        CLEAR: ntotal, cw4, nw1, nw2, nw3, nw4, nw5, mxx, wa_ind_rep.
        LOOP AT it_ind_req1 WHERE matnr = it_all_material-matnr.
          IF ( ( ( it_ind_req1-perxx EQ p_week  ) AND
                 ( it_ind_req1-entli EQ 2 ) ) OR
               ( ( it_ind_req1-pdatu EQ date1_in_currweek4 ) AND
                 ( it_ind_req1-entli EQ 1 ) ) OR
               ( ( it_ind_req1-pdatu EQ date2_in_currweek4 ) AND
                 ( it_ind_req1-entli EQ 1 ) ) OR
               ( ( it_ind_req1-pdatu EQ date3_in_currweek4 ) AND
                 ( it_ind_req1-entli EQ 1 ) ) OR
               ( ( it_ind_req1-pdatu EQ date4_in_currweek4 ) AND
                 ( it_ind_req1-entli EQ 1 ) ) OR
               ( ( it_ind_req1-pdatu EQ date5_in_currweek4 ) AND
                 ( it_ind_req1-entli EQ 1 ) ) OR
               ( ( it_ind_req1-pdatu EQ date6_in_currweek4 ) AND
                 ( it_ind_req1-entli EQ 1 ) ) OR
               ( ( it_ind_req1-pdatu EQ date7_in_currweek4 ) AND
                 ( it_ind_req1-entli EQ 1 ) ) OR
               ( ( it_ind_req1-perxx EQ p_week4 ) AND
                 ( it_ind_req1-entli EQ 2 ) ) OR
               ( ( it_ind_req1-pdatu EQ date1_in_currweek4_1 ) AND
                 ( it_ind_req1-entli EQ 1 ) ) OR
               ( ( it_ind_req1-pdatu EQ date2_in_currweek4_1 ) AND
                 ( it_ind_req1-entli EQ 1 ) ) OR
               ( ( it_ind_req1-pdatu EQ date3_in_currweek4_1 ) AND
                 ( it_ind_req1-entli EQ 1 ) ) OR
               ( ( it_ind_req1-pdatu EQ date4_in_currweek4_1 ) AND
                 ( it_ind_req1-entli EQ 1 ) ) OR
               ( ( it_ind_req1-pdatu EQ date5_in_currweek4_1 ) AND
                 ( it_ind_req1-entli EQ 1 ) ) OR
               ( ( it_ind_req1-pdatu EQ date6_in_currweek4_1 ) AND
                 ( it_ind_req1-entli EQ 1 ) ) OR
               ( ( it_ind_req1-pdatu EQ date7_in_currweek4_1 ) AND
                 ( it_ind_req1-entli EQ 1 ) ) ).
            cw4 = cw4 + it_ind_req1-plnmg.
          ELSEIF ( ( ( it_ind_req1-perxx EQ next_month_w1 ) AND
                     ( it_ind_req1-entli EQ 2 ) ) OR
                   ( ( it_ind_req1-pdatu EQ date1_in_nextmonth_week1 ) AND
                     ( it_ind_req1-entli EQ 1 ) ) OR
                   ( ( it_ind_req1-pdatu EQ date2_in_nextmonth_week1 ) AND
                     ( it_ind_req1-entli EQ 1 ) ) OR
                   ( ( it_ind_req1-pdatu EQ date3_in_nextmonth_week1 ) AND
                     ( it_ind_req1-entli EQ 1 ) ) OR
                   ( ( it_ind_req1-pdatu EQ date4_in_nextmonth_week1 ) AND
                     ( it_ind_req1-entli EQ 1 ) ) OR
                   ( ( it_ind_req1-pdatu EQ date5_in_nextmonth_week1 ) AND
                     ( it_ind_req1-entli EQ 1 ) ) OR
                   ( ( it_ind_req1-pdatu EQ date6_in_nextmonth_week1 ) AND
                     ( it_ind_req1-entli EQ 1 ) ) OR
                   ( ( it_ind_req1-pdatu EQ date7_in_nextmonth_week1 ) AND
                     ( it_ind_req1-entli EQ 1 ) ) ).
            nw1 = nw1 + it_ind_req1-plnmg.
          ELSEIF ( ( ( it_ind_req1-perxx EQ next_month_w2 ) AND
                     ( it_ind_req1-entli EQ 2 ) ) OR
                   ( ( it_ind_req1-pdatu EQ date1_in_nextmonth_week2 ) AND
                     ( it_ind_req1-entli EQ 1 ) ) OR
                   ( ( it_ind_req1-pdatu EQ date2_in_nextmonth_week2 ) AND
                     ( it_ind_req1-entli EQ 1 ) ) OR
                   ( ( it_ind_req1-pdatu EQ date3_in_nextmonth_week2 ) AND
                     ( it_ind_req1-entli EQ 1 ) ) OR
                   ( ( it_ind_req1-pdatu EQ date4_in_nextmonth_week2 ) AND
                     ( it_ind_req1-entli EQ 1 ) ) OR
                   ( ( it_ind_req1-pdatu EQ date5_in_nextmonth_week2 ) AND
                     ( it_ind_req1-entli EQ 1 ) ) OR
                   ( ( it_ind_req1-pdatu EQ date6_in_nextmonth_week2 ) AND
                     ( it_ind_req1-entli EQ 1 ) ) OR
                   ( ( it_ind_req1-pdatu EQ date7_in_nextmonth_week2 ) AND
                     ( it_ind_req1-entli EQ 1 ) ) ).
            nw2 = nw2 + it_ind_req1-plnmg.
          ELSEIF ( ( ( it_ind_req1-perxx EQ next_month_w3 ) AND
                     ( it_ind_req1-entli EQ 2 ) ) OR
                   ( ( it_ind_req1-pdatu EQ date1_in_nextmonth_week3 ) AND
                     ( it_ind_req1-entli EQ 1 ) ) OR
                   ( ( it_ind_req1-pdatu EQ date2_in_nextmonth_week3 ) AND
                     ( it_ind_req1-entli EQ 1 ) ) OR
                   ( ( it_ind_req1-pdatu EQ date3_in_nextmonth_week3 ) AND
                     ( it_ind_req1-entli EQ 1 ) ) OR
                   ( ( it_ind_req1-pdatu EQ date4_in_nextmonth_week3 ) AND
                     ( it_ind_req1-entli EQ 1 ) ) OR
                   ( ( it_ind_req1-pdatu EQ date5_in_nextmonth_week3 ) AND
                     ( it_ind_req1-entli EQ 1 ) ) OR
                   ( ( it_ind_req1-pdatu EQ date6_in_nextmonth_week3 ) AND
                     ( it_ind_req1-entli EQ 1 ) ) OR
                   ( ( it_ind_req1-pdatu EQ date7_in_nextmonth_week3 ) AND
                     ( it_ind_req1-entli EQ 1 ) ) ).
            nw3 = nw3 + it_ind_req1-plnmg.
          ELSEIF ( ( ( it_ind_req1-perxx EQ next_month_w4 ) AND
                     ( it_ind_req1-entli EQ 2 ) ) OR
                   ( ( it_ind_req1-pdatu EQ date1_in_nextmonth_week4 ) AND
                     ( it_ind_req1-entli EQ 1 ) ) OR
                   ( ( it_ind_req1-pdatu EQ date2_in_nextmonth_week4 ) AND
                     ( it_ind_req1-entli EQ 1 ) ) OR
                   ( ( it_ind_req1-pdatu EQ date3_in_nextmonth_week4 ) AND
                     ( it_ind_req1-entli EQ 1 ) ) OR
                   ( ( it_ind_req1-pdatu EQ date4_in_nextmonth_week4 ) AND
                     ( it_ind_req1-entli EQ 1 ) ) OR
                   ( ( it_ind_req1-pdatu EQ date5_in_nextmonth_week4 ) AND
                     ( it_ind_req1-entli EQ 1 ) ) OR
                   ( ( it_ind_req1-pdatu EQ date6_in_nextmonth_week4 ) AND
                     ( it_ind_req1-entli EQ 1 ) ) OR
                   ( ( it_ind_req1-pdatu EQ date7_in_nextmonth_week4 ) AND
                     ( it_ind_req1-entli EQ 1 ) ) ).
            nw4 = nw4 + it_ind_req1-plnmg.
          ELSEIF ( ( ( it_ind_req1-perxx EQ next_month_w5 ) AND
                     ( it_ind_req1-entli EQ 2 ) ) OR
                   ( ( it_ind_req1-pdatu EQ date1_in_nextmonth_week5 ) AND
                     ( it_ind_req1-entli EQ 1 ) ) OR
                   ( ( it_ind_req1-pdatu EQ date2_in_nextmonth_week5 ) AND
                     ( it_ind_req1-entli EQ 1 ) ) OR
                   ( ( it_ind_req1-pdatu EQ date3_in_nextmonth_week5 ) AND
                     ( it_ind_req1-entli EQ 1 ) ) OR
                   ( ( it_ind_req1-pdatu EQ date4_in_nextmonth_week5 ) AND
                     ( it_ind_req1-entli EQ 1 ) ) OR
                   ( ( it_ind_req1-pdatu EQ date5_in_nextmonth_week5 ) AND
                     ( it_ind_req1-entli EQ 1 ) ) OR
                   ( ( it_ind_req1-pdatu EQ date6_in_nextmonth_week5 ) AND
                     ( it_ind_req1-entli EQ 1 ) ) OR
                   ( ( it_ind_req1-pdatu EQ date7_in_nextmonth_week5 ) AND
                     ( it_ind_req1-entli EQ 1 ) ) ).
            nw5 = nw5 + it_ind_req1-plnmg.
          ELSEIF ( ( it_ind_req1-perxx EQ yyyymm_nextmonth ) AND
                   ( it_ind_req1-entli EQ 3 ) ).
            mxx    = mxx + it_ind_req1-plnmg.
            ntotal = ntotal + it_ind_req1-plnmg.
          ENDIF.
        ENDLOOP.
        ntotal = ntotal + ( nw1 + nw2 + nw3 + nw4 + nw5 ).
        wa_ind_rep-matnr   = it_all_material-matnr.
        wa_ind_rep-cw4     = cw4.
        wa_ind_rep-nw1     = nw1.
        wa_ind_rep-nw2     = nw2.
        wa_ind_rep-nw3     = nw3.
        wa_ind_rep-nw4     = nw4.
        wa_ind_rep-nw5     = nw5.
        wa_ind_rep-mxx     = mxx.
        wa_ind_rep-ntotal  = ntotal.
        IF wa_ind_rep-ntotal > 0.
          APPEND wa_ind_rep TO it_ind_rep.
        ENDIF.
      ENDLOOP.
    ENDFORM.
    *&      Form  date_2_week
    FORM date_2_week USING inp_date.
      CLEAR tmpweek.
      CALL FUNCTION 'DATE_GET_WEEK'
        EXPORTING
          date = inp_date
        IMPORTING
          week = tmpweek
        EXCEPTIONS
          date_invalid = 1
          others = 2.
    ENDFORM.
    *&      Form  get_date_in_currweek4
    FORM get_date_in_currweek4.
      PERFORM week_get_1st_day USING p_week.  "return to tmpdate
      date1_in_currweek4 = tmpdate.                "MON
      date2_in_currweek4 = date1_in_currweek4 + 1. "TUE
      date3_in_currweek4 = date2_in_currweek4 + 1. "WED
      date4_in_currweek4 = date3_in_currweek4 + 1. "THU
      date5_in_currweek4 = date4_in_currweek4 + 1. "FRI
      date6_in_currweek4 = date5_in_currweek4 + 1. "SAT
      date7_in_currweek4 = date6_in_currweek4 + 1. "SUN
      IF p_week4 NE 999999.
        PERFORM week_get_1st_day USING p_week4.  "return to tmpdate
        date1_in_currweek4_1 = tmpdate.                  "MON
        date2_in_currweek4_1 = date1_in_currweek4_1 + 1. "TUE
        date3_in_currweek4_1 = date2_in_currweek4_1 + 1. "WED
        date4_in_currweek4_1 = date3_in_currweek4_1 + 1. "THU
        date5_in_currweek4_1 = date4_in_currweek4_1 + 1. "FRI
        date6_in_currweek4_1 = date5_in_currweek4_1 + 1. "SAT
        date7_in_currweek4_1 = date6_in_currweek4_1 + 1. "SUN
      ENDIF.
    ENDFORM.
    *&      Form  get_date_in_week_in_nextmonth
    FORM get_date_in_week_in_nextmonth.
    *Date in week1 of next month
      PERFORM week_get_1st_day USING next_month_w1.  "return to tmpdate
      date1_in_nextmonth_week1 = tmpdate.                      "MON
      date2_in_nextmonth_week1 = date1_in_nextmonth_week1 + 1. "TUE
      date3_in_nextmonth_week1 = date2_in_nextmonth_week1 + 1. "WED
      date4_in_nextmonth_week1 = date3_in_nextmonth_week1 + 1. "THU
      date5_in_nextmonth_week1 = date4_in_nextmonth_week1 + 1. "FRI
      date6_in_nextmonth_week1 = date5_in_nextmonth_week1 + 1. "SAT
      date7_in_nextmonth_week1 = date6_in_nextmonth_week1 + 1. "SUN
    *Date in week2 of next month
      PERFORM week_get_1st_day USING next_month_w2.  "return to tmpdate
      date1_in_nextmonth_week2 = tmpdate.                      "MON
      date2_in_nextmonth_week2 = date1_in_nextmonth_week2 + 1. "TUE
      date3_in_nextmonth_week2 = date2_in_nextmonth_week2 + 1. "WED
      date4_in_nextmonth_week2 = date3_in_nextmonth_week2 + 1. "THU
      date5_in_nextmonth_week2 = date4_in_nextmonth_week2 + 1. "FRI
      date6_in_nextmonth_week2 = date5_in_nextmonth_week2 + 1. "SAT
      date7_in_nextmonth_week2 = date6_in_nextmonth_week2 + 1. "SUN
    *Date in week3 of next month
      PERFORM week_get_1st_day USING next_month_w3.  "return to tmpdate
      date1_in_nextmonth_week3 = tmpdate.                      "MON
      date2_in_nextmonth_week3 = date1_in_nextmonth_week3 + 1. "TUE
      date3_in_nextmonth_week3 = date2_in_nextmonth_week3 + 1. "WED
      date4_in_nextmonth_week3 = date3_in_nextmonth_week3 + 1. "THU
      date5_in_nextmonth_week3 = date4_in_nextmonth_week3 + 1. "FRI
      date6_in_nextmonth_week3 = date5_in_nextmonth_week3 + 1. "SAT
      date7_in_nextmonth_week3 = date6_in_nextmonth_week3 + 1. "SUN
    *Date in week4 of next month
      IF next_month_w4 NE 999999.
        PERFORM week_get_1st_day USING next_month_w4.  "return to tmpdate
        date1_in_nextmonth_week4 = tmpdate.                      "MON
        date2_in_nextmonth_week4 = date1_in_nextmonth_week4 + 1. "TUE
        date3_in_nextmonth_week4 = date2_in_nextmonth_week4 + 1. "WED
        date4_in_nextmonth_week4 = date3_in_nextmonth_week4 + 1. "THU
        date5_in_nextmonth_week4 = date4_in_nextmonth_week4 + 1. "FRI
        date6_in_nextmonth_week4 = date5_in_nextmonth_week4 + 1. "SAT
        date7_in_nextmonth_week4 = date6_in_nextmonth_week4 + 1. "SUN
      ENDIF.
    *Date in week5 of next month
      IF next_month_w5 NE 999999.
        PERFORM week_get_1st_day USING next_month_w5.  "return to tmpdate
        date1_in_nextmonth_week5 = tmpdate.                      "MON
        date2_in_nextmonth_week5 = date1_in_nextmonth_week5 + 1. "TUE
        date3_in_nextmonth_week5 = date2_in_nextmonth_week5 + 1. "WED
        date4_in_nextmonth_week5 = date3_in_nextmonth_week5 + 1. "THU
        date5_in_nextmonth_week5 = date4_in_nextmonth_week5 + 1. "FRI
        date6_in_nextmonth_week5 = date5_in_nextmonth_week5 + 1. "SAT
        date7_in_nextmonth_week5 = date6_in_nextmonth_week5 + 1. "SUN
      ENDIF.
    ENDFORM.
    *&      Form  get_week_next_month
    FORM get_week_next_month.
      DATA : date_by_week_of_parameter  LIKE  scal-date,
             date  LIKE  scal-date,
             week  LIKE  scal-week.
      PERFORM week_get_1st_day USING p_week. "return to tmpdate
      CALL FUNCTION 'LAST_DAY_OF_MONTHS'
        EXPORTING
          day_in             = tmpdate
        IMPORTING
          LAST_DAY_OF_MONTH  = next_month
        EXCEPTIONS
          DAY_IN_NO_DATE     = 1
          OTHERS             = 2.
      next_month = next_month + 1.  "YYYYMMDD 2006.xx.01
      PERFORM date_2_week USING next_month. "return to tmpweek
      week = tmpweek.
      PERFORM week_get_1st_day USING week. "return to tmpdate
      date = tmpdate.
      IF next_month NE date.
        PERFORM next_week USING week.
        next_month_w1 = tmp_next_week.
        week = tmp_next_week.
      ENDIF.
      next_month_w1 = week.          "**WEEK1**
      PERFORM next_week USING week.
      week = tmp_next_week.
      next_month_w2 = week.          "**WEEK2**
      PERFORM next_week USING week.
      week = tmp_next_week.
      next_month_w3 = week.          "**WEEK3**
      PERFORM next_week USING week.
      PERFORM week_get_1st_day USING tmp_next_week. "return to tmpdate
      IF tmpdate4(2) EQ next_month4(2).
        week = tmp_next_week.
        next_month_w4 = week.        "**WEEK4**
        PERFORM next_week USING week.
        PERFORM week_get_1st_day USING tmp_next_week. "return to tmpdate
        IF tmpdate4(2) EQ next_month4(2).
          week = tmp_next_week.
          next_month_w5 = week.      "**WEEK5**
        ELSE.
          next_month_w5 = 999999.
        ENDIF.
      ELSE.
        next_month_w4 = 999999.
        next_month_w5 = 999999.
      ENDIF.
    ENDFORM.
    *&      Form  get_week_next_next_month
    FORM get_week_next_next_month.
      DATA : date  LIKE  scal-date,
             week  LIKE  scal-week.
      CALL FUNCTION 'LAST_DAY_OF_MONTHS'
        EXPORTING
          day_in             = next_month
        IMPORTING
          LAST_DAY_OF_MONTH  = next_next_month
        EXCEPTIONS
          DAY_IN_NO_DATE     = 1
          OTHERS             = 2.
      next_next_month = next_next_month + 1.  "YYYYMMDD 2006.xx.01
      PERFORM date_2_week USING next_next_month. "return to tmpweek
      week = tmpweek.
      PERFORM week_get_1st_day USING week. "return to tmpdate
      date = tmpdate.
      IF next_next_month NE date.
        PERFORM next_week USING week. "Return to tmp_next_week
        week = tmp_next_week.
      ENDIF.
      next_next_month_w1 = week.          "**next_next_month WEEK1**
      PERFORM next_week USING week.
      week = tmp_next_week.
      next_next_month_w2 = week.          "**next_next_month WEEK2**
      PERFORM next_week USING week.
      week = tmp_next_week.
      next_next_month_w3 = week.          "**next_next_month WEEK3**
      PERFORM next_week USING week.
      PERFORM week_get_1st_day USING tmp_next_week. "return to tmpdate
      IF tmpdate4(2) EQ next_next_month4(2).
        week = tmp_next_week.
        next_next_month_w4 = week.             "**next_next_month WEEK4**
        PERFORM next_week USING week.
        PERFORM week_get_1st_day USING tmp_next_week. "return to tmpdate
        IF tmpdate4(2) EQ next_next_month4(2).
          week = tmp_next_week.
          next_next_month_w5 = week.           "**next_next_month WEEK5**
        ELSE.
          next_next_month_w5 = 999999.
        ENDIF.
      ELSE.
        next_next_month_w4 = 999999.
        next_next_month_w5 = 999999.
      ENDIF.
    ENDFORM.
    *&      Form  GET_SALES_HISTORY
    FORM get_sales_history.
      DATA : m_3  LIKE  s003-aemenge VALUE 0,
             m_2  LIKE  s003-aemenge VALUE 0,
             m_1  LIKE  s003-aemenge VALUE 0,
             m_0  LIKE  s003-aemenge VALUE 0.
      SELECT s003spbup s003vkorg s003~matnr
             s003aemenge s003ummenge
             s003ssour s003vrsio s003spmon s003sptag
             s003spwoc s003vtweg s003spart s003bzirk s003~kunnr
      INTO TABLE it_tmp_sales_hist
      FROM   s003
      WHERE  ( s003~spbup = prev_month0 OR
               s003~spbup = prev_month1 OR
               s003~spbup = prev_month2 OR
               s003~spbup = prev_month3
             ) AND
             s003~vkorg = p_werks AND
             s003~matnr IN s_matnr.
      LOOP AT it_tmp_sales_hist.
        CLEAR wa_sales_hist.
        wa_sales_hist-spbup   = it_tmp_sales_hist-spbup.
        wa_sales_hist-vkorg   = it_tmp_sales_hist-vkorg.
        wa_sales_hist-matnr   = it_tmp_sales_hist-matnr.
        wa_sales_hist-aemenge = it_tmp_sales_hist-aemenge.
        wa_sales_hist-ummenge = it_tmp_sales_hist-ummenge.
        COLLECT wa_sales_hist INTO it_sales_hist.
      ENDLOOP.
      LOOP AT it_all_material.
        CLEAR : m_3, m_2, m_1, m_0, wa_sales_report.
        LOOP AT it_sales_hist WHERE matnr = it_all_material-matnr.
          IF it_sales_hist-spbup = prev_month3.
            m_3 = it_sales_hist-ummenge.
          ELSEIF it_sales_hist-spbup = prev_month2.
            m_2 = it_sales_hist-ummenge.
          ELSEIF it_sales_hist-spbup = prev_month1.
            m_1 = it_sales_hist-ummenge.
          ELSEIF it_sales_hist-spbup = prev_month0.
            m_0 = it_sales_hist-ummenge.
          ENDIF.
        ENDLOOP.
        wa_sales_report-matnr = it_all_material-matnr.
        wa_sales_report-m_3   = m_3.
        wa_sales_report-m_2   = m_2.
        wa_sales_report-m_1   = m_1.
        wa_sales_report-m_0   = m_0.
        wa_sales_report-avg_sale = ( m_3 + m_2 + m_1 ) / 3.
        IF ( ( m_0 > 0 ) OR ( m_1 > 0 ) OR ( m_2 > 0 ) OR ( m_3 > 0 ) ).
          APPEND wa_sales_report TO it_sales_report.
        ENDIF.
      ENDLOOP.
    ENDFORM.
    *&      Form  PROCESS_GET_MONTH_FOR_SALES
    FORM process_get_month_for_sales.
      "Current Month
      PERFORM week_get_1st_day USING p_week.    "return to tmpdate
      prev_month0 = tmpdate+0(6).
      "Month -1
      PERFORM get_prev_month USING tmpdate.     "return to prev_month
      prev_month1 = prev_month+0(6).
      "Month -2
      PERFORM get_prev_month USING prev_month.  "return to prev_month
      prev_month2 = prev_month+0(6).
      "Month -3
      PERFORM get_prev_month USING prev_month.  "return to prev_month
      prev_month3 = prev_month+0(6).
    ENDFORM.
    *&      Form  GET_PREV_MONTH
    FORM get_prev_month USING inp_date LIKE sy-datum.
    inp_date+6(2) = '01'.
    CALL FUNCTION 'MONTH_PLUS_DETERMINE'
      EXPORTING
        months        =  -1
        olddate       =  inp_date
      IMPORTING
        newdate       =  prev_month.
    ENDFORM.
    *&      Form GET_LAST_DAY_OF_MONTH
    FORM get_last_day_of_month USING inp_date LIKE sy-datum.
    DATA : last_day_of_month LIKE scal-date.
    CALL FUNCTION 'RP_LAST_DAY_OF_MONTHS'
      EXPORTING
        day_in                 =  inp_date
    IMPORTING
       LAST_DAY_OF_MONTH       =  tmpdate
    EXCEPTIONS
       DAY_IN_NO_DATE          = 1
       OTHERS                  = 2.
    ENDFORM.
    *&      Form  WEEK_GET_FIRST_DAY
    FORM week_get_1st_day USING inp_week LIKE scal-week.
      CALL FUNCTION 'WEEK_GET_FIRST_DAY'
        EXPORTING
          week = inp_week
        IMPORTING
          date = tmpdate
        EXCEPTIONS
          week_invalid  = 1
          others        = 2.
    ENDFORM.
    *&      Form  NEXT_WEEK
    FORM next_week USING inp_week LIKE scal-week.
      CALL FUNCTION 'NEXT_WEEK'
        EXPORTING
          current_week       =  inp_week
        IMPORTING
          NEXT_WEEK          =  tmp_next_week.
    ENDFORM.
    *&      Form  GET_BACK_ORDER
    FORM get_back_order.
      DATA : back              TYPE P VALUE 0 DECIMALS 3,
             subtract          TYPE P VALUE 0 DECIMALS 3,
             do_qty    

    Hi ,
    Replace your  select statements as below in
    subroutines get_back_order and get_pending_order.
    Let me know your status of program from your rewards.
    Regards,
    Sankar
    FORM get_back_order.
    ranges : r_posnr for vbrp-posnr.
    r_posnr-low =  '000000'.
    r_posnr-high = '999999'.
    r_posnr-sign = 'I'.
    r_posnr-option = 'BT'.
    append r_posnr.
    SELECT vbapvbeln vbapposnr vbap~matnr
    vbapkwmeng vbapkbmeng vbap~klmeng
    INTO TABLE t_vbap FROM vbap
    WHERE
    ( vbeln LIKE '21%' OR " Sales Order
    vbeln LIKE '25%' OR " Exchange
    vbeln LIKE '26%' ) and
    posnr in r_posnr  and
    matnr IN s_matnr AND
    werks = p_werks 
    FORM get_pending_order.
    SELECT jestobjnr afpomatnr afpopsmng afpowemng
    INTO TABLE it_pending_order
    FROM aufk
    INNER JOIN afko
    ON aufkaufnr = afkoaufnr
    INNER JOIN afpo
    ON afkoaufnr = afpoaufnr
    INNER JOIN jest
    ON aufkobjnr = jestobjnr
    FOR ALL ENTRIES IN it_all_material
    WHERE
    jest~stat = 'I0002' AND "Status REL
    jest~inact <> 'X' AND
    afpo~matnr EQ it_all_material-matnr AND
    aufk~werks = p_werks.

  • How to purge Sales Data in Oracle Demantra

    Hi Demantra experts,
    I have one doubt in demantra:
    Suppose the user has loaded the historical data say Sales History data in SALES_DATA table.
    And after running the Analaytical Engine , forecast has been generated as well.
    Later he found that it was a wrong data and now it should be removed.
    If the user wants to remoe these records from SALES_DATA table .
    What is the process of purging the records?
    Thanks,
    Neeraj.

    Thanks a lot for your help.
    I checked the metalink note. It deals with removing the data from temporary tables and not the base tables.
    The Temprary tables acts like interface tables. We need to populate the records in the respective temp table and run the .bat file
    However the record stays in the temp table after the .bat file has loaded the data in base tables.
    The suggested metalink note provides script to cleanup the temp tables of demantra.
    My requirement is to remove the records from base tables.
    Thanks,
    Neeraj.

Maybe you are looking for

  • Oracle RAC Interconnect, PowerVM VLANs, and the Limit of 20

    Hello, Our company has a requirement to build a multitude of Oracle RAC clusters on AIX using Power VM on 770s and 795 hardware. We presently have 802.1q trunking configured on our Virtual I/O Servers, and have currently consumed 12 of 20 allowed VLA

  • Cannot access deployed JDeveloper App in Weblogic Server

    I have built and successfully deployed an Oracle JDeveloper 11.1.2.2.0 web application using ADF security to a clustered (two servers) Weblogic 10.3.5.0 server. The login page comes up when I type in the URL but upon submitting the login page I get t

  • Flash CS6 Corrupts Files Since I Installed CC

    Hi there everyone, I'm having a problem I hope we can get to the bottom of as I am an independent professional working with Flash to make advertisements. My timelines are always very tight but something new has been happening and it's happened with A

  • Rename & deletion of planning book & Data view

    Hi Experts, Is it possible to rename & deletion of planning book & Data view, if yes what is the procedure. Also suggest if hiding of same is possible

  • Smb: how do you log access & disconnect users?

    I've always relied on AFP for file sharing, but since it seems like that's kind of on the way out and SMB is the new way to do things, I've been trying that out instead. A few questions though... Where are the access logs? I'm looking for the equival