Help needed in the Merge Statement

Hi All,
I am using MERGE statement in my program. I want to maintain the log for the duplicate reords mean maintain the log for those reocrds which are updated in the merge statement.
Can any one help me in this that how can i maintain the log?
Thanks for your help in advance.
kind Regards,

http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:35615502072484

Similar Messages

  • Managing the first application of the MERGE statement in an ETL logic - SQL Server 2012

    Hi,
    in order to feed a fact table of a dwh from a staging table I'm using the MERGE statement in order to control insert and update operations. It is possible that the staging table has duplicate rows respect to the fields controlled in the merge condition:
    when I run the first time the MERGE statement unwanted rows could be inserted in the fact table.
    Does the MERGE statement allow to manage this case or do I need to filter data from the staging table before to write them into the fact table?
    Many thanks

    Hi Anuj,
    thank for your reply. Unfortunately the DISTINCT in the using clause isn't enough for my case: I need to read a subset of fields of a staging table and for this subset I could have duplicate rows, but also I need to the change date of the rows inserted in
    the staging table and I cannot include this date in the distincted columns.
    However the answer is that I need to handle the staging data before to write them into the fact table.
    Thanks
    Yes
    One more thing to note is when running MERGE statement subsequently in case there are multiple records which matches the update criteria then default behavior of MERGE is to throw an error indicating that it tried to update same record twice.
    So in any case you need to make sure you eliminate duplicates before applying MERGE over it at first.
    Please Mark This As Answer if it solved your issue
    Please Vote This As Helpful if it helps to solve your issue
    Visakh
    My Wiki User Page
    My MSDN Page
    My Personal Blog
    My Facebook Page

  • Issue while using SUBPARTITION clause in the MERGE statement in PLSQL Code

    Hello All,
    I am using the below code to update specific sub-partition data using oracle merge statements.
    I am getting the sub-partition name and passing this as a string to the sub-partition clause.
    The Merge statement is failing stating that the specified sub-partition does not exist. But the sub-partition do exists for the table.
    We are using Oracle 11gr2 database.
    Below is the code which I am using to populate the data.
    declare
    ln_min_batchkey PLS_INTEGER;
    ln_max_batchkey PLS_INTEGER;
    lv_partition_name VARCHAR2 (32767);
    lv_subpartition_name VARCHAR2 (32767);
    begin
    FOR m1 IN ( SELECT (year_val + 1) AS year_val, year_val AS orig_year_val
    FROM ( SELECT DISTINCT
    TO_CHAR (batch_create_dt, 'YYYY') year_val
    FROM stores_comm_mob_sub_temp
    ORDER BY 1)
    ORDER BY year_val)
    LOOP
    lv_partition_name :=
    scmsa_handset_mobility_data_build.fn_get_partition_name (
    p_table_name => 'STORES_COMM_MOB_SUB_INFO',
    p_search_string => m1.year_val);
    FOR m2
    IN (SELECT DISTINCT
    'M' || TO_CHAR (batch_create_dt, 'MM') AS month_val
    FROM stores_comm_mob_sub_temp
    WHERE TO_CHAR (batch_create_dt, 'YYYY') = m1.orig_year_val)
    LOOP
    lv_subpartition_name :=
    scmsa_handset_mobility_data_build.fn_get_subpartition_name (
    p_table_name => 'STORES_COMM_MOB_SUB_INFO',
    p_partition_name => lv_partition_name,
    p_search_string => m2.month_val);
                        DBMS_OUTPUT.PUT_LINE('The lv_subpartition_name => '||lv_subpartition_name||' and lv_partition_name=> '||lv_partition_name);
    IF lv_subpartition_name IS NULL
    THEN
                             DBMS_OUTPUT.PUT_LINE('INSIDE IF => '||m2.month_val);
    INSERT INTO STORES_COMM_MOB_SUB_INFO T1 (
    t1.ntlogin,
    t1.first_name,
    t1.last_name,
    t1.job_title,
    t1.store_id,
    t1.batch_create_dt)
    SELECT t2.ntlogin,
    t2.first_name,
    t2.last_name,
    t2.job_title,
    t2.store_id,
    t2.batch_create_dt
    FROM stores_comm_mob_sub_temp t2
    WHERE TO_CHAR (batch_create_dt, 'YYYY') = m1.orig_year_val
    AND 'M' || TO_CHAR (batch_create_dt, 'MM') =
    m2.month_val;
    ELSIF lv_subpartition_name IS NOT NULL
    THEN
                        DBMS_OUTPUT.PUT_LINE('INSIDE ELSIF => '||m2.month_val);
    MERGE INTO (SELECT *
    FROM stores_comm_mob_sub_info
    SUBPARTITION (lv_subpartition_name)) T1 --> Issue Here
    USING (SELECT *
    FROM stores_comm_mob_sub_temp
    WHERE TO_CHAR (batch_create_dt, 'YYYY') =
    m1.orig_year_val
    AND 'M' || TO_CHAR (batch_create_dt, 'MM') =
    m2.month_val) T2
    ON (T1.store_id = T2.store_id
    AND T1.ntlogin = T2.ntlogin)
    WHEN MATCHED
    THEN
    UPDATE SET
    t1.postpaid_totalqty =
    (NVL (t1.postpaid_totalqty, 0)
    + NVL (t2.postpaid_totalqty, 0)),
    t1.sales_transaction_dt =
    GREATEST (
    NVL (t1.sales_transaction_dt,
    t2.sales_transaction_dt),
    NVL (t2.sales_transaction_dt,
    t1.sales_transaction_dt)),
    t1.batch_create_dt =
    GREATEST (
    NVL (t1.batch_create_dt, t2.batch_create_dt),
    NVL (t2.batch_create_dt, t1.batch_create_dt))
    WHEN NOT MATCHED
    THEN
    INSERT (t1.ntlogin,
    t1.first_name,
    t1.last_name,
    t1.job_title,
    t1.store_id,
    t1.batch_create_dt)
    VALUES (t2.ntlogin,
    t2.first_name,
    t2.last_name,
    t2.job_title,
    t2.store_id,
    t2.batch_create_dt);
    END IF;
    END LOOP;
    END LOOP;
    COMMIT;
    end;
    Much appreciate your inputs here.
    Thanks,
    MK.
    (SORRY TO POST THE SAME QUESTION TWICE).
    Edited by: Maddy on May 23, 2013 10:20 PM

    Duplicate question

  • Error executing a stored procedure from SSIS using the MERGE statement between databases

    Good morning,
    I'm trying to execute from SSIS a stored procedure that compares the content of two tables on different databases in the same server and updates one of them. To perform this action, I've created a stored procedure in the destination database and I'm
    comparing the data between tables with the MERGE statement. When I execute the procedure on the destination database the error that I obtain is:
    "Msg 916, Level 14, State 1, Procedure RefreshDestinationTable, Line 13
    The server principal "XXXX" is not able to access the database "XXXX" under the current security context."
    Some things to take in account:
    1. I've created a temporary table on the same destination database to check if the problem was on the MERGE statement and it works fine.
    2. I've created the procedure with the option "WITH EXECUTE AS DBO".
    I've read that it can be a problem of permissions but I don't know if I'm executing the procedure from SSIS to which user/login I should give permissions and which.
    Could you give me some tip to continue investigating how to solve the problem?
    Thank you,
    Virgilio

    Read Erland's article http://www.sommarskog.se/grantperm.html
    Best Regards,Uri Dimant SQL Server MVP,
    http://sqlblog.com/blogs/uri_dimant/
    MS SQL optimization: MS SQL Development and Optimization
    MS SQL Consulting:
    Large scale of database and data cleansing
    Remote DBA Services:
    Improves MS SQL Database Performance
    SQL Server Integration Services:
    Business Intelligence

  • For the merge statement

    Hi,
    Is it possible to insert and update at the same time in the when not matched part of the MERGE statement.
    Pl provide me the information how to do it in MERGE statment.
    thanks in advance.

    Hi,
    Post an example of what you want to do.
    Include:
    (1) the version of Oracle you are using
    (2) the contents of the tables (both the destination table you are modifying and the soure table or tables) before the MERGE
    (3) the required contents of the destination table after the MERGE
    Executable SQL statements (like "CREATE TABLE AS ..." or "INSERT ..." statements) are best for (2).
    Formatted tabular output is okay for (3). Type {code} before and after the tabular text, to preserve spacing.

  • Need suggestion in MERGE Statement

    Hi,
    I have a scenario like, I have one table T1 with 500,000 to 700,000 records and now I want to check the other table T2 if record exists or not. If record exists with opposite amount ( - or + ) as compare with first table T1 then I need to insert this record from second table T2 to first table T1 and if record is not exists then need to update the flag with 'N' in first table T1. Can MERGE statement will be better solution in this scenario?
    Thanks,

    Here's something generic:
    insert into T1 (columns...)
    select (columns...)
    from   T1
    where  exists (select 1
                   from   T2
                   where  T2.some_key = T1.some_key
                   and    T2.some_value + T1.some_value = 0);
    update T1
    set    some_flag = 'N'
    where  not exists (select 1
                       from   T2
                       where  T2.some_key = T1.some_key);Sure seems odd though. Are you sure you wrote your original question correctly?

  • Help needed regarding the updation of "Relationships" in BP

    Hello Guys,
    This is to request you to kindly help me regarding the following.
    We have a scenario where all the employees assigned to an Organizational unit (in PPOMA_CRM) are not showing in the "Relationships" ("Has Employee")in the BP transaction of that Organizational Unit.
    Could anyone let me know whether there is any update program that updates the "Relationships" from the Organizational asssignment. Or we need to enter the employees manually in BP "Relationships". Please help. Thanks in anticipation.
    Regards,
    Kishore.

    Hi Amit,
    Thanks alot for your reply. Its really helpful for me.
    So,we usually enter these relationships manually only, right? Before going ahead with the custom program, could you please let me know whether there is any SAP note related to this.Once again thanks alot for you help.
    Regards,
    Kishore.

  • Flex 3 :Help needed in implementing View States

    Hi 
    I am new to Flex , i am trying to understand View States , tried for one hour but got confused .
    (Basically by seeing the examples i understood the concept , but failed to implement ) 
    Please help .
    Assume my requirement is at the load of the page , i want to show an Login Button and a Chnage State Button (common button) only .and when the Change State button is clicked on ,i want to show the Register Button .
    So for this i made two Forms , and a common button .
           <mx:Form id="RegForm">
                <mx:Button label="RegFormButton" id="RegFormButton"/>
            </mx:Form>
            <mx:Form id="loginForm">
                        <mx:Button label="LoginButton" id="loginButton"/>
            </mx:Form>
    <!-- A common button for both the States-->
      <mx:Button label="Change State"
                  click=""/>
    <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" currentState="Register">
    <mx:states>
    <mx:State name="Register">         
    <mx:SetProperty   target="RegForm"   value="Register"/>
    </mx:State>
    <mx:State name="loginForm">
    <mx:SetProperty   target="loginForm"   value="Login"/>
    </mx:State>
    </mx:states>
    ( I think some how i can write the Logic to chnage to the current state to loginForm when user clicks with some inline code , but please tell me At the start of the page please tell me why I am not able to show the Register.

    sorry for posting a dumb question .
    I realized my mistake .

  • Help needed with the nokia 7373

    hi, can anyone help me with changing the colour of the font when the phone is in the idle state and what does it change exactly on the front of the screen ? manythanks.

    Menu/Settings/Display/Standby mode font colour

  • Help needed for THE decision

    Hi everyone ☺
    I’m finally planning to start recording what I play, and after some hours of wandering on the web I found some interesting possibilities. Now what I need is to decide which one is more suitable for my needs, and here comes the moment for apple discussions
    Basically, I will record my own music one track/instrument at a time (I’m still not able to play more than one…and I dont’ want to spend 2.000$ to buy a 24-ins device just to record drum tracks), I’d like to have a software with built-in effects for guitar/bass/voice, integrated soundtrack possibilities (to play with video recordings), mixing options for both stereo and surround mixing, and I don’t want any card to be placed into my mac. Well, and obviously the sound quality must be pro-like…as anyone probably wants.
    So, here’s what I came up with:
    a) getting logic pro studio 8 and apogee duet
    b) getting pro tools m-powered and mbox 2
    c) getting one of the two softwares and a Monster iStudioLink Instrument cable and plug instruments directly into the mac
    Now, the questions are:
    if I can plug an instrument directly into my mac and control all parameters via one of the two softwares, what do tools like duet and mbox2 serve for?
    In the case this tools are useful [ ☺ ], why ☺ … and which is the couple software/hardware that can best suit my needs?
    I assume that every software has a proprietary file extension in which audio tracks are saved, so that it should be impossible to record an audio track with one software and edit it with another that has different functions/plugins (ex. from logic to pro tools, from pro tools to cakewalk sonar which I have on a pc etc.). Am I right, or is there any “standard”, non compressed high quality file type in which track can be saved and exported to be edited with different softwares?
    I know that from this post it may easily seem that I’m a hopeless digital idiot, but I swear the situation is not really that bad so no need for the kind of explanations with drawings like the ones you find in the “for dummies” guides lol so every experts’ advice will be greatly appreciated
    Neptune

    Thank you Bee Jay and Pancenter for the lighting-fast and useful answers
    now I am aware that an interface IS NEEDED lol (that means they are not produced without a reasons, are they?). I know Pro Tools is the industry standard but I don't like anyone/anything to tie me to their choices/interests (so that's why I was asking about Pro Tools, knowing that there's some sort of "hardware threat"). What I look for is just quality and if I understood what you both mean, as far as this aspect is concerned, Logic and Pro Tools are substantially comparable...isn't it? On the interfaces side, I already checked the Saffire ones (they seem quite good, and cross-platform use is definitely a plus), I will check the others mentioned and will let you know In fact, I didn't consider the "platform problem" but, as I wrote, I also own a PC with an Audigy 2 soundcard (midi/analog/optical/digital inputs/outputs and firewire port...not Madonna's private studio, but not as sad as Mac's little hole) and Sonar 6 Producer Edition, so that has been a really good point to ponder. And now, in the middle of this software/hardware battle...any personal suggestions based on tests/personal experience?

  • Help needed in the query.

    I have a table say T1 with a column of unique sequential numbers that begin at 1. When one inserts a new row, one muse use a sequence number that is not currently in the column. that is Fill the gaps. If there are no gaps, then and only then one can use the next highest integer in the sequence.
    create table T1
    ( seq_nbr INTEGER NOT NULL PRIMARY KEY
    CHECK (seq > 0);
    junk CHAR(5) NOT NULL);
    INSERT INTO T1
    VALUES (1,'Tom'), (2,'Dick'), (4,'Harry'), (5,'Moe');
    Here is the INSERT statement,i came across, where i am not able to understand how logic is working?
    INSERT INTO T1 (seq_nbr,junk)
    VALUES (CASE WHEN EXISTS -- no gaps
    ( SELECT 'no gaps'
    FROM T1
    HAVING COUNT(*) = MAX(seq_nbr))
    THEN ( SELECT MAX(seq_nbr) FROM T1 ) + 1
    ELSE ( SELECT MIN(seq_nbr) -- gaps
    FROM T1
    WHERE (seq_nbr -1)
    NOT IN (SELECT seq_nbr FROM T1)
    AND seq_nbr > 0) - 1, 'Jen');
    the thing is i am not able to understand how this query is executing and the logic.. Can someone please explain this to me?

    Hi,
    this works because the first part of the CASE statement assumes there are no gaps if the number of records in the table = the max(seq_nbr) and inserts the next one up. If there are gaps then it looks for the lowest missing seq_nbr. (without testing this code I wouldn't assume it works)
    Overall though this is not good practice because with high volume systems it will most likely lead to all sorts of concurrency problems. Instead you should just use a straight oracle sequence. Every time I've seen someone try to specify the requirement that a PK must be contiguous set of numbers with no gaps I've found it to be based on an individuals perverse sense of completeness or a left over from an old manual system. Usually the sequence numbers where generated from a ledger and the only way they could easily count throughput was by subtracting yesterdays closing sequence from todays. Once you point out that the database can count these things in fractions of seconds, the requirement disappears.
    Andre

  • HELP NEEDED WITH THE ERRORS

    Hi all
    we are a MDMP code page system and we upgraded to ECC 6.0.
    We fixed all our unicode errors by checking the unicode flag in the attributes  we activated the program without any syntax errors or warnings.
    Now when we go back to UCCHECK, it still shows erros especially for bdc programs
    My question why would it show as an errors in UCCHECK when the program gets activated without any warnings or errors.
    This is the error iam getting
    The system could not perform a static convertibility check on the current
    statement, because of untyped or generic operands. It can only carry out this
    . runtime.
    Whta exactly static convertibility check.
    Can anyone suggest what i have to do regarding this
    The error is pointing this piece of code
          FORM bdc_dynpro                                               *
    -->  PROGRAM                                                       *
    -->  DYNPRO                                                        *
    form bdc_dynpro using program dynpro.
      clear i_bdcdata.
      i_bdcdata-program  = program.
      i_bdcdata-dynpro   = dynpro.
      i_bdcdata-dynbegin = 'X'.
      append i_bdcdata.
    endform.
          FORM bdc_field                                                *
    -->  FNAM                                                          *
    -->  FVAL                                                          *
    form bdc_field using fnam fval.
      clear i_bdcdata.
      i_bdcdata-fnam = fnam.
      i_bdcdata-fval = fval.
      append i_bdcdata.
    endform.
    Thanks
    Suchitra

    Hi,,
    This is from the standard include bdcrecx1
           Start new screen                                              *
    FORM BDC_DYNPRO USING PROGRAM DYNPRO.
      CLEAR BDCDATA.
      BDCDATA-PROGRAM  = PROGRAM.
      BDCDATA-DYNPRO   = DYNPRO.
      BDCDATA-DYNBEGIN = 'X'.
      APPEND BDCDATA.
    ENDFORM.
           Insert field                                                  *
    FORM BDC_FIELD USING FNAM FVAL.
      IF FVAL <> NODATA.
        CLEAR BDCDATA.
        BDCDATA-FNAM = FNAM.
        BDCDATA-FVAL = FVAL.
        APPEND BDCDATA.
      ENDIF.
    ENDFORM.
    It looks the same way i wrote the code right.
    But again when i do syntax check it won't show up. It shows only in UCCHECK
    Thanks

  • Need Help in correcting the sql statement

    H Experts,
    I am not if I can post this query in this section, but as I am executing this statement on repository DB , I assumed to post here.
    I have a requirement to calculate the database sizes from the tables in repository.
    table 1 : MGMT$DB_TABLESPACES_ALL : has the information on all the tablespace information from each database. and it has information of all the databases.
    table 2: MGMT$DB_REDOLOGS_ALL : has the information on all the redolog files information from each database. and it has information of all the databases.
    Now to calculate the size of each database , we need to collect the sizes from both tables and then need to add.
    below is the sql i prepared and sql didn't return and systax error , but the final output is completely wrong. Seems like its multiplying the data somewhere and getting the wrong information.
    please help me in doing the required modifications.
    =================================================================================================
    select a.TARGET_NAME "DATABASE_NAME" ,sum(a.TABLESPACE_SIZE/1024/1024/1024)+sum(b.LOGSIZE/1024/1024/1024/1024) "DATABASE ALLOCATED SPACE(GB)",
    sum(a.TABLESPACE_USED_SIZE/1024/1024/1024)+sum(b.LOGSIZE/1024/1024/1024/1024) "DATABASE USED SPACE(GB)",
    sum(a.TABLESPACE_SIZE/1024/1024/1024)-sum(a.TABLESPACE_USED_SIZE/1024/1024/1024) "DATABASE FREE SPACE(GB)"
    from MGMT$DB_TABLESPACES_ALL a ,MGMT$DB_REDOLOGS_ALL b
    where a.TARGET_NAME=b.TARGET_NAME and a.TARGET_Name like '%d2oem%'
    group by a.target_name;
    ====================================================================================================
    Note: There are multiple records having the same TARGET_NAME value in both the tables.
    please Help me in correcting the sql statement

    H Experts,
    I am not if I can post this query in this section, but as I am executing this statement on repository DB , I assumed to post here.
    I have a requirement to calculate the database sizes from the tables in repository.
    table 1 : MGMT$DB_TABLESPACES_ALL : has the information on all the tablespace information from each database. and it has information of all the databases.
    table 2: MGMT$DB_REDOLOGS_ALL : has the information on all the redolog files information from each database. and it has information of all the databases.
    Now to calculate the size of each database , we need to collect the sizes from both tables and then need to add.
    below is the sql i prepared and sql didn't return and systax error , but the final output is completely wrong. Seems like its multiplying the data somewhere and getting the wrong information.
    please help me in doing the required modifications.
    =================================================================================================
    select a.TARGET_NAME "DATABASE_NAME" ,sum(a.TABLESPACE_SIZE/1024/1024/1024)+sum(b.LOGSIZE/1024/1024/1024/1024) "DATABASE ALLOCATED SPACE(GB)",
    sum(a.TABLESPACE_USED_SIZE/1024/1024/1024)+sum(b.LOGSIZE/1024/1024/1024/1024) "DATABASE USED SPACE(GB)",
    sum(a.TABLESPACE_SIZE/1024/1024/1024)-sum(a.TABLESPACE_USED_SIZE/1024/1024/1024) "DATABASE FREE SPACE(GB)"
    from MGMT$DB_TABLESPACES_ALL a ,MGMT$DB_REDOLOGS_ALL b
    where a.TARGET_NAME=b.TARGET_NAME and a.TARGET_Name like '%d2oem%'
    group by a.target_name;
    ====================================================================================================
    Note: There are multiple records having the same TARGET_NAME value in both the tables.
    please Help me in correcting the sql statement

  • Need help with correcting the select statement

    I have two tables mkt & error.
    The fields of mkt are
    app_id (xxx)
    c_mkt_id
    app_mkt_id
    The fields of error table are
    mkt_id
    intr_id (its in format xxx.yyy or xxx)
    xyz
    abc
    pqr
    I have to select * fields from error table such that
    ->mkt.app_id = error.intr_id (here i am using combination of sbstr & instr to get the part before "." if present)
    ->mkt.c_mkt_id=error.mkt_id
    Where ever the above two conditions match i have to replace the mkt_id field in my select * from error table query with the
    app_mkt_id field from mkt table. If the above two condtions dont match my select * from error table should return the original mkt_id present in the error table.
    I have presently developed a query(*) which selects the app_mkt_id from mkt table where ever the two conditions match.
    How should i go about using this to get my actual requirement.
    (*)=select app_mkt_id from mkt where app_id in (select case when case_when=1 then substr(intr_id, 1, instr(intr_id,'.')-1) else substr(intr_id, 1) end from (select intr_id, case when instr(intr_id,'.',1)=0 then 0 else 1 end case_when from error)) and
    c_mkt_id in (select mkt_id from error)

    you wrote:
    (*)=select app_mkt_id from mkt where ....What is this?
    If you are writing PL/SQL the syntax is:
    SELECT ....
    INTO ....
    FROM ....
    WHERE ....This seems to be school work and thus you really need to puzzle this out for yourself.

  • SAP PS Module Report, Help needed for the Right Logic.

    Hi,
             I have to develop a  PS module Report . This spec of this  report is when you enter , project # , month , date , proj type it should  display all the projects  and only the billing levels  with  different  fiels  like ITD cost, ITD sales, ytd cost,  sales,  awards  etc etc.
    Right now  Iam getting the O/P : in the  following manner, There are many fields  I am just showing the desired ones which have to be changed.
    Proj,           Title,         award,    ITDsales,         ITD cost ,    ytd sales,   ytd costs,
    14148,       New prj       123        --                   ---                    -
    14148-B01,  bill1          -
                234           -
                       456                -
    14148-B02,  bill2          -
                789          -
                       123                -
    14148.001    wbs1        -
             123                     -
                     456
    14148.001    wbs2        -
              567                    -
                     890
    But   for me  the desired output must be only for  project  and the billing levels. It shouldn’t be for WBS elements  xxxx.001  and xxxx.002.
    Desired  output:
    Proj,           Title,         award,    ITDsales,   ITD cost ,       ytd sales,      ytd costs,
    14148,       New prj       123        --               690                 -
                   1346
    14148-B01,  bill1          -
             234                -
                       456             -
    14148-B02,  bill2          -
             789                -
                      123              -
    The ITD costs  and YTD costs must be added   123 + 567 = 690 and
                                                                                 456+890 = 1346.
    And these values must come   on the project level.
    P.S:  I can restrict the values  for wbs elements  , means I can filter them at PRPS table  by giving prps-stufe LE ‘2’.  Then I wont get the wbs level, But I want the values of these to be added up and then show it on the project level.
    Please  go through  this code and let me  know where exactly I need to put the right logic  to work in the desired manner.
    Thanks   in advance
    Dan
    Code Below************************
    [code]TABLES: PROJ,                "Project Definition
            PRPS,                "WBS Elements
            prhi,
            CEPC,                " Profit Center w/ Group Head info
            BPGE,                "Plans (12, 13, etc.)
            COSP,                "Primary   Cost Element (Bill Sales, DPC)
            COSS,                "Secondary Cost Element (Shrd Sls,Sal,etc)
            COSB,                "Results Analysis Cost Elements (Unbil Sls)
            COOI,                "Commitments management: Line items
            JEST,                "Project Status
            TCJ04,               "Person Responsible for Project
            zpclasses,           "Project classes.
    New Added
            CRCO,            " Assignment of Work Center to Cost Center
            CRHD.            " Work Center Header
    Record Layout of extracted data
    TYPES: BEGIN OF EXDEF,       "Data definition of extract data
           X_BU(2)     TYPE C,   "Business Unit
           X_CNTR(10)  TYPE C,   " Profit Center
           X_PROJ(24)  TYPE C,   "Project def (Prj)
           X_CREP(30)  TYPE C,   "Contract Rep.
           X_BDREP(25) TYPE C,   "BD Rep. name
           X_GRPH(15)  TYPE C,   "Tech Rep employee name
           X_ACTREP(15)  TYPE C,  "Acct Rep employee name
           X_PMGR(15)  TYPE C,   "PM employee name
           X_TTLE(35)  TYPE C,   "Title
           X_CLNT(20)  TYPE C,   "Client
           X_POCN(20)  TYPE C,   "Prime Contract Number
           X_TYPE(13)  TYPE C,   "Order Type Sarnoff
           X_OPEN(10)  TYPE C,   "Open Date
           X_CLOSE(10) TYPE C,   "Close Date
           X_CGT(4)    TYPE C,   "CO, GV, TC
           X_DISTR(2)  TYPE C,   "Distribution Channel
           X_CONTR(6)  TYPE C,   "Percentage contribution
           X_AWRD(14)  TYPE C,   "Award        (Plan 11)
           X_P12R(14)  TYPE C,   "Auth Revenue (Plan 12 @ Rev)
           X_P12C(14)  TYPE C,   "Auth Cost    (Plan 12 @ Cost)
           X_P13R(14)  TYPE C,   "Auth Revenue (Plan 13 @ Rev)
           X_P13C(14)  TYPE C,   "Auth Cost    (Plan 13 @ Cost)
           X_ITDS(14)  TYPE C,   "ITD Sales
           X_ITDC(14)  TYPE C,   "ITD Costs
           X_YTDS(14)  TYPE C,   "YTD Sales
           X_YTDC(14)  TYPE C,   "YTD Costs
           X_MTHS(14)  TYPE C,   "Current Month Sales
           X_MTHC(14)  TYPE C,   "Current Month Costs
           X_ITDB(14)  TYPE C,   "ITD Billed Sales
           X_YTDB(14)  TYPE C,   "YTD Billed Sales
           X_MTHB(14)  TYPE C,   "Current Month Billed Sales
           X_COMM(14)  TYPE C,   "Commitments
           X_STAT(6)   TYPE C,   "Active or Inactive (REL, TECO, or CLSD)
           X_ZPROJCLASS(12),
           X_MTHIC(14) TYPE C,   "Current Month Incremental Costs
           X_YTDIC(14) TYPE C,   "YTD Incremental Costs
           X_ITDIC(14) TYPE C,   "ITD Incremental Costs
           X_ZSCURVE(10) TYPE C, "S-CURVE  Status
    New Added
           X_CM_COST(20) TYPE C,
           X_AM_COST(20) TYPE C,
           X_TL_COST(20) TYPE C,
           X_KP_COST(20) TYPE C,
           X_PM_COST(20) TYPE C,
    END OF EXDEF.
    Data declarations
    FIELD-SYMBOLS <MNT> .
    DATA: ETAB  TYPE  EXDEF   OCCURS 100  WITH  HEADER LINE.
    DATA:  X1_PM_COST(20) TYPE C,
           X1_TL_COST(20) TYPE C,
           X1_AM_COST(20) TYPE C,
           X1_CM_COST(20) TYPE C,
           X1_KP_COST(20) TYPE C.
    DATA: KOKRS_FIXED      LIKE PROJ-VKOKR VALUE 'DSRC',  "Controlling Area
          TOTAL_AWARD      LIKE BPGE-WTGES,
          TOTAL_AUTHR12    LIKE BPGE-WTGES,
          TOTAL_AUTHC12    LIKE BPGE-WTGES,
          TOTAL_AUTHR13    LIKE BPGE-WTGES,
          TOTAL_AUTHC13    LIKE BPGE-WTGES,
          TOTAL_ITDSALES   LIKE BPGE-WTGES,
          TOTAL_ITDCOSTS   LIKE BPGE-WTGES,
          TOTAL_ITDICOSTS  LIKE BPGE-WTGES,
          TOTAL_YTDSALES   LIKE BPGE-WTGES,
          TOTAL_YTDCOSTS   LIKE BPGE-WTGES,
          TOTAL_YTDICOSTS  LIKE BPGE-WTGES,
          TOTAL_MTHSALES   LIKE BPGE-WTGES,
          TOTAL_MTHCOSTS   LIKE BPGE-WTGES,
          TOTAL_MTHICOSTS  LIKE BPGE-WTGES,
          TOTAL_ITDBILLED  LIKE BPGE-WTGES,
          TOTAL_YTDBILLED  LIKE BPGE-WTGES,
          TOTAL_MTHBILLED  LIKE BPGE-WTGES,
          TOTAL_COMMITMENT LIKE COOI-WTGBTR,
          HOLD_PRART       LIKE PRPS-PRART,
          COUNT_PROJECTS   TYPE I,
          MNT_INDX(20)     TYPE C,
          HLD_INDX(3)      TYPE N,
          YYYY_MM(10)      TYPE C,
          TEMP-DATE(8)     TYPE C.
    Selection Screen
    SELECTION-SCREEN SKIP 3.
    SELECTION-SCREEN BEGIN OF BLOCK XEXTRPM WITH FRAME TITLE TEXT-001.
    SELECTION-SCREEN SKIP 2.
    PARAMETERS MONTH(2)  TYPE  N   OBLIGATORY.
    PARAMETERS YEAR(4)   TYPE  N   OBLIGATORY.
    SELECT-OPTIONS: EXTRPRJ  FOR PROJ-PSPID.     " Range of Projects
    SELECT-OPTIONS: EXTRTYP  FOR PRPS-PRART.  "Project Types (CO,GV,etc.*)
    SELECT-OPTIONS: EXTRPCTR FOR PROJ-PRCTR.     " Range of Profit centers
    SELECTION-SCREEN SKIP 2.
    PARAMETERS: OPT1 RADIOBUTTON GROUP OPTN,
                OPT2 RADIOBUTTON GROUP OPTN DEFAULT 'X'.
    select-options : s_pc for proj-zprojclass.   "project class
    SELECTION-SCREEN END OF BLOCK XEXTRPM.
    Select Tables
    START-OF-SELECTION.
    write: / 'Sales data (Unshared) extracted on: ', sy-datum.
    uline.
      CLEAR:  COUNT_PROJECTS,
              TOTAL_AWARD,
              TOTAL_AUTHR12,
              TOTAL_AUTHC12,
              TOTAL_AUTHR13,
              TOTAL_AUTHC13,
              TOTAL_ITDSALES,
              TOTAL_ITDCOSTS,
              TOTAL_YTDSALES,
              TOTAL_YTDCOSTS,
              TOTAL_MTHSALES,
              TOTAL_MTHCOSTS,
              TOTAL_ITDBILLED,
              TOTAL_YTDBILLED,
              TOTAL_MTHBILLED,
              TOTAL_COMMITMENT,
              ETAB.
    PROJ Table                                          Project Definition
      SELECT  * FROM PROJ                   "Project Definition
           WHERE PSPID IN EXTRPRJ AND      " Range of Project Numbers
              PRCTR IN EXTRPCTR and        " Range of Profit center
                zprojclass in s_pc.     "project class
    SELECT * FROM PRPS WHERE           "WBS Elements
                  PRART IN EXTRTYP         " Range of Proj.Types (CO,GV,TC..
                 and PSPHI = PROJ-PSPNR.
        HOLD_PRART   = '  '.               "clears project type
        CLEAR ETAB.
        ETAB-X_PROJ  = PRPS-POSID.
        ETAB-X_BU    = PRPS-PRCTR(2).      "Business Unit
        ETAB-X_PMGR = PROJ-VERNA.          "Project Manager
        IF PRPS-PRCTR(2) = '01'.
         ETAB-X_CNTR  = PRPS-PRCTR.         " Profit Center
         CONCATENATE SPACE PRPS-PRCTR INTO ETAB-X_CNTR SEPARATED BY SPACE.
        ELSE.
          ETAB-X_CNTR  = PRPS-PRCTR.         " Profit Center
        ENDIF.
         ETAB-X_TTLE  = PRPS-POST1.         "Title
        CLEAR  TEMP-DATE.
        TEMP-DATE    = PROJ-PLFAZ.         "Project planned start date
        CONCATENATE  TEMP-DATE4(2)  '/' TEMP-DATE6(2) '/'
                     TEMP-DATE+0(4)  INTO  ETAB-X_OPEN.
        TEMP-DATE    = PROJ-PLSEZ.         "Project planned finish date
        CONCATENATE  TEMP-DATE4(2)  '/' TEMP-DATE6(2) '/'
                     TEMP-DATE+0(4)  INTO  ETAB-X_CLOSE.
    Tech Lead
    will comment below
        SELECT SINGLE VERNA FROM TCJ04     "Tech Lead name from TCJ04
               INTO  (ETAB-X_GRPH) WHERE  VERNR = PROJ-ZGRPHD.
    End Of Tech Lead
    Account Manager
        SELECT SINGLE VERNA FROM TCJ04  "Acct Manager from TCJ04
               INTO  (ETAB-X_BDREP) WHERE  VERNR = PROJ-ZBUSDEV.
    ******End Of Account Manager
    Key Personnel
        SELECT SINGLE VERNA FROM TCJ04     "Account Rep name from TCJ04
               INTO  (ETAB-X_ACTREP) WHERE  VERNR = PROJ-ZRESPDIR.
    ********End of Key Personnel
    **Contract Manager
        SELECT SINGLE VERNA FROM TCJ04     "Contract Rep name from TCJ04
               INTO  (ETAB-X_CREP) WHERE  VERNR = PROJ-ZCNTREP.
    End of Contract Manager
    PRPS Table                            WBS's attached to the Project
       SELECT * FROM PRPS WHERE           "WBS Elements
                 PRART IN EXTRTYP         "Range of Proj.Types (CO,GV,TC..
                 AND PSPHI = PROJ-PSPNR.
                order by posid stufe.    "Sort by WBS & Level (needed?)
    get info from level 1 of the WBS
         IF PRPS-STUFE EQ 1.              "top-level WBS element
            HOLD_PRART  = PRPS-PRART.      "save project type for later
            ETAB-X_STAT = '????'.          "set ? as the default status
    get Status for level 1
            SELECT * FROM JEST             "use JEST to determine Status
               WHERE OBJNR =  PRPS-OBJNR
                 AND INACT EQ SPACE.       "space denotes an active status
               CASE JEST-STAT.             "find the system status (Ixxx)
                    WHEN 'I0001'.
                         ETAB-X_STAT = 'CRTD'.    "Created
                    WHEN 'I0002'.
                         ETAB-X_STAT = 'REL'.     "Released
                    WHEN 'I0045'.
                         ETAB-X_STAT = 'TECO'.    "Technically Complete
                    WHEN 'I0046'.
                         ETAB-X_STAT = 'CLSD'.    "Closed
               ENDCASE.
            ENDSELECT.
    Select only active projects (ie; those not with TECO or CLSD)
            IF  OPT2 EQ 'X'
               AND  ( ETAB-X_STAT EQ  'TECO'
                  OR  ETAB-X_STAT EQ  'CLSD' ).
                   EXIT.
            ENDIF.
    *comment Contract Rep and Proj man because we get them from PROJ now
           etab-x_crep   = prps-zzcont.     "Contract Rep.
           etab-x_pmgr   = prps-verna.      "Program Manager Name
            ETAB-X_CLNT   = PRPS-ZZMANDT.    "Client Name
            ETAB-X_CGT    = PRPS-PRART.      "CO, GV, TC, etc
            ETAB-X_DISTR  = PRPS-ZZVTWEG.    "Distrib Channel (ie; GP, etc.)
            ETAB-X_CONTR  = PRPS-USR04.      "Contribution %
            ETAB-X_POCN   = PRPS-ZZPOCN.     "Contract Number
            ETAB-X_TYPE   = PRPS-ZZORDT.     "Order Type Sarnoff
    Award and Authorization (Revenue & Cost)
            SELECT * FROM BPGE
               WHERE OBJNR   = PRPS-OBJNR
                 AND LEDNR   = '0001'        "Budget / Planning Ledger
                 AND TRGKZ   = 'N'           "Object indicator
                 AND WRTTP   = '01'          "Value Type
                 AND ( VERSN = '011'         "011 = Award
                    OR VERSN = '012'         "012 = Billing Authorization
                    OR VERSN = '013' ).      "013 = RA Authorization
                                             "010 = Funding Authorization
    Award                                                        Plan 11
              IF BPGE-VERSN = '011'.         "Plan 11 = Award
                CASE BPGE-VORGA.
                  WHEN 'KSTP'.               "KSTP = Cost level
                    ETAB-X_AWRD = ETAB-X_AWRD + BPGE-WTGES.
                ENDCASE.
              ENDIF.
        IF prps-stufe eq '2'.
    Authorization (Revenue & Cost plan 12)                       Plan 12
              IF BPGE-VERSN = '012'.         "Plan 12 = RA Authorization
                CASE BPGE-VORGA.
                  WHEN 'KSTR'.               "KSTR = Revenue level
                    ETAB-X_P12R = ETAB-X_P12R - BPGE-WTGES.
                  WHEN 'KSTP'.               "KSTP = Cost level
                    ETAB-X_P12C = ETAB-X_P12C + BPGE-WTGES.
                ENDCASE.
              ENDIF.
    Authorization (Revenue & Cost plan 13)                       Plan 13
              IF BPGE-VERSN = '013'.         "Plan 13 = RA Authorization
                CASE BPGE-VORGA.
                  WHEN 'KSTR'.               "KSTR = Revenue level
                    ETAB-X_P13R = ETAB-X_P13R - BPGE-WTGES.
                  WHEN 'KSTP'.               "KSTP = Cost level
                    ETAB-X_P13C = ETAB-X_P13C + BPGE-WTGES.
                ENDCASE.
              ENDIF.
        endif.
            ENDSELECT.                     "BPGE
      ENDIF.      "end of if prps-stufe eq 1. top-level WBS element
    COSP Table (External Postings)                     Awards
    COSP Table (External Postings)                     Billed Sales
    COSP Table (External Postings)                     DPC's & Legacy Load
            SELECT * FROM COSP
               WHERE OBJNR = PRPS-OBJNR    AND
                     GJAHR LE YEAR
             AND (
                 ( kstar = '0000400999'   and        "old CE for Award $
                   ( KSTAR BETWEEN '0000400990' AND '0000400999' AND
                     VERSN = '011'              AND    "11 = Award
                     WRTTP = '01' )                    "01 = Planned
              OR ( ( KSTAR BETWEEN '0000400001' AND '0000400989' OR
                     KSTAR BETWEEN '0000999001' AND '0000999003' ) AND
                     WRTTP = '04' )                    "04 = Actuals
              OR ( ( KSTAR BETWEEN '0000998001' AND '0000998010' OR
                     KSTAR BETWEEN '0000600001' AND '0000601999' ) AND
                     WRTTP = '04' )                    "04 = Actuals
    *------- Awards
           if cosp-kstar = '0000400999' and          "old 400999 = Awards
             IF COSP-KSTAR BETWEEN '0000400990' AND '0000400999' AND
                COSP-VERSN = '011'              AND    "11 = Award
                COSP-WRTTP = '01'.                     "01 = Planned
               IF YEAR       = COSP-GJAHR.
                 DO.
                     IF SY-INDEX LE MONTH.
                        MOVE SY-INDEX TO HLD_INDX.
                        MNT_INDX =  'COSP-WKGXXX'.
                        REPLACE 'XXX' WITH HLD_INDX INTO MNT_INDX.
                        ASSIGN  (MNT_INDX) TO <MNT>.
                        ETAB-X_AWRD = ETAB-X_AWRD + <MNT>.
                     ELSE.
                        EXIT.
                     ENDIF.
                 ENDDO.
               ELSEIF YEAR > COSP-GJAHR.
                   ETAB-X_AWRD = ETAB-X_AWRD +
                                 COSP-WKG001 + COSP-WKG002 +
                                 COSP-WKG003 + COSP-WKG004 +
                                 COSP-WKG005 + COSP-WKG006 +
                                 COSP-WKG007 + COSP-WKG008 +
                                 COSP-WKG009 + COSP-WKG010 +
                                 COSP-WKG011 + COSP-WKG012 +
                                 COSP-WKG013 + COSP-WKG014 +
                                 COSP-WKG015 + COSP-WKG016.
               ELSE.
                 EXIT.
               ENDIF.
             ENDIF.
    *------- Billed Sales
             IF ( COSP-KSTAR BETWEEN '0000400001' AND '0000400989' OR
                  COSP-KSTAR BETWEEN '0000999001' AND '0000999003' ) AND
                  COSP-WRTTP = '04'.
                                     "0000999001 = ITD Sales
                                     "0000999003 = ITD Billed Revenue
                IF YEAR = COSP-GJAHR.
                  DO.
                   IF SY-INDEX LE MONTH.
                      MOVE SY-INDEX TO HLD_INDX.
                      MNT_INDX =  'COSP-WKGXXX'.
                      REPLACE 'XXX' WITH HLD_INDX INTO MNT_INDX.
                      ASSIGN  (MNT_INDX) TO <MNT>.
                      ETAB-X_ITDB = ETAB-X_ITDB - <MNT>.
                      ETAB-X_YTDB = ETAB-X_YTDB - <MNT>.
                      IF SY-INDEX = MONTH.
                         ETAB-X_MTHB = ETAB-X_MTHB - <MNT>.
                      ENDIF.
                   ELSE.
                      EXIT.
                   ENDIF.
                  ENDDO.
                ELSEIF YEAR > COSP-GJAHR.
                  ETAB-X_ITDB = ETAB-X_ITDB -
                             COSP-WKG001 - COSP-WKG002 -
                             COSP-WKG003 - COSP-WKG004 -
                             COSP-WKG005 - COSP-WKG006 -
                             COSP-WKG007 - COSP-WKG008 -
                             COSP-WKG009 - COSP-WKG010 -
                             COSP-WKG011 - COSP-WKG012 -
                             COSP-WKG013 - COSP-WKG014 -
                             COSP-WKG015 - COSP-WKG016.
                ELSE.
                  EXIT.
                ENDIF.
             ENDIF.
    *------- DPC's & Legacy Load
             IF ( COSP-KSTAR BETWEEN '0000998001' AND '0000998010' OR
                  COSP-KSTAR BETWEEN '0000600001' AND '0000601999' ) AND
                  COSP-WRTTP = '04'.
               IF YEAR = COSP-GJAHR.
                 DO.
                     IF SY-INDEX LE MONTH.
                        MOVE SY-INDEX TO HLD_INDX.
                        MNT_INDX =  'COSP-WKGXXX'.
                        REPLACE 'XXX' WITH HLD_INDX INTO MNT_INDX.
                        ASSIGN  (MNT_INDX) TO <MNT>.
                        ETAB-X_ITDC  = ETAB-X_ITDC  + <MNT>.
                        ETAB-X_YTDC  = ETAB-X_YTDC  + <MNT>.
                        IF SY-INDEX = MONTH.
                           ETAB-X_MTHC  = ETAB-X_MTHC  + <MNT>.
                        ENDIF.
                     ELSE.
                        EXIT.
                     ENDIF.
                 ENDDO.
               ELSEIF YEAR > COSP-GJAHR.
                   ETAB-X_ITDC = ETAB-X_ITDC +
                                 COSP-WKG001 + COSP-WKG002 +
                                 COSP-WKG003 + COSP-WKG004 +
                                 COSP-WKG005 + COSP-WKG006 +
                                 COSP-WKG007 + COSP-WKG008 +
                                 COSP-WKG009 + COSP-WKG010 +
                                 COSP-WKG011 + COSP-WKG012 +
                                 COSP-WKG013 + COSP-WKG014 +
                                 COSP-WKG015 + COSP-WKG016.
               ELSE.
                  EXIT.
               ENDIF.
             ENDIF.
           ENDSELECT.
    COOI Table (Commitments)              commitments for the WBS elements
           SELECT  * FROM COOI
             WHERE OBJNR =  PRPS-OBJNR.
               ETAB-X_COMM = ETAB-X_COMM + COOI-WTGBTR.
           ENDSELECT.
    COSS Table (External Postings)                    G&A on Commitments
    COSS Table (External Postings)                    Shared Billed Sales
    COSS Table (External Postings)                    Shared DPC's
    COSS Table (External Postings)                    Salary,ESE,OH, & G&A
           SELECT  *   FROM  COSS
             WHERE
              ( OBJNR =  PRPS-OBJNR AND
                WRTTP =  '22' )                         "G&A on Commitments
                    OR
              ( OBJNR =  PRPS-OBJNR AND
                GJAHR LE YEAR       AND
                WRTTP = '04'        AND                 "04 = Actuals
                   (                                   "Shared Billed Sales
                     (   KSTAR BETWEEN '0000400001' AND '0000400989' OR
                         KSTAR BETWEEN '0000999001' AND '0000999003' )
                     OR                                "Shared DPC's
                     (   KSTAR BETWEEN '0000600001' AND '0000601999' )
                     OR                                "Salary,ESE,OH, & G&A
                     ( ( KSTAR BETWEEN '0000001000' AND '0000001999'  OR
                         KSTAR BETWEEN '0000002100' AND '0000002199'  OR
                         KSTAR BETWEEN '0000002500' AND '0000002599'  OR
                         KSTAR BETWEEN '0000002800' AND '0000002899' ) )
                  and  parob not like 'PR%' ) "commented out on 4/19/2000
    *------- G&A on Commitments    (NOTE: data is always as of the RUN date)
             IF  COSS-WRTTP = '22'.
                   ETAB-X_COMM = ETAB-X_COMM +
                                 COSS-WKG001 + COSS-WKG002 +
                                 COSS-WKG003 + COSS-WKG004 +
                                 COSS-WKG005 + COSS-WKG006 +
                                 COSS-WKG007 + COSS-WKG008 +
                                 COSS-WKG009 + COSS-WKG010 +
                                 COSS-WKG011 + COSS-WKG012 +
                                 COSS-WKG013 + COSS-WKG014 +
                                 COSS-WKG015 + COSS-WKG016.
             ENDIF.
    *------- Shared Billed Sales
             IF ( COSS-KSTAR BETWEEN '0000400001' AND '0000400989' OR
                  COSS-KSTAR BETWEEN '0000999001' AND '0000999003' ) AND
                  COSS-WRTTP = '04'.
               IF YEAR = COSS-GJAHR.
                 DO.
                     IF SY-INDEX LE MONTH.
                        MOVE SY-INDEX TO HLD_INDX.
                        MNT_INDX =  'COSS-WKGXXX'.
                        REPLACE 'XXX' WITH HLD_INDX INTO MNT_INDX.
                        ASSIGN  (MNT_INDX) TO <MNT>.
                        ETAB-X_ITDB = ETAB-X_ITDB - <MNT>.
                        ETAB-X_YTDB = ETAB-X_YTDB - <MNT>.
                        IF SY-INDEX = MONTH.
                           ETAB-X_MTHB = ETAB-X_MTHB - <MNT>.
                        ENDIF.
                     ELSE.
                        EXIT.
                     ENDIF.
                 ENDDO.
               ELSEIF YEAR > COSS-GJAHR.
                 ETAB-X_ITDB = ETAB-X_ITDB -
                               COSS-WKG001 - COSS-WKG002 -
                               COSS-WKG003 - COSS-WKG004 -
                               COSS-WKG005 - COSS-WKG006 -
                               COSS-WKG007 - COSS-WKG008 -
                               COSS-WKG009 - COSS-WKG010 -
                               COSS-WKG011 - COSS-WKG012 -
                               COSS-WKG013 - COSS-WKG014 -
                               COSS-WKG015 - COSS-WKG016.
               ELSE.
                  EXIT.
               ENDIF.
             ENDIF.
    *------- Shared DPC's
             IF COSS-KSTAR BETWEEN '0000600001' AND '0000601999' AND
                COSS-WRTTP = '04'.
               IF YEAR = COSS-GJAHR.
                 DO.
                     IF SY-INDEX LE MONTH.
                        MOVE SY-INDEX TO HLD_INDX.
                        MNT_INDX =  'COSS-WKGXXX'.
                        REPLACE 'XXX' WITH HLD_INDX INTO MNT_INDX.
                        ASSIGN  (MNT_INDX) TO <MNT>.
                        ETAB-X_ITDC  = ETAB-X_ITDC  + <MNT>.
                        ETAB-X_YTDC  = ETAB-X_YTDC  + <MNT>.
                        IF SY-INDEX = MONTH.
                           ETAB-X_MTHC  = ETAB-X_MTHC  + <MNT>.
                       ENDIF.
                     ELSE.
                        EXIT.
                     ENDIF.
                 ENDDO.
               ELSEIF YEAR > COSS-GJAHR.
                   ETAB-X_ITDC = ETAB-X_ITDC +
                                 COSS-WKG001 + COSS-WKG002 +
                                 COSS-WKG003 + COSS-WKG004 +
                                 COSS-WKG005 + COSS-WKG006 +
                                 COSS-WKG007 + COSS-WKG008 +
                                 COSS-WKG009 + COSS-WKG010 +
                                 COSS-WKG011 + COSS-WKG012 +
                                 COSS-WKG013 + COSS-WKG014 +
                                 COSS-WKG015 + COSS-WKG016.
               ELSE.
                  EXIT.
               ENDIF.
             ENDIF.
    *------- Salary,ESE,OH,& G&A
             IF ( COSS-KSTAR BETWEEN '0000001000' AND '0000001999'  OR
                  COSS-KSTAR BETWEEN '0000002100' AND '0000002199'  OR
                  COSS-KSTAR BETWEEN '0000002500' AND '0000002599'  OR
                  COSS-KSTAR BETWEEN '0000002800' AND '0000002899' ) AND
                  COSS-WRTTP = '04'.
               IF YEAR = COSS-GJAHR.
                 DO.
                   IF SY-INDEX LE MONTH.
                      MOVE SY-INDEX TO HLD_INDX.
                      MNT_INDX =  'COSS-WKGXXX'.
                      REPLACE 'XXX' WITH HLD_INDX INTO MNT_INDX.
                      ASSIGN  (MNT_INDX) TO <MNT>.
                      ETAB-X_ITDC = ETAB-X_ITDC + <MNT>.
                      ETAB-X_YTDC = ETAB-X_YTDC + <MNT>.
                      IF SY-INDEX = MONTH.
                          ETAB-X_MTHC = ETAB-X_MTHC + <MNT>.
                      ENDIF.
                   ELSE.
                      EXIT.
                   ENDIF.
                 ENDDO.
               ELSEIF YEAR > COSS-GJAHR.
                 ETAB-X_ITDC = ETAB-X_ITDC +
                               COSS-WKG001 + COSS-WKG002 +
                               COSS-WKG003 + COSS-WKG004 +
                               COSS-WKG005 + COSS-WKG006 +
                               COSS-WKG007 + COSS-WKG008 +
                               COSS-WKG009 + COSS-WKG010 +
                               COSS-WKG011 + COSS-WKG012 +
                               COSS-WKG013 + COSS-WKG014 +
                               COSS-WKG015 + COSS-WKG016.
               ELSE.
                 EXIT.
                ENDIF.
             ENDIF.
            ENDSELECT.
    COSB Table (Results from running RA)                    Unbilled Sales
            SELECT * FROM COSB
               WHERE OBJNR = PRPS-OBJNR
                 AND KSTAR BETWEEN '0000003004' AND '0000003005'
                                   "0000003004 = Unbilled Revenue
                                   "0000003005 = Unearned Revenue
                 AND GJAHR LE YEAR
                 AND WRTTP = '32'.                    "32 = Results Analysis
               IF YEAR = COSB-GJAHR.
                 DO.
                     IF SY-INDEX LE MONTH.
                        MOVE SY-INDEX TO HLD_INDX.
                        MNT_INDX =  'COSB-WKGXXX'.
                        REPLACE 'XXX' WITH HLD_INDX INTO MNT_INDX.
                        ASSIGN  (MNT_INDX) TO <MNT>.
                        ETAB-X_ITDS = ETAB-X_ITDS - <MNT>.
                        ETAB-X_YTDS = ETAB-X_YTDS - <MNT>.
                        IF SY-INDEX = MONTH.
                           ETAB-X_MTHS = ETAB-X_MTHS - <MNT>.
                        ENDIF.
                     ELSE.
                        EXIT.
                     ENDIF.
                 ENDDO.
               ELSEIF YEAR > COSB-GJAHR.
                 ETAB-X_ITDS = ETAB-X_ITDS -
                               COSB-WKG001 - COSB-WKG002 -
                               COSB-WKG003 - COSB-WKG004 -
                               COSB-WKG005 - COSB-WKG006 -
                               COSB-WKG007 - COSB-WKG008 -
                               COSB-WKG009 - COSB-WKG010 -
                               COSB-WKG011 - COSB-WKG012 -
                               COSB-WKG013 - COSB-WKG014 -
                               COSB-WKG015 - COSB-WKG016.
               ELSE.
                  EXIT.
               ENDIF.
            ENDSELECT.
      ENDSELECT.               "End of WBS records (from PRPS) for project
    Get Total Sales by adding Billed Sales to Unbilled Sales.
       ETAB-X_ITDS  =  ETAB-X_ITDS  +  ETAB-X_ITDB.
       ETAB-X_YTDS  =  ETAB-X_YTDS  +  ETAB-X_YTDB.
       ETAB-X_MTHS  =  ETAB-X_MTHS  +  ETAB-X_MTHB.
       IF  HOLD_PRART IN EXTRTYP.   "Matches the user requested project type
         IF  OPT1 EQ 'X' OR         "All projects
           ( OPT2 EQ 'X' AND        "Only active projects
             ETAB-X_STAT NE  'TECO' AND
             ETAB-X_STAT NE  'CLSD' ).
               TOTAL_AWARD      = TOTAL_AWARD      + ETAB-X_AWRD.
               TOTAL_AUTHR12    =   TOTAL_AUTHR12    + ETAB-X_P12R .
              TOTAL_AUTHC12    = TOTAL_AUTHC12    + ETAB-X_P12C.
               TOTAL_AUTHR13    = TOTAL_AUTHR13    + ETAB-X_P13R.
               TOTAL_AUTHC13    = TOTAL_AUTHC13    + ETAB-X_P13C.
               TOTAL_ITDSALES   = TOTAL_ITDSALES   + ETAB-X_ITDS.
               TOTAL_ITDCOSTS   = TOTAL_ITDCOSTS   + ETAB-X_ITDC.
               TOTAL_YTDSALES   = TOTAL_YTDSALES   + ETAB-X_YTDS.
               TOTAL_YTDCOSTS   = TOTAL_YTDCOSTS   + ETAB-X_YTDC.
               TOTAL_MTHSALES   = TOTAL_MTHSALES   + ETAB-X_MTHS.
               TOTAL_MTHCOSTS   = TOTAL_MTHCOSTS   + ETAB-X_MTHC.
               TOTAL_ITDBILLED  = TOTAL_ITDBILLED  + ETAB-X_ITDB.
               TOTAL_YTDBILLED  = TOTAL_YTDBILLED  + ETAB-X_YTDB.
               TOTAL_MTHBILLED  = TOTAL_MTHBILLED  + ETAB-X_MTHB.
               TOTAL_COMMITMENT = TOTAL_COMMITMENT + ETAB-X_COMM.
               PERFORM SHIFT_SIGN.
               APPEND  ETAB.              "Write data to internal table
               CLEAR   ETAB.
               COUNT_PROJECTS = COUNT_PROJECTS + 1. "Count # of Projects
         ENDIF.
       ENDIF.
       ENDSELECT.
    ENDSELECT.                          "End of Projects from PROJ table
      PERFORM GRAND_TOTALS.
      SORT  ETAB  BY  X_BU X_PROJ.
      ETAB-X_BU    = 'BU'.
      ETAB-X_CNTR  = 'PrftCntr'.
      ETAB-X_PROJ  = 'Proj'.
      ETAB-X_CREP  = 'Contract Mgr'.
      ETAB-X_BDREP = 'Account Mgr'.
      ETAB-X_GRPH  = 'Technical Lead'.
      ETAB-X_ACTREP = 'Key Person1'.
      ETAB-X_PMGR  = 'Program Mgr'.
      ETAB-X_TTLE  = 'Title'.
      ETAB-X_CLNT  = 'Client'.
      ETAB-X_POCN  = 'Contract #'.
      ETAB-X_TYPE  = 'Type'.
      ETAB-X_OPEN  = 'Open'.
      ETAB-X_CLOSE = 'Close'.
      ETAB-X_CGT   = 'CGT'.
      ETAB-X_DISTR = 'DC'.
      ETAB-X_CONTR = 'Contr%'.
      ETAB-X_AWRD  = 'Award'.
      ETAB-X_P12R  = 'Auth12 Sales'.
      ETAB-X_P12C  = 'Auth12 Cost'.
      ETAB-X_P13R  = 'Auth13 Sales'.
      ETAB-X_P13C  = 'Auth13 Cost'.
      ETAB-X_ITDS  = 'ITD Sales'.
      ETAB-X_ITDC  = 'ITD Costs'.
      ETAB-X_YTDS  = 'YTD Sales'.
      ETAB-X_YTDC  = 'YTD Costs'.
      ETAB-X_MTHS  = 'Mth Sales'.
      ETAB-X_MTHC  = 'Mth Costs'.
      ETAB-X_ITDB  = 'ITD Billed'.
      ETAB-X_YTDB  = 'YTD Billed'.
      ETAB-X_MTHB  = 'Mth Billed'.
      ETAB-X_COMM  = 'Commitments'.
      ETAB-X_STAT  = 'Status'.
      INSERT ETAB  INDEX 1.    "Write a report header line to internal table
      CLEAR  ETAB.
    CALL FUNCTION 'Z_RH_START_EXCEL_DATA_OLE'
        EXPORTING
           data_name = 'C:\WINNT\Profiles\cbraswell\Desktop\TestTemp.xlt'
             DATA_NAME          = 'ZSales.XLS'
             DATA_PATH_FLAG     = 'W'
             DATA_TYPE          = 'DAT'
             DATA_BIN_FILE_SIZE = 'ZSales'
             CHART_TITLE        = 'ZSales'
             CHART_TYPE         = 2
             CATEGORY_TITLE     = 'ZSales'
             VALUE_TITLE        = 'ZSales'
             DATA_XTOP_COR      = 0
             DATA_YTOP_COR      = 0
             DATA_XBOT_COR      = 0
             DATA_YBOT_COR      = 0
             CATEGORY_XTOP_COR  = 0
             CATEGORY_YTOP_COR  = 0
             CATEGORY_XBOT_COR  = 0
             CATEGORY_YBOT_COR  = 0
         TABLES
              DATA_TAB           =    ETAB
         EXCEPTIONS
              NO_BATCH           = 1
              DOWNLOAD_ERROR     = 2
              INVALID_TYPE       = 3
              INTERNAL_ERROR     = 4
              NO_OLE_SUPPORT     = 5
              OLE_FILE_ERROR     = 6
              OLE_ERROR          = 7
              NO_DATA            = 8
              COORDINATE_ERROR   = 9
              OTHERS             = 10.
    Negative # sign in the front of number for downloading to Excel
    FORM  SHIFT_SIGN.
      IF ETAB-X_AWRD CA '-'.    SHIFT ETAB-X_AWRD RIGHT CIRCULAR.     ENDIF.
      IF ETAB-X_P12R CA '-'.    SHIFT ETAB-X_P12R RIGHT CIRCULAR.     ENDIF.
      IF ETAB-X_P12C CA '-'.    SHIFT ETAB-X_P12C RIGHT CIRCULAR.     ENDIF.
      IF ETAB-X_P13R CA '-'.    SHIFT ETAB-X_P13R RIGHT CIRCULAR.     ENDIF.
      IF ETAB-X_P13C CA '-'.    SHIFT ETAB-X_P13C RIGHT CIRCULAR.     ENDIF.
      IF ETAB-X_ITDS CA '-'.    SHIFT ETAB-X_ITDS RIGHT CIRCULAR.     ENDIF.
      IF ETAB-X_ITDIC CA '-'.   SHIFT ETAB-X_ITDIC RIGHT CIRCULAR.    ENDIF.
      IF ETAB-X_ITDC CA '-'.    SHIFT ETAB-X_ITDC RIGHT CIRCULAR.     ENDIF.
      IF ETAB-X_YTDS CA '-'.    SHIFT ETAB-X_YTDS RIGHT CIRCULAR.     ENDIF.
      IF ETAB-X_YTDC CA '-'.    SHIFT ETAB-X_YTDC RIGHT CIRCULAR.     ENDIF.
      IF ETAB-X_YTDIC CA '-'.   SHIFT ETAB-X_YTDIC RIGHT CIRCULAR.    ENDIF.
      IF ETAB-X_MTHS CA '-'.    SHIFT ETAB-X_MTHS RIGHT CIRCULAR.     ENDIF.
      IF ETAB-X_MTHC CA '-'.    SHIFT ETAB-X_MTHC RIGHT CIRCULAR.     ENDIF.
      IF ETAB-X_MTHIC CA '-'.   SHIFT ETAB-X_MTHIC RIGHT CIRCULAR.    ENDIF.
      IF ETAB-X_ITDB CA '-'.    SHIFT ETAB-X_ITDB RIGHT CIRCULAR.     ENDIF.
      IF ETAB-X_YTDB CA '-'.    SHIFT ETAB-X_YTDB RIGHT CIRCULAR.     ENDIF.
      IF ETAB-X_MTHB CA '-'.    SHIFT ETAB-X_MTHB RIGHT CIRCULAR.     ENDIF.
      IF ETAB-X_COMM CA '-'.    SHIFT ETAB-X_COMM RIGHT CIRCULAR.     ENDIF.
    ENDFORM.
    FORM  GRAND_TOTALS.
    SKIP 1.    .
    WRITE: / '----
    WRITE: / 'System ID                  = ', SY-SYSID,
           / 'Client                     = ', SY-MANDT,
           / 'User                       = ', SY-UNAME,
           / 'Date of data extract       = ', SY-DATUM ,
           / 'Number of Projects          =           ',   COUNT_PROJECTS,
           / 'total Award      (Plan 11)  = ', TOTAL_AWARD,
           / 'total Auth Sales

    Hi all,
        Iam really waiting for someone to see and  get the logic right  for this code.Iam completely stuck up.  i need ur help
    Thanks

Maybe you are looking for

  • If I move my iTunes media folder to the Shared folder....

    Hello I'd like to share my music libary with my wife's user account on our MacBook Pro so she can get some of my music onto her iPhone. I've read the article on the Apple site as well as similar articles from other reputable Mac user websites and it

  • Is SharePoint Enterprise Needed For Digital Signatures?

    Hey SharePoint Fam, Had a request come in for Digital Signature use and was wondering is this even possible without Enterprise version?  We are on Standard 2010 version...... Thanks n advance

  • Audio Speed

    I filmed a wedding and want to add songs over top of the audio from the DJ because the hall had a lot of echo. The problem is that the DJ sped up the songs slightly. Now I need to speed up my songs but I can't figure out how. I know I can do it in Lo

  • Deleting old library folder?

    Hi there! I recently updated to Lion, and I found out that some people couldn't see their library folder after upgrading, but I could see mine. I tried that method with option-clicking on the 'Go'-tab, and I got into a new library folder. The content

  • Stuck in the stone age and need some advice

    while ($true) $A = (Get-Date -DisplayHint time) $log = "c:\Alert-2.csv" Myscript | wc > c:Alert.log Get-Content -path c:Alert.log | % { $_.Substring(1,7).Trim( ); } > c:Alert-1.log Get-Content -path c:Alert-1.log >> c:Alert-2.csv Add-Content >> ($(c: