GL Trial Balance Report Query with date Effectivity

We have a requirement to show the GL Trial Balance report with Effective dates as Parameters.
Current Analysis:
The Journals get updated with corresponding CCID in GL_BALANCES table when the Journal is posted. GL_BALANCE is SOB specific, if the SOB has month as period then the balances in GL_BALANCES would get updated against the month(period).
To overcome the period problem, we explored the option of using a View based on GL_JE_HEADERS and GL_JE_LINES for 'Posted' Journal Batches of a SOB. We are checking whether the GL_JE_HEADERS.default_effective_date lies between the :p_from_date and :p_to_date which is sent to the Report as a parameter. The above idea does not return expected data when the custom Trial Balance Report is run.
Following is the Query we have written for it:
SELECT cc.segment4 ACCOUNT, bal.code_combination_id,
bal.begin_balance_dr
+ SUM (NVL (gljel.accounted_dr, 0)) opening_bal_dr,
bal.begin_balance_cr
+ SUM (NVL (gljel.accounted_cr, 0)) opening_bal_cr,
ffv.description,
(SELECT SUM (NVL (gljel.accounted_dr, 0))
FROM gl_je_headers gljeh,
gl_je_lines gljel,
gl_code_combinations gcc
WHERE gljeh.default_effective_date BETWEEN :p_from_date
AND :p_to_date
AND gljeh.je_header_id = gljel.je_header_id
AND gljel.code_combination_id = gcc.code_combination_id
AND gljel.period_name = gljeh.period_name
AND gljel.set_of_books_id = :p_set_of_books_id
AND gljeh.status = 'P'
AND gljel.status = 'P'
AND gljeh.actual_flag = 'A'
--AND gljel.code_combination_id =
-- bal.code_combination_id
AND gcc.segment4 = cc.segment4
GROUP BY gcc.segment4) c_dr,
(SELECT SUM (NVL (gljel.accounted_cr, 0))
FROM gl_je_headers gljeh,
gl_je_lines gljel,
gl_code_combinations gcc
WHERE gljeh.default_effective_date BETWEEN :p_from_date
AND :p_to_date
AND gljeh.je_header_id = gljel.je_header_id
AND gljel.period_name = gljeh.period_name
AND gljel.code_combination_id = gcc.code_combination_id
AND gljel.set_of_books_id = :p_set_of_books_id
AND gljeh.status = 'P'
AND gljel.status = 'P'
AND gljeh.actual_flag = 'A'
AND gcc.segment4 = cc.segment4
GROUP BY gcc.segment4) c_cr
FROM gl_period_statuses per,
gl_code_combinations cc,
gl_balances bal,
gl_je_headers gljeh,
gl_je_lines gljel,
fnd_flex_values_vl ffv,
fnd_flex_value_sets ffvs
WHERE cc.chart_of_accounts_id = :p_chart_of_accts_id
AND bal.currency_code = :p_currency
AND bal.actual_flag = 'A'
AND bal.period_name = per.period_name
AND cc.template_id IS NULL
AND cc.code_combination_id = bal.code_combination_id
AND per.set_of_books_id = :p_set_of_books_id
AND per.application_id = 101
AND :p_from_date BETWEEN per.start_date AND per.end_date
AND gljeh.period_name = per.period_name
AND gljeh.default_effective_date <= :p_from_date
AND gljeh.je_header_id = gljel.je_header_id
AND gljel.period_name = gljeh.period_name
AND gljel.set_of_books_id = :p_set_of_books_id
AND ffv.flex_value_set_id = ffvs.flex_value_set_id
AND ffvs.flex_value_set_name = 'JSWEL_ACCOUNT'
AND gljeh.status = 'P'
AND gljel.status = 'P'
AND cc.summary_flag = ffv.summary_flag
AND cc.segment4 = ffv.flex_value
AND gljeh.actual_flag = 'A'
AND gljel.code_combination_id = bal.code_combination_id
GROUP BY bal.begin_balance_dr,
bal.begin_balance_cr,
cc.segment4,
ffv.description,
bal.code_combination_id
The problem is that not all expected columns are being queried. Kindly advise as appropriate.
Note: I have also posted this thread on the Financials forum. Posting here to present the query to a larger audience with the expectation that my query would be answered.
Thanks & Regards
Sumit

suggest to create customize TB report.

Similar Messages

  • AP Trial Balance Report Query

    Hi - We use the AP Trial Balance Report as a supporting schedule to reconcile our General Ledger AP Creditor Control Account against.
    Ordinarily we would use the total remaining amount at the end of the report (which has historically balanced to the GL).
    The value in the remaining amount column has always equalled the value in the amount column.
    However, during P12 when we have generated the report we have identified several transactions that have an amount appearing in the 'remaining amount' column but no corresponding entry in the 'amount' column.
    We're not sure what the 2 column represent and why this would be the case.
    Consequently by using the 'Remaining Amount' total and comparing it to the GL balance we are out by the amounts that are only appearing on one side of the AP Trial Balance.
    I've looked at the accounting postings on the AP for some of the particualr records and can see that there is a debit and credit posting to expenditure that net off and and also a debit and credit posting to the AP Creditor Control Account that also net off
    Can anyone provide us with an explantion please?

    Hi,
    Please check note:553484.1, there are some queries provided to check the TB data like queries to compare XLA and GL data.
    Hope it helps

  • GL Trial Balance Report with Effective Dates as Parameters

    We have a requirement to show the GL Trial Balance report with Effective dates as Parameters.
    Current Analysis:
    The Journals get updated with corresponding CCID in GL_BALANCES table when the Journal is posted. GL_BALANCE is SOB specific, if the SOB has month as period then the balances in GL_BALANCES would get updated against the month(period).
    To overcome the period problem, we explored the option of using a View based on GL_JE_HEADERS and GL_JE_LINES for 'Posted' Journal Batches of a SOB. We are checking whether the GL_JE_HEADERS.default_effective_date lies between the :p_from_date and :p_to_date which is sent to the Report as a parameter. The above idea does not return expected data when the custom Trial Balance Report is run.
    Following is the Query being used:
    SELECT cc.segment4 ACCOUNT, bal.code_combination_id,
    bal.begin_balance_dr
    + SUM (NVL (gljel.accounted_dr, 0)) opening_bal_dr,
    bal.begin_balance_cr
    + SUM (NVL (gljel.accounted_cr, 0)) opening_bal_cr,
    ffv.description,
    (SELECT SUM (NVL (gljel.accounted_dr, 0))
    FROM gl_je_headers gljeh,
    gl_je_lines gljel,
    gl_code_combinations gcc
    WHERE gljeh.default_effective_date BETWEEN :p_from_date
    AND :p_to_date
    AND gljeh.je_header_id = gljel.je_header_id
    AND gljel.code_combination_id = gcc.code_combination_id
    AND gljel.period_name = gljeh.period_name
    AND gljel.set_of_books_id = :p_set_of_books_id
    AND gljeh.status = 'P'
    AND gljel.status = 'P'
    AND gljeh.actual_flag = 'A'
    --AND gljel.code_combination_id =
    -- bal.code_combination_id
    AND gcc.segment4 = cc.segment4
    GROUP BY gcc.segment4) c_dr,
    (SELECT SUM (NVL (gljel.accounted_cr, 0))
    FROM gl_je_headers gljeh,
    gl_je_lines gljel,
    gl_code_combinations gcc
    WHERE gljeh.default_effective_date BETWEEN :p_from_date
    AND :p_to_date
    AND gljeh.je_header_id = gljel.je_header_id
    AND gljel.period_name = gljeh.period_name
    AND gljel.code_combination_id = gcc.code_combination_id
    AND gljel.set_of_books_id = :p_set_of_books_id
    AND gljeh.status = 'P'
    AND gljel.status = 'P'
    AND gljeh.actual_flag = 'A'
    AND gcc.segment4 = cc.segment4
    GROUP BY gcc.segment4) c_cr
    FROM gl_period_statuses per,
    gl_code_combinations cc,
    gl_balances bal,
    gl_je_headers gljeh,
    gl_je_lines gljel,
    fnd_flex_values_vl ffv,
    fnd_flex_value_sets ffvs
    WHERE cc.chart_of_accounts_id = :p_chart_of_accts_id
    AND bal.currency_code = :p_currency
    AND bal.actual_flag = 'A'
    AND bal.period_name = per.period_name
    AND cc.template_id IS NULL
    AND cc.code_combination_id = bal.code_combination_id
    AND per.set_of_books_id = :p_set_of_books_id
    AND per.application_id = 101
    AND :p_from_date BETWEEN per.start_date AND per.end_date
    AND gljeh.period_name = per.period_name
    AND gljeh.default_effective_date <= :p_from_date
    AND gljeh.je_header_id = gljel.je_header_id
    AND gljel.period_name = gljeh.period_name
    AND gljel.set_of_books_id = :p_set_of_books_id
    AND ffv.flex_value_set_id = ffvs.flex_value_set_id
    AND ffvs.flex_value_set_name = 'JSWEL_ACCOUNT'
    AND gljeh.status = 'P'
    AND gljel.status = 'P'
    AND cc.summary_flag = ffv.summary_flag
    AND cc.segment4 = ffv.flex_value
    AND gljeh.actual_flag = 'A'
    AND gljel.code_combination_id = bal.code_combination_id
    GROUP BY bal.begin_balance_dr,
    bal.begin_balance_cr,
    cc.segment4,
    ffv.description,
    bal.code_combination_id
    Kindly suggest if I am missing anything. I am sure that the great guns here can help me out.
    Thanks
    Sumit

    suggest to create customize TB report.

  • Fault found with opening balances output on Trial Balance report

    When running the Trial Balance report and adding "Opening Balances" and taking the "OB from Start of Fiscal Year" option, the relevant opening balances are not shown from the closing balance of the prior period.
    All balance sheet accounts should always show a "brought forward" balance if one exists, whereas P&L Accounts should only carry balances forward over monthend boundaries, resetting at the point of a yearend. This is not the output provided by the report.
    This issue has been checked on numerous patch levels (including the beta release of 2007a SP01 by a support consultant) and returns the same problem.

    Hi Julian,
    I checked the functionality by myself and I have two findings:
    1) that the Trial balance displays in the opening balance balances for the P&L accounts from previous period.
    2) On the other side there is a functionality "Add closing balances" on the Trial balance selection criteria with option "Closing balances before Selected Period Only" which would adjust the presented opening balances for P&L accounts in point 1.
    Based on your description I understand that Global Support Center knows about the issue, so I think the point 2 could be used as temporary workaround till the system is corrected.
    Best Regards,
    Martin Slavik
    SAP Business One Solution Manager

  • Start Date for AP trial balance report

    Hello
    Am working on generating the Trial balance report in the Payables. I am running the "Accounts Payables Trial Balance report. For this report, in the parameters, there is "As of Date" parameter, but I do not have the "Start Date" parameter. I wanted to get a trial balance report for a given analysis period, like between Jan 03 and Dec 03.
    Can any one please let me know about this.
    Thank you
    Bob

    Hi Bob.
    I'm affraid such report is not available.
    You may get something similar by running the RX-only: Payables Invoice Register by Detail. You also have the option to change the way data appears on the report on it is an RX report.
    Octavio

  • FI doc not having effect in Balance Sheet or Trial Balance Reports

    Hello All,
    An FI doc which debits an G/L Account (Part of Asset side) & credits "Creditors Reconciliation account". when I see the effects thru FBL3N it has been posted correctly.
    But When I see Balance Sheet Report or Trial Balance Report, such reports are not taking effect of above refered FI doc.
    For Ex." GL Account 1234"  is having balance Rs. 10000/- (credit balance) (If seen thru FBL3N)
    One doc for Rs. 100 is posted which credits this account (included in above INR 10000)
    Now when I see Balance Sheet, It only shows balance of "G/L 1234" INR 9900
    Please try to resolve the problem. Waiting for your reply.
    Thanx & best Regards

    Issue resolved......GLT0 table was not updated
    Manish Katyal

  • GL Trial Balance Report with Source Field

    Hi All,
    How can we add Source Column to Trial Balance Report. As this Oracle's Seeded report is developed based on GL_BALANCES Table, how can we add source column to this report? Can anyone suggest on this to add source column to this report? If not possible to add the column then, is there any possibility to create new report ? If yes, then please suggest us to do that way
    Sources are like Receivables, Payables, Manual, Spreadsheet, etc.
    Regards,
    Bharat

    suggest to create customize TB report.

  • Related Data Source for Customer Trial Balance Report

    Hi Guys,
    Can any one please let me know the related Datasource, DSO and Cube available to develop Customer Trial Balance report on BEx.
    <b>My required Row/Colum objects are</b>
    <b>KPIs    Calculated/restricted     Formula/Logic     Unit     Authorisation</b>
    Total                Calculated     Sum of all the          Quantity
    invoiced                                     invoices for a
    Quantity                          FME
    Proposed
    Base Price        Calculated     Average price            Amount
                                                    for all invoices
                                                    per FME     
    Average Eqv.
    Base Price        Calculated     Average price            Amount
                                                    for all invoices
                                                    per FME     
    Price
    Difference             Calculated     Proposed Base         Amount
                                                    Price -  Average
                                                     Eqv. Base Price          
    <b>The aggregation behavior of the individual KPI</b>
    Key Figure                                  Aggregation            Characteristic             Time
                                              (Sum, Max, Last)          
    Net Debit Amount                         Sum                           All                  All
    Net Credit Amount                         Sum                           All                  All
    Total Debit Amount                         Sum                           All                   All
    Total Credit Amount                          Sum                          All                   All
    <b>Characteristics</b>
                         Hierarchy     Display Authorisation     Selection     Status/Mapping
    Customer Number                                 Yes     KNA1-KUNNR
    Customer Name                    
    Business Area                                  Yes        PRCTR
    Special GL Indicator                                  Yes                        Company Code                                   Yes      BKPF-BUKRS
    Industry Code                                     KNA1-BRAN1
    This is how my Functional Spec is..
    Please let me know ASAP.
    Thanks
    Murali

    hi,
    You can use this report.
    RFSLD00 Trial balance
    For Further Reference use the link.
    http://www.abapcode.info/2007/06/standard-sap-reports.html
    Regards
    Sumit AGarwal

  • AP Trial Balance Report Issue

    Hi gurus- I run the AP Trial Balance report and have an issue that I cannot reconcile with my raw data because when I export into excel, the invoice number is cut off after 20 characters.  This client has long invoice numbers.  Is there any way to get the SQL for this report and run it separately so I may see the invoice numbers and reconcile?  Thanks a lot.

    Hi,
    Please check note:553484.1, there are some queries provided to check the TB data like queries to compare XLA and GL data.
    Hope it helps

  • (11) TRIAL BALANCE REPORT에 PAID 된 INVOICE가 보이는 CASE

    제품 : FIN_AP
    작성날짜 : 2003-05-13
    TRIAL BALANCE REPORT에 PAID 된 INVOICE가 보이는 CASE
    ==============================================
    PURPOSE
    Applications 11.0.3 환경에서 AP의 Trial Balance Report 실행시 잘못 생성된 data가 보여지는 경우의 문제를 해결한다.
    Problem Description
    Paid 가 완전히 이루어져서 gl 로 까지 transfer 된 invoice가 trial balance report에 여전히 remaining 금액과 함께 나타나고 있다.
    이 때 Payament가 한번 void 되었다가 다시 reissue 된 경우이다.
    Workaround
    1. Aplist11.sql 이나 아래의 select 문으로 invoice 상태를 check한다.
    SELECT invoice_id, invoice_amount
    FROM ap_invoices_all
    WHERE invoice_num = <'problem invoice'>;
    2. Trial balance에 data가 어떻게 entry 되었는지 확인한다.
    SELECT *
    FROM ap_trial_balance
    WHERE invoice_id = <results from query #1>;
    3. Invoice 에 대한 payment 정보를 확인한다.
    SELECT invoice_id, invoice_payment_id, accounting_date, accrual_posted_flag,
    cash_posted_flag, posted_flag
    FROM ap_invoice_payments_all
    WHERE invoice_id = <results from query #1>;
    4. Payment에 대한 distribution line 정보를 확인한다.
    SELECT invoice_payment_id, payment_line_number, line_type_lookup_code,
    amount, base_amount
    FROM ap_payment_distributions_all
    WHERE invoice_payment_id = <invoice_payment_id returned in query #3>;
    일반적으로 void 되었다가 reissue 된 payment의 trial balance가 잘못된 경우는 ap_payment_distributions_all table에 data가 잘못 생성되었기 때문이다.
    위의 테이블에서 잘못 생성된 data를 correct 하거나 delete 한다음에
    patch 375496 을 이용하여 trial balance 를 rebuil 하는것이 workaround 이다.
    Solution Description
    $AP_TOP/patch/110/sql/apautopb.pls 의 버젼이 110.6 보다 낮은경우 이런 문제 예방을 위해 AP D patchset 이상을 적용한다.
    Reference Documents
    NOTE 106744.1

    maybe OP want to extract all numbers from his inbox using regular expressions?

  • Accounts Payable Trial Balance Report does not include a Credit Memo amount

    Hello Experts,
                        We are having an issue with Ap Trial Balance report not displaying a credit memo amount whereas Gl Balance shows that amount. The Credit Memo has a August invoice date and September pay date but it’s not showing up in the trial balance for August. The acconting date on the Creditmemo is in august.
    Thanks in advance for any help.

    Hi,
    We also faced the same problem and approached Oracle support.
    They provided us with a patch and datafix. Better raise an SR and get specific support.
    Regards,
    Sridhar

  • Trial balance report - general question

    Hi,
    This is the first time that I am using the trial balance report (to compare it with a Discoverer report that was built for another purpose).
    If I am running a trial balance for the end of May, and an account has a payment due in June, then the account does not appear in the report.
    The user feels that it really should.
    Can someone explain to me the purpose of the trial balance, i.e. if the report is supposed to only show the balance of due invoices or of any invoice that is not fully paid?
    Thank you.
    Leah

    Hi John,
    First, let me explain that we have an aging report that was written and our user is comparing it with the trial balance report. This is how the whole thing began. There is too big a difference. Yesterday, our user suggested that we run the trial balance for May since there is too much activity happening now in June.
    I decided to run a trial balance for the first of February 2010 figuring that was plenty safe. One of the customers listed had 4 invoices in the report. One invoice that was missing, though, was an invoice from January 17, 2010 that was paid (GL date) March 28, 2010. (There are others like that). The question: should it have been listed or not? It was in the aging report which our user felt was correct.
    Being (I assume-maybe I am wrong) that the trial balance report was not written just for our company, I am assuming that it must be correct otherwise there would be complaints from all over. That is why I finally turned to the forum to try to get an understanding. If the trial balance is correct, then the user cannot compare the aging report with the trial balance. If it is not correct, then we must turn to Oracle.
    Is there some information that I should look for from the missing invoice that I gave as an example that would explain it not appearing in the report?
    Thank you.
    Leah
    I would just like to add that I just noticed that there is another invoice from January 17th that IS in the report. It is also paid on March 28th. The only difference between the two invoices that I see, is in the distributions. The one that is in the report has the amount split between ITEM and TAX while the one that is not in the report has the full amount as type ITEM. Both have Withholding Tax as 0.
    Sorry for these added comments. We had an electricity problem all day at work (I am at home right now) but someone suggested that the invoice that is missing might have had a creation date AFTER the first of February even though the invoice day was in January and that is why it does not appear. I will not be able to check it until I am at work tomorrow (which will be around 10:00GMT).
    Thanks.
    Edited by: user476771 on Jun 21, 2010 9:52 PM
    Edited by: user476771 on Jun 21, 2010 10:21 PM
    Edited by: user476771 on Jun 22, 2010 5:41 AM

  • Customize AP Trial Balance Report in R12.1.3

    Hi
    I have to customize AP Trial Balance Report in R12 Version 12.1.3.
    Can any one please provide some pointers how do we do it?
    Here is some background for AP Trial Balance Report:
    Its an XML Publisher Report with XDODTEXE Executable. XLAAPRPT.xml is the file uploaded to data definition(Code: APTBRPT) for Accounts Payable Trial Balance . XML template XDODTEXE calls oracle’ s seeded XML template “XLAAPRPT.xml ", this template further calls package XLA_TB_AP_REPORT_PVT for Trial balance.
    Our customiztion has to populate trial balance data in to our custom table instead of global temp table . XLA_TB_AP_REPORT_PVT package has a private procedure populate_trial_balance_gt which populates trial balance data into xla_trial_balances_GT.
    Please provide some ideas for customization of standard XML publisher reports in R12.1.3.
    Any ideas are appreciated.
    Thanks
    Theja R

    Hi Vamsi,
    I've recreated the standard oracle Trial balance package & XML file . Now i'm able to populate the data into custom table as well as standard table . But the report out doesn't show data in it . it just shows report title, columns bUT NO DATA. the xml file itself doesnt contain data. The custom report completes in 2 mins. But standard report completes in 7 mins
    Steps
    1. Create custom package similar to oracle standard package & added new insert statement to populate trial balance data into custom table.
    2. created new datadefinition with new datatemplate(refering custom package) similar to oracle standard datatemplate.
    3. create template same as standard template.
    4. copy of standard conc program with custom application
    5. Ran the report ...able to populate data into custom table .....but unable to see data in the report.
    Please let me know if i'm missing anythng.

  • GL TRIAL BALANCE Report debits and Credits Reconciliation

    I am trying to do some GL Account reconciliation and found that when I run the GL Trial Balance report that the Debits and Credits Totals for the account I am interested in do not match the totals in the Account Analysis Report and that showing on the Account Inquiry Screen. The Account Inquiry totals and Account Analysis Report totals agree - showing the same figures but do not agree with the GL TB report figures.
    I've tried to run some sql to get the journal lines details from the journal tables and the output of my query agrees also with the account inquiry screen and account analysis reports totals.
    The ledger is a GBP functional currency book and practically no foreign currencies transactions are going through the subledgers.
    Has anyone seen this scenario before? Could there be a bug in the GL TB report? I've looked in 'My Oracle Support' (metalink) and can't find anything on this.
    Running R12 version 2.1.1
    Thanks.
    Edited by: user12066021 on 08-Feb-2012 02:44

    suggest to create customize TB report.

  • Building Trial Balance Report. Please help

    Hello guys,
    I have a trial balance report which reports over more than one period (say between jan and march).
    I have registered functions to get the opening and closing balance. Then included total debits and credits for each period. I'd like to think I've done this successfully and to the best of my knowledge.
    However for some code combinations I see an opening balance (say 1,000,000) , total credits 0, total debits 5,000 and closing balance 400,000. What I mean basically is, the figures do not seem to tally. When I analyze the account from GL inquiry the total debits and total credits are exactly as shown in my report. Can anyone help me with this or maybe anyone with a better query. I am doing this project on 11i.
    Many Thanks.
    Here are my functions:
    create or replace function get_open_balance
    (p_code_combination_id in number,
    p_set_of_books_id in number,
    p_period_name in varchar2)
    return number
    is
    v_open_balance number := 0;
    begin
              SELECT
    nvl(sum(bal.begin_balance_dr - bal.begin_balance_cr),0)
    INTO v_open_balance
              FROM gl_code_combinations_kfv cc
              ,gl_balances bal
              WHERE
              cc.code_combination_id = bal.code_combination_id
              AND cc.code_combination_id = p_code_combination_id
              AND bal.period_name = p_period_name
              AND bal.set_of_books_id = p_set_of_books_id
              ORDER by
              cc.concatenated_segments;
    return v_open_balance;
    exception
    when no_data_found then
    return 0;
    when others then
    return 0;
    end get_open_balance;
    create or replace function get_close_balance
    (p_code_combination_id in number,
    p_set_of_books_id in number,
    p_period_name in varchar2)
    return number
    is
    v_close_balance number := 0;
    begin
              SELECT
    nvl(sum(bal.begin_balance_dr - bal.begin_balance_cr +
    bal.period_net_dr - bal.period_net_cr),0)
    INTO v_close_balance
              FROM gl_code_combinations_kfv cc
              ,gl_balances bal
              WHERE
              cc.code_combination_id = bal.code_combination_id
              AND cc.code_combination_id = p_code_combination_id
              AND bal.period_name = p_period_name
              AND bal.set_of_books_id = p_set_of_books_id
              ORDER by
              cc.concatenated_segments;
    return v_close_balance;
    exception
    when no_data_found then
    return 0;
    when others then
    return 0;
    end get_close_balance;
    Then here is my query:
    select
    gcc.code_combination_id,
    gcc.concatenated_segments,
    gsob.currency_code,
    gsob.name sob_name,
    gl_flexfields_pkg.get_description_sql(gcc.chart_of_accounts_id,
    4, gcc.segment4) account_description,
    get_open_balance(gcc.code_combination_id, gsob.set_of_books_id, :p_period_from) opening_balance,
    nvl((select sum(entered_cr)
    from gl_je_lines gjl
    where gjl.code_combination_id = gcc.code_combination_id
    and gjl.status = 'P'
    and gjl.effective_date between to_date('01-' || :p_period_from)
    and last_day(to_date('01-' || :p_period_to))),0) credit,
    nvl((select sum(entered_dr)
    from gl_je_lines gjl
    where gjl.code_combination_id = gcc.code_combination_id
    and gjl.status = 'P'
    and gjl.effective_date between to_date('01-' || :p_period_from)
    and last_day(to_date('01-' || :p_period_to))),0) debit,
    get_close_balance(gcc.code_combination_id, gsob.set_of_books_id, :p_period_to) closing_balance
    from gl_code_combinations_kfv gcc, gl_sets_of_books gsob
    where gsob.chart_of_accounts_id = gcc.chart_of_accounts_id
    and gsob.set_of_books_id = nvl(:p_set_of_books_id, gsob.set_of_books_id)

    Excellent!
    Thank you very much.
    Here is the update (this is for R12. In 11i just replace bal.ledger_id in the get_open_balance and get_close_balance functions with bal.set_of_books_id):
    create or replace
    function get_open_balance
    (p_company in varchar2,
    p_code_combination_id in number,
    p_set_of_books_id in number,
    p_period_name in varchar2)
    return number
    is
    v_open_balance number := 0;
    v_currency_code varchar2(500);
    begin
    -- get currency code for the set of books
    begin
    select currency_code
    into v_currency_code
    from gl_sets_of_books
    where set_of_books_id = p_set_of_books_id;
    exception
    when others then
    null;
    end;
    -- get sum
    SELECT
    nvl(sum(bal.begin_balance_dr - bal.begin_balance_cr),0)
    INTO v_open_balance
    FROM gl_code_combinations_kfv cc
    ,gl_balances bal
    WHERE
    cc.code_combination_id = bal.code_combination_id
    AND cc.code_combination_id = p_code_combination_id
    AND bal.period_name = p_period_name
    AND bal.actual_flag = 'A'
    AND bal.translated_flag is null
    AND cc.segment1 = p_company
    AND bal.currency_code = v_currency_code
    AND bal.ledger_id = p_set_of_books_id
    ORDER by
    cc.concatenated_segments;
    return v_open_balance;
    exception
    when no_data_found then
    return 0;
    when others then
    return 0;
    end get_open_balance;
    create or replace
    function get_close_balance
    (p_company in varchar2,
    p_code_combination_id in number,
    p_set_of_books_id in number,
    p_period_name in varchar2)
    return number
    is
    v_close_balance number := 0;
    v_currency_code varchar2(500);
    begin
    -- get currency code for the set of books
    begin
    select currency_code
    into v_currency_code
    from gl_sets_of_books
    where set_of_books_id = p_set_of_books_id;
    exception
    when others then
    null;
    end;
    -- get sum
    SELECT
    nvl(sum(bal.begin_balance_dr - bal.begin_balance_cr +
    bal.period_net_dr - bal.period_net_cr),0)
    INTO v_close_balance
    FROM gl_code_combinations_kfv cc
    ,gl_balances bal
    WHERE
    cc.code_combination_id = bal.code_combination_id
    AND cc.code_combination_id = p_code_combination_id
    AND bal.period_name = p_period_name
    AND bal.actual_flag = 'A'
    AND bal.translated_flag is null
    AND cc.segment1 = p_company
    AND bal.currency_code = v_currency_code
    AND bal.ledger_id = p_set_of_books_id
    ORDER by
    cc.concatenated_segments;
    return v_close_balance;
    exception
    when no_data_found then
    return 0;
    when others then
    return 0;
    end get_close_balance;
    select
    gcc.code_combination_id,
    gcc.concatenated_segments,
    gsob.currency_code,
    gsob.name sob_name,
    gcc.segment3 account_code,
    gl_flexfields_pkg.get_description_sql(gcc.chart_of_accounts_id,
    3, gcc.segment3) account_description,
    get_open_balance(gcc.segment1, gcc.code_combination_id, gsob.set_of_books_id, :p_period_from) opening_balance,
    nvl((select sum(decode(gjh.currency_code, gsob.currency_code, entered_cr, accounted_cr))
    from gl_je_lines gjl, gl_je_headers gjh
    where gjl.code_combination_id = gcc.code_combination_id
    and gjh.actual_flag = 'A'
    and gjh.je_header_id = gjl.je_header_id
    and gjh.status = 'P'
    and gjh.ledger_id = gjl.ledger_id
    and gjl.status = 'P'
    and gjl.effective_date between to_date('01-' || :p_period_from)
    and last_day(to_date('01-' || :p_period_to))),0) credit,
    nvl((select sum(decode(gjh.currency_code, gsob.currency_code, entered_dr, accounted_dr))
    from gl_je_lines gjl, gl_je_headers gjh
    where gjl.code_combination_id = gcc.code_combination_id
    and gjh.actual_flag = 'A'
    and gjh.je_header_id = gjl.je_header_id
    and gjh.status = 'P'
    and gjl.status = 'P'
    and gjh.ledger_id = gjl.ledger_id
    and gjl.effective_date between to_date('01-' || :p_period_from)
    and last_day(to_date('01-' || :p_period_to))),0) debit,
    get_close_balance(gcc.segment1, gcc.code_combination_id, gsob.set_of_books_id, :p_period_to) closing_balance
    from gl_code_combinations_kfv gcc, gl_sets_of_books gsob
    where gsob.chart_of_accounts_id = gcc.chart_of_accounts_id
    and gcc.segment1 = :p_company
    and gsob.set_of_books_id = nvl(:p_set_of_books_id, gsob.set_of_books_id)
    Edited by: igwe on Jul 16, 2012 4:21 AM

Maybe you are looking for