Mimimum balance

here is the table structure for storing the transaction of cretain a/c holders.
br_daily_depo
trans_cd varchar2(3)
day_dt date
depo_accno number(8)
credit number(14,2)
debit number(14,2)
VERSION ORACLE 8.1.6
for maintaining the details of deposit holders. here i had not included a field for
storing the balance. i need to find the minimum of balace between two given dates.
(balance is (credit) -(debit) for each transaction )
following is the example of data . here i had also displayed the balace of
each transacion. in this the minimum balance is 60 and the date is 22-aug-2002.
trans_cd     day_dtdepo_accno|credit debit     |balance (not a database field)
1000|01-aug-2002|10012 1000          1000     
1000|02-aug-2002|10012           50     950     
1000|03-aug-2002|10012          40     910
1000|03-aug-2002|10012 200          1110
1000|05-aug-2002|10012 1000          2110
1000|05-aug-2002|10012      100     2010     
1000|11-aug-2002|10012 1000          3010
1000|22-aug-2002|10012      50          3060
1000|18-aug-2002|10012      2000     1060     
1000|22-aug-2002|10012      1000     60
1000|30-aug-2002|10012 1000          1060     
1000|31-aug-2002|10012      50     1010
now i am finding the minimum balance by inserting credit, debit and balace of each transaction to a temporary
table and then finding the min(balance) . but this is time consuming.
can i achieve the same by using a single query.
sincerely
raj

Although you only included one value for trans_cd in your sample data, I am assuming that you have many trans_cd values and that you want the minimum running balance for each trans_cd, so I added some additional data in the example below. I have included a query to show the test data and a query to show the running balance, but all you need is the last query to get the minimum running balance for each trans_cd.
SQL> -- test data:
SQL> SELECT * FROM br_daily_depot
  2  /
TRAN DAY_DT      DEPO_ACCNO     CREDIT      DEBIT
1000 01-aug-2002      10012       1000
1000 02-aug-2002      10012                    50
1000 03-aug-2002      10012                    40
1000 03-aug-2002      10012        200
1000 05-aug-2002      10012       1000
1000 05-aug-2002      10012                   100
1000 11-aug-2002      10012       1000
1000 12-aug-2002      10012         50
1000 18-aug-2002      10012                  2000
1000 22-aug-2002      10012                  1000
1000 30-aug-2002      10012       1000
1000 31-aug-2002      10012                    50
1001 18-aug-2002      10013       2000
1001 30-aug-2002      10013       1000
1001 31-aug-2002      10013                    50
15 rows selected.
SQL>
SQL>
SQL> -- query to get running balance:
SQL> SELECT      trans_cd, day_dt, depo_accno, credit, debit,
  2           SUM (NVL (credit, 0) - NVL (debit, 0)) OVER
  3               (PARTITION BY trans_cd ORDER BY day_dt) AS balance
  4  FROM        br_daily_depot
  5  /
TRAN DAY_DT      DEPO_ACCNO     CREDIT      DEBIT    BALANCE
1000 01-aug-2002      10012       1000                  1000
1000 02-aug-2002      10012                    50        950
1000 03-aug-2002      10012                    40        910
1000 03-aug-2002      10012        200                  1110
1000 05-aug-2002      10012       1000                  2010
1000 05-aug-2002      10012                   100       2010
1000 11-aug-2002      10012       1000                  3010
1000 12-aug-2002      10012         50                  3060
1000 18-aug-2002      10012                  2000       1060
1000 22-aug-2002      10012                  1000         60
1000 30-aug-2002      10012       1000                  1060
1000 31-aug-2002      10012                    50       1010
1001 18-aug-2002      10013       2000                  2000
1001 30-aug-2002      10013       1000                  3000
1001 31-aug-2002      10013                    50       2950
15 rows selected.
SQL>
SQL>
SQL> -- query to get minimum running balance for each trans_cd:
SQL> SELECT      trans_cd, day_dt, depo_accno, balance
  2  FROM        (SELECT        trans_cd, day_dt, depo_accno, balance,
  3                     RANK () OVER (PARTITION BY trans_cd ORDER BY balance) AS rk
  4            FROM     (SELECT   trans_cd, day_dt, depo_accno, credit, debit,
  5                               SUM (NVL (credit, 0) - NVL (debit, 0)) OVER
  6                                   (PARTITION BY trans_cd ORDER BY day_dt) AS balance
  7                      FROM     br_daily_depot))
  8  WHERE       rk = 1
  9  /
TRAN DAY_DT      DEPO_ACCNO    BALANCE
1000 22-aug-2002      10012         60
1001 18-aug-2002      10013       2000

Similar Messages

  • Open and closing balances std report

    Dear All,
    please suggest me open and closing balances std report and can i suggest my user below t.code for viewing open and closing balnces for India scenarion T.code:J3RFLVMOBVED
    Regards
    Gopal.S

    hi
    kindly chk MB5B it will fullfill your requirement
    regards
    praveen.k

  • Urgent - "Vendor balances carried forward and line items report."

    Hello,
    Is there any report which will give me the vendor balance carried forward and the line items during that period.
    ==============================================
    Format-
    eg: statement taken from 1.8.2006 to 30.9.2006 is required as
    Bal b/f …………………………… 25000 cr.
    3.8.2006 Purchase Inv XXX ……   3000 cr.
    5.9.2006 Payment Chq XX ……  26000 dr.
    Bal c/f ……………………………  2000 cr.
    ==============================================
    Please advise on this.....
    Regards,
    J

    thanks for the response, but i have already tried those transactions.
    FK10N will give me the periodic bal statements and NOT line items display which will also have balance carried forward.
    F.41 and F.43 again gives the periodic and line items...but i want the vendor balances to  be in the format given above..
    like say, account statement.
    Please advise............
    Regards,
    J

  • PS report for Actual and commitment Balance

    Dear experts,
    Is there any report in PS where i can see list of projects has actual balance and commitment balance?
    Note: I want to see only the balance of actual cost ( which is not settled) and commitment balance (Open PO, PR etc..)
    Regard
    Vetrivelan

    Hi,
    For commitment- CJI5
    actual - CJI3 with correct layout as per you requirement.
    also try S_ALR_87013558 report & go to line item report for detail actuals(& you have to change the layout accordingly) & commitment.
    hope this would help you...
    regards,
    SL

  • Open Balance on Sales Order Cost Report

    Hi SAP Group -
    I have a couple questions about the settlement of manufacturing variance to COPA.
    When our settlement process is complete (production order and sales order both settled to COPA), there is a balance remaining on the sales order cost report which is equal to the manufacturing variance on the production order.
    It seems that the manufacturing variance is posting from the production order to the sales order, but is not being assigned to the PSEG and flowing to COPA.
    I am looking for advice in two areas:
    First, how do we "clear" these balances on old orders that are already settled?
    Second, how do we prevent this from happening on future orders?
    Thanks !!!

    Refer to OSS 183250 and note 186485.
    If you don’t specify in the settlement profile for the production order that the variances are not transferred from the production order into CO-PA, you will settle the variances to <b>CO-PA twice</b>: once from the production order (broken down into variance categories), and once from the sales order item. The settlement rule still references the material and not the sales order item.
    Special Features of Product Cost by Sales Order with Valuated Sales Order Stock
    <a href="http://help.sap.com/erp2005_ehp_02/helpdata/en/90/ba66cc446711d189420000e829fbbd/content.htm">Read the topic on 'Special Features of Product Cost by Sales Order with Valuated Sales Order Stock'</a>
    You may want to check the period of the variance settlement from mfg order to sales order and ensure the settlement of sales order is also done the same period, if the type is PER.

  • Report for vendor balances

    Hello,
    I need to run a query or transaction to find the vendor opening and closing balances at the beginning and end of the financial years. Is there any standard report that can provide both these amounts? or any transparent  tables that hold them?
    Thanks a lot!

    Hi,
    Go to SAP Menu >Accounting >Accounts Payable >Information System >Reports for Accounts Payable Accounting >Vendor Balances
    Here you can find variety of reports for vendor.
    Thanks,
    Nirav

  • Report Open balance for Customers back in time

    Dear All,
    I would like to have a question: How can I report Highest Balances for Customers back in time? So I have to list Date and Amount, in the last one year, when Customers had their Highest Balances (highest outstanding amount). I have a transaction that can show actual status but I cannot report it for a long period in the past.
    Does anyone have an idea how could I do it?
    It would be very helpful.
    Thank you!
    A.

    Hello,
    Solution Manager does not desal with Customer Balances. Perhaps you wanted one of the banking industry forums, or FI AR/AP?
    In any event this question will not help you much in this forum.
    Regards,
    Paul

  • FAGL Table to fetch closing balances period wise

    Dear Experts,
    I want to fetch GL Closing balances period wise.  I have checked GLT0, where no entry is recorded.
    Further i have checked FAGLFLEXT, which does not support period wise closing balances.
    I require GL closing balance, period wise, as shown in FS10N in FI.
    My requirement is to display period wise closing balance,  on GL,  in the report.
    Please suggest and advise.
    Thanks in advance......Alok

    Hi,
    Debug the program RFGLBALANCE , the code and the logic used is easily understandable

  • GL account opening/closing balances by day

    Hi All.
    I wish to list day by day opening and closing balances of G/L account by restricting the result to a time interval.
    Anyone know how to write the query for G/L account opening & closing balances by day?
    I found this in the forum and modify it to below:
    declare @fr char(10)
    declare @to char(10)
    set @fr=convert (char(10),[%0],20)
    set @to=convert (char(10),[%1],20)
    declare @PrCl dec(19,6)
    declare @de dec(19,6)
    declare @cr dec(19,6)
    declare @acc char(20)
    declare @Pracc char(20)
    Create table #W
      (M char(10), Acc char(20), Me char(100), Tid char(10), Br char(10), TT char(30), Op dec(19,6),De dec(19,6),Cr dec(19,6),Cl dec(19,6) )
    Insert into #W (M,Acc,Me,Tid,Br,TT,Op,De,Cr,Cl)
    SELECT convert (char(10),T1.[RefDate],20)Mo, T1.[Account],T0.Memo, T0.TransId, T0.BaseRef, CASE
    WHEN T0.TransType = 13 THEN 'AR Inv'
    WHEN T0.TransType = 14 THEN 'AR CN'
    WHEN T0.TransType = 18 THEN 'AP Inv'
    WHEN T0.TransType = 19 THEN 'AP CN'
    WHEN T0.TransType = 24 THEN 'Incoming Payment'
    WHEN T0.TransType = 30 THEN 'JE'
    WHEN T0.TransType = 46 THEN 'Outgoing Payment'
    ELSE 'Other'
    END AS 'Trans Type',
      0,T1.[Debit] De , T1.[Credit] Cr,0
    FROM OJDT T0 INNER JOIN JDT1 T1 ON T0.TransId = T1.TransId
    Group by T1.[Account],convert (char(10),T1.[RefDate],20),T0.Memo, T0.TransId, T0.BaseRef, T0.TransType,  T1.Debit, T1.Credit
    Order By T1.[Account],convert (char(10),T1.[RefDate],20)
    Declare cu cursor for
    Select acc,de,cr from #W
      for update
    set @PrAcc=''
    Open cu
    Fetch next from cu into @acc,@de,@cr
    While @@FETCH_STATUS = 0
    Begin
    If @acc!=@PrAcc set @PrCl=0
    Update #W
       set op=@PrCl,
           cl=@PrCl-@Cr+@de
      where current of cu
    set @PrCl=@PrCl-@Cr+@de
    set @PrAcc=@acc
    Fetch next from cu into @acc,@de,@cr
    End
    deallocate cu
    Select * from #w
    Where M between @fr and @to
    Drop table #W
    but some of the rows are missing from the result. e.g. row with the same value of debit/credit ( same TransId and BaseRef) will come out once only in the result.
    Please guide me on the above issue.
    Thanks & Best Regards,
    Leng

    Hi,
    You have to make use of many tables for this purpose.
    1. You have to claculate the previuos period and finscal year for the given date..
    2. You have to calculate the G/L balances for this period for the given G/L account from table GLT0.(You can use some of the standard function modules for the same)
    3. You have get the line items from the various tables like BSIS,BSAS,BSIK, BASK, BSID and BSAD for the dates from the begining of the month to the given date-1. sum upthis amount with the amount retrieved from step 2 .This will be the opening balance for the given date.
    4.retrieve the data from he same tables like step 3 for the given date. This will the transactions of the given date.
    5. sum up  the amounts from step 4 with step 3. this will be the closing balance for that date.
    let me know id you want any further info..
    Reward the points if i answered your question..

  • Opening and Closing balance in FBL3N?

    Hi All,
    In other ERP systems, if you browse GL Account, i.e. FBL3N in SAP, you get the list of documents within specified period but in other systems you also get the OPENING balance as well as CLOSING balance and the current postings are in between them. Is there any standard report or report painter is to be used for such requirement.
    Balances can be checked through FS10N and S_ALR_87012301 etc. but requirement is to get the list of documents with opening and closing balance in beginning and end of the report. The best example is of Cash Journal (Txn FBCJ)
    Thanks

    Thank you Will,
    Yes, actually if other system provide such functionality then SAP should be providing that. I searched within table TSTC for such transaction but unable to get. Accountants requirement is when they execute FBL3N within specified period, the cummulative opening balance and closing balance should be provided with report.
    Thanks for your answer!
    Regards,
    Nayab

  • Opening & Closing balances of Vendor

    Hi Experts,
    I am doing a report where in i need to get the opening & closing balances for Vendor(s). I am using BSIK & BSAK tables. Are there any more tables involved and how do i carry out the calculations?
    Please help.
    Thanks
    Dany

    hi Dn,
    That would suffice for your requirement .
    Regards,
    Santosh

  • Opening & closing balances for Vendor

    Hi Experts,
    I am doing a report where in i need to get the opening & closing balances for Vendor(s). I am using BSIK & BSAK tables. Are there any more tables involved and how do i carry out the calculations?
    Please help.
    Thanks
    Dany

    Hi,
    There are various t. code to check line items for vendor like: S_ALR_87012103 but Any table is not helping to check opening/closeing balance for vendor.
    Table BSIK and BSAK are having are records for open items and close items for vendor and system calculate the balance by using these tables.
    Regards,
    Vinod

  • Opening and closing balance logic

    How to get opening and closing balances for a material and chapter-id for tarif-wise report for sales and captive consumption...
    Edited by: vijetasap on Apr 13, 2009 2:25 PM

    Hi Vijeta...
    Try posting this question related to the functional domain forum of your requirement.. you might have more luck there..

  • Opening and closing stock balances

    Hi
    What report can i use to show the opening and closing stock balances of materials for the last 12 months.
    Thanks
    Vinesh

    You can view the report in MMBE.
    other than this you can try
    MBEWH and MARDH
    Also follow the link:
    Re: op.& closing stock detail in MM
    Thanks
    Nisha

  • Opening Balances and Closing Balance of customer

    Hi,
    Does SAP provide any standard customer account statement for Opening Balances and Closing Balance for specific date range have given in selection screen?
    The statement also contains reference number, order, and Delivery number.
    Note: FBL5N Transaction code will not sufficient for the requirement, so looking for any other transaction code / report provided by SAP already for it.
    Thanks in advance,
    Shwetha

    Hi,
    There are several standard reports which could be easily accessed through the menu (Accounts Receivable - Information systems). If none of these reports does not suit your requirement, you have to develop your own.
    Regards,
    Eli

Maybe you are looking for

  • How to retain the work item in inbox of user if user press the icon cancel?

    HI, we  are using a text editor in approval section of workflow where the user needs to enter the reason for apporval or rejection. the requirement is how to retain the work item in inbox of user if user press the icon cancel? there are two icons in

  • How do I update IPad 2 to ios6.0?

    iI've upgraded my I. Pad, and gave my husband my 2. He has been trying to download the Facebook app, and keeps being told he has to upgrade to iOS 6.0. I thought I just did that! with credit card payment and all! and it still doesn't download....help

  • Service Master items in RRB

    Hello All, In RRB, during customer billing, we have to show, in the invoice/billing request, the Service Master and not the material configured DIP profile currently generic material "EXT_LABOUR". How can we copy the Service Material description into

  • A6000 - Font not supporting Indic languages like Tamil

    A6000 - If I open a webpage which is at tamil unicode, it is rendered with plentry of junk characters. It is the case with all the browsers, Chrome, Firefox, Opera, UC Browser. Same issue on my friend's A6000. So it is confirmed, it is not a browser

  • Benefits of implementing SAP GRC AC in Lifescience/Pharma.

    Dear All, Would be great if anyone could please share the benefits of implementing SAP GRC Access Controls in Lifescience/Pharma industry, more specifically which all regulations and laws it takes care of. Regards, Hersh. Edited by: HERSH GUPTA on De