AR aging report (summary by customer)

Hi Experts,
I would like to ask if how to create an aging report showing only the:
1. Customer
2. Credit Limit
3. Payment Term
4. Total AR
5. Due 0-30
6. Due 31-60
7. Due 61-90
8. Not Due
Hopefully the balance should be the same as with FBL5N. We have around 100 customers and we would like to see in one file only the summary per customer not not really the line items. Thanks.
I have consumed a lot of time searching for the answers in the forum but I cannot clearly figure out how to proceed. Which tcode do I configure this? Thanks in advance

If standard report does not suffice your requirement, then create your own.
FOR vendor USE K in transaction code instead of D.
Hello,
The following example I have given is for customers.
The only difference is in transaction codes. For customer you go to FDI1, for vendor you go to FKI1 (reports).
For Customer you go to FDI4, for vendor you go to FKI4 for forms.
Remaining all are the same.
Hello,
Go to transaction code FDI4
Select Form Type RFFRRD20 Line item analysis
Give your form name and description
Structure (Two axis) - as defaulted
Click on Create
You will have lead column
Delete the rows 2, 3 and 4
Double click on column 1
Enter the customer numbers from 1 to 999999
First column double click (A)
Slelect following values
Due date analysis 1
Days for net due date 0 to 30
Give the short name, medium name and long text for the column.
Repeat this step in next columns like 31 to 60, 61 to 90, 91 to 120 and 121 to 99999 days etc in other columns and select due date analysis 1. (B,C,D,E)
Create one more column by way of formula. To create a new column you need to double click on blue line. Put formula add all five columns you have created above. (F = ABCDE)
You prepare one more column with
Due date analysis 2 (G)
Now you prepare one more column add (F+G) = This will be total open items = over due and not due.
Now go to FDI1 and prepare a report - assign the form created in FDI4 to the report.
Characteristics you need to select are
Account Type (Select Account Type as D for customers)
Currency
Customer
Document Type
Special G/L Ind
Company Code
Change the output types and options according to your requirement.
Refer FDI2 and FDI3 for other standard reports created.
Refer FDI5 and FDI6 for other standard forms created.
Save your report and execute.
Regards,
Ravi

Similar Messages

  • Can I email the Customer Recievables Aging Reports to the customer?

    Running SAP Business One 2007 A (8.00.178) SP:00 PL:42
    In the Business Partner Module --> Business Partners Reports --> Aging --> Customer Recievables Aging
    It has been requested to me that the results from running this report needs to be emailed to the customer if the email address exists for the customer on the Business Partner Master record.
    Is this possible?
    Erin

    Hi Erin......
    Plase check this thread.......
    Auto send Email through SAP B1
    This may give you an idea......
    Regards,
    Rahul

  • Vendor Aging Report

    Hi All
    i am trying to get a legitimate vendor Aging report from within SAP
    The 2 reports that I am currently looking at are:
    S_ALR_87012085 - Vendor Payment History with OI Sorted List
    S_ALR_87012084 - Open Items - Vendor Due Date Forecast
    But both these do not bring out the output the way i want it - and i tried changing the output control and it still doesnt bring out the report as i want it - I want a report like the S_ALR_87012178 for customers, with output control 1, 6 and a 0 - which gives me a logical list of the aged customers.
    Is there one like this for vendors too? Any suggestions?
    Thank you
    Rukshana

    Hi Ruksaana,
    You can customize the vendor report to show the items overdue per vendor by using the following steps
    1. Create a form using T Code - FKI4
        In this form ( two-axis structure) provide the details for each column as per your Client requirement - Due from 0 - 30 days
        etc. You can create a column (using formula method) at the end by adding the previous columns, this will give you total     
        amount of overdue items for each vendor
    2. Create a report using T Code - FKI1
        Based on the Form created in the above step. Make additional selections based on  client  requirements like document type,
        company code, account type, currency etc. Execute the report.
    The following link will give provides detail steps for the creation of the aforementioned form and report.
    Re: AR aging report (summary by customer)
    Hope this helps.
    - Sadha.

  • Aging Report with Customer/Vendor Ref. No. should allow backdate

    Aging Reports for Suppliers and Customers.
    The current printing of the aging reports using Sales Document tab or the Purchase Document tab does not tie with the GL balances when the dates are backdated. It is important that the detail aging report to show the customer/ vendor ref. no.
    There are times when urgent outgoing/ incoming payment are entered into the system for the current period when the vendor detail aging reports or the customer statement with the customer/ vendor ref. no is not ready to be printed for the previous period.
    By allow backdating, it gives the users much needed flexibility in creating the transactions into SAP Business One without having to wait till all the previous month financial reporting is finalized. This is especially important during the financial year end.
    Current Workaround: None.

    Hello,
    Thank you for your input. The limitation is solved in 2007 A / 2007 B version as a part of new Internal Reconciliation concept.
    Regards,
    Peter Dominik
    Solution Manager
    B1 Product Definition Team

  • Customized Vendor Aging Report

    Dear Experts,
    We had developed a customized Vendor Aging Crystal Report as on Date for one of our customer which is similar to SAP's Vendor Liabilities Aging, just a minor change we have been done in our report for calculating the due date of AP Invoice only for the document type as Item, from AP Invoice document date to GRPO's posting date.
    So to build this report we had consider following transactions AP Invoice, AP Credit Memo, AP Down Payment Invoice, Outgoing Payment, Incoming Payment & Journal Entry and also we had concluded following scenario's:-
    AP Invoice based on GRPO
    Standalone AP Invoice's Item / Service.
    AP Invoice adjusted against AP Credit Memo.
    AP Invoice knocked off against Reconciliation.
    AP Credit Memo based on AP Invoice
    AP Credit Memo standalone Item /Service
    AP Credit Memo adjusted against Outgoing Payment
    AP Credit Memo knocked off against Reconciliation
    AP Down Payment Invoice - Open.
    Outgoing Payment - On Account
    Outgoing Payment - Against Transaction.
    Outgoing Payment - Direct Knocked off in Reconciliation.
    Incoming Payment - On Account
    Incoming Payment - Direct Knocked off in Reconciliation.
    Journal Entry - Adjusted and Unadjusted
    After considering all the possible scenario which do have impact with Vendor has been covered but still our report gets failed to tally with SAP Vendor Liabilities Aging Report on back dated date specially with reco happened transaction which get failed on comparison with Input parameter date against transaction date and reconciled date.
    Please refer the attachment contains Store Procedure of this report. We would highly appreciate and thankful if some one could help us in optimizing our store procedure which could get tallied with SAP Vendor Liabilities Aging Report.
    Many Thanks in Advance......
    Regards
    Krishna Kumar

    Hi,
    Not able to open attached file. Please check these threads:
    Vendor Aging Report SAP B1
    Customer Receivables Aging - Query
    Thanks & Regards,
    Nagarajan

  • Customer Aging Report

    Hi all,
    Our client requires aging report
    for a customer in the following format
    Customer Code,Name,0-30 Days,31-60 days,61-90 days,
    91-120 days,121-150 days,151-180 days,180 + above days,Row Total (all days).
    Condition:  By Aging date
    Thanks
    Jeyakanthan

    Hi Jeyakanthan,
    SAP Business One displays the relevant open receivables in four columns for the time interval for customer aging report.
    The fourth column includes open receivables for the days/months/periods prior to the first three columns. For more information please refer to the explanation for 'Time Intervals' field in Online help.
    Based on the testing in 2007 version, it is improved that there is one more column added there, which means if you set 'Time Intervals' as month, you may get five columns in aging report, the first four columns are for 4 months and the last column shows open receivables for the months prior to the first four columns.
    Regards,
    Van Xue
    SAP Business One Forums Team

  • Vendor ref. no. not appearing in print preview of vendor aging report

    Dear all,
    Vendor reference number is not appearing in print preview of vendor ageing report,we have
    customized template AGE3 collection report,we have taken print outs before a month,vendor
    reference number get printed in report,now it is not appearing
    What could be problem ?
    Any one faces this issue ?
    We are using SAP Business One 2005 B (7.40.252)  SP: 00  PL: 41.
    Latest patch upgrade to PL:46 will solve the issue ?
    Jeyakanthan

    hi all,
    Thru a workaround i brought up vendor reference number in print preview/print,
    Applied formatted search in  journal remarks of ap invoice thru query
    SELECT $[OPCH.NumAtCard]
    ,this will populate vendor ref. no in journal remarks
    which can be displayed in details in aging report.
    Is there any solution other than above to bring vendor reference number in print ?
    Jeyakanthan

  • Liabilities Ageing report not acknowledging old journal entries

    Hello,
    I have just upgraded a system from 2007A SP00 PL48 to 8.8 SP00 PL17.  When I ran the Vendor Liabilities report in 8.8 I noticed that one of the business partners has a journal entry and an open invoice.  The journal entry has no value when displayed in the report however when i open the journal up, it is showing a debit for the exact same amount as the invoice, but was created as a result of a foreign exchange gain and has not been reconciled against the invoice.  The ageing report is showing that the invoice is still outstanding and needs to be paid.  However when I run exactly the same report in version 2007, the two amounts are seen to conteract each other and therefore no oustanding amount is shown in the ageing report for this customer.  When I reproduce the scenario in 8.8 with a new invoice and new journal entry, the two transactions are shown to counteract and no outstanding balance is displayed.
    Does anyone know if there is a problem with old journal entries being recognised in the ageing report in version 8.8 or specifically journals created as a result of foreign exchange rate losses/gains?
    Many thanks,
    Kate

    Hi Kate,
    We recently upgraded to 8.8 and in reviewing the aging reports realized some manually reconciled entries had to be redone.
    In particular, it seemed to be for entries where foreign currencies were involved. There is a new field in the Internal Rec window in the top left corner - select it and the entries with only SC value will then appear (i.e. you will see all unreconciled entries) along with other entries.
    HTH,
    Heather

  • AR aging report does not print alphabetically by customer name in 8.8

    AR aging report does not print alphabetically by customer name in version 8.8.
    It is possible to create a custom layout for the receivables aging summary report (to print alphabetically by BP name) to overcome this problem. However, itu2019s not possible for the u201Cdetailed receivables aging reportu201D or u201Ccustomer statement reportu201D.
    Why has SAP changed this functionality? In version 2007 SAP takes the order of the rows set on the screen unless other order is specified in the layout.
    How can we make the u201Cdetailed receivables aging reportu201D and u201Ccustomer statement reportu201D print alphabetically by customer name?
    Steps to reproduce:
    Business partners > Business partner reports > Aging > customer receivables aging
    Doubleclick on customer name to sort it in alphabetical order.
    Click on preview and select u201Creceivables aging summary reportu201D.
    The system layouts do not print by customer name in alphabetical order.
    Click on preview and select u201Cdetailed receivables aging reportu201D. The system layouts do not print by customer name in alphabetical order.
    Also, customer statement report does not print by customer name in alphabetical order.
    In SAP 2007 versions, when a marketing document or aging report is printed, SAP takes the order of the rows set on the screen unless other order is specified in the layout.
    In SAP 8.8 although it works the same way for marketing documents, it doesnu2019t work like this for Aging reports.
    I was able to change the order for the u201CReceivables Aging Summary Reportu201D only.  We cannot overwrite a System report, I had to create a new layout called:  u201CBusiness Partner Aging (Summary) (Alphabetically Sorted)u201D.
    I couldnu2019t set up the order based on BP Name for the other 2 options: Detailed Receivables Aging Report and Customer Statement Report (One page per Customer).
    Iu2019ve checked print settings and properties, and I donu2019t see any way of changing the default order for these reports.

    Reported it to SAP support + they plan to fix it in a future patch.

  • Ageing wise vendor  and customer report

    hi....
    Where i can get ageing wise vendor  and customer report?
    Thanks & Regards
    Rekha shrama

    Hello
    First configure credit management & customise.
    A/R Summary
    Degree of ageing
    You can set the allowed degree of ageing in Customizing for Sales, under Basic Functions ® Credit Management/Risk Management ® Credit Management ® Define Automatic Credit Control.
    Under Checks in financial accounting/ old A/R summary, you can enter the permitted degree of ageing for the A/R summary, in the fíelds Permitted days and Permitted hours. Here, you can define how old the A/R summary can be, in order to be called up for a check. If the permitted degree of ageing for the A/R summary is exceeded in the credit check, then the document is blocked.
    Fields allowed days and allowed hours are only available for entry if you have entered an X in field Read A/R Summary in Customizing. The path is: Accounts Receivable and Accounts ® Credit Management ® Credit Control Account ® Make basic settings for credit management.
    Updating
    The A/R summary is either sent periodically (with the help of the report RFCMCRCV) from central Financial Accounting to the decentralized Sales and Distribution units according to ALE distribution model or, if an obsolete A/R summary is presented, updated for the credit check by the system per remote function.
    In order that the system is burdened as little as possible, SAP recommends you stick to the following order:
    Program run: Incoming payments in central FI
    Program run: Distribution A/R summary from central FI to decentralized Sales and Distribution units
    Program run: Renewed credit check for blocked sales documents in decentralized Sales and Distribution units
    Status Management for Obsolete A/R Summary
    If the A/R summary is obsolete, the credit status Credit data obsolete is set. This means that the document is blocked, and appears in the credit representativeu2019s worklist. In Customizing for Sales, in the section Automatic Credit Control, for the single, aforementioned checks, for which FI data is necessary, you can define whether a warning appears in the obsolete data, or whether a status is set.
    If you are working with the A/R summary, and would like to re-process obsolete data, it is recommended that you set a status.
    Reg
    suresh

  • Customer Ageing - Report Painter

    Hi,
       Can any tell whether we can achieve the customized reports for the customer ageing (Txn: S_ALR_870121276) through report painter. If so can i get any help for the steps to be followed /material regarding this.
    Regards,
    Nagendra Prasad.J

    This is one aging report.. have a look at it and see if its useful.
    This displays cusomer and vendor aging report.
    Award points if useful.
    REPORT zgar_ic_custvend_aging NO STANDARD PAGE HEADING
                                  LINE-SIZE 192
                                  MESSAGE-ID zz
                                  LINE-COUNT 65.
                           Data declaration                              *
    TABLES: bsik,                          "Secondary Index for Vendors
            t880,                          "Global Company Data
            t001s,                         "Accounting Clerks
            t001.                          "Company Codes
                   Internal table declaration.                           *
    *Store data from vendor tables (BSIK, BSAK).
    DATA: BEGIN OF g_t_venddata OCCURS 0,
             bukrs LIKE bsak-bukrs,          "Company code
             lifnr LIKE bsak-lifnr,          "Vendor number
             gjahr LIKE bsak-gjahr,          "Fiscal year
             zuonr LIKE bsak-zuonr,          "Assignment number
             shkzg LIKE bsak-shkzg,          "Debit/credit indicator
             dmbtr LIKE bsak-dmbtr,          "Amount in local currency
             dmbe2 LIKE bsak-dmbe2,          "Amount in global currency
             belnr LIKE bsak-belnr,          "Document number
             augdt LIKE bsak-augdt,          "Clearing date
             augbl LIKE bsak-augbl,          "Doc. no. of clearing document
             budat LIKE bsak-budat,          "Posting date
             hkont LIKE bsak-hkont,          "GL account
             waers LIKE bsak-waers,          "Currency key
             xblnr LIKE bsak-xblnr,          "Document number
             acctp TYPE c,                   "Account type. D or K
             name1 LIKE kna1-name1,          "Comp nmae
         END OF g_t_venddata.
    *Store data from customer tables (BSID, BSAD).
    DATA: BEGIN OF g_t_custdata OCCURS 0,
            kunnr LIKE bsad-kunnr,                "Customer Number
            bukrs LIKE bsad-bukrs,                "Company Code
            gjahr LIKE bsad-gjahr,                "Fiscal year
            augdt LIKE bsad-augdt,                "clearing date
            zuonr LIKE bsad-zuonr,                "Assignment number
            belnr LIKE bsad-belnr,                "acct doc no
            name1 LIKE lfa1-name1,                "name from cust master
            budat LIKE bsad-budat,                "posting date
            bldat LIKE bsad-bldat,                "document date
            xblnr LIKE bsad-xblnr,                "document number
            shkzg LIKE bsad-shkzg,                "debit/credit indicator
            dmbtr LIKE bsad-dmbtr,                "local currency
            dmbe2 LIKE bsad-dmbe2,                "Group currency
            waers LIKE bsad-waers,                "Currency key
            hkont LIKE bsad-hkont,                "GL account
            acctp TYPE c,                         "Account type  D/K
          END OF g_t_custdata.
    *Store data according to age category.
    DATA: BEGIN OF g_t_maintab OCCURS 0,
            bukrs LIKE bsad-bukrs,                "Company Code
            tpart(10) TYPE c,                     "Trading partner
            acctp TYPE c,                         "Account type D/K
            gjahr LIKE bsad-gjahr,                "Fiscal year
            augdt LIKE bsad-augdt,                "clearing date
            zuonr LIKE bsad-zuonr,                "Assignment number
            belnr LIKE bsad-belnr,                "acct doc no
            name1 LIKE lfa1-name1,                "name from cust master
            budat LIKE bsad-budat,                "posting date
            bldat LIKE bsad-bldat,                "document date
            xblnr LIKE bsad-xblnr,                "document number
            shkzg LIKE bsad-shkzg,                "debit/credit indicator
            dmbtr LIKE bsad-dmbtr,                "local currency
            hkont   LIKE bsad-hkont,              "GL account
            bktxt   LIKE bkpf-bktxt,              "Document header text
            butxt   LIKE t001-butxt,              "company name
            waers   LIKE bsad-waers,              "Currency key
            balamt  TYPE dmbtr,                   "balance amount
            amount1 TYPE dmbtr,                   "Amount for category 1
            amount2 TYPE dmbtr,                   "Amount for category 2
            amount3 TYPE dmbtr,                   "Amount for category 3
            amount4 TYPE dmbtr,                   "Amount for category 4
          END OF g_t_maintab.
    *Store all the vendor numbers
    DATA: BEGIN OF g_t_vend OCCURS 5000,
            lifnr                LIKE lfa1-lifnr,
            name1                LIKE lfa1-name1,
          END OF g_t_vend.
    *Store all the customer numbers
    DATA: BEGIN OF g_t_cust OCCURS 5000,
            kunnr                LIKE kna1-kunnr,
            name1                LIKE kna1-name1,
          END OF g_t_cust.
    *Range to store trading partner numbers.
    RANGES : r_tpart FOR lfa1-lifnr.
    Variables to maintain open items count
    DATA: g_open_items  TYPE i,
          g_open_items1 TYPE i,
          g_open_items2 TYPE i,
          g_open_items3 TYPE i,
          g_open_items4 TYPE i.
    *Header texts (For report header)
    DATA: g_headertext1(50),
          g_headertext2(16).
                   Selection screen declaration.                         *
    SELECT-OPTIONS p_ccode FOR bsik-bukrs OBLIGATORY.      "Company code
    SELECT-OPTIONS p_tpartv FOR t880-rcomp.                "Trading partner
    SELECT-OPTIONS p_clerk FOR t001s-busab.                "Accounting clerk
    SELECT-OPTIONS p_pdate FOR sy-datum.                   "Posting date
    PARAMETERS p_adate LIKE sy-datum DEFAULT sy-datum.     "Age as of date
    *GL Account codes
    SELECT-OPTIONS p_glacc FOR bsik-hkont DEFAULT '48200000' TO '48299999'
                   OBLIGATORY.
    *Data Column range (Age range)
    SELECTION-SCREEN SKIP.
    SELECTION-SCREEN BEGIN OF BLOCK age_range WITH FRAME TITLE text-001.
    SELECTION-SCREEN BEGIN OF LINE.
    SELECTION-SCREEN COMMENT 1(20) text-002.
    SELECTION-SCREEN POSITION 33.
    PARAMETERS p_range1(4) TYPE c DEFAULT '30' OBLIGATORY.
    SELECTION-SCREEN POSITION 43.
    PARAMETERS p_range2(4) TYPE c DEFAULT '60' OBLIGATORY.
    SELECTION-SCREEN POSITION 53.
    PARAMETERS p_range3(4) TYPE c DEFAULT '90' OBLIGATORY.
    SELECTION-SCREEN END OF LINE.
    SELECTION-SCREEN END OF BLOCK age_range.
    *Reporting Currency
    SELECTION-SCREEN SKIP.
    SELECTION-SCREEN BEGIN OF BLOCK crr_sel WITH FRAME TITLE text-003.
    PARAMETERS: p_local  RADIOBUTTON GROUP cgrp DEFAULT 'X',
                p_grpcrr RADIOBUTTON GROUP cgrp.
    SELECTION-SCREEN END OF BLOCK crr_sel.
    *Type of report
    SELECTION-SCREEN SKIP.
    SELECTION-SCREEN BEGIN OF BLOCK rep_sel WITH FRAME TITLE text-004.
    PARAMETERS: p_detrep  RADIOBUTTON GROUP rgrp DEFAULT 'X',
                p_sumrep  RADIOBUTTON GROUP rgrp.
    SELECTION-SCREEN END OF BLOCK rep_sel.
                               Top-Of-Page                               *
    TOP-OF-PAGE.
      IF p_detrep = 'X'.
    Write report header for detailed report.
        PERFORM f8000_write_comp_header
                USING g_t_maintab-bukrs
                      g_t_maintab-waers
                      g_t_maintab-butxt
                      text-t02
                      g_headertext1.
      ELSE.
    Write report header for summary report.
        PERFORM f8000_write_comp_header
                USING '0000'
                      g_t_maintab-waers
                      text-t05
                      g_headertext1
                      g_headertext2.
      ENDIF.
    *Eject
                           Line selection event                          *
    AT LINE-SELECTION.
      IF p_detrep = 'X'.
        SET PARAMETER ID 'BLN' FIELD g_t_maintab-belnr.
        SET PARAMETER ID 'BUK' FIELD g_t_maintab-bukrs.
        SET PARAMETER ID 'GJR' FIELD g_t_maintab-gjahr.
        IF NOT g_t_maintab-belnr IS INITIAL.
    Call transaction FB03 to display line item details.
          CALL TRANSACTION 'FB03' AND SKIP FIRST SCREEN.
        ELSE.
          MESSAGE e999 WITH text-e01.
        ENDIF.
    Clear belnr.
        MOVE space TO g_t_maintab-belnr.
      ENDIF.
    *Eject
                   Main processing of program starts here                *
    START-OF-SELECTION.
    Pad zeroes to the trading partner range to make it 10 chars
      PERFORM f0100_prepare_tradingpartners.
    Fetch data from customer and vendor tables.
      PERFORM f1000_fetch_data.
    Prepare data. Assign sign to amount, separate line items into 4 age
    categories
      PERFORM f2000_prepare_data.
         End of selection.
    END-OF-SELECTION.
    Write reports
      IF NOT g_t_maintab[] IS INITIAL.
        IF p_detrep = 'X'.
          PERFORM f4000_write_detailed_rep.
        ELSE.
          PERFORM f5000_write_summary_rep.
        ENDIF.
      ELSE.
        MESSAGE i999 WITH text-e02 text-e03.
      ENDIF.
    *Eject
    *&      Form  f0100_prepare_tradingpartners
          Subroutine for preparing trading partner numbers. Pad extra
          zeros to make trading partner field size 10.
    FORM f0100_prepare_tradingpartners.
      LOOP AT p_tpartv.
        MOVE-CORRESPONDING p_tpartv TO r_tpart.
        IF NOT r_tpart-low IS INITIAL.
          CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
               EXPORTING
                    input  = r_tpart-low
               IMPORTING
                    output = r_tpart-low.
        ENDIF.
        IF NOT r_tpart-high IS INITIAL.
          CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
               EXPORTING
                    input  = r_tpart-high
               IMPORTING
                    output = r_tpart-high.
        ENDIF.
        APPEND r_tpart.
      ENDLOOP.
    ENDFORM.                    " f0100_prepare_tradingpartners
    *Eject
    *&      Form  f1000_fetch_data
          This subroutine is used to fetch data from customer (BSID and
           BSAD) and vendor (BSIK and BSAK) tables.
    FORM f1000_fetch_data.
    *Get vendor data.
      PERFORM f1100_fetch_vend_data.
    *Get customer data.
      PERFORM f1200_fetch_cust_data.
    ENDFORM.                    " f1000_fetch_data
    *Eject
    *&      Form  f1100_fetch_vend_data
          This subroutine is used to get data from BSIK and BSAK
          tables. First all vendors are selected then all line items are
          retrieved from BSIK and BSAK tables.
    FORM f1100_fetch_vend_data.
      PERFORM f9000_progress_indicator USING text-m01.
    *Select all vendors.
      SELECT h~lifnr
             h~name1
      INTO TABLE g_t_vend
      FROM lfa1 AS h
      JOIN lfb1 AS c
        ON h~lifnr = c~lifnr
    WHERE h~lifnr IN r_tpart
       AND c~bukrs IN p_ccode
       AND c~busab IN p_clerk.
      IF NOT g_t_vend[] IS INITIAL.
        PERFORM f9000_progress_indicator USING text-m01.
    Select open line items.
        SELECT bukrs                 "company
               lifnr                 "vendor number
               augdt                 "clearing date
               augbl                 "docno for clearing doc
               zuonr                 "allocation number
               gjahr                 "fiscal year
               belnr                 "acct doc no
               buzei                 "line item within doc
               budat                 "posting date
               waers                 "Currency key
               xblnr                 "document number
               shkzg                 "debit, credit indicator
               dmbtr                 "local currency
               hkont                 "gl acct
               dmbe2                 "group currency
         FROM bsik
         INTO CORRESPONDING FIELDS OF TABLE g_t_venddata
         FOR ALL ENTRIES IN g_t_vend
         WHERE bukrs IN p_ccode           "company code
         AND lifnr = g_t_vend-lifnr       "trading partner
         AND budat IN  p_pdate            "Posting date
         AND budat <= p_adate
         AND hkont IN p_glacc             "gl acct
        PERFORM f9000_progress_indicator USING text-m04.
    Select cleared line items.
        SELECT bukrs                 "company
               lifnr                 "vendor number
               augdt                 "clearing date
               augbl                 "docno for clearing doc
               zuonr                 "allocation number
               gjahr                 "fiscal year
               belnr                 "acct doc no
               buzei                 "line item within doc
               budat                 "posting date
               waers                 "Currency key
               xblnr                 "document number
               shkzg                 "debit, credit indicator
               dmbtr                 "local currency
               hkont                 "gl acct
               dmbe2                 "group currency
         FROM bsak
         APPENDING CORRESPONDING FIELDS OF TABLE g_t_venddata
         FOR ALL ENTRIES IN g_t_vend
         WHERE bukrs IN p_ccode           "Company code
         AND lifnr =   g_t_vend-lifnr     "Selected vendors
         AND augdt >   p_adate
         AND budat IN  p_pdate            "Posting date
         AND budat <=  p_adate
         AND hkont IN  p_glacc            "GL acct
      ENDIF.
      IF NOT g_t_venddata[] IS INITIAL.
    *Set Account type flag for vendors -- 'K'.
        SORT g_t_venddata BY bukrs lifnr.
        SORT g_t_vend     BY lifnr.
        g_t_venddata-acctp = text-k01.
        MODIFY g_t_venddata TRANSPORTING acctp WHERE acctp = ' '.
    Add vendor names.
        LOOP AT g_t_venddata WHERE name1 = ' '.
          READ TABLE g_t_vend
               WITH KEY lifnr = g_t_venddata-lifnr BINARY SEARCH.
          IF sy-subrc = 0.
            g_t_venddata-name1 = g_t_vend-name1.
            MODIFY g_t_venddata TRANSPORTING name1 WHERE lifnr =
                   g_t_venddata-lifnr.
          ENDIF.
        ENDLOOP.
      ENDIF.
    ENDFORM.                    " f1100_fetch_vend_data
    *Eject
    *&      Form  f1200_fetch_cust_data
          This function module is used to get data from BSID and BSAD
          tables. First all customers are selected then all line items
          are retrieved from BSIK and BSAK tables.
    FORM f1200_fetch_cust_data.
      PERFORM f9000_progress_indicator USING text-m06.
    *Select all customers.
      SELECT h~kunnr
           h~name1
      INTO TABLE g_t_cust
      FROM kna1 AS h
      JOIN knb1 AS c
        ON h~kunnr = c~kunnr
    WHERE h~kunnr IN r_tpart
       AND c~bukrs IN p_ccode
       AND c~busab IN p_clerk.
      IF NOT g_t_cust[] IS INITIAL.
        PERFORM f9000_progress_indicator USING text-m06.
    *Fetch customer open items.
        SELECT bukrs                 "company
               kunnr                 "customer number
               augdt                 "clearing date
               augbl                 "docno for clearing doc
               zuonr                 "allocation number
               gjahr                 "fiscal year
               belnr                 "acct doc no
               buzei                 "line item within doc
               budat                 "posting date
               waers                 "Currency key
               xblnr                 "document number
               shkzg                 "debit, credit indicator
               dmbtr                 "local currency
               hkont                 "gl acct
               dmbe2                 "group currency
         FROM bsid
         INTO CORRESPONDING FIELDS OF TABLE g_t_custdata
         FOR ALL ENTRIES IN g_t_cust
         WHERE bukrs IN p_ccode           "company code
         AND kunnr = g_t_cust-kunnr       "Selected customer
         AND budat IN  p_pdate            "Posting date
         AND budat <= p_adate
         AND hkont IN  p_glacc            "GL acct
        PERFORM f9000_progress_indicator USING text-m07.
    Select Customer cleared line items.
        SELECT bukrs                 "company
               kunnr                 "customer number
               augdt                 "clearing date
               augbl                 "docno for clearing doc
               zuonr                 "allocation number
               gjahr                 "fiscal year
               belnr                 "acct doc no
               buzei                 "line item within doc
               budat                 "posting date
               waers                 "Currency key
               xblnr                 "document number
               shkzg                 "debit, credit indicator
               dmbtr                 "local currency
               hkont                 "gl acct
               dmbe2                 "group currency
         FROM bsad
         APPENDING CORRESPONDING FIELDS OF TABLE g_t_custdata
         FOR ALL ENTRIES IN g_t_cust
         WHERE bukrs IN p_ccode           "company code
         AND kunnr = g_t_cust-kunnr       "Selected customer
         AND augdt > p_adate
         AND budat IN  p_pdate            "Posting date
         AND budat <= p_adate
         AND hkont IN p_glacc             "GL acct
      ENDIF.
      IF NOT g_t_custdata[] IS INITIAL.
    *Set account type for customers -- 'D'.
        SORT g_t_custdata BY bukrs kunnr.
        SORT g_t_cust     BY kunnr.
        g_t_custdata-acctp = text-d01.
        MODIFY g_t_custdata TRANSPORTING acctp WHERE acctp = ' '.
    Add customer names.
        LOOP AT g_t_custdata WHERE name1 = ' '.
          READ TABLE g_t_cust
               WITH KEY kunnr = g_t_custdata-kunnr BINARY SEARCH.
          IF sy-subrc = 0.
            g_t_custdata-name1 = g_t_cust-name1.
            MODIFY g_t_custdata TRANSPORTING name1 WHERE kunnr =
                   g_t_custdata-kunnr.
          ENDIF.
        ENDLOOP.
      ENDIF.
    ENDFORM.                    " f1200_fetch_cust_data
    *Eject
    *&      Form  f2000_Prepare_data
          This function module is used to format data according to report
          1. Fetch local or global amount value according to user
             parametrs.
          2. Sign is assigned to each amount
          3. Line items are categorized according to the aging category
          4. Populate document header text.
          5. Populate company names.
    FORM f2000_prepare_data.
      DATA : l_amount TYPE dmbtr,
             l_age_of_item TYPE p,
             l_as_of_age TYPE d,
             l_posting_date TYPE d,
             l_time TYPE t,
             l_count TYPE sy-tabix.
      DATA: BEGIN OF l_t_doc_txt OCCURS 0,
            bukrs TYPE bkpf-bukrs,
            belnr TYPE bkpf-belnr,
            bktxt LIKE bkpf-bktxt,
            END OF l_t_doc_txt.
      DATA: BEGIN OF l_t_curr_txt OCCURS 0,
              bukrs LIKE t001-bukrs,
              waers LIKE t001-waers,
              butxt LIKE t001-butxt,
            END OF l_t_curr_txt.
      PERFORM f9000_progress_indicator USING text-m03.
      l_as_of_age = p_adate.
      MOVE text-t01 TO l_time.
    *Prepare G_T_MAINTAB, 1. Populate vendor data.
      LOOP AT g_t_venddata.
        CLEAR: g_t_maintab, l_amount, l_age_of_item, l_posting_date.
        MOVE-CORRESPONDING g_t_venddata TO g_t_maintab.
        g_t_maintab-tpart = g_t_venddata-lifnr.
    Check for currency selected by the user.
        IF p_local = 'X'.
          l_amount = g_t_venddata-dmbtr.
        ELSE.
          l_amount = g_t_venddata-dmbe2.
        ENDIF.
    Check for type of transaction. Debit or Credit.
        IF g_t_venddata-shkzg = 'H'.
          l_amount = l_amount * -1.
        ENDIF.
        MOVE g_t_venddata-budat TO l_posting_date.
    Assign amount value to appropriate aging category.
    Calculate age of line item
        CALL FUNCTION '/SDF/CMO_DATETIME_DIFFERENCE'
             EXPORTING
                  date1            = l_posting_date
                  time1            = l_time
                  date2            = l_as_of_age
                  time2            = l_time
             IMPORTING
                  datediff         = l_age_of_item
             EXCEPTIONS
                  invalid_datetime = 1
                  OTHERS           = 2.
        IF sy-subrc <> 0.
          MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
                  WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
        ENDIF.
        IF l_age_of_item <= p_range1.                           "Range1
          g_t_maintab-amount1 = l_amount.
        ELSE.
          IF l_age_of_item > p_range1 AND l_age_of_item <= p_range2."Range2
            g_t_maintab-amount2 = l_amount.
          ELSE.
            IF l_age_of_item > p_range2
                AND l_age_of_item <= p_range3.                  "Range3
              g_t_maintab-amount3 = l_amount.
            ELSE.                                               "Range4
              g_t_maintab-amount4 = l_amount.
            ENDIF.
          ENDIF.
        ENDIF.
    Assign balance amounts.
        g_t_maintab-balamt  = l_amount.
    Add record to main internal table
        APPEND g_t_maintab.
      ENDLOOP.
    *Prepare G_T_MAINTAB, 2. Populate customer data.
      LOOP AT g_t_custdata.
        CLEAR: g_t_maintab, l_amount, l_age_of_item, l_posting_date.
        MOVE-CORRESPONDING g_t_custdata TO g_t_maintab.
        g_t_maintab-tpart = g_t_custdata-kunnr.
    Check for currency selected by the user.
        IF p_local = 'X'.
          l_amount = g_t_custdata-dmbtr.
        ELSE.
          l_amount = g_t_custdata-dmbe2.
        ENDIF.
    Check for type of transaction. Debit or Credit.
        IF g_t_custdata-shkzg = 'H'.
          l_amount = l_amount * -1.
        ENDIF.
        MOVE g_t_custdata-budat TO l_posting_date.
    Assign amount value to appropriate aging category.
    Calculate age of line item
        CALL FUNCTION '/SDF/CMO_DATETIME_DIFFERENCE'
             EXPORTING
                  date1            = l_posting_date
                  time1            = l_time
                  date2            = l_as_of_age
                  time2            = l_time
             IMPORTING
                  datediff         = l_age_of_item
             EXCEPTIONS
                  invalid_datetime = 1
                  OTHERS           = 2.
        IF sy-subrc <> 0.
          MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
                  WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
        ENDIF.
        IF l_age_of_item <= p_range1.                           "Range1
          g_t_maintab-amount1 = l_amount.
        ELSE.
          IF l_age_of_item > p_range1 AND l_age_of_item <= p_range2."Range2
            g_t_maintab-amount2 = l_amount.
          ELSE.
            IF l_age_of_item > p_range2
               AND l_age_of_item <= p_range3.                   "Range3
              g_t_maintab-amount3 = l_amount.
            ELSE.                                               "Range4
              g_t_maintab-amount4 = l_amount.
            ENDIF.
          ENDIF.
        ENDIF.
    Assign balance amounts.
        g_t_maintab-balamt  = l_amount.
        APPEND g_t_maintab.
      ENDLOOP.
      IF NOT g_t_maintab[] IS INITIAL.
        SORT g_t_maintab BY bukrs belnr.
        SELECT bukrs belnr bktxt FROM bkpf
              INTO CORRESPONDING FIELDS OF TABLE l_t_doc_txt
              FOR ALL ENTRIES IN g_t_maintab
              WHERE bukrs = g_t_maintab-bukrs AND
                    belnr = g_t_maintab-belnr AND
                    gjahr = g_t_maintab-gjahr.
        SELECT bukrs butxt waers FROM t001
               INTO CORRESPONDING FIELDS OF TABLE l_t_curr_txt
               WHERE bukrs IN p_ccode.
        SORT l_t_doc_txt BY bukrs belnr.
        SORT l_t_curr_txt BY bukrs.
    Add Document header texts
        LOOP AT g_t_maintab.
          l_count = sy-tabix.
          READ TABLE l_t_doc_txt
               WITH KEY bukrs = g_t_maintab-bukrs belnr = g_t_maintab-belnr
               BINARY SEARCH.
          IF sy-subrc = 0.
            g_t_maintab-bktxt = l_t_doc_txt-bktxt.
            MODIFY g_t_maintab INDEX l_count TRANSPORTING bktxt.
          ENDIF.
          CLEAR l_t_doc_txt-bktxt.
        ENDLOOP.
        PERFORM f9000_progress_indicator USING text-m03.
    Update company name and currency field.
        LOOP AT g_t_maintab WHERE butxt =  ' ' OR waers = ' '.
          READ TABLE l_t_curr_txt
               WITH KEY bukrs = g_t_maintab-bukrs BINARY SEARCH.
          IF sy-subrc = 0.
            g_t_maintab-butxt    = l_t_curr_txt-butxt.
            g_t_maintab-waers    = l_t_curr_txt-waers.
            MODIFY g_t_maintab TRANSPORTING butxt waers
                      WHERE bukrs = g_t_maintab-bukrs.
          ENDIF.
          CLEAR: l_t_curr_txt-butxt, l_t_curr_txt-waers.
        ENDLOOP.
      ENDIF.                    "IF NOT g_t_maintab[] IS INITIAL
    ENDFORM.                    " f2000_Prepare_data
    *Eject
    *&      Form  f4000_write_detailed_rep
          This subroutine is used to write detailed report.
    FORM f4000_write_detailed_rep.
      DATA l_t_maintab LIKE g_t_maintab.
    Variables for summary amount of each account type of a trading pair
      DATA: l_tpart_acc1 TYPE dmbtr,
            l_tpart_acc2 TYPE dmbtr,
            l_tpart_acc3 TYPE dmbtr,
            l_tpart_acc4 TYPE dmbtr,
            l_tpart_acc_bal TYPE dmbtr.
    Variables for summary amount of each trading pair
      DATA: l_tpart1 TYPE dmbtr,
            l_tpart2 TYPE dmbtr,
            l_tpart3 TYPE dmbtr,
            l_tpart4 TYPE dmbtr,
            l_tpart_bal TYPE dmbtr.
      SET TITLEBAR 'DETAILED_REPORT'.
    Prepare header texts for report header.
      CONCATENATE  p_adate4(2)  '/' p_adate6(2) '/' p_adate+0(4) INTO
           g_headertext1.
      CONCATENATE text-h20 g_headertext1
                  INTO g_headertext1 SEPARATED BY space.
      SORT g_t_maintab BY bukrs tpart acctp.
    *Start detailed report.
      FORMAT INTENSIFIED OFF.
      LOOP AT g_t_maintab.
        l_t_maintab = g_t_maintab.
    *At new company code write page header
        AT NEW bukrs.
          g_t_maintab = l_t_maintab.
          NEW-PAGE.
        ENDAT.
    *Write line item records.
        WRITE:/2    l_t_maintab-tpart,      "Trading partner
                14  l_t_maintab-acctp,      "Account type
                17  l_t_maintab-belnr,      "Document number
                35  l_t_maintab-budat,      "posting date
                47  l_t_maintab-xblnr,      "Reference doc. number
                65  l_t_maintab-bktxt,      "Doc header text.
                92  l_t_maintab-balamt,     "balance amount
                114 l_t_maintab-amount1,    "Amount cat 1
                136 l_t_maintab-amount2,    "Amount cat 2
                158 l_t_maintab-amount3,    "Amount cat 3
                180 l_t_maintab-amount4.    "Amount cat 4
        g_t_maintab-bukrs = l_t_maintab-bukrs.
        g_t_maintab-gjahr = l_t_maintab-gjahr.
        g_t_maintab-belnr = l_t_maintab-belnr.
    Hide values so that these can be used on line selection event.
        HIDE: g_t_maintab-bukrs, g_t_maintab-gjahr, g_t_maintab-belnr.
    Calculate amounts for account summary.
        l_tpart_acc1    = l_tpart_acc1 + l_t_maintab-amount1.
        l_tpart_acc2    = l_tpart_acc2 + l_t_maintab-amount2.
        l_tpart_acc3    = l_tpart_acc3 + l_t_maintab-amount3.
        l_tpart_acc4    = l_tpart_acc4 + l_t_maintab-amount4.
        l_tpart_acc_bal = l_tpart_acc_bal + l_t_maintab-balamt.
    Calculate amounts for trading partner summary.
        l_tpart1 = l_tpart1 + l_t_maintab-amount1.
        l_tpart2 = l_tpart2 + l_t_maintab-amount2.
        l_tpart3 = l_tpart3 + l_t_maintab-amount3.
        l_tpart4 = l_tpart4 + l_t_maintab-amount4.
        l_tpart_bal = l_tpart_bal + l_t_maintab-balamt.
    *At end of one account type write summary for account type.
        AT END OF acctp.
          g_t_maintab = l_t_maintab.
          PERFORM f8100_write_acctype_summary
                  USING l_tpart_acc1 l_tpart_acc2 l_tpart_acc3 l_tpart_acc4
                        l_tpart_acc_bal l_t_maintab-acctp l_t_maintab-tpart
                        l_t_maintab-name1.
          CLEAR: l_tpart_acc1, l_tpart_acc2, l_tpart_acc3, l_tpart_acc4,
                 l_tpart_acc_bal.
        ENDAT.
    At end of trading pair, write trading partner summary.
        AT END OF tpart.
          g_t_maintab = l_t_maintab.
          PERFORM f8200_write_tradingpair_summar
                  USING l_tpart1 l_tpart2 l_tpart3 l_tpart4 l_tpart_bal
                        l_t_maintab-tpart l_t_maintab-name1.
          CLEAR: l_tpart1, l_tpart2, l_tpart3, l_tpart4, l_tpart_bal.
        ENDAT.
      ENDLOOP.
    ENDFORM.                    " f4000_write_detailed_rep
    *Eject
    *&      Form  f5000_write_summary_rep
          Subroutine to write summary report.
    FORM f5000_write_summary_rep.
    *Counters for trading partner
      DATA: l_count_tpart  TYPE i,     "Counter for trading pairs.
            l_count_tpart1 TYPE i,     "Trading partner in age cat 1
            l_count_tpart2 TYPE i,     "Trading partner in age cat 2
            l_count_tpart3 TYPE i,     "Trading partner in age cat 3
            l_count_tpart4 TYPE i.     "Trading partner in age cat 4
    Flag for trading partner count.
      DATA: l_flag_tpart1 TYPE c,     "Flag for Trading partner in age cat 1
            l_flag_tpart2 TYPE c,     "Flag for Trading partner in age cat 2
            l_flag_tpart3 TYPE c,     "Flag for Trading partner in age cat 3
            l_flag_tpart4 TYPE c.     "Flag for Trading partner in age cat 4
    Variables to store sum of all line items for a company code.
      DATA: l_comp_amt_bal TYPE dmbtr,
            l_comp_amt1    TYPE dmbtr,
            l_comp_amt2    TYPE dmbtr,
            l_comp_amt3    TYPE dmbtr,
            l_comp_amt4    TYPE dmbtr.
    Internal table to store sum of amounts for all the companies selected.
      DATA: BEGIN OF l_t_compall_amt OCCURS 0,
              waers   LIKE bsad-waers,              "Currency key
              balamt  TYPE dmbtr,                   "Total balance amount
              amount1 TYPE dmbtr,                   "Amount for category 1
              amount2 TYPE dmbtr,                   "Amount for category 2
              amount3 TYPE dmbtr,                   "Amount for category 3
              amount4 TYPE dmbtr,                   "Amount for category 4
            END OF l_t_compall_amt.
      DATA: l_tpart_amt_bal TYPE dmbtr,
            l_tpart_amt1    TYPE dmbtr,
            l_tpart_amt2    TYPE dmbtr,
            l_tpart_amt3    TYPE dmbtr,
            l_tpart_amt4    TYPE dmbtr.
      DATA l_currtxt(11).
      DATA l_t_maintab LIKE g_t_maintab.
    Prepare header texts for report header.
      CONCATENATE  p_adate4(2)  '/' p_adate6(2) '/' p_adate+0(4) INTO
                   g_headertext2.
      CONCATENATE text-t04 p_glacc-low text-h06 p_glacc-high
                  INTO g_headertext1 SEPARATED BY space.
      CONCATENATE text-t03 g_headertext2 INTO g_headertext2 SEPARATED BY
                  space.
      SET TITLEBAR 'SUMMARY_REPORT'.
      SORT g_t_maintab BY bukrs tpart acctp.
    DESCRIBE TABLE g_t_maintab LINES l_count_tpart. "***
      FORMAT INTENSIFIED OFF.
      CLEAR: l_flag_tpart1, l_flag_tpart2, l_flag_tpart3, l_flag_tpart4.
      CLEAR: l_tpart_amt_bal,
             l_tpart_amt1,
             l_tpart_amt2,
             l_tpart_amt3,
             l_tpart_amt4.
      CLEAR: l_comp_amt_bal,
             l_comp_amt1,
             l_comp_amt2,
             l_comp_amt3,
             l_comp_amt4.
    Write summary report.
      LOOP AT g_t_maintab.
        l_t_maintab = g_t_maintab.
    Maintain open items count
        g_open_items = g_open_items + 1.
        IF l_t_maintab-amount1 <> 0.
          g_open_items1 = g_open_items1 + 1.
        ELSEIF l_t_maintab-amount2 <> 0.
          g_open_items2 = g_open_items2 + 1.
        ELSEIF l_t_maintab-amount3 <> 0.
          g_open_items3 = g_open_items3 + 1.
        ELSEIF l_t_maintab-amount4 <> 0.
          g_open_items4 = g_open_items4 + 1.
        ENDIF.
    *Calculate amounts for trading partners and maintain trading partner
    *count.
        l_tpart_amt_bal = l_tpart_amt_bal + l_t_maintab-balamt.
        IF g_t_maintab-amount1 <> 0.
          l_tpart_amt1    = l_tpart_amt1    + l_t_maintab-amount1.
    Increase count according to flag.
          IF l_flag_tpart1 IS INITIAL.
            l_count_tpart1 = l_count_tpart1 + 1.
            l_flag_tpart1 = 'X'.
          ENDIF.
        ELSEIF g_t_maintab-amount2 <> 0.
          l_tpart_amt2    = l_tpart_amt2    + l_t_maintab-amount2.
    Increase count according to flag.
          IF l_flag_tpart2 IS INITIAL.
            l_count_tpart2 = l_count_tpart2 + 1.
            l_flag_tpart2 = 'X'.
          ENDIF.
        ELSEIF g_t_maintab-amount3 <> 0.
          l_tpart_amt3    = l_tpart_amt3    + l_t_maintab-amount3.
    Increase count according to flag.
          IF l_flag_tpart3 IS INITIAL.
            l_count_tpart3 = l_count_tpart3 + 1.
            l_flag_tpart3 = 'X'.
          ENDIF.
        ELSEIF g_t_maintab-amount4 <> 0.
          l_tpart_amt4    = l_tpart_amt4    + l_t_maintab-amount4.
    Increase count according to flag.
          IF l_flag_tpart4 IS INITIAL.
            l_count_tpart4 = l_count_tpart4 + 1.
            l_flag_tpart4 = 'X'.
          ENDIF.
        ENDIF.                                     "g_t_maintab-amount1 <> 0
    Calculate total of amount for all companies
    Separate totals into different rows for different local currency.
        IF p_local = 'X'.
          READ TABLE l_t_compall_amt WITH KEY waers = l_t_maintab-waers.
        ELSE.
          READ TABLE l_t_compall_amt INDEX 1.
        ENDIF.
        IF sy-subrc = 0.
          l_t_compall_amt-balamt  = l_t_compall_amt-balamt  +
                                    l_t_maintab-balamt.
          l_t_compall_amt-amount1 = l_t_compall_amt-amount1  +
                                    l_t_maintab-amount1.
          l_t_compall_amt-amount2 = l_t_compall_amt-amount2  +
                                    l_t_maintab-amount2.
          l_t_compall_amt-amount3 = l_t_compall_amt-amount3  +
                                    l_t_maintab-amount3.
          l_t_compall_amt-amount4 = l_t_compall_amt-amount4  +
                                    l_t_maintab-amount4.
          MODIFY l_t_compall_amt FROM l_t_compall_amt INDEX sy-tabix.
        ELSE.
          MOVE-CORRESPONDING l_t_maintab TO l_t_compall_amt.
          IF NOT p_local = 'X'.
            MOVE 'GRP' TO l_t_maintab-waers.
          ENDIF.
          APPEND l_t_compall_amt.
        ENDIF.
    Calculate total amount for current company.
        l_comp_amt_bal = l_comp_amt_bal + l_t_maintab-balamt.
        l_comp_amt1    = l_comp_amt1    + l_t_maintab-amount1.
        l_comp_amt2    = l_comp_amt2    + l_t_maintab-amount2.
        l_comp_amt3    = l_comp_amt3    + l_t_maintab-amount3.
        l_comp_amt4    = l_comp_amt4    + l_t_maintab-amount4.
        IF p_local = 'X'.
          CONCATENATE text-h04 l_t_maintab-waers
                      INTO l_currtxt SEPARATED BY space.
        ELSE.
          MOVE text-h05 TO l_currtxt.
        ENDIF.
    Write subtotal for each trading partner.
        AT END OF tpart.
          l_count_tpart = l_count_tpart + 1.
    Write the summary lines
          WRITE:/2    l_t_maintab-bukrs,
                 10   l_t_maintab-tpart,
                 42   l_tpart_amt_bal,
                 64   l_currtxt,
                 87   l_tpart_amt1,
                 109  l_tpart_amt2,
                 131  l_tpart_amt3,
                 153  l_tpart_amt4.
          CLEAR: l_tpart_amt_bal,
                 l_tpart_amt1,
                 l_tpart_amt2,
                 l_tpart_amt3,
                 l_tpart_amt4.
          CLEAR: l_flag_tpart1, l_flag_tpart2, l_flag_tpart3, l_flag_tpart4.
        ENDAT.
    Write subtotal for each company code.
        AT END OF bukrs.
          PERFORM f8300_write_comp_summ USING l_comp_amt_bal
                                              l_comp_amt1
                                              l_comp_amt2
                                              l_comp_amt3
                                              l_comp_amt4
                                              l_t_maintab-bukrs
                                              l_t_maintab-butxt
                                              l_t_maintab-waers.
          CLEAR: l_comp_amt_bal,
                 l_comp_amt1,
                 l_comp_amt2,
                 l_comp_amt3,
                 l_comp_amt4.
        ENDAT.
      ENDLOOP.
     

  • Customer / Vendor Aging Report

    Hi,
    It´s important to consider the next filter or selection criteria for the reports:
    -. Customer and Vendor Aging Reports
    Filters:
    -. by Sales Employee (Customer Aging)
    -. by Buyer (Vendor Aging)
    regards

    Hello Humberto,
    New selection criteria of Sales Employee/Buyer is part of enhancements of Aging Reports in SAP Business One 8.8 release.
    When you generate the aging report in v8.8:
    u2022 You can group the report by customer or sales employee in the customer receivables aging report, and by vendor or buyer in the vendor liabilities aging report.
    u2022 You can specify more flexible time interval. For the time interval Days, 4 new fields are added for you to specify the duration.
    u2022 You can hide the Future Remit column on the report by choosing Ignore Future Remit.
    u2022 When the aging report has been generated, you can view multicustomer/multivendor detailed information in the aging report window. There is no need to double-click each customer/vendor row to view the details.
    Peter Dominik
    B1 Solution Management

  • Vendor aging report ,customer aging report

    hi to all
    can u pls what is vendor aging report . what is the purpose of it . can u pls some theoritical description
    i will definitely reward points pls its urgent  pls tell if there r any standard reports exists for theese . pls give some custom reports on theese  with coding.
      and for customer aging also
    pls.................

    Hi,
    Check the Vendor against report code:
    REPORT zvender_os NO STANDARD PAGE HEADING
    LINE-SIZE 132
    LINE-COUNT 65.
    Tables
    TABLES: bsik, "open items (A/C: Secondary Index for Customers)
    lfa1, "customer master
    lfb1,
    rf140, "temp stru (Work Fields for Corrence(SAPF140*))
    bsak, "cleared items (A/c Secnd Index for Cust(Clrms))
    skat.
    constants and variables
    TYPE-POOLS: slis.
    DATA: fieldcat TYPE slis_t_fieldcat_alv,
    fieldcat1 TYPE slis_t_fieldcat_alv,
    fieldcat_ln TYPE slis_fieldcat_alv,
    layout_in TYPE slis_layout_alv,
    layout_in1 TYPE slis_layout_alv,
    sortcat TYPE slis_t_sortinfo_alv,
    sortcat1 TYPE slis_t_sortinfo_alv,
    sortcat_ln LIKE LINE OF sortcat,
    eventcat1 TYPE slis_t_event,
    eventcat TYPE slis_t_event,
    eventcat_ln LIKE LINE OF eventcat,
    col_pos TYPE i.
    DATA: targ_month(2) TYPE n, "0001
    targ_year(4) TYPE n, "0001
    targ_mth_abs TYPE p, "0001
    doc_month(2) TYPE n, "0001
    doc_year(4) TYPE n, "0001
    doc_mth_abs TYPE p, "0001
    mth_result TYPE p, "0001
    doc_days TYPE p,
    targ_days TYPE p,
    addl_days TYPE p,
    ext_days TYPE p,
    v_days(3) TYPE c,
    v_kkber LIKE knkk-kkber.
    DATA:
    BEGIN OF inrec OCCURS 1000, "0001
    lifnr LIKE bsik-lifnr,
    belnr LIKE bsik-belnr,
    gjahr LIKE bsik-gjahr,
    bldat LIKE bsik-bldat,
    xblnr LIKE bsik-xblnr,
    blart LIKE bsik-blart,
    sgtxt LIKE bsik-sgtxt,
    shkzg LIKE bsik-shkzg,
    dmbtr LIKE bsik-dmbtr,
    zfbdt LIKE bsik-zfbdt,
    zbd1t LIKE bsik-zbd1t,
    zbd2t LIKE bsik-zbd2t,
    zbd3t LIKE bsik-zbd3t,
    zuonr LIKE bsik-zuonr,
    END OF inrec.
    DATA:
    BEGIN OF inrect OCCURS 1000, "0001
    lifnr LIKE bsik-lifnr,
    belnr LIKE bsik-belnr,
    gjahr LIKE bsik-gjahr,
    bldat LIKE bsik-bldat,
    xblnr LIKE bsik-xblnr,
    blart LIKE bsik-blart,
    sgtxt LIKE bsik-sgtxt,
    shkzg LIKE bsik-shkzg,
    dmbtr LIKE bsik-dmbtr,
    zfbdt LIKE bsik-zfbdt,
    zbd1t LIKE bsik-zbd1t,
    zbd2t LIKE bsik-zbd2t,
    zbd3t LIKE bsik-zbd3t,
    zuonr LIKE bsik-zuonr,
    END OF inrect,
    BEGIN OF t_item OCCURS 1000, " 0001
    lifnr LIKE bsik-lifnr,
    belnr LIKE bsik-belnr,
    gjahr LIKE bsik-gjahr,
    bldat LIKE bsik-bldat,
    xblnr LIKE bsik-xblnr,
    blart LIKE bsik-blart,
    sgtxt LIKE bsik-sgtxt,
    zfbdt LIKE bsik-zfbdt,
    dmbtr LIKE bsik-dmbtr,
    days(3) TYPE c,
    zuonr LIKE bsik-zuonr,
    END OF t_item,
    t_line LIKE t_item OCCURS 1000 WITH HEADER LINE, " 0001
    BEGIN OF itab OCCURS 1000,
    lifnr LIKE lfa1-lifnr,
    total LIKE bsik-dmbtr,
    zfuture LIKE bsik-dmbtr,
    zcurrent LIKE bsik-dmbtr,
    crbal LIKE bsik-dmbtr,
    30days LIKE bsik-dmbtr,
    60days LIKE bsik-dmbtr,
    90days LIKE bsik-dmbtr,
    99days LIKE bsik-dmbtr,
    120days LIKE bsik-dmbtr,
    180days LIKE bsik-dmbtr,
    365days LIKE bsik-dmbtr,
    bzirk LIKE knvv-bzirk,
    vkbur LIKE knvv-vkbur,
    vwerk LIKE knvv-vwerk,
    vkgrp LIKE knvv-vkgrp,
    klimk LIKE knkk-klimk,
    cashd LIKE knkk-cashd,
    grupp LIKE knkk-grupp,
    erdat LIKE lfa1-erdat,
    name1 LIKE lfa1-name1,
    name2 LIKE lfa1-name2,
    stras LIKE lfa1-stras,
    ort01 LIKE lfa1-ort01,
    telf1 LIKE lfa1-telf1,
    psort(10),
    sperr LIKE lfa1-sperr,
    totsal LIKE bsik-dmbtr,
    txt50 LIKE skat-txt50,
    gsber LIKE bsik-gsber,
    END OF itab.
    DATA: sel_tab TYPE TABLE OF rsparams WITH HEADER LINE,
    p_debit(1) TYPE c,
    p_credit(1) TYPE c.
    DATA: t_variant LIKE disvariant OCCURS 0 WITH HEADER LINE.
    parameters and select-options
    SELECTION-SCREEN BEGIN OF BLOCK blck0 WITH FRAME TITLE text-002.
    PARAMETERS: stida LIKE sy-datum DEFAULT sy-datum OBLIGATORY,
    p_bukrs LIKE t001-bukrs DEFAULT 'PIIL' MEMORY ID buk
    OBLIGATORY.
    P_BUKRS LIKE T001-BUKRS DEFAULT 'CC01' OBLIGATORY. "0003
    SELECT-OPTIONS: s_lifnr FOR bsik-lifnr ,
    s_vkbur FOR knvv-vkbur,
    s_vkgrp FOR knvv-vkgrp,
    s_bzirk FOR knvv-bzirk,
    s_konda FOR knvv-konda,
    s_kdgrp FOR knvv-kdgrp NO-DISPLAY ,
    s_kvgr2 FOR knvv-kvgr2 NO-DISPLAY ,
    s_kkber FOR knkk-kkber NO-DISPLAY ,
    s_grupp FOR knkk-grupp NO-DISPLAY ,
    s_ctlpc FOR knkk-ctlpc,
    s_akont FOR lfb1-akont,
    s_gsber FOR bsik-gsber.
    PARAMETERS: p_future AS CHECKBOX DEFAULT 'X'.
    SELECTION-SCREEN END OF BLOCK blck0.
    SELECTION-SCREEN BEGIN OF BLOCK blck1 WITH FRAME TITLE text-002.
    PARAMETERS: p_abs RADIOBUTTON GROUP zrad,
    p_due RADIOBUTTON GROUP zrad DEFAULT 'X'.
    SELECTION-SCREEN END OF BLOCK blck1.
    *SELECTION-SCREEN BEGIN OF BLOCK blck2 WITH FRAME TITLE text-003.
    *PARAMETERS: c_run RADIOBUTTON GROUP zrac DEFAULT 'X',
    c_blk RADIOBUTTON GROUP zrac,
    c_all RADIOBUTTON GROUP zrac.
    *SELECTION-SCREEN END OF BLOCK blck2.
    *SELECTION-SCREEN BEGIN OF BLOCK blck3 WITH FRAME TITLE text-004.
    *PARAMETERS: p_debit AS CHECKBOX DEFAULT 'X' ,
    p_credit AS CHECKBOX DEFAULT 'X' NO-DISPLAY,
    *selection-screen end of block blck3.
    start-of-selection.
    START-OF-SELECTION.
    PERFORM BUILD_EVENTCAT.
    p_debit = 'X'.
    p_credit = 'X'.
    PERFORM get_customer_invoices.
    filter records based on selection criteria
    PERFORM filter_records.
    END-OF-SELECTION.
    PERFORM add_sort_field.
    PERFORM modify_field.
    PERFORM write_report.
    *& Form FILTER_RECORDS
    To collect all the required data from DB and store them in
    internal table.
    --> p1 text
    <-- p2 text
    FORM filter_records.
    delete records based on selection criteria
    LOOP AT itab.
    SELECT vkbur vkgrp vwerk erdat konda kdgrp bzirk kvgr2
    INTO (itab-vkbur, itab-vkgrp, itab-vwerk, knvv-erdat,
    knvv-konda, knvv-kdgrp,itab-bzirk,knvv-kvgr2)
    FROM knvv WHERE lifnr = itab-lifnr
    ORDER BY erdat DESCENDING.
    AKS :- Not Required for PI
    CASE itab-vkbur.
    WHEN 'SA1'.
    itab-vkbur = 'SF25'.
    WHEN 'QLD1'.
    itab-vkbur = 'SF23'.
    WHEN 'WA1'.
    itab-vkbur = 'SF26'.
    ENDCASE.
    AKS.
    EXIT.
    ENDSELECT.
    IF itab-vkbur IN s_vkbur AND
    itab-vkgrp IN s_vkgrp AND
    knvv-konda IN s_konda AND
    knvv-kdgrp IN s_kdgrp AND
    itab-bzirk IN s_bzirk AND
    knvv-kvgr2 IN s_kvgr2.
    ELSE.
    DELETE itab.
    CONTINUE.
    ENDIF.
    SELECT SINGLE klimk grupp cashd
    INTO (itab-klimk, itab-grupp, itab-cashd)
    FROM knkk WHERE lifnr = itab-lifnr
    AND kkber IN s_kkber
    AND ctlpc IN s_ctlpc
    AND grupp IN s_grupp.
    IF SY-SUBRC NE 0.
    DELETE ITAB.
    CONTINUE.
    ENDIF.
    SELECT SINGLE skat~txt50
    INTO (itab-txt50)
    FROM lfb1 INNER JOIN skat
    ON lfb1akont EQ skatsaknr
    WHERE lfb1~lifnr = itab-lifnr
    AND lfb1~akont IN s_akont
    AND skat~spras EQ 'EN'.
    IF sy-subrc NE 0.
    DELETE itab.
    CONTINUE.
    ENDIF.
    SELECT SINGLE name1 name2 telf1 erdat stras ort01 sperr
    INTO (itab-name1, itab-name2, itab-telf1,
    itab-erdat, itab-stras, itab-ort01, itab-sperr )
    FROM lfa1
    WHERE lifnr = itab-lifnr
    IF sy-subrc NE 0 .
    DELETE itab.
    CONTINUE.
    ENDIF.
    AKS For Filteration of Customer base on Block Area.
    IF c_all NE 'X'.
    IF c_run EQ 'X' AND itab-sperr EQ 'X'.
    DELETE itab.
    CONTINUE.
    ELSE.
    IF c_blk EQ 'X' AND itab-sperr NE 'X'.
    DELETE itab.
    CONTINUE.
    ENDIF.
    ENDIF.
    ENDIF.
    MODIFY itab.
    ENDLOOP.
    ENDFORM. " FILTER_RECORDS
    *& Form GET_CUSTOMER_INVOICES
    text
    --> p1 text
    <-- p2 text
    FORM get_customer_invoices.
    DATA:ztotcre LIKE bsik-dmbtr.
    DATA:ztotsal LIKE bsik-dmbtr.
    DATA: fsdate LIKE sy-datum.
    DATA: l_perio(4) TYPE c.
    MOVE stida TO rf140-stida.
    MOVE rf140-stida+4(2) TO targ_month.
    MOVE rf140-stida+0(4) TO targ_year.
    MOVE rf140-stida+6(2) TO targ_days.
    targ_mth_abs = ( targ_year * 12 ) + targ_month.
    CALL FUNCTION 'ZGET_PERIOD_FROM_DATE'
    EXPORTING
    i_date = stida
    IMPORTING
    e_perio = l_perio.
    CONCATENATE l_perio '0401' INTO fsdate.
    select open items.
    IF p_due EQ 'X'.
    SELECT lifnr belnr gjahr bldat xblnr blart sgtxt " 0001
    shkzg dmbtr zfbdt zbd1t zbd2t zbd3t
    zuonr
    FROM bsik INTO TABLE inrect
    WHERE bukrs = p_bukrs
    AND budat LE stida
    AND lifnr IN s_lifnr
    AND gsber IN s_gsber
    AND umskz NE 'T'
    AND umskz NE 'F'
    AND umskz NE 'R'
    AND umskz NE 'P'
    AND umskz NE 'J'
    AND umskz NE 'L'.
    LOOP AT INREC.
    IF INREC-SHKZG = 'H'.
    INREC-DMBTR = INREC-DMBTR * -1.
    ENDIF.
    MOVE-CORRESPONDING INREC TO T_ITEM. " 0001
    PERFORM COLLECT_INVOICE USING INREC-lifnr INREC-DMBTR
    INREC-ZFBDT INREC-ZBD1T
    INREC-ZBD2T INREC-ZBD3T.
    APPEND T_ITEM.
    CLEAR T_ITEM.
    ENDLOOP.
    LOOP AT inrect.
    inrec-lifnr = inrect-lifnr.
    inrec-belnr = inrect-belnr.
    inrec-gjahr = inrect-gjahr.
    inrec-bldat = inrect-bldat.
    inrec-xblnr = inrect-xblnr.
    inrec-blart = inrect-blart.
    inrec-sgtxt = inrect-sgtxt.
    inrec-shkzg = inrect-shkzg.
    inrec-dmbtr = inrect-dmbtr.
    CALL FUNCTION 'NJ_CAL_DATE_IN_INTERVAL'
    EXPORTING
    date = inrect-zfbdt
    days = inrect-zbd1t
    months = 00
    signum = '+'
    years = 00
    IMPORTING
    calc_date = inrec-zfbdt.
    inrec-zbd1t = inrect-zbd1t.
    inrec-zbd2t = inrect-zbd2t.
    inrec-zbd3t = inrect-zbd3t.
    inrec-zuonr = inrect-zuonr.
    APPEND inrec.
    CLEAR inrec.
    ENDLOOP.
    ELSE.
    SELECT lifnr belnr gjahr bldat xblnr blart sgtxt " 0001
    shkzg dmbtr zfbdt zbd1t zbd2t zbd3t
    zuonr
    FROM bsik INTO TABLE inrec
    WHERE bukrs = p_bukrs
    AND budat LE stida
    AND lifnr IN s_lifnr
    AND gsber IN s_gsber
    AND umskz NE 'T'
    AND umskz NE 'F'
    AND umskz NE 'R'
    AND umskz NE 'P'
    AND umskz NE 'J'
    AND umskz NE 'L'.
    ENDIF.
    SORT inrec BY lifnr shkzg zfbdt .
    LOOP AT inrec.
    AT NEW lifnr.
    For Customers Credit Balance Transaction to be display in Report
    End of Credit Balance
    ztotcre = 0.
    ztotsal = 0.
    ENDAT.
    IF inrec-shkzg = 'H'.
    inrec-dmbtr = inrec-dmbtr * -1.
    ztotcre = ztotcre + inrec-dmbtr.
    ELSE.
    IF inrec-blart = 'RV'.
    IF inrec-bldat GE fsdate.
    ztotsal = ztotsal + inrec-dmbtr.
    ENDIF.
    ENDIF.
    ztotcre = ztotcre + inrec-dmbtr.
    endif.
    IF p_debit EQ 'X'.
    IF ztotcre > 0.
    MOVE-CORRESPONDING inrec TO t_item. " 0001
    PERFORM collect_invoice USING inrec-lifnr ztotcre
    inrec-zfbdt inrec-zbd1t
    inrec-zbd2t inrec-zbd3t
    ztotsal.
    APPEND t_item.
    CLEAR t_item.
    ztotcre = 0.
    ztotsal = 0.
    ENDIF.
    ENDIF.
    ENDIF.
    IF p_credit EQ 'X'.
    AT END OF lifnr.
    IF ztotcre < 0.
    MOVE-CORRESPONDING inrec TO t_item. " 0001
    PERFORM collect_invoice USING inrec-lifnr ztotcre
    inrec-zfbdt inrec-zbd1t
    inrec-zbd2t inrec-zbd3t
    ztotsal.
    APPEND t_item.
    CLEAR t_item.
    ztotcre = 0.
    ztotsal = 0.
    APPEND t_item.
    CLEAR t_item.
    ENDIF.
    ENDAT.
    ENDIF.
    ENDLOOP.
    select cleared items
    IF p_due EQ 'X'.
    REFRESH inrect. CLEAR inrect.
    SELECT lifnr belnr gjahr bldat xblnr blart sgtxt
    shkzg dmbtr zfbdt zbd1t zbd2t zbd3t
    zuonr
    FROM bsak INTO TABLE inrect
    WHERE bukrs = p_bukrs
    AND budat LE stida
    AND augdt > stida
    AND lifnr IN s_lifnr
    AND gsber IN s_gsber
    REFRESH inrec. CLEAR inrec.
    LOOP AT inrect.
    inrec-lifnr = inrect-lifnr.
    inrec-belnr = inrect-belnr.
    inrec-gjahr = inrect-gjahr.
    inrec-bldat = inrect-bldat.
    inrec-xblnr = inrect-xblnr.
    inrec-blart = inrect-blart.
    inrec-sgtxt = inrect-sgtxt.
    inrec-shkzg = inrect-shkzg.
    inrec-dmbtr = inrect-dmbtr.
    CALL FUNCTION 'NJ_CAL_DATE_IN_INTERVAL'
    EXPORTING
    date = inrect-zfbdt
    days = inrect-zbd1t
    months = 00
    signum = '+'
    years = 00
    IMPORTING
    calc_date = inrec-zfbdt.
    inrec-zbd1t = inrect-zbd1t.
    inrec-zbd2t = inrect-zbd2t.
    inrec-zbd3t = inrect-zbd3t.
    inrec-zuonr = inrect-zuonr.
    APPEND inrec.
    CLEAR inrec.
    ENDLOOP.
    ELSE.
    REFRESH inrec. CLEAR inrec.
    SELECT lifnr belnr gjahr bldat xblnr blart sgtxt
    shkzg dmbtr zfbdt zbd1t zbd2t zbd3t
    zuonr
    FROM bsak INTO TABLE inrec
    WHERE bukrs = p_bukrs
    AND budat LE stida
    AND augdt > stida
    AND lifnr IN s_lifnr
    AND gsber IN s_gsber
    ENDIF.
    SORT inrec BY lifnr shkzg zfbdt .
    LOOP AT inrec.
    AT NEW lifnr.
    ztotcre = 0.
    ztotsal = 0.
    ENDAT.
    IF inrec-shkzg = 'H'.
    inrec-dmbtr = inrec-dmbtr * -1.
    ztotcre = ztotcre + inrec-dmbtr.
    ELSE.
    IF inrec-blart = 'RV'.
    IF inrec-bldat GE fsdate.
    ztotsal = ztotsal + inrec-dmbtr.
    ENDIF.
    ENDIF.
    ztotcre = ztotcre + inrec-dmbtr.
    endif.
    IF p_debit EQ 'X'.
    IF ztotcre > 0.
    MOVE-CORRESPONDING inrec TO t_item. " 0001
    PERFORM collect_invoice USING inrec-lifnr ztotcre
    inrec-zfbdt inrec-zbd1t
    inrec-zbd2t inrec-zbd3t
    ztotsal.
    APPEND t_item.
    CLEAR t_item.
    ztotcre = 0.
    ztotsal = 0.
    ENDIF.
    ENDIF.
    ENDIF.
    IF p_credit EQ 'X'.
    AT END OF lifnr.
    IF ztotcre < 0.
    MOVE-CORRESPONDING inrec TO t_item. " 0001
    PERFORM collect_invoice USING inrec-lifnr ztotcre
    inrec-zfbdt inrec-zbd1t
    inrec-zbd2t inrec-zbd3t
    ztotsal.
    APPEND t_item.
    CLEAR t_item.
    ztotcre = 0.
    ztotsal = 0.
    APPEND t_item.
    CLEAR t_item.
    ENDIF.
    ENDAT. " 0001
    ENDIF.
    ENDLOOP.
    ENDFORM. " GET_CUSTOMER_INVOICES
    *& Form COLLECT_INVOICE
    text
    -->P_bsik_lifnr text
    -->P_bsik_DMBTR text
    -->P_bsik_ZFBDT text
    -->P_bsik_ZFBDT1 text
    -->P_bsik_ZFBDT2 text
    -->P_bsik_ZFBDT3 text
    FORM collect_invoice USING pp_lifnr
    pp_dmbtr
    pp_zfbdt
    pp_zbd1t
    pp_zbd2t
    pp_zbd3t
    pp_ztotsal.
    doc_month = pp_zfbdt+4(2).
    doc_year = pp_zfbdt+0(4).
    doc_mth_abs = ( doc_year * 12 ) + doc_month.
    mth_result = ( targ_mth_abs - doc_mth_abs ).
    logic given by Mr. Ashok Singhvi
    doc_days = pp_zfbdt+6(2).
    addl_days = ( doc_days - targ_days ).
    IF addl_days <= 0.
    ADD 1 TO mth_result.
    ENDIF.
    IF NOT pp_zbd3t IS INITIAL.
    MOVE pp_zbd3t TO ext_days.
    ELSEIF NOT pp_zbd2t IS INITIAL.
    MOVE pp_zbd2t TO ext_days.
    ELSEIF NOT pp_zbd1t IS INITIAL.
    MOVE pp_zbd1t TO ext_days.
    ELSE.
    CLEAR ext_days.
    ENDIF.
    CHECK with Andrew whether this is working or not
    if extended payment terms exist, subtract no of mths from mth_result
    IF NOT ext_days IS INITIAL.
    CASE ext_days.
    WHEN 30.
    SUBTRACT 1 FROM mth_result.
    WHEN 60.
    SUBTRACT 2 FROM mth_result.
    WHEN 90.
    SUBTRACT 3 FROM mth_result.
    WHEN 120.
    SUBTRACT 4 FROM mth_result.
    ENDCASE.
    ENDIF.
    change to key date
    IF pp_dmbtr > 0.
    IF p_future = 'X'. " 0001
    IF mth_result <= 0.
    itab-zcurrent = pp_dmbtr.
    t_item-days = 'CUR'.
    ELSEIF mth_result = 1.
    itab-30days = pp_dmbtr.
    t_item-days = '30D'.
    ELSEIF mth_result = 2.
    itab-60days = pp_dmbtr.
    t_item-days = '60D'.
    ELSEIF mth_result = 3.
    itab-90days = pp_dmbtr.
    t_item-days = '90D'.
    ELSEIF mth_result > 3 AND mth_result <= 4 .
    itab-99days = pp_dmbtr.
    t_item-days = '99D'.
    ELSEIF mth_result > 4 AND mth_result <= 6 .
    itab-120days = pp_dmbtr.
    t_item-days = '120D'.
    ELSEIF mth_result > 6 AND mth_result <= 12 .
    itab-180days = pp_dmbtr.
    t_item-days = '180D'.
    ELSEIF mth_result > 12 .
    itab-365days = pp_dmbtr.
    t_item-days = '365D'.
    ENDIF.
    ELSE.
    IF mth_result < 0.
    itab-zfuture = pp_dmbtr.
    t_item-days = 'FUT'.
    ELSEIF mth_result = 0.
    itab-zcurrent = pp_dmbtr.
    t_item-days = 'CUR'.
    ELSEIF mth_result = 1.
    itab-30days = pp_dmbtr.
    t_item-days = '30D'.
    ELSEIF mth_result = 2.
    itab-60days = pp_dmbtr.
    t_item-days = '60D'.
    ELSEIF mth_result = 3.
    itab-90days = pp_dmbtr.
    t_item-days = '90D'.
    ELSEIF mth_result > 3 AND mth_result <= 4 .
    itab-99days = pp_dmbtr.
    t_item-days = '99D'.
    ELSEIF mth_result > 4 AND mth_result <= 6 .
    itab-120days = pp_dmbtr.
    t_item-days = '120D'.
    ELSEIF mth_result > 6 AND mth_result <= 12 .
    itab-180days = pp_dmbtr.
    t_item-days = '180D'.
    ELSEIF mth_result > 12 .
    itab-365days = pp_dmbtr.
    t_item-days = '365D'.
    ENDIF.
    ENDIF. " 0001
    itab-crbal = 0.
    itab-total = pp_dmbtr.
    ELSE.
    IF p_future = 'X'. " 0001
    IF mth_result <= 0.
    itab-zcurrent = pp_dmbtr.
    t_item-days = 'CUR'.
    ELSEIF mth_result = 1.
    itab-30days = pp_dmbtr.
    t_item-days = '30D'.
    ELSEIF mth_result = 2.
    itab-60days = pp_dmbtr.
    t_item-days = '60D'.
    ELSEIF mth_result = 3.
    itab-90days = pp_dmbtr.
    t_item-days = '90D'.
    ELSEIF mth_result > 3 AND mth_result <= 4 .
    itab-99days = pp_dmbtr.
    t_item-days = '99D'.
    ELSEIF mth_result > 4 AND mth_result <= 6 .
    itab-120days = pp_dmbtr.
    t_item-days = '120D'.
    ELSEIF mth_result > 6 AND mth_result <= 12 .
    itab-180days = pp_dmbtr.
    t_item-days = '180D'.
    ELSEIF mth_result > 12 .
    itab-365days = pp_dmbtr.
    t_item-days = '365D'.
    ENDIF.
    ELSE.
    IF mth_result < 0.
    itab-zfuture = pp_dmbtr.
    t_item-days = 'FUT'.
    ELSEIF mth_result = 0.
    itab-zcurrent = pp_dmbtr.
    t_item-days = 'CUR'.
    ELSEIF mth_result = 1.
    itab-30days = pp_dmbtr.
    t_item-days = '30D'.
    ELSEIF mth_result = 2.
    itab-60days = pp_dmbtr.
    t_item-days = '60D'.
    ELSEIF mth_result = 3.
    itab-90days = pp_dmbtr.
    t_item-days = '90D'.
    ELSEIF mth_result > 3 AND mth_result <= 4 .
    itab-99days = pp_dmbtr.
    t_item-days = '99D'.
    ELSEIF mth_result > 4 AND mth_result <= 6 .
    itab-120days = pp_dmbtr.
    t_item-days = '120D'.
    ELSEIF mth_result > 6 AND mth_result <= 12 .
    itab-180days = pp_dmbtr.
    t_item-days = '180D'.
    ELSEIF mth_result > 12 .
    itab-365days = pp_dmbtr.
    t_item-days = '365D'.
    ENDIF.
    ENDIF. " 0001
    itab-total = pp_dmbtr.
    itab-crbal = 0.
    ENDIF.
    itab-lifnr = pp_lifnr.
    itab-totsal = pp_ztotsal.
    COLLECT itab.
    CLEAR itab.
    ENDFORM. " COLLECT_INVOICE
    *& Form ADD_SORT_FIELD
    text
    --> p1 text
    <-- p2 text
    FORM add_sort_field.
    DATA: l_amount(9) TYPE n.
    IF p_future = 'X'.
    LOOP AT itab.
    l_amount = 999999999.
    IF itab-365days > 0.
    l_amount = l_amount - itab-365days.
    CONCATENATE 'A' l_amount INTO itab-psort.
    ELSEIF itab-180days > 0.
    l_amount = l_amount - itab-180days.
    CONCATENATE 'B' l_amount INTO itab-psort.
    ELSEIF itab-120days > 0.
    l_amount = l_amount - itab-120days.
    CONCATENATE 'C' l_amount INTO itab-psort.
    ELSEIF itab-99days > 0.
    l_amount = l_amount - itab-99days.
    CONCATENATE 'D' l_amount INTO itab-psort.
    ELSEIF itab-90days > 0.
    l_amount = l_amount - itab-90days.
    CONCATENATE 'E' l_amount INTO itab-psort.
    ELSEIF itab-60days > 0.
    l_amount = l_amount - itab-60days.
    CONCATENATE 'F' l_amount INTO itab-psort.
    ELSEIF itab-30days > 0.
    l_amount = l_amount - itab-30days.
    CONCATENATE 'G' l_amount INTO itab-psort.
    ELSEIF itab-zcurrent > 0.
    l_amount = l_amount - itab-zcurrent.
    CONCATENATE 'H' l_amount INTO itab-psort.
    ELSEif itab-zfuture > 0.
    L_AMOUNT = L_AMOUNT - ITAB-zfuture.
    CONCATENATE 'F' L_AMOUNT INTO ITAB-PSORT.
    ELSE.
    l_amount = ABS( itab-total ).
    CONCATENATE 'I' l_amount INTO itab-psort.
    ENDIF.
    MODIFY itab.
    ENDLOOP.
    ELSE.
    LOOP AT itab.
    l_amount = 999999999.
    IF itab-365days > 0.
    l_amount = l_amount - itab-365days.
    CONCATENATE 'A' l_amount INTO itab-psort.
    ELSEIF itab-180days > 0.
    l_amount = l_amount - itab-180days.
    CONCATENATE 'B' l_amount INTO itab-psort.
    ELSEIF itab-120days > 0.
    l_amount = l_amount - itab-120days.
    CONCATENATE 'C' l_amount INTO itab-psort.
    ELSEIF itab-99days > 0.
    l_amount = l_amount - itab-99days.
    CONCATENATE 'D' l_amount INTO itab-psort.
    ELSEIF itab-90days > 0.
    l_amount = l_amount - itab-90days.
    CONCATENATE 'E' l_amount INTO itab-psort.
    ELSEIF itab-60days > 0.
    l_amount = l_amount - itab-60days.
    CONCATENATE 'F' l_amount INTO itab-psort.
    ELSEIF itab-30days > 0.
    l_amount = l_amount - itab-30days.
    CONCATENATE 'G' l_amount INTO itab-psort.
    ELSEIF itab-zcurrent > 0.
    l_amount = l_amount - itab-zcurrent.
    CONCATENATE 'H' l_amount INTO itab-psort.
    ELSEIF itab-zfuture > 0.
    l_amount = l_amount - itab-zfuture.
    CONCATENATE 'I' l_amount INTO itab-psort.
    ELSE.
    l_amount = ABS( itab-total ).
    CONCATENATE 'J' l_amount INTO itab-psort.
    ENDIF.
    MODIFY itab.
    ENDLOOP.
    ENDIF.
    ENDFORM. " ADD_SORT_FIELD
    *& Form WRITE_REPORT
    text
    --> p1 text
    <-- p2 text
    FORM write_report.
    PERFORM build_fieldcat.
    PERFORM build_sortcat.
    PERFORM build_eventcat.
    PERFORM build_layout.
    PERFORM start_list_viewer.
    ENDFORM. " WRITE_REPORT
    *& Form BUILD_FIELDCAT
    text
    --> p1 text
    <-- p2 text
    FORM build_fieldcat.
    lifnr
    ADD 1 TO col_pos.
    CLEAR fieldcat_ln.
    fieldcat_ln-ref_tabname = 'lfa1'.
    fieldcat_ln-fieldname = 'LIFNR'.
    fieldcat_ln-col_pos = col_pos.
    fieldcat_ln-hotspot = 'X'.
    fieldcat_ln-emphasize = 'C41'.
    APPEND fieldcat_ln TO fieldcat.
    Name1
    ADD 1 TO col_pos.
    CLEAR fieldcat_ln.
    fieldcat_ln-ref_tabname = 'lfa1'.
    fieldcat_ln-fieldname = 'NAME1'.
    fieldcat_ln-emphasize = 'C41'.
    fieldcat_ln-col_pos = col_pos.
    fieldcat_ln-seltext_l = 'Name'.
    APPEND fieldcat_ln TO fieldcat.
    City Details
    ADD 1 TO col_pos.
    CLEAR fieldcat_ln.
    fieldcat_ln-ref_tabname = 'lfa1'.
    fieldcat_ln-fieldname = 'ORT01'.
    fieldcat_ln-seltext_l = 'City'.
    fieldcat_ln-col_pos = col_pos.
    APPEND fieldcat_ln TO fieldcat.
    Credit Limit
    ADD 1 TO col_pos.
    CLEAR fieldcat_ln.
    fieldcat_ln-ref_tabname = 'KNKK'.
    fieldcat_ln-fieldname = 'KLIMK'.
    fieldcat_ln-col_pos = col_pos.
    fieldcat_ln-emphasize = 'C41'.
    APPEND fieldcat_ln TO fieldcat.
    ADD 1 TO col_pos.
    CLEAR fieldcat_ln.
    fieldcat_ln-ref_tabname = 'bsik'.
    fieldcat_ln-ref_fieldname = 'DMBTR'.
    fieldcat_ln-fieldname = 'CRBAL'.
    fieldcat_ln-col_pos = col_pos.
    fieldcat_ln-emphasize = 'C41'.
    fieldcat_ln-do_sum = 'X'.
    fieldcat_ln-seltext_l = 'Cr. Bal.'.
    fieldcat_ln-seltext_m = 'Cr. Bal.'.
    fieldcat_ln-seltext_s = 'Cr. Bal.'.
    APPEND fieldcat_ln TO fieldcat.
    Total Amount
    ADD 1 TO col_pos.
    CLEAR fieldcat_ln.
    fieldcat_ln-fieldname = 'TOTAL'.
    fieldcat_ln-col_pos = col_pos.
    fieldcat_ln-emphasize = 'C41'.
    fieldcat_ln-do_sum = 'X'.
    fieldcat_ln-hotspot = 'X'.
    fieldcat_ln-seltext_l = 'Out.St.Amt.'.
    fieldcat_ln-seltext_m = 'Out.St.Amt.'.
    fieldcat_ln-seltext_s = 'Out.St.Amt.'.
    fieldcat_ln-ref_tabname = 'zbsik'.
    fieldcat_ln-ref_fieldname = 'ZDMBTR'.
    APPEND fieldcat_ln TO fieldcat.
    IF p_future NE 'X'.
    Future
    ADD 1 TO col_pos.
    CLEAR fieldcat_ln.
    fieldcat_ln-ref_tabname = 'bsik'.
    fieldcat_ln-ref_fieldname = 'DMBTR'.
    fieldcat_ln-fieldname = 'ZFUTURE'.
    fieldcat_ln-col_pos = col_pos.
    fieldcat_ln-do_sum = 'X'.
    fieldcat_ln-hotspot = 'X'.
    fieldcat_ln-emphasize = 'C41'.
    fieldcat_ln-seltext_l = 'Future Due'.
    fieldcat_ln-seltext_m = 'Future Due'.
    fieldcat_ln-seltext_s = 'Future Due'.
    APPEND fieldcat_ln TO fieldcat.
    ENDIF.
    Current
    ADD 1 TO col_pos.
    CLEAR fieldcat_ln.
    fieldcat_ln-ref_tabname = 'bsik'.
    fieldcat_ln-ref_fieldname = 'DMBTR'.
    fieldcat_ln-fieldname = 'ZCURRENT'.
    fieldcat_ln-col_pos = col_pos.
    fieldcat_ln-do_sum = 'X'.
    fieldcat_ln-hotspot = 'X'.
    fieldcat_ln-emphasize = 'C41'.
    fieldcat_ln-seltext_l = 'Normal Due'.
    fieldcat_ln-seltext_m = 'Normal Due'.
    fieldcat_ln-seltext_s = 'Normal Due'.
    APPEND fieldcat_ln TO fieldcat.
    30 Days
    ADD 1 TO col_pos.
    CLEAR fieldcat_ln.
    fieldcat_ln-ref_tabname = 'bsik'.
    fieldcat_ln-ref_fieldname = 'DMBTR'.
    fieldcat_ln-fieldname = '30DAYS'.
    fieldcat_ln-col_pos = col_pos.
    fieldcat_ln-do_sum = 'X'.
    fieldcat_ln-hotspot = 'X'.
    fieldcat_ln-emphasize = 'C41'.
    fieldcat_ln-seltext_l = '0-30 Days'.
    fieldcat_ln-seltext_m = '0-30 Days'.
    fieldcat_ln-seltext_s = '0-30 Days'.
    APPEND fieldcat_ln TO fieldcat.
    60 Days
    ADD 1 TO col_pos.
    CLEAR fieldcat_ln.
    fieldcat_ln-ref_tabname = 'bsik'.
    fieldcat_ln-ref_fieldname = 'DMBTR'.
    fieldcat_ln-fieldname = '60DAYS'.
    fieldcat_ln-col_pos = col_pos.
    fieldcat_ln-do_sum = 'X'.
    fieldcat_ln-hotspot = 'X'.
    fieldcat_ln-emphasize = 'C41'.
    fieldcat_ln-seltext_l = '31-60 Days'.
    fieldcat_ln-seltext_m = '31-60 Days'.
    fieldcat_ln-seltext_s = '31-60 Days'.
    APPEND fieldcat_ln TO fieldcat.
    90 Days
    ADD 1 TO col_pos.
    CLEAR fieldcat_ln.
    fieldcat_ln-ref_tabname = 'bsik'.
    fieldcat_ln-ref_fieldname = 'DMBTR'.
    fieldcat_ln-fieldname = '90DAYS'.
    fieldcat_ln-col_pos = col_pos.
    fieldcat_ln-do_sum = 'X'.
    fieldcat_ln-hotspot = 'X'.
    fieldcat_ln-emphasize = 'C41'.
    fieldcat_ln-seltext_l = '61-90 Days'.
    fieldcat_ln-seltext_m = '61-90 Days'.
    fieldcat_ln-seltext_s = '61-90 Days'.
    APPEND fieldcat_ln TO fieldcat.
    99 Days
    ADD 1 TO col_pos.
    CLEAR fieldcat_ln.
    fieldcat_ln-ref_tabname = 'bsik'.
    fieldcat_ln-ref_fieldname = 'DMBTR'.
    fieldcat_ln-fieldname = '99DAYS'.
    fieldcat_ln-col_pos = col_pos.
    fieldcat_ln-do_sum = 'X'.
    fieldcat_ln-hotspot = 'X'.
    fieldcat_ln-emphasize = 'C41'.
    fieldcat_ln-seltext_l = '91-120 Days'.
    fieldcat_ln-seltext_m = '91-120 Days'.
    fieldcat_ln-seltext_s = '91-120 Days'.
    APPEND fieldcat_ln TO fieldcat.
    *120Days
    ADD 1 TO col_pos.
    CLEAR fieldcat_ln.
    fieldcat_ln-ref_tabname = 'bsik'.
    fieldcat_ln-ref_fieldname = 'DMBTR'.
    fieldcat_ln-fieldname = '120DAYS'.
    fieldcat_ln-col_pos = col_pos.
    fieldcat_ln-do_sum = 'X'.
    fieldcat_ln-hotspot = 'X'.
    fieldcat_ln-emphasize = 'C41'.
    fieldcat_ln-seltext_l = '121-180 Days'.
    fieldcat_ln-seltext_m = '121-180 Days'.
    fieldcat_ln-seltext_s = '121-180 Days'.
    APPEND fieldcat_ln TO fieldcat.
    *180 Days
    ADD 1 TO col_pos.
    CLEAR fieldcat_ln.
    fieldcat_ln-ref_tabname = 'bsik'.
    fieldcat_ln-ref_fieldname = 'DMBTR'.
    fieldcat_ln-fieldname = '180DAYS'.
    fieldcat_ln-col_pos = col_pos.
    fieldcat_ln-do_sum = 'X'.
    fieldcat_ln-hotspot = 'X'.
    fieldcat_ln-emphasize = 'C41'.
    fieldcat_ln-seltext_l = '181-365 Days'.
    fieldcat_ln-seltext_m = '181-365 Days'.
    fieldcat_ln-seltext_s = '181-365 Days'.
    APPEND fieldcat_ln TO fieldcat.
    *365 Days
    ADD 1 TO col_pos.
    CLEAR fieldcat_ln.
    fieldcat_ln-ref_tabname = 'bsik'.
    fieldcat_ln-ref_fieldname = 'DMBTR'.
    fieldcat_ln-fieldname = '365DAYS'.
    fieldcat_ln-col_pos = col_pos.
    fieldcat_ln-do_sum = 'X'.
    fieldcat_ln-hotspot = 'X'.
    fieldcat_ln-emphasize = 'C41'.
    fieldcat_ln-seltext_l = '>365 Days'.
    fieldcat_ln-seltext_m = '>365 Days'.
    fieldcat_ln-seltext_s = '>365 Days'.
    APPEND fieldcat_ln TO fieldcat.
    Last Payment Date
    ADD 1 TO col_pos.
    CLEAR fieldcat_ln.
    fieldcat_ln-ref_tabname = 'KNKK'.
    fieldcat_ln-fieldname = 'CASHD'.
    fieldcat_ln-col_pos = col_pos.
    APPEND fieldcat_ln TO fieldcat.
    Street Name
    ADD 1 TO COL_POS.
    CLEAR FIELDCAT_LN.
    FIELDCAT_LN-REF_TABNAME = 'lfa1'.
    FIELDCAT_LN-FIELDNAME = 'STRAS'.
    FIELDCAT_LN-COL_POS = COL_POS.
    APPEND FIELDCAT_LN TO FIELDCAT.
    Telephone
    ADD 1 TO COL_POS.
    CLEAR FIELDCAT_LN.
    FIELDCAT_LN-REF_TABNAME = 'lfa1'.
    FIELDCAT_LN-FIELDNAME = 'TELF1'.
    FIELDCAT_LN-COL_POS = COL_POS.
    APPEND FIELDCAT_LN TO FIELDCAT.
    Credit Group
    ADD 1 TO COL_POS.
    CLEAR FIELDCAT_LN.
    FIELDCAT_LN-REF_TABNAME = 'KNKK'.
    FIELDCAT_LN-FIELDNAME = 'GRUPP'.
    FIELDCAT_LN-COL_POS = COL_POS.
    APPEND FIELDCAT_LN TO FIELDCAT.
    *Sales District
    ADD 1 TO col_pos.
    CLEAR fieldcat_ln.
    fieldcat_ln-ref_tabname = 'KNVV'.
    fieldcat_ln-fieldname = 'BZIRK'.
    fieldcat_ln-col_pos = col_pos.
    fieldcat_ln-seltext_l = 'S_Distt'.
    fieldcat_ln-seltext_m = 'S_Distt'.
    fieldcat_ln-seltext_s = 'S_Distt'.
    APPEND fieldcat_ln TO fieldcat.
    Sales Office
    ADD 1 TO col_pos.
    CLEAR fieldcat_ln.
    fieldcat_ln-ref_tabname = 'KNVV'.
    fieldcat_ln-fieldname = 'VKBUR'.
    fieldcat_ln-col_pos = col_pos.
    fieldcat_ln-seltext_l = 'S_Off'.
    fieldcat_ln-seltext_m = 'S_Off'.
    fieldcat_ln-seltext_s = 'S_Off'.
    APPEND fieldcat_ln TO fieldcat.
    Cust Creat Date
    ADD 1 TO COL_POS.
    CLEAR FIELDCAT_LN.
    FIELDCAT_LN-REF_TABNAME = 'lfa1'.
    FIELDCAT_LN-FIELDNAME = 'ERDAT'.
    FIELDCAT_LN-COL_POS = COL_POS.
    APPEND FIELDCAT_LN TO FIELDCAT.
    Del Plant
    ADD 1 TO col_pos.
    CLEAR fieldcat_ln.
    fieldcat_ln-ref_tabname = 'KNVV'.
    fieldcat_ln-fieldname = 'VWERK'.
    fieldcat_ln-col_pos = col_pos.
    APPEND fieldcat_ln TO fieldcat.
    Sales Group
    ADD 1 TO col_pos.
    CLEAR fieldcat_ln.
    fieldcat_ln-ref_tabname = 'KNVV'.
    fieldcat_ln-fieldname = 'VKGRP'.
    fieldcat_ln-col_pos = col_pos.
    APPEND fieldcat_ln TO fieldcat.
    Sort Criteria
    ADD 1 TO col_pos.
    CLEAR fieldcat_ln.
    fieldcat_ln-ref_tabname = 'bsik'.
    fieldcat_ln-ref_fieldname = 'lifnr'.
    fieldcat_ln-fieldname = 'PSORT'.
    fieldcat_ln-col_pos = col_pos.
    fieldcat_ln-do_sum = 'X'.
    fieldcat_ln-seltext_l = 'Sort Field'.
    fieldcat_ln-seltext_m = 'Sort Field'.
    fieldcat_ln-seltext_s = 'Sort Field'.
    APPEND fieldcat_ln TO fieldcat.
    Sales of Customer
    ADD 1 TO col_pos.
    CLEAR fieldcat_ln.
    fieldcat_ln-ref_tabname = 'bsik'.
    fieldcat_ln-ref_fieldname = 'DMBTR'.
    fieldcat_ln-fieldname = 'TOTSAL'.
    fieldcat_ln-col_pos = col_pos.
    fieldcat_ln-do_sum = 'X'.
    fieldcat_ln-hotspot = 'X'.
    fieldcat_ln-emphasize = 'C41'.
    fieldcat_ln-seltext_l = 'Total Sales'.
    fieldcat_ln-seltext_m = 'Total Sales'.
    fieldcat_ln-seltext_s = 'Total Sales'.
    APPEND fieldcat_ln TO fieldcat.
    ENDFORM. " BUILD_FIELDCAT
    *& Form BUILD_SORTCAT
    text
    --> p1 text
    <-- p2 text
    FORM build_sortcat.
    SORTCAT_LN-SPOS = '1'.
    sortcat_ln-spos = '2'. " 0001
    sortcat_ln-fieldname = 'PSORT'.
    sortcat_ln-up = 'X'. " 0001
    sortcat_ln-subtot = 'X'.
    APPEND sortcat_ln TO sortcat.
    CLEAR sortcat_ln.
    SORTCAT_LN-SPOS = '2'.
    SORTCAT_LN-FIELDNAME = 'lifnr'.
    sortcat_ln-spos = '1'. " 0001
    sortcat_ln-fieldname = 'NAME1'. " 0001
    sortcat_ln-up = 'X'.
    APPEND sortcat_ln TO sortcat.
    ENDFORM. " BUILD_SORTCAT
    *& Form BUILD_EVENTCAT
    text
    --> p1 text
    <-- p2 text
    FORM build_eventcat.
    eventcat_ln-name = 'TOP_OF_PAGE'.
    eventcat_ln-form = 'PAGE_HEADER'.
    APPEND eventcat_ln TO eventcat.
    ENDFORM. " BUILD_EVENTCAT
    *& Form BUILD_LAYOUT
    text
    --> p1 text
    <-- p2 text
    FORM build_layout.
    layout_in-colwidth_optimize = 'X'.
    layout_in-no_hotspot = 'X'.
    layout_in-zebra = 'X'.
    layout_in-get_selinfos = 'X'.
    ENDFORM. " BUILD_LAYOUT
    *& Form START_LIST_VIEWER
    text
    --> p1 text
    <-- p2 text
    FORM start_list_viewer.
    DATA: pgm LIKE sy-repid.
    pgm = sy-repid.
    if t_variant[] is initial.
    t_variant-report = pgm.
    t_variant-variant = '/ATB'.
    t_variant-TEXT = '/ATB'.
    t_variant-DEPENDVARS = 'S'.
    append t_variant.
    clear t_variant.
    endif.
    CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
    EXPORTING
    i_callback_program = pgm
    i_callback_user_command = 'USER_COMMAND'
    it_fieldcat = fieldcat
    it_sort = sortcat
    is_layout = layout_in
    i_save = 'A'
    IS_VARIANT = t_variant
    it_events = eventcat
    TABLES
    t_outtab = itab
    EXCEPTIONS
    OTHERS = 2.
    ENDFORM. " START_LIST_VIEWER
    FORM user_command USING ucomm LIKE sy-ucomm
    selfield TYPE slis_selfield.
    DATA l_lifnr(10) TYPE n.
    READ TABLE itab INDEX selfield-tabindex.
    CHECK sy-subrc = 0.
    CASE ucomm.
    WHEN '&IC1'.
    CASE selfield-sel_tab_field.
    WHEN 'ITAB-LIFNR'.
    SET PARAMETER ID 'LIF' FIELD itab-lifnr.
    SET PARAMETER ID 'BUK' FIELD p_bukrs.
    IF itab-lifnr CO '0123456789 '.
    l_lifnr = itab-lifnr.
    itab-lifnr = l_lifnr.
    ENDIF.
    SELECT SINGLE kkber INTO knkk-kkber
    FROM knkk WHERE lifnr = itab-lifnr.
    IF sy-subrc EQ 0.
    v_kkber = knkk-kkber.
    ELSE.
    CLEAR v_kkber.
    ENDIF.
    REFRESH sel_tab[].
    MOVE: 'lifnr' TO sel_tab-selname,
    'P' TO sel_tab-kind, " PARAMETER
    itab-lifnr TO sel_tab-low.
    APPEND sel_tab.
    CLEAR sel_tab.
    MOVE: 'KKBER' TO sel_tab-selname,
    'P' TO sel_tab-kind, " PARAMETER
    v_kkber TO sel_tab-low.
    APPEND sel_tab.
    CLEAR sel_tab.
    SUBMIT rfdkli41
    USING SELECTION-SET 'VAR1'
    WITH SELECTION-TABLE sel_tab
    AND RETURN.
    CALL TRANSACTION 'XK03' AND SKIP FIRST SCREEN.
    WHEN 'ITAB-ZCURRENT'. " 0001
    v_days = 'CUR'.
    PERFORM display_line_item_level.
    WHEN 'ITAB-ZFUTURE'.
    v_days = 'FUT'.
    PERFORM display_line_item_level.
    WHEN 'ITAB-30DAYS'.
    v_days = '30D'.
    PERFORM display_line_item_level.
    WHEN 'ITAB-60DAYS'.
    v_days = '60D'.
    PERFORM display_line_item_level.
    WHEN 'ITAB-90DAYS'.
    v_days = '90D'.
    PERFORM display_line_item_level.
    WHEN 'ITAB-99DAYS'.
    v_days = '99D'.
    PERFORM display_line_item_level.
    WHEN 'ITAB-120DAYS'.
    v_days = '120D'.
    PERFORM display_line_item_level.
    WHEN 'ITAB-180DAYS'.
    v_days = '180D'.
    PERFORM display_line_item_level.
    WHEN 'ITAB-365DAYS'.
    v_days = '365D'.
    PERFORM display_line_item_level.
    WHEN 'ITAB-TOTAL'.
    v_days = ' '.
    PERFORM display_line_item_level. " 0001
    ENDCASE.
    ENDCASE.
    ENDFORM. "USER_COMMAND
    PAGE_HEADER
    FORM page_header.
    WRITE:/115 'Time:', sy-timlo.
    WRITE: /115 'Date:', sy-datum.
    WRITE: /52 'Customer Outstanding Agewise ', "0002
    115 'Page:', sy-pagno.
    SKIP.
    IF p_abs EQ 'X'.
    WRITE: /52 'Vendor Outstanding Agewise (Absolute Aging)',
    115 'Page:', sy-pagno.
    ELSE.
    WRITE: /52 'Vendor Outstanding Agewise (Due Date Aging)',
    115 'Page:', sy-pagno.
    ENDIF.
    SKIP.
    ULINE /(132).
    WRITE: /02 'Open Items as of:', stida.
    IF NOT s_vkgrp[] IS INITIAL.
    IF s_vkgrp-high IS INITIAL.
    WRITE: 52 'Sales Group :',s_vkgrp-low.
    ELSE.
    WRITE: 52 'Sales Group :',s_vkgrp-low,'to',s_vkgrp-high.
    ENDIF.
    ELSE.
    WRITE: 52 'Sales Group : All'.
    ENDIF.
    IF NOT s_grupp[] IS INITIAL.
    IF s_grupp-high IS INITIAL.
    WRITE: 107 'Credit group :',s_grupp-low.
    ELSE.
    WRITE: 107 'Credit group :',s_grupp-low,' to',s_grupp-high.
    ENDIF.
    ELSE.
    WRITE: 107 'Credit Group : All'.
    ENDIF.
    WRITE: /02 'Comapany Code :', p_bukrs.
    IF NOT s_konda[] IS INITIAL.
    IF s_konda-high IS INITIAL.
    WRITE: 52 'Price group :',s_konda-low.
    ELSE.
    WRITE: 52 'Price group :',s_konda-low,' to',s_konda-high.
    ENDIF.
    ELSE.
    WRITE: 52 'Price Group : All'.
    ENDIF.
    IF NOT s_ctlpc[] IS INITIAL.
    IF s_ctlpc-high IS INITIAL.
    WRITE: 107 'Risk category:',s_ctlpc-low.
    ELSE.
    WRITE: 107 'Risk category:',s_ctlpc-low,' to',s_ctlpc-high.
    ENDIF.
    ELSE.
    WRITE: 107 'Risk category: All'.
    ENDIF.
    IF NOT s_vkbur[] IS INITIAL.
    IF s_vkbur-high IS INITIAL.
    WRITE:/02 'Sales Office :',s_vkbur-low.
    ELSE.
    WRITE:/02 'Sales Office :',s_vkbur-low,' to',s_vkbur-high.
    ENDIF.
    ELSE.
    WRITE:/02 'Sales Office : All'.
    ENDIF.
    IF NOT s_kdgrp[] IS INITIAL.
    IF s_kdgrp-high IS INITIAL.
    WRITE: 52 'Customer group :',s_kdgrp-low.
    ELSE.
    WRITE: 52 'Customer group :',s_kdgrp-low,' to',s_kdgrp-high.
    ENDIF.
    ELSE.
    WRITE: 52 'Customer group : All'.
    ENDIF.
    IF NOT s_ktokd[] IS INITIAL.
    IF s_ktokd-high IS INITIAL.
    WRITE: 107 'Account Group:',s_ktokd-low.
    ELSE.
    WRITE: 107 'Account Group:',s_ktokd-low,' to',s_ktokd-high.
    ENDIF.
    ELSE.
    WRITE: 107 'Account Group: All'.
    ENDIF.
    IF NOT s_lifnr[] IS INITIAL.
    IF s_lifnr-high IS INITIAL.
    WRITE: /02 'Vendor No :',s_lifnr-low.
    ELSE.
    WRITE: /02 'Vendor No :',s_lifnr-low,' to',s_lifnr-high.
    ENDIF.
    ELSE.
    WRITE: /02 'Vendor No : All'.
    ENDIF.
    IF NOT s_kkber[] IS INITIAL.
    IF s_kkber-high IS INITIAL.
    WRITE: 52 'Credit Control Area:',s_kkber-low.
    ELSE.
    WRITE: 52 'Credit Control Area:',s_kkber-low,' to',s_kkber-high.

  • Ageing Report for Outstanding Amount from Customer

    Dear All,
    Kindly let me know if any ageing report available to find the out the outstanding amount for list of customers?
    We want to know how many days customers crossed their credit period?
    If the customer has 50 days credit, it may be crossed 50 days or still customer may have 20 days. These reports we want from SAP.
    Kindly let me know if one available in standard SAP.
    Regards,
    Mullairaj

    Hi,
    Not availabe a standard report in sap go through with the help of abaper sa per your requirement.
    Regards,
    Kanike

  • Customer (or Vendor) Ageing Report Problem

    Dear Experts,
    Firstly, Glad to be before you.
    Here, we have developed tht ageing report for Customers and Vendors.In which the Partial payment line item (let us say A) against an Invoice (lets say X) is not being shown under the same age of Invoice Line Item.
    For example:
    Scenario 1)
    Let me say that the Payment Terms 'Z001' under which the line Items fall due only after 30 days.
    I have posted an invoice on 01.09.2011 with Rs. 20000
    If we run the Ageing as on 16.12.2011, the output is projected as follows:
    ============================================Days in Arrears
    0-20--20-4040-60--
    60-80
    Line Item X (Invoice)----
    20000
    Total Balance agewise:--000--
    20000
    Here for Invoice NO PROBLEM is being raised, as the Invoice Posting Date is taken as the Baseline Date from which the Ageing will be calculated based on Payment terms assigned to Customer in the master data.
    But the Proble is when we do partial payment:
    Scenario 2)
    Let me Take the same example:
    Let me say that the Payment Terms 'Z001' under which the line Items fall due only after 30 days.
    I have posted an invoice on 01.09.2011 with Rs. 20000 (Due by 77 days as on 16.12.2011)
    We have received payment of 8000 against the invoice, on 22.09.2011 (due by 55 days as on 16.12.2011)
    now the Ageing report is ran on same 16.12.2011, for which the output is as follows:
    ============================================Days in Arrears
    0-20--20-4040-60--
    60-80
    Line Item X (Invoice) -
    20000
    Line Item Y (Partial Pyment)----
    (8000)
    Total Balance agewise:--00(8000)--
    20000
    As per Technical logic whats happenning is correct. Because the Base Line date of the partial payment line Item is being picked from the posting date of the same. BUT NOW, THE REQUIREMENT IS AS FOLLOW:
    The wants to see the related Partial payment items also in the same AGE in the report. i.e., we should make the system pick the Baseline date of the partial payment line item(Y) from the posting date(01.09.2011) of the other line item(X) i.e., from the Invoice(X) which is being partial cleared. Can you please suggest me a logic?
    Ramana.Gottipati

    Change the base line date of partial payment document to 01.09.2011 after receiving payment.
    Standard SAP will not automatically change the base line date of partial payment document to a back date and you develop with above logic
    Or you need to change manually
    Srinivas

Maybe you are looking for

  • Photos not staying after rendering

    I had this problem before, after installing Leopard. Got the machine fixed and doubled the RAM. Now I have a video of the holidays to edit and it STILL won't keep photos. They render and the panel turns black, the video stops when it gets to the phot

  • Problems in Oracle9i

    The excuses of the case that I cannot ingles much, I speak Spanish. I will explain step by step what made until the moment... I have made the following steps to install oracle in my computer with Windows 2003 server http://www.ajpdsoft.com/modules.ph

  • Oracle 11g installation with OWB component

    Hi, I want install oracle 11g (11.2.0.3) software without installing the OWB component. Could someone please help me. How to select the indiviual components while installing 11g. Thanks in advance.

  • How to initiate a work flow when the button is pressed in a form

    Hi All, I am new to workflow, I am working with oracle apps r12 and form 10g and workflow builder 2.3. I have develop a form in that i have a button called Initiate approval, When the user clicks the button the workflow need to called. Can any one pl

  • How long is dose apple cover the power adapter?

    I got a macbook pro one year and one week ago, and today the power adapter part that can come off the brick, broke, like it just came unglued? so the brick is ok and the part that pulgs in the wall is not .... so does anyone know ?