Cumulative output based on flag...

Hi,
I have a table as
Txn No Flag Amt
1 C 500
2 D 100
3 C 200
4 C 100
5 D 400
6 D 100
I am trying to write a query which will give me the total amount that is based on the Flag value i.e. D or C.
If Flag is D subtract the current amount from previous amt
if Flag is C add the current amount to previous amt
Txn No Flag Total Amt
1 C 500
2 D 400
3 C 600
4 C 700
5 D 300
6 D 200
Please guide me...
Thanks in advance
Regards
Kaustubh

Like this ?
SQL> with tbl as
  2  (select 1 as c1, 'C' as c2, 500 as c3 from dual union all
  3   select 2, 'D', 400 from dual union all
  4   select 3, 'C', 600 from dual union all
  5   select 4, 'C', 700 from dual union all
  6   select 5, 'D', 300 from dual union all
  7   select 6, 'D', 200 from dual )
  8  select c1,c2, c3, sum(decode(c2,'C',c3,c3*-1)) over (order by c1)
  9  from tbl;
        C1 C         C3 SUM(DECODE(C2,'C',C3,C3*-1))OVER(ORDERBYC1)
         1 C        500                                         500
         2 D        400                                         100
         3 C        600                                         700
         4 C        700                                        1400
         5 D        300                                        1100
         6 D        200                                         900
6 rows selected.
SQL> Nicolas.

Similar Messages

  • How to retrive new logical column based on flag values in table.

    Hi,
    i have two tables in rpd
    1.file table contains the coulmns------->date,file_count,record_count,cldm_stg,cmsa_stg,archive_stg
    2.rejection table columns---------> are same as above
    both have same common columns.my requirement is publish a dashboard like:
    date | land_files count |alnd_recordscount| target_files count|target_records count|Rejection filecount|rejection record count
    These report ineed retrive from those two tables.based on flag values.taget countcomes when all stg values set to ='y'
    i.e(cldm_stg='y' and cmsa_stg='y'and archive_stg='y') if not then it will be in rejection file.
    Please give solution how to achive my output.
    nQSError: 14026] Unable to navigate requested expression: Target_record:[DAggr(FILE_CONTROL.Target_record by [ FILE_CONTROL.FILE_NAME, REJECTED_FILES.FILE_NAME, REJECTED_FILES.NO_OF_ROWS, File_landing.NO_OF_ROWS, File_landing.FILE_LOAD_DATE] SB FILE_CONTROL)]. Please fix the metadata consistency warnings. (HY000)
    Edited by: user8767586 on Jan 12, 2010 4:29 AM

    Tanks for ypur reply .only two tables are there named as above.i taken file_control as a fact table.
    and i create one new tablecalled target in bmm layer taking logical source as file_control(fact table). and iset the where clause for the new table.and i create a new measure called target_file and target_records.in where clause my query is like
    dwbidb."".AUDIT_PROD.FILE_CONTROL.ARCHIVE_STATUS = 'Y' AND dwbidb."".AUDIT_PROD.FILE_CONTROL.CMSA_STATUS = 'Y' AND dwbidb."".AUDIT_PROD.FILE_CONTROL.LND_STATUS = 'Y' AND dwbidb."".AUDIT_PROD.FILE_CONTROL.SCRIPT_STATUS = 'Y' AND dwbidb."".AUDIT_PROD.FILE_CONTROL.STG_STATUS = 'Y'
    please tell me if this is right way to achive mt report. and tell me difference between fragmentation and whereclause.for my requrement i ahve to follow which method either fragmentation or whereclause.and in rpd there are no errors and warnings.but in answers i get a follwing error
    State: HY000. Code: 10058. [NQODBC] [SQL_STATE: HY000] [nQSError: 10058] A general error has occurred. [nQSError: 14026] Unable to navigate requested expression: TARGET_FILECOUNT:[DAggr(TARGET.TARGET_FILECOUNT by [ TARGET.FILE_NAME] SB TARGET)]. Please fix the metadata consistency warnings. (HY000)
    SQL Issued: SELECT TARGET.FILE_LOAD_DATE saw_0, TARGET.TARGET_FILECOUNT saw_1, TARGET.TARGET_FILECOUNT saw_2 FROM AUDIT_PROD ORDER BY saw_0.
    Please tell me to achive my report.
    Regards
    Edited by: user8767586 on Jan 12, 2010 5:21 AM
    Edited by: user8767586 on Jan 12, 2010 5:21 AM
    Edited by: user8767586 on Jan 12, 2010 5:24 AM

  • User wants to get the cumulative values based on his input.

    Hi
    I am working one FI Report; the out put values are Cumulative values for Current, Previous years. I developed and it fetches the data last 3 years Cumulative year’s data without any input FYMonth based on SAPexits and varible offsets. But user wants to put Fiscal year Month as input. So he wants get the cumulative values based on his input. For example, If his input SEP'2005(062005), Then Query gives the Output Cumulative Value (I.e., Sum of Total values of Form APR'2005 to SEP'2005)
    Please provide the solution…
    Thanks
    Mannev

    Mannev,
    You can try doing this.
    1. If the user input is fiscal period(2005006) , you can create a customer exit variable which will take the user value (i_step =2), and change the variable value to 20005001. (this is a simple code where tye last 2 digits are replaced by 01).
    if the user is entering calmonth, you can use FM - DATE_TO_PERIOD_CONVERT, to convert the month to fiscal period.
    2. You can create a rkf with restrictions on time char based on the customer exit variable and the user entered variable.
    -Saket

  • Block invoices for PO with no GR-based IV flag

    Hello SAP experts,
    I need your help with finding a way to block invoices for PO with no GR-based IV flag.  At our company, we treat service POs almost the same as material POs (to avoid receipt of service entry).  The only difference from material PO is that service PO does not have the flag for GR.  We customized our EBP to have this done.
    Now, accounting wants to automatically block all invoices associate with service POs.  In this case it would be a PO with no GR.  I tried LIV configuration but it is only for price, quantity and etc.  I also tried blocking with IR before GR but it didn't work because there is no GR.
    Is there a way to achive automatic invoice block in this case?
    Appreciate your help.
    -AT-

    Hi Annie,
    if the configuration doesn't help you enough, you would have to add some custom logic after the invoice has been created.
    Technically speaking, I believe there exists a business add-in (BAdI) where you could enter a piece of code which would after the invoice creation check the GR and block it if appropriate. Another implementation option would be a mini-workflow - there you would have a step which checks the GR existence and blocks the invoice.
    Hope this helps, I suggest talking to your local abap consultant for more details,
    -Mikko

  • How to populate GR Based IV flag for Po.

    Hi,
        We are using Extended Classic scenario.When the Po is getting replicated to Backend R/3.G.R based Invoice flag in Invoice Tab in Me23n is blank.One solution we think of is flagging the G.R IV flag at vendor master level in xk03 (Purchasing data view ).Is there any SPRO level configurations to attain the same.
    Thanks.
    Rakesh.

    No. Vendor master is the way to go in both SRM and ECC. You can adjust some flags in BBP_ECS_PO_OUT_BADI, but than SRM and ECC PO will have differences.
    SRM has its own mysterious ways in the way (and mostly when!) it retrieves the flags from the vendor master. If you can manage it don't touch any flags using badi's and keep those flags synchronised in SRM and ECC.
    Regards,
    Robin

  • How to populate the GR based Invoice Flag in PO.

    Hi,
      How to check the GR based Invoice flag for a purchase order.One solution we think of is flagging the G.R IV flag at vendor master level in xk03 (Purchasing data view ).Are there any SPRO level configurations to attain the same.
    Thanks.
    Rakesh.

    Hi,
    Look into
    SPRO->MM->Inventory Mgmt->Good receipt->For GR-Based IV
    Refer:
    Re: CAN GR/GI  BE REVERSED EVEN THOUGH DEBIT NOTE IS RAISED

  • Setting time critical digital output based on axis position (PCI-7358)

    HI,
    I need to set a time critical digital output based on encoder position (this will switch fast acting valves). I was planning to try the general purpose DIO but I can't find any examples, I have been through the manuals, searched the site etc. Where can I find help with this, all the examples only seem to deal with digital input triggering or RTSI? I'm thinking of an onboard program that just monitors encoder positions and sets digital outputs.
    Some time back I seem to remember reading that general purpose DIO should not be used for time critical operations, is that correct? And if so what are the other options - RTSI going to another DIO board? The DIO really needs to be deterministic, is RTSI the only option?
    Any advice appreciated / Martin
    Certified LabVIEW Architect

    Even with an onboard program you will always get a delay of several milliseconds between your axis has crossed the position and until the digital outputs are set. If this is ok for you then you could choose this approach.
    For the case that you only want to toggle one digital line the Breakpoint feature should be the best solution as it toggles the breakpoint output almost immediately when the breakpoint positions are reached.
    If you need to change a whole pattern instead of only a single line then the approach you mentioned would be the best solution (RTSI and high-speed DIO like the 653x boards). Combine this approach with the breakpoint feature by routing the breakpoint output to RTSI and using this as a update clock signal for the DIO board.
    Best regards,
    Jochen Klier
    National Instruments Germany

  • GR based IV flag not checked in PO

    Hello,
    I have checked the GR based IV flag in the vendor master record. However, when I create a PO the GR based IV flag is not flowing through to the PO. The flag remains unchecked in the PO.
    Can someone please point what could be the issue?
    Thank you.

    Hi,
    Please check the GR based IV flag checked or not in Inforecord. If not , you need to  tick in  inforecord. It will work. Try this out.
    Regards,
    abi

  • GR Based INV flag set on Purchase Order

    Hello,
    We are on SRM 5.5 and R3 ECC 6.0 classic scenario. We want to swihtch off the GR Based Invoice flag which is maintained in de vendor master. Vendor has no info record or contract. When creating a PO directly in R3 the flag is also disabled on the PO. However, when we create a shopping cart, the system automatically creates the purchase req and when the purchaser creates the Purchase order the GR Based Inv. flag is set again ? Can anybody let me know how this is possible ?
    Thanks as eve for your help.
    Antoinette

    Hi Antoinette Stork,
    Here is the way we have achieved. I am not an ABAPer and hence providing you more concepts than code.
    01)  A custom program is written and is scheduled on hourly basis as a back ground job.
    02)  This program is executed after the BBP_VENDOR_SYNC is executed as a background job as well.
    03)  BBP_VENDOR_SYNC will bring the updates and new vendors from the R/3 back end.
    04)  This will bring the vendors with the confirmation flag set on SRM (no corresponding field exists on the R/3 side vendor master) and also will check the GR based invoice verification flag on (the corresponding field exists on the ECC vendor master).
    05)  After 15 minutes the custom program will read the BUT000 table for the total number of vendors changed or created between two successive jobs.
    06)  Then query on the VENMAP table to get the GUIDs of the corresponding vendors.
    07)  Within the custom program use the FMs
         BBP_BUPA_FRG0060_CHANGE  and
         BAPI_TRANSACTION_COMMIT
    to set the flags for
          goodsrec_confex = ' '  and
          GR_BASEDIV
    Sorry for being unable to provide you the code dump.  This is working perfectly fine for us.
    Also, we have used the badi "BBP_ECS_PO_OUT_BADI"  with the method "BBP_B46B_PO_OUTBOUND"  as a safety net as our invoice processing is two way match and we do not absolutely want the flags to be set to the R/3 PO.
      DATA: ls_bapi_poitem TYPE bbps_if_bapimepoitem_pi.
    Loop through the item details that gets passed to Backend*
      LOOP AT ct_bapi_poitem INTO ls_bapi_poitem.
    Clear the GR and GR-Based Invoice Verification Indicator.*
        CLEAR : ls_bapi_poitem-gr_ind,
                ls_bapi_poitem-gr_basediv.
        MODIFY ct_bapi_poitem FROM ls_bapi_poitem
               TRANSPORTING gr_ind gr_basediv.
      ENDLOOP.
    ENDMETHOD.
    Hope this helps,
    DV

  • GR Based IV Flag for Limit Shopping carts.

    Hello,
            We are on ECS SRM 3.0,EBP 4.0.There is a requirement to populate GR based Invoice verification flag (GR Based IV flag) for a PO for any  Limit shopping carts raised.For all other shopping carts this flag should not be set.One option we can think is a condition set in the Badi which replicates the PO to backend.Are there any settings to achieve the same.
    Thanks
    Rakesh.

    Hi Rakesh,
    As Dave said the simple way is using BADI BBP_CREATE_BE_PO_NEW.
    There is a way to achive this for Limit shopping carts. Choose 'Confirmation and Invoice' as Follow-on doc in the Limit shopping cart, this will create PO with GR flag active always. But this will not solve your other requirement that all non Limit orders should create PO with no GR flag. In that case you need to use BADI again.
    It is up to you, think and decide which way is better..:)
    Thanks,
    Jagadish

  • Gr-based-IV flag not changable by SRM buyer

    Hi,
    We are on SRM 7, ECS. Our vendor masters in ECC do not have GR-based-IV flag ticked. When we create a SRM PO, the GR-based-IV is not ticket by default. The following are the default status of the 3 indicators in SRM PO by default:
    GR indicator: Ticked
    Invoice Expected: Ticked
    Confirmation based Invoice verification (this is GR-based-IV): Not ticked
    Now the buyer wants to enable the GR-based-IV indicator in the SRM PO, while keeping the GR indicator and Invoice Expected ticked. He is unable to so, since the field is grayed out.  Is this a SRM bug , since this is allowed in ECC PO  ( i.e. if we  directly an ECC PO)
    On similar lines, if the vendor master has u201CConfirmation based Invoice verificationu201D ticked and the SRM PO also has Confirmation based Invoice verification ticked, how the buyer can untick it while keeping the GR indicator and Invoice Expected as ticked.
    This SRM behavior is different from ECC behavior. Is this a bug and is there a note for it?
    Rgds
    sumendra

    Hi,
    you have told that in the vendor master in the ECC the Flag is not ticked.
    If the vendor has been replicated from ECC then in SRM also the tick will  not be there.
    Option 1
    if you want the GR Flag to be ticked .please do so in ECC and replicate the vendor in SRM
    Option 2.
    go to the supplier POWL .
    Select the supplier and tick the
    Confirmation based Invoice verification (this is GR-based-IV).
    Create Shopping cart PO will be created with flag ticked
    This SRM behavior is different from ECC behavior. Is this a bug and is there a note for it?
    No
    Regards
    G.Ganesh Kumar

  • GR based IV flag Update in PO

    Hi,
    Here is the situation.
    We have 2000 PO's are not update GR based IV flag. This is due to PIR's are not updated with GR based IV flag.
    Now we identified the PIR's and updated GR based flag. But In the PO's we cant able to update.
    These PO's already delivery completed.
    Please guide me how to Update this Indicator in PO's?
    Thanks,
    Sridhar

    hi, you've mentioned that "PO's already delivery completed" that means GRs are done for all these POs. You can not change GR based IV indicator after posting follow on docs.
    still check below OSS note which explains how and when you can change it (even after psoting of follow on docs like GR and IV)
    Note 550163 - Change of GR-based invoice verification indicator
    Also, if GRs are already done for these 2000 POs you should not worry about updating this indicator as main purpose of this indicator is to make sure that GR is done before posting Invoice and you already completed that.
    yogesh

  • GR based IV flag

    Hello,
    I have checked the GR based IV flag in the vendor master record their is no tick over selected.  However, when I create a PO the GR based IV flag is coming automaticlly . It should not come checked in case of this vendor.
    please advice.
    Thank you.

    Hi,
    Go to ME1L, input the material and vendor codes and execute.
    If there is an info record, system will populate the same.
    Regards,
    Siva

  • Correcting POs with GR Based IV Flag set

    We are on SRM 550 SP10 ECS. One of the bugs in the earlier SP level related to POs was
      GR Based IV is checked if GR is checked and IR is checked ignoring the master vendor record information related to this flag. This is fixed in Note 1010791. This will fix the new POs created after the note is applied. I am wondering if anybody knows of any z program which will unset the earlier POs (created before the note is applied) for the GR Based IV flag. With the flag set, we cannot enter the invoice before the Goods receipt.

    hi, you've mentioned that "PO's already delivery completed" that means GRs are done for all these POs. You can not change GR based IV indicator after posting follow on docs.
    still check below OSS note which explains how and when you can change it (even after psoting of follow on docs like GR and IV)
    Note 550163 - Change of GR-based invoice verification indicator
    Also, if GRs are already done for these 2000 POs you should not worry about updating this indicator as main purpose of this indicator is to make sure that GR is done before posting Invoice and you already completed that.
    yogesh

  • How to group the output based on DAYS field

    Hi
    I am modifying the predefined ALV report "RFTMBL01" .I had added the days field to that report output and I have to group the output based on the DAYS field
    Records within 0-10 days in one group
    Records within 10-30 days in one group
    Records above 30 days should be  one group
    No of days may repeat that means with no of days 10 .many records will be there
    There is also a field by name "AMOUNT" in my output.
    I have to calculate SUBTOTALs at the end of every group and at the end of the report i should caluculate GRAND TOTAL.
    Please remember that i should not use any any BLOCKED ALVs and for Totals i should not use the SYMBOLS provided in the application toolbar of the report
    Thanks in Advance

    <b>>>>The file has to be routed based on the Company Code</b>
    check with xpaths.
    /people/shabarish.vijayakumar/blog/2006/06/07/customise-your-xpath-expressions-in-receiver-determination
    /people/shabarish.vijayakumar/blog/2005/08/03/xpath-to-show-the-path-multiple-receivers
    <b>>>>different file should have different file name again based on the company code.</b>
    /people/jayakrishnan.nair/blog/2005/06/20/dynamic-file-name-using-xi-30-sp12-part--i
    /people/jayakrishnan.nair/blog/2005/06/28/dynamic-file-namexslt-mapping-with-java-enhancement-using-xi-30-sp12-part-ii

Maybe you are looking for

  • "Error in creating error file" message

    Tried to install Palm Desktop 6.2 that came with my new Centro and at the end the message "Error in creating error file" keeps popping up numerous times. What can be the reason? Post relates to: Centro (AT&T)

  • Trying to repair Satellite A105-S4201 (driver/software issue)

    I have been fixing a friend's laptop that had about 83 viruses on it, and ended up having to reinstall windows in order to get it to boot properly. I rebuilt a windows install disk using the I386 folder provided on her hard drive. Everything checked

  • Problem printing Payment Advice

    Hi, I am using tcode F110 But when I do automatic payment transactions as following Job started                         Step 001 started (program SAPF110S, Log for proposal run for payment on End of log                          Step 002 started (prog

  • PS document flow

    hi ALL i want to see no of process done  for perticular project e.g. raw material procurement, sub con, gr ,GI, sale order, delivery, billing . how it is possible ? is there any standard report ?

  • Canon Pixma MP500 Printer won't print with MacBook Pro

    I just bought a brand new MacBook Pro to replace an older PowerBook G4 laptop. I have a relatively new printer - maybe one year old - a Pixma MP500 from Canon that worked fine with the old laptop. I can't seem to get it to work with the new MacBook.