Ageing report on over 30 days

Hi Experts
How to do the selection for Ageing Report in Over 30days, Over 211 days Above 30 days, Total Over 30 days  explain detailed with offest values.
Edited by: Sk Babu999 on Dec 29, 2010 2:01 PM

Hi:
Take a look at the paper by Surendra Reddy.
"Calculating the Ageing of the Materials"
http://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/30f15839-0cf1-2b10-c6a7-ebe68cc87cdc?quicklink=index&overridelayout=true
Another example is the paper by Neelesh Kumar Jain.
"Creating Bucket Scenarios using Exception Aggregation (SAP Netweaver 7.0 BI)"
http://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/c09f49c2-7448-2c10-ac92-d75f263a0dce?quicklink=index&overridelayout=true
Regards,
Francisco Milán.

Similar Messages

  • Aging Report, variable for Days Outstanding

    Does anyone know the Variable for the 'No. of Days Outstanding' in the Aging report?
    Thanks,
    Marisa

    Hi Marisa......
    It is Variable No. 40 for no. of Days Outstanding.......
    Hope this will work.....
    Regards,
    Rahul

  • Can using query create aging report for GL Account

    Hi all expert,
    I have a challenge scenario which customer request print out aging report for the following GL Account.
    This is not a business partner account. However, customer want display like aging report.
    30 days aging report for the following GL accounts by projects:-
         i)     WIP (Work In Progress) account
         ii)     Accrued Revenue account
         iii)     Accrued Cost account
    Examples:
                            Current Balance       30 day   60 day  90 day   120 day
    Account  WIP         10000               2000        3000      5000     0
    Any idea or example given? If yes, can you provide a query here?
    Regards,
    Eric Tan

    Hi Eric
    In standard SAP Business One this is difficult as the reports are 2 dimensional. To achieve this you will need to write multiple select statements into a temporary table and then select the final result from the temp table. Here is a sample for you to test:
    USE [*DATABASE_NAME*]
    GO
    /****** Object:  StoredProcedure [dbo].[REPORT_NAME]    Script Date: 04/24/2009 13:17:21 ******/
    SET ANSI_NULLS ON
    GO
    SET QUOTED_IDENTIFIER ON
    GO
    CREATE proc [dbo].[*REPORT_NAME*]
    as
    set nocount on
    begin
    DECLARE @Day_no varchar(2)
    DECLARE @Month_no varchar(2)
    DECLARE @Year_no varchar(4)
    DECLARE @Start_Date Datetime
    SET @Day_no = DAY(GetDate())
    SET @Month_no = MONTH(GetDate())
    SET @Year_no = YEAR(GetDate())
    SET @Start_Date = @Year_No + '/' + @Month_no + '/' + @Day_no --  + '/' + @Year_No
    IF OBJECT_ID(N'tempdb..#CRDAGEING', N'U') IS NOT NULL
    drop table #CRDAGEING
    SELECT T0.[CardCode] AS [CardCode], T0.[CardName] AS [CardName], -T0.[Balance] AS [Balance], CAST(0 AS MONEY) AS [Current], CAST(0 AS MONEY) AS [1Week], CAST(0 AS MONEY) AS [2Weeks], CAST(0 AS MONEY) AS [3Weeks], CAST(0 AS MONEY) AS [4Weeks], CAST(0 AS MONEY) AS [5Weeks], CAST(0 AS MONEY) AS [6Weeks], CAST(0 AS MONEY) AS [Over6Weeks], CAST(0 AS MONEY) AS [Avg3Months], CAST (0 AS MONEY) AS [Onhand] INTO #CRDAGEING FROM OCRD T0 WHERE T0.[CardType] = 'S' -- and T0.[CardCode] <> '' --and T0.[DocDate] >= @FromDate AND T0.[DocDate] <= @ToDate
    INSERT dbo.#CRDAGEING SELECT T1.[ShortName], NULL, 0, -SUM(T1.[BalDueDeb] - T1.[BalDueCred]), 0, 0, 0, 0, 0, 0, 0, 0, 0 FROM JDT1 T1, OCRD T2 WHERE T2.[CardType] = 'S' and T2.[CardCode] = T1.[ShortName] and T1.[DueDate] <= @Start_Date GROUP BY T1.[ShortName]
    INSERT dbo.#CRDAGEING SELECT T1.[ShortName], NULL, 0, 0, -SUM(T1.[BalDueDeb] - T1.[BalDueCred]), 0, 0, 0, 0, 0, 0, 0, 0 FROM JDT1 T1, OCRD T2 WHERE T2.[CardType] = 'S' and T2.[CardCode] = T1.[ShortName] and T1.[DueDate] >= DATEADD(DAY,1,@Start_Date) and T1.[DueDate] <= DATEADD(DAY,8,@Start_Date) GROUP BY T1.[ShortName]
    INSERT dbo.#CRDAGEING SELECT T1.[ShortName], NULL, 0, 0, 0, -SUM(T1.[BalDueDeb] - T1.[BalDueCred]), 0, 0, 0, 0, 0, 0, 0 FROM JDT1 T1, OCRD T2 WHERE T2.[CardType] = 'S' and T2.[CardCode] = T1.[ShortName] and T1.[DueDate] > DATEADD(DAY,8,@Start_Date) and T1.[DueDate] <= DATEADD(DAY,15,@Start_Date) GROUP BY T1.[ShortName]
    INSERT dbo.#CRDAGEING SELECT T1.[ShortName], NULL, 0, 0, 0, 0, -SUM(T1.[BalDueDeb] - T1.[BalDueCred]), 0, 0, 0, 0, 0, 0 FROM JDT1 T1, OCRD T2 WHERE T2.[CardType] = 'S' and T2.[CardCode] = T1.[ShortName] and T1.[DueDate] > DATEADD(DAY,15,@Start_Date) and T1.[DueDate] <= DATEADD(DAY,22,@Start_Date) GROUP BY T1.[ShortName]
    INSERT dbo.#CRDAGEING SELECT T1.[ShortName], NULL, 0, 0, 0, 0, 0, -SUM(T1.[BalDueDeb] - T1.[BalDueCred]), 0, 0, 0, 0, 0 FROM JDT1 T1, OCRD T2 WHERE T2.[CardType] = 'S' and T2.[CardCode] = T1.[ShortName] and T1.[DueDate] > DATEADD(DAY,22,@Start_Date) and T1.[DueDate] <= DATEADD(DAY,29,@Start_Date) GROUP BY T1.[ShortName]
    INSERT dbo.#CRDAGEING SELECT T1.[ShortName], NULL, 0, 0, 0, 0, 0, 0, -SUM(T1.[BalDueDeb] - T1.[BalDueCred]), 0, 0, 0, 0 FROM JDT1 T1, OCRD T2 WHERE T2.[CardType] = 'S' and T2.[CardCode] = T1.[ShortName] and T1.[DueDate] > DATEADD(DAY,29,@Start_Date) and T1.[DueDate] <= DATEADD(DAY,36,@Start_Date) GROUP BY T1.[ShortName]
    INSERT dbo.#CRDAGEING SELECT T1.[ShortName], NULL, 0, 0, 0, 0, 0, 0, 0, -SUM(T1.[BalDueDeb] - T1.[BalDueCred]), 0, 0, 0 FROM JDT1 T1, OCRD T2 WHERE T2.[CardType] = 'S' and T2.[CardCode] = T1.[ShortName] and T1.[DueDate] > DATEADD(DAY,36,@Start_Date) and T1.[DueDate] <= DATEADD(DAY,43,@Start_Date) GROUP BY T1.[ShortName]
    INSERT dbo.#CRDAGEING SELECT T1.[ShortName], NULL, 0, 0, 0, 0, 0, 0, 0, 0, -SUM(T1.[BalDueDeb] - T1.[BalDueCred]), 0, 0 FROM JDT1 T1, OCRD T2 WHERE T2.[CardType] = 'S' and T2.[CardCode] = T1.[ShortName] and T1.[DueDate] > DATEADD(DAY,43,@Start_Date)  GROUP BY T1.[ShortName]
    SELECT SR.[CardCode], MAX(SR.[CardName]), SUM(SR.[Balance]) AS [BalanceOwing], SUM(SR.[Current]) AS [Current], SUM(SR.[1Week]) AS [1Week], SUM(SR.[2Weeks]) AS [2Weeks], SUM(SR.[3Weeks]) AS [3Weeks], SUM(SR.[4Weeks]) AS [4Weeks], SUM(SR.[5Weeks]) AS [5Weeks], SUM(SR.[6Weeks]) AS [6Weeks], SUM(SR.[Over6Weeks]) AS [Over6Weeks] FROM dbo.#CRDAGEING SR GROUP BY SR.[CardCode] ORDER BY SR.[CardCode]
    END
    Go to Microsoft SQL Studio manager and select your company database. Then expand the list and select Programmability > Stored Procedures. Right click on Stored Procedures and select New Stored Procedure. Copy the above code over the code in the edit window and change the database name as well as report name. Then select Execute to create the stored procedure. If you make changes, remember to change the word CREATE to ALTER (with other words CREATE for the first execute, and ALTER thereafter). Then in SAP Business One create a new query and leave everything blank. Click on execute and select the pencil to change to edit mode. Remove the words SELECT and type in EXEC REPORT_NAME (change the REPORT_NAME to the name you used in SQL). Then execute again and the results will be displayed in SAP Business One.
    Let me know if you get stuck. Remember the above is an example and will need to be changed to use your tables and fields as required. The basic idea is to move across by one column with each select statement. So for example the first select statement does the CURRENT column, the second one the 30DAYS column, and so on.
    Kind regards
    Peter Juby

  • Variable of No of Days Outstanding in Vendor Liabilities Aging Report

    Dear Experts,
    Which Variable No is use for No of Days Outstanding in Vendor Liabilities Aging Report?
    Thanks,
    Srujal Patel

    Yes I m asking for No of Days Outstanding and I know thats the day.
    But as per My Formula only Days are calculate.
    1. Eg, 10/11/2011 Due Date  14/11/2011 Aging Date
    Result is 4 Days Out Standing thats right.
    But
    2. Eg. 10/09/2011 Due Date 14/11/2011 Aging Date
    Result is 4 Days outstanding thats wrong
    Actual result is 65 Days
    So, which formula I have use in PLD to get proper result

  • Ageing report-Days range as an I/p

    Based on posting date we designed an Ageing report
    0  30  60  90  120  ....
    now users want day range as an i/p
    means => user will i/p day range say 40 then report will be executed for 0  40  80  120 .....
    if i/p for day range is 60 then 0  60  120  180 ......
    previously we resticted the key figure by posting date variable by settng the offset range
    like RFK1--- 0balance restricted by var (0-30)
          RKF2--- 0balance restricted by var (31-60) and so on...
    before we were able to hardcore it but with the current requirment we have to take user i/p var and then accordingly ageing report will be generated..
    pl let us know the right way

    okay...
    we have created one char : ZOFFSET (no of days) and included in the target on which ageing report is based on...,,,, after that we crearted a user exit variable Zvar_offset(ready for i/p) on char ZOFFSET.....
    In ZXRSRU01,
    when zpost_dt  {zpost_dt is the user exit variable ,ready for i/p,defined for posting date}
    if i_step = 1
    date_low = zpost_dt.
    date_high = zpost_dt - Zvar_offset. {not sure whether this logic will work or not!!!}
    CLEAR L_S_RANGE.
    L_S_RANGE-LOW  = date_low.
    L_S_RANGE-high  = date_high.
    L_S_RANGE-SIGN = 'I'.
    L_S_RANGE-OPT  = 'BT'.
    APPEND L_S_RANGE TO E_T_RANGE.
    even after this we cant achieve the motive, as zpost_dt will have range value high and low after user exit execution  but in our query its a single value i/p (user will give only one posting date) ,,,
    also what abt other buckets (other ranges for the same offset) because code will return only one range however we want more ranges for different intervals

  • No. of days outstanding variable in aging report for SAP 8.8

    Hi All,
    Would like to check whether anyone knows what are the variable numbers for 'No of days outstanding' column in aging report? I would like to include this field in the detail aging report print out. Thanks.

    Hi....
    Check this link: [PLD_Variables_8.8|https://websmp105.sap-ag.de/~sapidb/011000358700000449672010E/HowTo_PLD_Variables_88.zip]
    Regards,
    Bala

  • 180 days - customer aging report

    Hi Experts,
    I'm required to revise the Customer Receivable Aging Report from  Business Partners > Business Partner Reports > Aging > Customer Receivable Aging.  the Standard report shows only up to 120+ days.  We require  180+ days.  Could you help me with the work around on this.

    Hi Sachin,
    Could you please send your SQL (and maybe also Crystal Report) for SAP B1 "Customer Aging Report" to me too?
    I am trying to write the SQL which will mimic the SAP B1 standard report, and then add a few more fields because Management wants these.I need to do a lot of Excel gymnastics each time I produce an ageing. I am looking for an SQL Query that will   give the same total as the standard report. It must also list all outstanding invoices individually and their amounts, as well as all other unreconciled items.
    Send me what you have (SQL). I'll try to modify it to suit my requirements. As I'm newbee, it is much easier for me to start from some existing code.
    Thanks a lot
    LEONLAI

  • SAP Query for AR Aging Report

    Hello Gurus-
    I am trying to build a query for Aging report, and would like to include something like this:
    Customer-Reference-Payment terms-Due date-Current-31-60days-61-90days-91-120days-over120days-toatal amount.
    I have an infoset which includes BSID, KNA1, KNB1. I have maintained local fields:
    Due Date  =     Baseline date + cash discount days
    Statement Date = My input date.
    Current    = Condition (DUEDTE >= STATDTE - 30) formula (Amount)
    31 - 60 Days = Condition (DUEDTE >= STATDTE - 60 AND DUEDTE < STATDTE - 30) formula (Amount)
    61 - 90 Days = similar to above
    91 - 120 Days = similar to above
    Amount  = - 1 * (If Debit credit indicator = "H" then "Amount in local currency") otherwise "Amt in Loc.Cur"
    Over 120 Days = similar to above
    When I enter a statement date of today it works hunky dory...it all looks good...my current column looks good and do the rest. When i want to run this query as of couple of months ago (if today is 12/19/08 and i wanted to run my aging report for 10/31/08) it should give me aging as of my statement date 10/31/08 but it does not. It calculates the total amount as of today. I know because of local field "Amount" where i gave amount in local currency, but how would I tell that it should pick up amount in local currency till the statement date?
    Any input in this regards is highly helpful.
    Thanks,
    RNarayan

    Hi Ram,
    On your aging report you want to see invoices which are still not paid (or still open) as of a certain date. This date is "key date". You need to define a variable for key date (which is normally system date if you run today) but it could be a past date.
    So key date is let us say Oct 31st (X) and the system date is Dec 19th. When you run the report as of Oct 31st all invoices that are posted prior to Oct 31st (posting date less than X) and are still in BSID will show on your report. There is no issue here.
    Let us say an invoice was created on Oct 25th (Y) and was paid on Nov 15th (Z). The clearing date is Z. That means if you run the aging report today this invoice will not show.
    But you want to run the report on Oct 31st. This means X is greater than Y but is less than Z.
    Clearing date and posting date are part of BSAD. Report run date is the user input and is a variable.
    With the above concept and with the help of an ABAP programmer you should be able to solve the problem.
    Regards
    Sharabh

  • Aging report from a different base date

    Hi,
    There is a requirement in Aging report. The report should show the the 30, 30-60, 60-90 etc with a different base date/(reference date (OPEN DATE) in stead of the current date. In this case current date should be shown as RUNDATE and there should be one more date field as OPEN DATE  in the page footer.
    Please help me to solve this. Thanks in advance.
    BABASHARI

    Add a parameter for the date that you want to age by.  Use the datediff() function to determine the age of each item in a formula field that uses that age to group items by the range of dates desired (basic syntax):
    dim days as number
    days = datediff("d",{due date}, {?date parameter})
    if days < 31
      formula = "  0 to  30"
    elseif days < 61
      formula = " 31 to  60"
    elseif days < 91
      formula = " 61 to  90"
    elseif days < 121
      formula = " 91 to 120"
    else
      formula = "Over 120"
    end if
    HTH,
    Carl

  • Aging Report SQL Query

    Dear Guys,
    I have tried for aging report query , but still my expected results is not come. Please go through below the table and script data for your reference. Please wirte a query for aging report.
    USE [SAMPLES]
    GO
    /****** Object: Table [dbo].[NEW_DCB_REPORT] Script Date: 02/12/2015 01:19:06 ******/
    SET ANSI_NULLS ON
    GO
    SET QUOTED_IDENTIFIER ON
    GO
    SET ANSI_PADDING OFF
    GO
    CREATE TABLE [dbo].[NEW_DCB_REPORT](
    [MFDB_LedgerNumber] [int] IDENTITY(1,1) NOT NULL,
    [MFDB_TxnDate] [datetime] NOT NULL,
    [MFDB_StateId] [int] NOT NULL,
    [MFDB_RegionId] [int] NOT NULL,
    [MFDB_BranchId] [int] NOT NULL,
    [MFDB_SHGId] [int] NOT NULL,
    [MFDB_SHGName] [varchar](75) NOT NULL,
    [MFDB_ShgMemberId] [int] NOT NULL,
    [MFDB_MemberName] [varchar](50) NOT NULL,
    [MFDB_VillageId] [int] NOT NULL,
    [MFDB_LoanNumber] [int] NOT NULL,
    [MFDB_LoanAmount] [int] NOT NULL,
    [MFDB_DisbursedDate] [datetime] NOT NULL,
    [MFDB_DemandDate] [datetime] NULL,
    [MFDB_CollectionDate] [datetime] NULL,
    [MFDB_InstallmentNumber] [int] NOT NULL,
    [MFDB_ArrearPrincipal] [numeric](18, 2) NOT NULL,
    [MFDB_ArrearInterest] [numeric](18, 2) NOT NULL,
    [MFDB_DemandPrincipal] [numeric](18, 2) NOT NULL,
    [MFDB_DemandInterest] [numeric](18, 2) NOT NULL,
    [MFDB_TotDemandPrincipal] [numeric](18, 2) NOT NULL,
    [MFDB_TotDemandInterest] [numeric](18, 2) NOT NULL,
    [MFDB_AdvOBPrincipal] [numeric](18, 2) NOT NULL,
    [MFDB_AdvOBInterest] [numeric](18, 2) NOT NULL,
    [MFDB_CollectedPrincipal] [numeric](18, 2) NOT NULL,
    [MFDB_CollectedInterest] [numeric](18, 2) NOT NULL,
    [MFDB_AdvCBPrincipal] [numeric](18, 2) NOT NULL,
    [MFDB_AdvCBInterest] [numeric](18, 2) NOT NULL,
    [MFDB_BalancePrincipal] [numeric](18, 2) NOT NULL,
    [MFDB_BalanceInterest] [numeric](18, 2) NOT NULL,
    [MFDB_OS_Pri] [numeric](18, 2) NOT NULL,
    [MFDB_OS_Int] [numeric](18, 2) NOT NULL,
    [MFDB_RepaymentPercentage] [int] NOT NULL,
    [MFDB_LoanSchemeId] [int] NOT NULL,
    [MFDB_LActivityId] [int] NOT NULL,
    [MFDB_LActSpecId] [int] NOT NULL,
    [MFDB_FundAgencyId] [int] NOT NULL,
    [MFDB_LSourceId] [int] NOT NULL,
    [MFDB_Months] [varchar](15) NOT NULL,
    [MFDB_PanchayatId] [int] NOT NULL,
    [MFDB_PanchayatName] [varchar](100) NOT NULL,
    [MFDB_VillageName] [varchar](100) NOT NULL
    ) ON [PRIMARY]
    GO
    SET ANSI_PADDING OFF
    GO
    USE [SAMPLES];
    SET NOCOUNT ON;
    SET XACT_ABORT ON;
    GO
    SET IDENTITY_INSERT [dbo].[NEW_DCB_REPORT] ON;
    BEGIN TRANSACTION;
    INSERT INTO [dbo].[NEW_DCB_REPORT]([MFDB_LedgerNumber], [MFDB_TxnDate], [MFDB_StateId], [MFDB_RegionId], [MFDB_BranchId], [MFDB_SHGId], [MFDB_SHGName], [MFDB_ShgMemberId], [MFDB_MemberName], [MFDB_VillageId], [MFDB_LoanNumber], [MFDB_LoanAmount], [MFDB_DisbursedDate], [MFDB_DemandDate], [MFDB_CollectionDate], [MFDB_InstallmentNumber], [MFDB_ArrearPrincipal], [MFDB_ArrearInterest], [MFDB_DemandPrincipal], [MFDB_DemandInterest], [MFDB_TotDemandPrincipal], [MFDB_TotDemandInterest], [MFDB_AdvOBPrincipal], [MFDB_AdvOBInterest], [MFDB_CollectedPrincipal], [MFDB_CollectedInterest], [MFDB_AdvCBPrincipal], [MFDB_AdvCBInterest], [MFDB_BalancePrincipal], [MFDB_BalanceInterest], [MFDB_OS_Pri], [MFDB_OS_Int], [MFDB_RepaymentPercentage], [MFDB_LoanSchemeId], [MFDB_LActivityId], [MFDB_LActSpecId], [MFDB_FundAgencyId], [MFDB_LSourceId], [MFDB_Months], [MFDB_PanchayatId], [MFDB_PanchayatName], [MFDB_VillageName])
    SELECT 18, '20140422 00:00:00.000', 6, 16, 67, 5514, N'MAHALAXMI-5514', 66735, N'SUNITA', 4624, 1, 10000, '20140422 00:00:00.000', NULL, NULL, 0, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 10000.00, 1051.00, 0, 3, 4, 77, 3, 2, N'Apr - 14', 2927, N'PALI', N'PALI' UNION ALL
    SELECT 162, '20140521 00:00:00.000', 6, 16, 67, 5514, N'MAHALAXMI-5514', 66735, N'SUNITA', 4624, 1, 10000, '20140422 00:00:00.000', '20140521 00:00:00.000', NULL, 1, 0.00, 0.00, 0.00, 150.00, 0.00, 150.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 150.00, 10000.00, 1051.00, 0, 3, 4, 77, 3, 2, N'May - 14', 2927, N'PALI', N'PALI' UNION ALL
    SELECT 13932, '20140621 00:00:00.000', 6, 16, 67, 5514, N'MAHALAXMI-5514', 66735, N'SUNITA', 4624, 1, 10000, '20140422 00:00:00.000', '20140621 00:00:00.000', NULL, 2, 0.00, 150.00, 909.00, 150.00, 909.00, 300.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 909.00, 300.00, 10000.00, 1051.00, 0, 3, 4, 77, 3, 2, N'Jun - 14', 2927, N'PALI', N'PALI' UNION ALL
    SELECT 32505, '20140721 00:00:00.000', 6, 16, 67, 5514, N'MAHALAXMI-5514', 66735, N'SUNITA', 4624, 1, 10000, '20140422 00:00:00.000', '20140721 00:00:00.000', NULL, 3, 909.00, 300.00, 909.00, 136.00, 1818.00, 436.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 1818.00, 436.00, 10000.00, 1051.00, 0, 3, 4, 77, 3, 2, N'Jul - 14', 2927, N'PALI', N'PALI' UNION ALL
    SELECT 62524, '20140821 00:00:00.000', 6, 16, 67, 5514, N'MAHALAXMI-5514', 66735, N'SUNITA', 4624, 1, 10000, '20140422 00:00:00.000', '20140821 00:00:00.000', NULL, 4, 1818.00, 436.00, 909.00, 123.00, 2727.00, 559.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 2727.00, 559.00, 10000.00, 1051.00, 0, 3, 4, 77, 3, 2, N'Aug - 14', 2927, N'PALI', N'PALI' UNION ALL
    SELECT 100871, '20140921 00:00:00.000', 6, 16, 67, 5514, N'MAHALAXMI-5514', 66735, N'SUNITA', 4624, 1, 10000, '20140422 00:00:00.000', '20140921 00:00:00.000', NULL, 5, 2727.00, 559.00, 909.00, 109.00, 3636.00, 668.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 3636.00, 668.00, 10000.00, 1051.00, 0, 3, 4, 77, 3, 2, N'Sep - 14', 2927, N'PALI', N'PALI' UNION ALL
    SELECT 153679, '20141021 00:00:00.000', 6, 16, 67, 5514, N'MAHALAXMI-5514', 66735, N'SUNITA', 4624, 1, 10000, '20140422 00:00:00.000', '20141021 00:00:00.000', NULL, 6, 3636.00, 668.00, 909.00, 96.00, 4545.00, 764.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 4545.00, 764.00, 10000.00, 1051.00, 0, 3, 4, 77, 3, 2, N'Oct - 14', 2927, N'PALI', N'PALI' UNION ALL
    SELECT 203840, '20141119 00:00:00.000', 6, 16, 67, 5514, N'MAHALAXMI-5514', 66735, N'SUNITA', 4624, 1, 10000, '20140422 00:00:00.000', NULL, '20141119 00:00:00.000', 2, 4545.00, 764.00, 0.00, 0.00, 4545.00, 764.00, 0.00, 0.00, 10000.00, 150.00, 5455.00, 0.00, 0.00, 614.00, 0.00, 901.00, 0, 3, 4, 77, 3, 2, N'Nov - 14', 2927, N'PALI', N'PALI' UNION ALL
    SELECT 291259, '20141221 00:00:00.000', 6, 16, 67, 5514, N'MAHALAXMI-5514', 66735, N'SUNITA', 4624, 1, 10000, '20140422 00:00:00.000', '20141221 00:00:00.000', NULL, 8, 0.00, 614.00, 909.00, 68.00, 909.00, 682.00, 5455.00, 0.00, 0.00, 0.00, 4546.00, 0.00, 0.00, 682.00, 0.00, 901.00, 0, 3, 4, 77, 3, 2, N'Dec - 14', 2927, N'PALI', N'PALI' UNION ALL
    SELECT 363176, '20150121 00:00:00.000', 6, 16, 67, 5514, N'MAHALAXMI-5514', 66735, N'SUNITA', 4624, 1, 10000, '20140422 00:00:00.000', '20150121 00:00:00.000', NULL, 9, 0.00, 682.00, 909.00, 55.00, 909.00, 737.00, 4546.00, 0.00, 0.00, 0.00, 3637.00, 0.00, 0.00, 737.00, 0.00, 901.00, 0, 3, 4, 77, 3, 2, N'Jan - 15', 2927, N'PALI', N'PALI'
    COMMIT;
    RAISERROR (N'[dbo].[NEW_DCB_REPORT]: Insert Batch: 1.....Done!', 10, 1) WITH NOWAIT;
    GO
    SET IDENTITY_INSERT [dbo].[NEW_DCB_REPORT] OFF;
    I expected results as below:
    Report As On Date: 30-10-2014
    S.No. SHG NAME MEMBER NAME <=30 31-60 61-90 91-120 91-180 181-365 365 - 689 Above 2 Yrs
    1 MAHALAXMI-5514 SUNITA 0 909 1818 2727 3636 4545 0 0
    Report As On Date:
    30-10-2014
    S.No.
    SHG NAME
    MEMBER NAME
    <=30
    31-60
    61-90
    91-120
    91-180
    181-365
    365 - 689
    Above 2 Yrs
    1
    MAHALAXMI-5514
    SUNITA
    0
    909
    1818
    2727
    3636
    4545
    0
    0

    Thanks for your replay,  I have checked your query it seems nearly ok, Please find my script which i tried above for the same.
    DECLARE @i_AsOnDate AS DATETIME = '2014-09-30'
    ;WITH CA1 AS
    SELECT ROW_NUMBER() OVER(Order  By DR.MFDB_SHGName,DR.MFDB_MemberName)
    AS SerialNumber,
      DR.MFDB_SHGId
    AS ShgId,
      DR.MFDB_SHGName
    AS ShgName,
      DR.MFDB_ShgMemberId
    AS MemId,
      DR.MFDB_MemberName
    AS MemName,
      ISNULL((SELECT CAST(SUM(LD.MFDB_StdPrincipal) AS BIGINT )
      FROM  MFDB_LOAN_DISBURSEMENT LD
      WHERE LD.MFDB_SHGId
    = DR.MFDB_SHGId 
      AND   LD.MFDB_ShgMemberId
    = DR.MFDB_ShgMemberId 
      AND   LD.MFDB_LoanNumber
    = DR.MFDB_LoanNumber
      AND   LD.MFDB_ApprovalStatus = 1
      AND   DATEDIFF(DAY,@i_AsOnDate,LD.MFDB_CollectionDate) > 0 ),0)
    AS YETDUE,
    ISNULL((SELECT TOP 1 CAST(ND.MFDB_BalancePrincipal AS BIGINT )
    FROM dbo.MFDB_NEW_DCB_REPORT ND
    WHERE ND.MFDB_SHGId
    = DR.MFDB_SHGId 
    AND   ND.MFDB_ShgMemberId
    = DR.MFDB_ShgMemberId  
    AND   ND.MFDB_LoanNumber
    = DR.MFDB_LoanNumber
    AND   DATEDIFF(Day,ND.MFDB_TxnDate,@i_AsOnDate) >= 0
    AND   DATEDIFF(Day,ND.MFDB_TxnDate,@i_AsOnDate) <= 30
    ORDER BY ND.MFDB_LedgerNumber DESC),0)
    AS '0-30',
    ISNULL((SELECT TOP 1 CAST(ND.MFDB_BalancePrincipal AS BIGINT )
    FROM dbo.MFDB_NEW_DCB_REPORT ND
    WHERE ND.MFDB_SHGId
    = DR.MFDB_SHGId 
    AND   ND.MFDB_ShgMemberId
    = DR.MFDB_ShgMemberId  
    AND   ND.MFDB_LoanNumber
    = DR.MFDB_LoanNumber
    AND   DATEDIFF(Day,ND.MFDB_TxnDate,@i_AsOnDate) <= 60 
    AND   DATEDIFF(Day,ND.MFDB_TxnDate,@i_AsOnDate) > 30
    ORDER BY ND.MFDB_LedgerNumber DESC),0)
    AS '31-60',
    ISNULL((SELECT TOP 1 CAST(ND.MFDB_BalancePrincipal AS BIGINT )
    FROM dbo.MFDB_NEW_DCB_REPORT ND
    WHERE ND.MFDB_SHGId
    = DR.MFDB_SHGId 
    AND   ND.MFDB_ShgMemberId
    = DR.MFDB_ShgMemberId  
    AND   ND.MFDB_LoanNumber
    = DR.MFDB_LoanNumber
    AND   DATEDIFF(Day,ND.MFDB_TxnDate,@i_AsOnDate) <= 90 
    AND   DATEDIFF(Day,ND.MFDB_TxnDate,@i_AsOnDate) > 60
    ORDER BY ND.MFDB_LedgerNumber DESC),0)
    AS '61-90',
    ISNULL((SELECT TOP 1 CAST(ND.MFDB_BalancePrincipal AS BIGINT )
    FROM dbo.MFDB_NEW_DCB_REPORT ND
    WHERE ND.MFDB_SHGId
    = DR.MFDB_SHGId 
    AND   ND.MFDB_ShgMemberId
    = DR.MFDB_ShgMemberId  
    AND   ND.MFDB_LoanNumber
    = DR.MFDB_LoanNumber
    AND   DATEDIFF(Day,ND.MFDB_TxnDate,@i_AsOnDate) <= 120 
    AND   DATEDIFF(Day,ND.MFDB_TxnDate,@i_AsOnDate) > 90
    ORDER BY ND.MFDB_LedgerNumber DESC),0)
    AS '91-120',
    ISNULL((SELECT TOP 1 CAST(ND.MFDB_BalancePrincipal AS BIGINT )
    FROM dbo.MFDB_NEW_DCB_REPORT ND
    WHERE ND.MFDB_SHGId
    = DR.MFDB_SHGId 
    AND   ND.MFDB_ShgMemberId
    = DR.MFDB_ShgMemberId  
    AND   ND.MFDB_LoanNumber
    = DR.MFDB_LoanNumber
    AND   DATEDIFF(Day,ND.MFDB_TxnDate,@i_AsOnDate) <= 180 
    AND   DATEDIFF(Day,ND.MFDB_TxnDate,@i_AsOnDate) > 120
    ORDER BY ND.MFDB_LedgerNumber DESC),0)
    AS '121-180',
    ISNULL((SELECT TOP 1 CAST(ND.MFDB_BalancePrincipal AS BIGINT )
    FROM dbo.MFDB_NEW_DCB_REPORT ND
    WHERE ND.MFDB_SHGId
    = DR.MFDB_SHGId 
    AND   ND.MFDB_ShgMemberId
    = DR.MFDB_ShgMemberId  
    AND   ND.MFDB_LoanNumber
    = DR.MFDB_LoanNumber
    AND   DATEDIFF(Day,ND.MFDB_TxnDate,@i_AsOnDate) <= 365 
    AND   DATEDIFF(Day,ND.MFDB_TxnDate,@i_AsOnDate) > 180
    ORDER BY ND.MFDB_LedgerNumber DESC),0)
    AS '181-365',
    ISNULL((SELECT TOP 1 CAST(ND.MFDB_BalancePrincipal AS BIGINT )
    FROM dbo.MFDB_NEW_DCB_REPORT ND
    WHERE ND.MFDB_SHGId
    = DR.MFDB_SHGId 
    AND   ND.MFDB_ShgMemberId
    = DR.MFDB_ShgMemberId  
    AND   ND.MFDB_LoanNumber
    = DR.MFDB_LoanNumber
    AND   DATEDIFF(Day,ND.MFDB_TxnDate,@i_AsOnDate) <= 689 
    AND   DATEDIFF(Day,ND.MFDB_TxnDate,@i_AsOnDate) > 365
    ORDER BY ND.MFDB_LedgerNumber DESC),0)
    AS '366-689',
    ISNULL((SELECT TOP 1 CAST(ND.MFDB_BalancePrincipal AS BIGINT )
    FROM dbo.MFDB_NEW_DCB_REPORT ND
    WHERE ND.MFDB_SHGId
    = DR.MFDB_SHGId 
    AND   ND.MFDB_ShgMemberId
    = DR.MFDB_ShgMemberId  
    AND   ND.MFDB_LoanNumber
    = DR.MFDB_LoanNumber
    AND   DATEDIFF(Day,ND.MFDB_TxnDate,@i_AsOnDate) <= 730 
    AND   DATEDIFF(Day,ND.MFDB_TxnDate,@i_AsOnDate) > 689
    ORDER BY ND.MFDB_LedgerNumber DESC),0)
    AS 'Above_2_Yrs'   
    FROM DBO.MFDB_NEW_DCB_REPORT DR
    WHERE DR.MFDB_BranchId
    = 67
    AND   DR.MFDB_SHGId
    IN (5514)
    AND   DR.MFDB_ShgMemberId = 66735
    AND   DATEDIFF(DAY,MFDB_TxnDate,@i_AsOnDate) >= 0  
    SELECT * FROM CA1
    results after the execution of the script:
    SerialNumber
    ShgId
    ShgName
    MemId
    MemName
    YETDUE
    0-30
    31-60
    61-90
    91-120
    121-180
    181-365
    366-689
    Above_2_Yrs
    3
    5514
    MAHALAXMI-5514
    SUNITA
    10000
    3636
    2727
    1818
    909
    0
    0
    0
    0
    2
    5514
    MAHALAXMI-5514
    SUNITA
    10000
    3636
    2727
    1818
    909
    0
    0
    0
    0
    6
    5514
    MAHALAXMI-5514
    SUNITA
    10000
    3636
    2727
    1818
    909
    0
    0
    0
    0
    4
    5514
    MAHALAXMI-5514
    SUNITA
    10000
    3636
    2727
    1818
    909
    0
    0
    0
    0
    1
    5514
    MAHALAXMI-5514
    SUNITA
    10000
    3636
    2727
    1818
    909
    0
    0
    0
    0
    5
    5514
    MAHALAXMI-5514
    SUNITA
    10000
    3636
    2727
    1818
    909
    0
    0
    0
    0
    But I expected results is:
    s.n
    ShgId
    ShgName
    MemId
    MemName
    YETDUE
    0-30
    31-60
    61-90
    91-120
    121-180
    181-365
    366-689
    Above_2_Yrs
    1
    5514
    MAHALAXMI-5514
    66735
    SUNITA
    10000
    909
    1818
    2727
    3636
    0
    0
    0
    I want only one record per member with aging .. please advice me for further action.

  • Ar aging report, need help urgent please help!

    Hey All Gurus,
    Im in a thick soup here. I am trying to do something like this -
    if you see the selection screen i have rep and super rep, when a user enters a rep value --- it should use the same value to pull all open items for the super rep as well, since they are essentially the same. please help! this one needs to be done fast. i am pasting the code so that it will be easier ...
    thanks a million!
    *& Report ZFDOFW04_NEW
    REPORT ZFDOFW04_NEW MESSAGE-ID FR
    LINE-SIZE 132
    LINE-COUNT 60.
    *==================================================================
    Program: ZFDOFW03 - Aged Trial Balance Report
    This produces an Accounts Receivable Past Due Aging Report
    in a more simplified/condensed format than the
    SAP supplied aging report program - RFDOPR10.
    This program is a modified copy of RFDOFW00, - a SAP
    Future-Due Report.
    This was a 'rush' job - program probably should be
    rewritten someday not using logical databases as that
    maybe why this runs so slowly!
    Original: Feb 1997.
    MAINTENANCE HISTORY:
    NES071797 Copied from ZFDOFW03. Adding parameter for saeles rep.
    JDEDERER - changed header text so it is differnet from ZFDORW03. 9/23
    *TEXT SYMBOLS :
    001 Open items per
    002 O p e n
    003 D u e o n
    004 cc ba in total
    005 until
    006 Days until
    007 Days over
    008 Days
    009 over
    011 valid until........
    012 Insurance limit.....
    016 F u t u r e
    017 + days
    018 D u e
    020 Last dunn.notice...
    021 Dunning level....
    030 S U M M A R Y S H E E T
    031 =====================
    050 Name Page
    051 Burton Snowboard
    SELECTION TEXTS:
    SUMMEN Output totals only
    TAGE1 Due date I until
    TAGE2 Due date II until
    TAGE3 Due date III until
    TAGE4 Due date IV until
    TABLES: T001, KNA1, KNB1, KNB5, BSID, BSEGA, RFPDO1, KNVP,
    T014, "credit control areas JAM
    KNVK, "cust master - contact partner JAM
    T014T, "Credit control areas names
    BKPF, "TONY ISSUE 4743
    TVKO, "TONY ISSUE 4743
    KNKK. "cust master - credit mgmt JAM
    TYPES: BEGIN OF TOT_TYPE, "DEVK939546
    BUKRS LIKE LFB1-BUKRS, "DEVK939546
    GSBER LIKE BSIK-GSBER, "DEVK939546
    KKBER LIKE BSID-KKBER,
    RAST1 TYPE P, "DEVK939546
    RAST2 TYPE P, "DEVK939546
    RAST3 TYPE P, "DEVK939546
    RAST4 TYPE P, "DEVK939546
    RAST5 TYPE P, "DEVK939546
    RAST6 TYPE P, "DEVK939546
    RAST7 TYPE P, "DEVK939546
    END OF TOT_TYPE, "DEVK939546
    TOT_TAB TYPE TOT_TYPE OCCURS 0. "DEVK939546
    CONSTANTS:
    C_FALSE TYPE I VALUE 0, "JAM
    C_TRUE TYPE I VALUE 1.
    DATA: BEGIN OF GTAB OCCURS 1000,
    SUPER(10) TYPE C, "TONYC
    REP(10) TYPE C, "TONYC
    FILKD(10), "tonyc show buying groups
    LAND1 LIKE KNA1-LAND1,
    GSBER LIKE BSIK-GSBER,
    REGIO LIKE KNA1-REGIO,
    NAME1 LIKE KNA1-NAME1,
    NAME2 LIKE KNA1-NAME2,
    ORT01 LIKE KNA1-ORT01,
    TELF1 LIKE KNVK-TELF1, "telephone number JAM
    CONT_NAME1 LIKE KNVK-NAME1, "contact name JAM
    NAMEV LIKE KNVK-NAMEV, "contact name JAM
    KUNNR LIKE KNA1-KUNNR, "TONYC
    BUKRS LIKE LFB1-BUKRS, "TONYC
    KKBER LIKE BSID-KKBER, "tonyc issue #2500
    ZTERM LIKE KNB1-ZTERM, "tonyc issue #2500
    KLIMK_TXT(22) TYPE C, "credit limit JAM
    WAERS LIKE T014-WAERS, "currency JAM
    SORT_GSB, "TONYC
    RAST1 TYPE P,
    RAST2 TYPE P,
    RAST3 TYPE P,
    RAST4 TYPE P,
    RAST5 TYPE P,
    RAST6 TYPE P,
    RAST7 TYPE P,
    T_IND,
    END OF GTAB.
    DATA HOLD_NAME(40).
    DATA HOLD_BUKRS LIKE T001-BUKRS. "tonyc
    DATA GOOD_SUPER_REP. "tonyc
    DATA: HOLD_REP LIKE KNA1-KUNNR, "tonyc
    SUPER_NAME LIKE KNA1-NAME1, "tonyc
    REP_NAME LIKE KNA1-NAME1. "tonyc
    DATA NAME_LENGTH(2) TYPE C. "tonyc
    DATA BACKSLASH(3) VALUE ' / '. "tonyc
    DATA REPS_INFO(70) TYPE C. "tonyc
    DATA REPORT_TYPE(12) TYPE C.
    DATA: C_CREDIT_ABTNR LIKE KNVK-ABTNR. "dept 003 = credit
    DATA Z_HOLD_LIMIT(22) TYPE N. "tonyc issue#2216
    DATA Z_DESCRIPTION(18). "tonyc issue#2216
    DATA WRITE_TOTAL.
    DATA HOLD_KLIMK LIKE KNKK-KLIMK.
    DATA HOLD_KLIMK2(22) TYPE C.
    DATA HOLD-CTLPC LIKE KNKK-CTLPC.
    DATA HOLD-CTLPC-TEXT LIKE T691T-RTEXT.
    DATA HOLD_ZTERM LIKE KNVV-ZTERM.
    DATA TOTAL_RAST7 TYPE P.
    DATA TOTAL_RAST2 TYPE P.
    DATA TOTAL_RAST3 TYPE P.
    DATA TOTAL_RAST4 TYPE P.
    DATA TOTAL_RAST5 TYPE P.
    DATA TOTAL_RAST6 TYPE P.
    DATA TOTAL_RAST1 TYPE P.
    DATA HOLD_BUKRS2 LIKE T001-BUKRS.
    DATA HOLD_KKBER LIKE BSID-KKBER.
    DATA HOLD_KKBER_DESC LIKE T014T-KKBTX.
    DATA HOLD_KKBER_DESC2 LIKE T014T-KKBTX.
    DATA HOLD_KUNNR2 LIKE KNA1-KUNNR.
    DATA L_FIRST_DAY_OF_FISCAL LIKE SY-DATUM. "tonyc issue #3047
    DATA: STAB TYPE TOT_TAB WITH HEADER LINE, "DEVK939546
    RTOT TYPE TOT_TAB WITH HEADER LINE, "DEVK939546
    STOT TYPE TOT_TAB WITH HEADER LINE, "DEVK939546
    OP,
    MAXMANDT LIKE DD_STIDA,
    MAXMANST TYPE P,
    SUMKLIMB TYPE P,
    SUMVLIBB TYPE P,
    VERZUG TYPE P,
    OBAD TYPE P,
    BLOCK_CNT TYPE P,
    INTENS,
    ONEBYTE(1) TYPE C,
    TAGE1A LIKE RFPDO1-ALLGFAEL,
    TAGE2A LIKE RFPDO1-ALLGFAEL,
    TAGE3A LIKE RFPDO1-ALLGFAEL,
    HOLD_KUNNR LIKE KNA1-KUNNR, "tonyc
    HOLD_SUPER LIKE KNA1-KUNNR, "tonyc
    HOLD_REP2 LIKE KNA1-KUNNR, "tonyc
    SUPER_REP LIKE KNA1-KUNNR, "tonyc
    TEMP_TELF1 LIKE KNA1-TELF1, "JAM
    IT_T014 LIKE T014 OCCURS 0 WITH HEADER LINE, "JAM
    G_KLIMK_TXT LIKE GTAB-KLIMK_TXT, "JAM
    G_WAERS LIKE GTAB-WAERS, "JAM
    G_CONT_NAME(50) TYPE C. "JA
    DATA FILL_REP_INFO.
    BC SUNILP 05/14/2007
    DATA: BEGIN OF ITAB_VBRP OCCURS 0.
    INCLUDE STRUCTURE VBRP.
    DATA: END OF ITAB_VBRP.
    DATA: T_PERC TYPE F,
    SUM_NETWR LIKE VBRP-NETWR.
    *DATA: GTAB_LINES LIKE GTAB OCCURS 0 WITH HEADER LINE.
    DATA: BEGIN OF GTAB_LINES OCCURS 0.
    INCLUDE STRUCTURE GTAB.
    DATA: IND(1),
    OBAD TYPE P.
    DATA: END OF GTAB_LINES.
    DATA: BEGIN OF ITAB_VBRP1 OCCURS 0,
    VBELN LIKE VBRP-VBELN,
    NETWR LIKE VBRP-NETWR,
    ZZMREP LIKE VBRP-ZZMREP, "Super Rep
    ZZLREP LIKE VBRP-ZZLREP, "Rep
    PERC TYPE F,
    END OF ITAB_VBRP1.
    EC SUNILP 05/14/2007
    BEGIN_OF_BLOCK 2.
    PARAMETERS: REGIO LIKE KNA1-REGIO.
    PARAMETERS: CONSOL AS CHECKBOX. "TONYC
    PARAMETERS: P_KKBER AS CHECKBOX, "TONYC
    P_CONV AS CHECKBOX. "tonyc issue #3047
    PARAMETERS: SUMMEN LIKE RFPDO1-ALLGSUMM,
    TAGE1 LIKE RFPDO1-ALLGFAEL DEFAULT '30',
    TAGE2 LIKE RFPDO1-ALLGFAEL DEFAULT '60',
    TAGE3 LIKE RFPDO1-ALLGFAEL DEFAULT '90',
    TAGE4 LIKE RFPDO1-ALLGFAEL DEFAULT '120'.
    END_OF_BLOCK 2.
    BEGIN_OF_BLOCK 3.
    SELECT-OPTIONS: P_SUPREP FOR KNVP-KUNNR, "Super REP "DEVK939546
    P_REP FOR KNVP-KUNNR, "SALES REP "DEVK939546
    P_VKORG FOR TVKO-VKORG, "TONYC ISSUE 4743
    P_LOTKZ FOR BKPF-LOTKZ. "TONYC ISSUE 4743
    END_OF_BLOCK 3.
    INITIALIZATION. "JAM
    PERFORM LOAD_T014. "JAM
    refresh dd_augdt.
    clear dd_augdt.
    dd_augdt-option = 'EQ'.
    dd_augdt-sign = 'I'.
    dd_augdt-low = ' '.
    append dd_augdt.
    AT SELECTION-SCREEN.
    IF CONSOL = 'X'.
    IF NOT P_SUPREP[] IS INITIAL. "DEVK939546
    MESSAGE E999 WITH 'Consolidated report not allowed w/ Super Rep'.
    ENDIF.
    ENDIF.
    CHECK IF THE REP INFO IS ADDED OR NOT - VS
    IF NOT P_SUPREP IS INITIAL OR"TONY ISSUE 4743
    NOT P_REP IS INITIAL."TONY ISSUE 4743
    FILL_REP_INFO = 'X'."TONY ISSUE 4743
    ENDIF."TONY ISSUE 4743
    START-OF-SELECTION.
    get_frame_title 2.
    add function module to track usage JD 10/13/98 *****
    CALL FUNCTION 'Z_RUN_LOG'
    EXCEPTIONS
    OTHERS = 1.
    *IF NOT P_SUPREP IS INITIAL AND NOT P_REP IS INITIAL.
    P_SUPREP = ' '.
    *ENDIF.
    GET KNA1 FIELDS LAND1 REGIO KUNNR NAME1 NAME2 ORT01 TELF1. "JAM
    new-page.
    skip.
    TEMP_TELF1 = KNA1-TELF1.
    MAXMANDT = '19000101'.
    MAXMANST = 0.
    SUMVLIBB = 0.
    PERFORM GET_CUST_CONTACT. "JAM
    Check sales rep- NES071797
    Get any valid record and exit.
    IF NOT p_suprep[] IS INITIAL. "DEVK939546 "TONY ISSUE 4743 start
    good_super_rep = ' '.
    SELECT kunn2 INTO super_rep FROM knvp UP TO 1 ROWS
    WHERE
    kunnr = kna1-kunnr AND
    parvw = 'ZS' AND
    kunn2 IN p_suprep.
    EXIT.
    ENDSELECT.
    IF sy-subrc = 0.
    good_super_rep = 'X'.
    gtab-super = super_rep.
    super_rep = ' '.
    ENDIF.
    CHECK good_super_rep = 'X'.
    SELECT kunn2 INTO gtab-rep FROM knvp UP TO 1 ROWS
    WHERE
    kunnr = kna1-kunnr AND
    parvw = 'ZR' AND
    kunn2 IN p_rep.
    EXIT.
    ENDSELECT.
    CHECK sy-subrc = 0.
    ELSEIF NOT p_rep[] IS INITIAL. "DEVK939546
    SELECT kunn2 INTO gtab-rep FROM knvp UP TO 1 ROWS
    WHERE
    kunnr = kna1-kunnr AND
    parvw = 'ZR' AND
    kunn2 IN p_rep.
    EXIT.
    ENDSELECT.
    CHECK sy-subrc = 0.
    ENDIF. "TONY ISSUE 4743 end
    GET KNB1 FIELDS BUKRS VLIBB ZTERM. "tonyc #2500
    GTAB-BUKRS = KNB1-BUKRS.
    GTAB-ZTERM = KNB1-ZTERM.
    SUMVLIBB = SUMVLIBB + KNB1-VLIBB.
    GET KNB5.
    IF KNB5-MADAT > MAXMANDT.
    MAXMANDT = KNB5-MADAT.
    ENDIF.
    IF KNB5-MAHNS > MAXMANST.
    MAXMANST = KNB5-MAHNS.
    ENDIF.
    SUMKLIMB = SUMKLIMB + KLIMB.
    GET BSID.
    CHECK BSID-BSTAT = SPACE.
    field was intended for Business Area, changed to use Currency
    GTAB-GSBER = BSID-WAERS.
    IF P_KKBER = 'X'. "TONYC ISSUE #2500
    IF BSID-KKBER = ' '.
    GTAB-KKBER = BSID-BUKRS.
    ELSE.
    GTAB-KKBER = BSID-KKBER. "TONYC ISSUE #2500
    ENDIF.
    ENDIF. "TONYC ISSUE #2500
    SELECT SINGLE * FROM BKPF "TONY ISSUE 4743
    WHERE BUKRS = BSID-BUKRS "TONY ISSUE 4743
    AND BELNR = BSID-BELNR "TONY ISSUE 4743
    AND GJAHR = BSID-GJAHR. "TONY ISSUE 4743
    BC SUNILP 05/14/2007
    IF BKPF-XREF2_HD IS NOT INITIAL.
    CHECK BKPF-XREF2_HD IN P_SUPREP. "TONY ISSUE 4743
    ELSE.
    IF P_REP[] IS INITIAL.
    REFRESH: ITAB_VBRP, ITAB_VBRP1.
    IF NOT BKPF-XBLNR IS INITIAL.
    SELECT * FROM VBRP INTO ITAB_VBRP WHERE VBELN = BKPF-XBLNR.
    APPEND ITAB_VBRP. CLEAR ITAB_VBRP.
    ENDSELECT.
    CHECK ITAB_VBRP[] IS NOT INITIAL.
    CLEAR: SUM_NETWR.
    LOOP AT ITAB_VBRP.
    CHECK ITAB_VBRP-ZZMREP IN P_SUPREP.
    CHECK ITAB_VBRP-ZZLREP IN P_REP.
    MOVE-CORRESPONDING ITAB_VBRP TO ITAB_VBRP1.
    COLLECT: ITAB_VBRP1.
    SUM_NETWR = SUM_NETWR + ITAB_VBRP-NETWR.
    CLEAR ITAB_VBRP.
    ENDLOOP.
    CHECK ITAB_VBRP1[] IS NOT INITIAL.
    LOOP AT ITAB_VBRP1.
    CLEAR: T_PERC.
    T_PERC = ( ITAB_VBRP1-NETWR / SUM_NETWR ).
    ITAB_VBRP1-PERC = T_PERC.
    MODIFY ITAB_VBRP1 INDEX SY-TABIX TRANSPORTING PERC.
    ENDLOOP.
    ENDIF.
    ENDIF.
    ENDIF.
    EC SUNILP 05/14/2007
    IF FILL_REP_INFO = 'X'.
    GTAB-SUPER = BKPF-XREF2_HD. "TONY ISSUE 4743 "MOVE THE CONTENTS OF XREF2_HD TO GTAB INTERNAL TABLE - VS
    ENDIF.
    BC SUNILP 05/14/2007
    IF BKPF-XREF1_HD IS NOT INITIAL.
    CHECK BKPF-XREF1_HD IN P_REP. "TONY ISSUE 4743 " ELSE MOVE THE CONTENTS OF - VS
    ELSE.
    REFRESH: ITAB_VBRP, ITAB_VBRP1.
    IF NOT BKPF-XBLNR IS INITIAL.
    SELECT * FROM VBRP INTO ITAB_VBRP WHERE VBELN = BKPF-XBLNR.
    APPEND ITAB_VBRP. CLEAR ITAB_VBRP.
    ENDSELECT.
    CHECK ITAB_VBRP[] IS NOT INITIAL.
    CLEAR: SUM_NETWR.
    LOOP AT ITAB_VBRP.
    CHECK ITAB_VBRP-ZZMREP IN P_SUPREP.
    CHECK ITAB_VBRP-ZZLREP IN P_REP.
    MOVE-CORRESPONDING ITAB_VBRP TO ITAB_VBRP1.
    COLLECT: ITAB_VBRP1.
    SUM_NETWR = SUM_NETWR + ITAB_VBRP-NETWR.
    CLEAR ITAB_VBRP.
    ENDLOOP.
    CHECK ITAB_VBRP1[] IS NOT INITIAL.
    LOOP AT ITAB_VBRP1.
    CLEAR: T_PERC.
    T_PERC = ( ITAB_VBRP1-NETWR / SUM_NETWR ).
    ITAB_VBRP1-PERC = T_PERC.
    MODIFY ITAB_VBRP1 INDEX SY-TABIX TRANSPORTING PERC.
    ENDLOOP.
    ENDIF.
    ENDIF.
    EC SUNILP 05/14/2007
    IF FILL_REP_INFO = 'X'.
    GTAB-REP = BKPF-XREF1_HD. "TONY ISSUE 4743
    ENDIF.
    CHECK BKPF-LOTKZ IN P_LOTKZ. "TONY ISSUE 4743
    CHECK BKPF-BRNCH IN P_VKORG. "TONY ISSUE 4743
    SELECT SINGLE FILKD INTO GTAB-FILKD FROM BSEG
    WHERE BUKRS = BSID-BUKRS
    AND BELNR = BSID-BELNR
    AND GJAHR = BSID-GJAHR
    AND BUZEI = BSID-BUZEI.
    gtab-gsber = bsid-gsber.
    get rep info for each bsid record
    IF NOT P_SUPREP IS INITIAL. "tonyc
    SELECT KUNNR FROM VBPA INTO HOLD_REP UP TO 1 ROWS "tonyc
    WHERE VBELN = BSID-VBELN "tonyc
    AND PARVW = 'ZR'. "tonyc
    ENDSELECT. "tonyc
    IF NOT P_REP IS INITIAL. "tonyc
    CHECK HOLD_REP = P_REP. "tonyc
    ENDIF. "tonyc
    GTAB-REP = HOLD_REP. "tonyc
    HOLD_REP = ' '. "tonyc
    ENDIF. "tonyc
    PERFORM GET_KNKK_INFO. "JAM
    GTAB-KLIMK_TXT = G_KLIMK_TXT.
    GTAB-WAERS = G_WAERS.
    GTAB-LAND1 = KNA1-LAND1.
    GTAB-REGIO = KNA1-REGIO.
    GTAB-KUNNR = KNA1-KUNNR.
    GTAB-NAME1 = KNA1-NAME1.
    GTAB-NAME2 = KNA1-NAME2.
    GTAB-ORT01 = KNA1-ORT01.
    *if there is no phone number for the contact, pull the phone
    *number from the sold-to
    IF KNVK-TELF1 = ' '.
    GTAB-TELF1 = TEMP_TELF1.
    ELSE.
    GTAB-TELF1 = KNVK-TELF1. "JAM
    ENDIF.
    GTAB-CONT_NAME1 = KNVK-NAME1.
    GTAB-NAMEV = KNVK-NAMEV.
    verzug = bsega-netdt - dd_stida.
    VERZUG = DD_STIDA - BSEGA-NETDT. "days past due calculation
    OP = 'X'.
    GTAB-RAST2 = GTAB-RAST3 = GTAB-RAST4 = 0.
    GTAB-RAST5 = GTAB-RAST6 = OBAD = GTAB-RAST7 = 0.
    IF VERZUG LE 0. "future due
    GTAB-RAST1 = BSEGA-WRSHB.
    ELSE.
    IF VERZUG LE TAGE1. "past due 1 to tage1 days
    GTAB-RAST1 = BSEGA-WRSHB.
    GTAB-RAST2 = BSEGA-WRSHB.
    OBAD = BSEGA-WRSHB.
    ELSE.
    IF VERZUG LE TAGE2. "past due tage1 to tage2 days
    GTAB-RAST1 = BSEGA-WRSHB.
    GTAB-RAST3 = BSEGA-WRSHB.
    OBAD = BSEGA-WRSHB.
    ELSE.
    IF VERZUG LE TAGE3. "past due tage2 to tage3 days
    GTAB-RAST1 = BSEGA-WRSHB.
    GTAB-RAST4 = BSEGA-WRSHB.
    OBAD = BSEGA-WRSHB.
    ELSE.
    IF VERZUG LE TAGE4. "past due tage3 to tage4 days
    GTAB-RAST1 = BSEGA-WRSHB.
    GTAB-RAST5 = BSEGA-WRSHB.
    OBAD = BSEGA-WRSHB.
    ELSE.
    IF VERZUG GT TAGE4. "past due > tage4 days
    GTAB-RAST1 = BSEGA-WRSHB.
    GTAB-RAST6 = BSEGA-WRSHB.
    OBAD = BSEGA-WRSHB.
    ENDIF.
    ENDIF.
    ENDIF.
    ENDIF.
    ENDIF.
    ENDIF.
    GTAB-RAST7 = GTAB-RAST1 - OBAD.
    stab = gtab.
    MOVE-CORRESPONDING GTAB TO STAB.
    BC SUNILP 05/15/2007
    IF ITAB_VBRP1[] IS NOT INITIAL.
    GTAB-T_IND = 'X'.
    LOOP AT ITAB_VBRP1.
    MOVE-CORRESPONDING GTAB TO GTAB_LINES.
    GTAB_LINES-SORT_GSB = '1'.
    GTAB_LINES-SUPER = ITAB_VBRP1-ZZMREP.
    GTAB_LINES-REP = ITAB_VBRP1-ZZLREP.
    GTAB_LINES-RAST1 = GTAB_LINES-RAST1 * ITAB_VBRP1-PERC.
    GTAB_LINES-RAST2 = GTAB_LINES-RAST2 * ITAB_VBRP1-PERC.
    GTAB_LINES-RAST3 = GTAB_LINES-RAST3 * ITAB_VBRP1-PERC.
    GTAB_LINES-RAST4 = GTAB_LINES-RAST4 * ITAB_VBRP1-PERC.
    GTAB_LINES-RAST5 = GTAB_LINES-RAST5 * ITAB_VBRP1-PERC.
    GTAB_LINES-RAST6 = GTAB_LINES-RAST6 * ITAB_VBRP1-PERC.
    GTAB_LINES-RAST7 = GTAB_LINES-RAST7 * ITAB_VBRP1-PERC.
    GTAB_LINES-OBAD = GTAB_LINES-OBAD * ITAB_VBRP1-PERC.
    COLLECT: GTAB_LINES.
    ENDLOOP.
    ELSE.
    MOVE-CORRESPONDING GTAB TO GTAB_LINES.
    GTAB_LINES-T_IND = 'X'.
    GTAB_LINES-SORT_GSB = '1'.
    IF GTAB_LINES-SUPER IN P_SUPREP OR GTAB_LINES-REP IN P_REP.
    COLLECT: GTAB_LINES.
    ENDIF.
    ENDIF.
    EC SUNILP 05/15/2007
    gtab-sort_gsb = stab-sort_gsb = '0'.
    collect: gtab, stab.
    gtab-gsber = stab-gsber = '****'.
    GTAB-SORT_GSB = '1'.
    IF REGIO = SPACE OR REGIO = GTAB-REGIO.
    IF GTAB_LINES-SUPER IN P_SUPREP OR GTAB_LINES-REP IN P_REP.
    COLLECT: GTAB, STAB.
    ENDIF.
    ENDIF.
    END-OF-SELECTION.
    TAGE1A = TAGE1 + 1.
    TAGE2A = TAGE2 + 1.
    TAGE3A = TAGE3 + 1.
    IF SUMMEN = ' '.
    sort gtab by bukrs land1 regio kunnr gsber sort_gsb.
    sort gtab by bukrs land1 regio name1 kunnr gsber sort_gsb. "JAM
    IF CONSOL = 'X'.
    SORT GTAB BY LAND1 REGIO NAME1 KUNNR BUKRS KKBER GSBER SORT_GSB.
    "TONYC
    REPORT_TYPE = 'consolidated'.
    ELSEIF NOT P_SUPREP[] IS INITIAL. "DEVK939546
    SORT GTAB
    BY SUPER REP NAME1 BUKRS KKBER LAND1 REGIO NAME1 GSBER SORT_GSB.
    BC SUNILP 05/15/2007
    SORT GTAB_LINES
    BY SUPER REP NAME1 BUKRS KKBER LAND1 REGIO NAME1 GSBER SORT_GSB.
    EC SUNILP 05/15/2007
    REPORT_TYPE = 'super rep'.
    CLEAR STAB. "tonyc 03/06/2004
    REFRESH STAB. "tonyc 03/06/2004
    ELSEIF NOT P_REP[] IS INITIAL. "DEVK939546
    SORT GTAB "DEVK939546
    BY REP NAME1 BUKRS KKBER LAND1 REGIO NAME1 GSBER SORT_GSB.
    "DEVK939546
    BC SUNILP 05/15/2007
    SORT GTAB_LINES
    BY REP NAME1 BUKRS KKBER LAND1 REGIO NAME1 GSBER SORT_GSB.
    EC SUNILP 05/15/2007
    REPORT_TYPE = 'rep'. "DEVK939546
    CLEAR STAB. "tonyc 03/06/2004
    REFRESH STAB. "tonyc 03/06/2004
    ELSE.
    SORT GTAB BY BUKRS KKBER LAND1 REGIO NAME1 KUNNR GSBER SORT_GSB.
    BC SUNILP 05/15/2007
    SORT GTAB_LINES BY BUKRS KKBER LAND1 REGIO NAME1 KUNNR GSBER SORT_GSB.
    EC SUNILP 05/15/2007
    REPORT_TYPE = 'regular'.
    ENDIF.
    BC SUNILP 05/15/2007
    DELETE ADJACENT DUPLICATES FROM GTAB COMPARING BUKRS NAME1.
    LOOP AT GTAB_LINES.
    IF P_REP[] IS INITIAL.
    IF GTAB_LINES-SUPER NOT IN P_SUPREP.
    DELETE GTAB_LINES.
    ENDIF.
    ELSE.
    IF GTAB_LINES-SUPER NOT IN P_SUPREP OR GTAB_LINES-REP NOT IN P_REP.
    DELETE GTAB_LINES.
    ENDIF.
    ENDIF.
    ENDLOOP.
    LOOP AT GTAB.
    READ TABLE GTAB_LINES WITH KEY BUKRS = GTAB-BUKRS
    NAME1 = GTAB-NAME1.
    IF SY-SUBRC NE '0'.
    DELETE GTAB.
    ENDIF.
    ENDLOOP.
    EC SUNILP 05/15/2007
    LOOP AT GTAB.
    MOVE GTAB-BUKRS TO T001-BUKRS. READ TABLE T001.
    RESERVE 5 LINES.
    CASE REPORT_TYPE.
    WHEN 'regular'.
    IF HOLD_BUKRS <> GTAB-BUKRS.
    IF SY-TABIX > 1. "TONYC
    NEW-PAGE. SKIP. "TONYC
    ENDIF. "TONYC
    ENDIF.
    PERFORM WRITE_CUST_INFO. "TONYC
    PERFORM WRITE_DETAIL.
    hold_bukrs = gtab-bukrs. "tonyc
    WHEN 'consolidated'.
    IF HOLD_KUNNR <> GTAB-KUNNR. "TONYC
    PERFORM WRITE_CUST_INFO. "TONYC
    ENDIF. "TONYC
    HOLD_KUNNR = GTAB-KUNNR. "TONYC
    PERFORM WRITE_DETAIL.
    WHEN 'super rep'.
    IF GTAB-T_IND NE 'X'.
    BC SUNILP 05/22/2007
    READ TABLE GTAB_LINES WITH KEY BUKRS = GTAB-BUKRS
    NAME1 = GTAB-NAME1.
    EC SUNILP 05/22/2007
    IF ( HOLD_SUPER <> GTAB_LINES-SUPER ) OR
    ( HOLD_REP2 <> GTAB_LINES-REP ).
    NEW-PAGE.
    PERFORM GET_AND_WRITE_SUPERINFO.
    ENDIF.
    HOLD_REP2 = GTAB_LINES-REP.
    HOLD_SUPER = GTAB_LINES-SUPER.
    IF HOLD_KUNNR <> GTAB-KUNNR. "TONYC
    WRITE :/. "TONYC
    ULINE. "TONYC
    PERFORM WRITE_CUST_INFO. "TONYC
    ENDIF. "TONYC
    HOLD_KUNNR = GTAB-KUNNR. "TONYC
    PERFORM WRITE_DETAIL. "TONYC
    AT END OF REP. "DEVK939546
    SKIP. "DEVK939546
    RESERVE 7 LINES. "DEVK939546
    FORMAT COLOR COL_TOTAL INTENSIFIED. "DEVK939546
    WRITE: / 'Summary for Rep:', "DEVK939546
    GTAB-REP, '/', REP_NAME, 132 ONEBYTE."DEVK939546
    PERFORM WRITE_TOTS TABLES RTOT. "DEVK939546
    REFRESH RTOT. "DEVK939546
    ENDAT. "DEVK939546
    AT END OF SUPER. "DEVK939546
    CLEAR STAB. "tonyc 03/06/2004
    REFRESH STAB. "tonyc 03/06/2004
    NEW-PAGE. SKIP. "DEVK939546
    FORMAT COLOR COL_TOTAL INTENSIFIED. "DEVK939546
    WRITE: / 'Summary for Super Rep:', "DEVK939546
    GTAB-SUPER, '/', SUPER_NAME, 132 ONEBYTE."DEVK939546
    PERFORM WRITE_TOTS TABLES STOT. "DEVK939546
    REFRESH STOT. "DEVK939546
    ENDAT. "DEVK939546
    ELSE.
    LOOP AT GTAB_LINES WHERE BUKRS = GTAB-BUKRS
    AND NAME1 = GTAB-NAME1.
    IF ( HOLD_SUPER <> GTAB_LINES-SUPER ) OR
    ( HOLD_REP2 <> GTAB_LINES-REP ).
    NEW-PAGE.
    PERFORM GET_AND_WRITE_SUPERINFO.
    ENDIF.
    HOLD_REP2 = GTAB_LINES-REP.
    HOLD_SUPER = GTAB_LINES-SUPER.
    IF HOLD_KUNNR <> GTAB_LINES-KUNNR.
    WRITE :/.
    ULINE.
    PERFORM WRITE_CUST_INFO.
    ENDIF.
    HOLD_KUNNR = GTAB_LINES-KUNNR.
    PERFORM WRITE_DETAIL.
    AT END OF REP.
    SKIP.
    RESERVE 7 LINES.
    FORMAT COLOR COL_TOTAL INTENSIFIED.
    WRITE: / 'Summary for Rep:',
    GTAB_LINES-REP, '/', REP_NAME, 132 ONEBYTE.
    PERFORM WRITE_TOTS TABLES RTOT.
    REFRESH RTOT.
    ENDAT.
    AT END OF SUPER.
    CLEAR STAB. "tonyc 03/06/2004
    REFRESH STAB. "tonyc 03/06/2004
    NEW-PAGE. SKIP.
    FORMAT COLOR COL_TOTAL INTENSIFIED.
    WRITE: / 'Summary for Super Rep:',
    GTAB_LINES-SUPER, '/', SUPER_NAME, 132 ONEBYTE.
    PERFORM WRITE_TOTS TABLES STOT.
    REFRESH STOT.
    ENDAT.
    ENDLOOP.
    ENDIF.
    WHEN 'rep'. "DEVK939546
    LOOP AT GTAB_LINES WHERE BUKRS = GTAB-BUKRS
    AND NAME1 = GTAB-NAME1.
    IF HOLD_REP2 <> GTAB_LINES-REP. "DEVK939546
    NEW-PAGE. "DEVK939546
    PERFORM GET_AND_WRITE_REPINFO. "DEVK939546
    ENDIF. "DEVK939546
    HOLD_REP2 = GTAB_LINES-REP. "DEVK939546
    IF HOLD_KUNNR <> GTAB_LINES-KUNNR. "DEVK939546
    WRITE :/. "DEVK939546
    ULINE. "DEVK939546
    PERFORM WRITE_CUST_INFO. "DEVK939546
    ENDIF. "DEVK939546
    HOLD_KUNNR = GTAB_LINES-KUNNR. "DEVK939546
    PERFORM WRITE_DETAIL. "DEVK939546
    AT END OF REP. "DEVK939546
    SKIP. "DEVK939546
    RESERVE 7 LINES. "DEVK939546
    FORMAT COLOR COL_TOTAL INTENSIFIED. "DEVK939546
    WRITE: / 'Summary for Rep:', "DEVK939546
    GTAB_LINES-REP, '/', REP_NAME, 132 ONEBYTE."DEVK939546
    PERFORM WRITE_TOTS TABLES RTOT. "DEVK939546
    REFRESH RTOT. "DEVK939546
    ENDAT. "DEVK939546
    ENDLOOP.
    ENDCASE.
    ENDLOOP.
    ENDIF.
    OP = ' '.
    REFRESH GTAB.
    IF NOT REPORT_TYPE = 'super rep'.
    ULINE.
    ENDIF.
    SKIP 1.
    IF SUMMEN = ' '. "if 'output totals only' bypass new-page
    NEW-PAGE. SKIP.
    ENDIF.
    WRITE: /25 TEXT-030, 132 ONEBYTE, /25 TEXT-031, 132 ONEBYTE.
    PERFORM WRITE_TOTS TABLES STAB. "DEVK939546
    TOP-OF-PAGE.
    INTENS = SPACE.
    FORMAT COLOR COL_HEADING INTENSIFIED ON.
    WRITE: / SY-VLINE, 1 TEXT-001, DD_STIDA, 75 TEXT-051, 132 SY-VLINE.
    ULINE.
    WRITE: / SY-VLINE, 13 SY-VLINE, 30 SY-VLINE,
    47 SY-VLINE, 58 TEXT-003, 81 SY-VLINE,
    92 TEXT-003, 115 SY-VLINE, 118 TEXT-003, 132 SY-VLINE,
    / SY-VLINE, 02 TEXT-004, 13 SY-VLINE, TEXT-002,
    30 SY-VLINE, 32 TEXT-018, 47 SY-VLINE,
    50 '1', 54 TEXT-040, 57 TAGE1, 64 SY-VLINE, " 65 tage2,
    67 TAGE1A, 72 TEXT-040, 75 TAGE2,
    81 SY-VLINE, 83 TAGE2A, 89 TEXT-040, 91 TAGE3, 98 SY-VLINE,
    101 TAGE3A, 107 TEXT-040, 110 TAGE4, 115 SY-VLINE,
    117 TAGE4, 123 TEXT-017, 132 SY-VLINE.
    ULINE.
    SKIP 1.
    SUMMARY.
    FORMAT COLOR COL_HEADING INTENSIFIED OFF.
    FORM write_tots *
    --> PTAB *
    FORM WRITE_TOTS TABLES PTAB TYPE TOT_TAB. "DEVK939546
    CLEAR INTENS. "DEVK939546
    FORMAT COLOR COL_HEADING INTENSIFIED OFF. "DEVK939546
    IF P_CONV = 'X'. "tonyc issue #3047 begin
    WRITE /4 TEXT-101.
    WRITE: /4 TEXT-102,
    50 TEXT-100.
    ENDIF. "tonyc issue #3047 end
    ULINE. "DEVK939546
    SORT PTAB BY BUKRS GSBER. "DEVK939546
    LOOP AT PTAB. "DEVK939546
    IF SY-TABIX > 1.
    WRITE_TOTAL = 'X'.
    ENDIF.
    MOVE PTAB-BUKRS TO T001-BUKRS. READ TABLE T001. "DEVK939546
    MOVE PTAB-GSBER TO T001-WAERS. "DEVK939546
    IF P_CONV = 'X'. "tonyc issue #3047 begin
    PERFORM CONVERT_VALUES USING STAB-RAST1
    STAB-GSBER.
    PERFORM CONVERT_VALUES USING STAB-RAST2
    STAB-GSBER.
    PERFORM CONVERT_VALUES USING STAB-RAST3
    STAB-GSBER.
    PERFORM CONVERT_VALUES USING STAB-RAST4
    STAB-GSBER.
    PERFORM CONVERT_VALUES USING STAB-RAST5
    STAB-GSBER.
    PERFORM CONVERT_VALUES USING STAB-RAST6
    STAB-GSBER.
    PERFORM CONVERT_VALUES USING STAB-RAST7
    STAB-GSBER.
    ENDIF. "TOnyc issue #3047 end
    MOVE-CORRESPONDING PTAB TO STAB.
    COLLECT STAB.
    IF P_KKBER = 'X'. "TONYC ISSUE #2500
    CLEAR HOLD_KKBER_DESC2.
    SELECT SINGLE KKBTX INTO HOLD_KKBER_DESC2 FROM T014T
    WHERE KKBER = STAB-KKBER AND
    SPRAS = 'E'.
    IF SY-SUBRC <> '0'.
    HOLD_KKBER_DESC2 = 'Undetermined'.
    ENDIF.
    FORMAT COLOR OFF.
    WRITE: / SY-VLINE.
    FORMAT COLOR COL_HEADING INTENSIFIED OFF.
    WRITE: 6 STAB-GSBER, HOLD_KKBER_DESC2, SY-VLINE.
    ULINE.
    FORMAT COLOR OFF.
    WRITE: / SY-VLINE.
    FORMAT COLOR COL_HEADING INTENSIFIED OFF.
    IF P_CONV = 'X'. "tonyc issue #3047 begin
    T001-WAERS = 'USD'.
    ENDIF. "tonyc issue #3047 end
    WRITE: 13 STAB-RAST1 NO-ZERO CURRENCY T001-WAERS, SY-VLINE,
    (14) STAB-RAST7 NO-ZERO CURRENCY T001-WAERS, SY-VLINE,
    (14) STAB-RAST2 NO-ZERO CURRENCY T001-WAERS, SY-VLINE,
    (14) STAB-RAST3 NO-ZERO CURRENCY T001-WAERS, SY-VLINE,
    (14) STAB-RAST4 NO-ZERO CURRENCY T001-WAERS, SY-VLINE,
    (14) STAB-RAST5 NO-ZERO CURRENCY T001-WAERS, SY-VLINE,
    (14) STAB-RAST6 NO-ZERO CURRENCY T001-WAERS, SY-VLINE.
    HOLD_BUKRS2 = STAB-BUKRS. "TONYC ISSUE #2500
    ULINE.
    FORMAT COLOR OFF.
    TOTAL_RAST1 = STAB-RAST1 + TOTAL_RAST1.
    TOTAL_RAST2 = STAB-RAST2 + TOTAL_RAST2.
    TOTAL_RAST3 = STAB-RAST3 + TOTAL_RAST3.
    TOTAL_RAST4 = STAB-RAST4 + TOTAL_RAST4.
    TOTAL_RAST5 = STAB-RAST5 + TOTAL_RAST5.
    TOTAL_RAST6 = STAB-RAST6 + TOTAL_RAST6.
    TOTAL_RAST7 = STAB-RAST7 + TOTAL_RAST7.
    ELSE.
    FORMAT COLOR COL_NORMAL INTENSIFIED OFF. "DEVK939546
    IF INTENS = SPACE. "DEVK939546
    FORMAT COLOR COL_NORMAL INTENSIFIED OFF. "DEVK939546
    INTENS = 'X'. "DEVK939546
    ELSE. "DEVK939546
    FORMAT COLOR COL_NORMAL INTENSIFIED ON. "DEVK939546
    INTENS = SPACE. "DEVK939546
    ENDIF. "DEVK939546
    WRITE: / SY-VLINE, PTAB-BUKRS, PTAB-GSBER, SY-VLINE, "DEVK939546
    (14) PTAB-RAST1 NO-ZERO CURRENCY T001-WAERS, SY-VLINE,"DEVK939546
    (14) PTAB-RAST7 NO-ZERO CURRENCY T001-WAERS, SY-VLINE,"DEVK939546
    (14) PTAB-RAST2 NO-ZERO CURRENCY T001-WAERS, SY-VLINE,"DEVK939546
    (14) PTAB-RAST3 NO-ZERO CURRENCY T001-WAERS, SY-VLINE,"DEVK939546
    (14) PTAB-RAST4 NO-ZERO CURRENCY T001-WAERS, SY-VLINE,"DEVK939546
    (14) PTAB-RAST5 NO-ZERO CURRENCY T001-WAERS, SY-VLINE,"DEVK939546
    (14) PTAB-RAST6 NO-ZERO CURRENCY T001-WAERS, SY-VLINE."DEVK939546
    TOTAL_RAST1 = STAB-RAST1 + TOTAL_RAST1.
    TOTAL_RAST2 = STAB-RAST2 + TOTAL_RAST2.
    TOTAL_RAST3 = STAB-RAST3 + TOTAL_RAST3.
    TOTAL_RAST4 = STAB-RAST4 + TOTAL_RAST4.
    TOTAL_RAST5 = STAB-RAST5 + TOTAL_RAST5.
    TOTAL_RAST6 = STAB-RAST6 + TOTAL_RAST6.
    TOTAL_RAST7 = STAB-RAST7 + TOTAL_RAST7.
    ENDIF.
    ENDLOOP. "DEVK939546
    ULINE. "DEVK939546
    IF P_KKBER = 'X'. "TONYC ISSUE #2500
    IF P_CONV = 'X'. "tonyc issue #3047 begin
    FORMAT COLOR OFF.
    FORMAT COLOR COL_HEADING INTENSIFIED OFF.
    WRITE: SY-VLINE,
    6 'TOTAL ', SY-VLINE.
    ULINE.
    FORMAT COLOR OFF.
    WRITE: / SY-VLINE.
    FORMAT COLOR COL_HEADING INTENSIFIED OFF.
    WRITE: 13 TOTAL_RAST1 NO-ZERO CURRENCY T001-WAERS, SY-VLINE,
    (14) TOTAL_RAST7 NO-ZERO CURRENCY T001-WAERS, SY-VLINE,
    (14) TOTAL_RAST2 NO-ZERO CURRENCY T001-WAERS, SY-VLINE,
    (14) TOTAL_RAST3 NO-ZERO CURRENCY T001-WAERS, SY-VLINE,
    (14) TOTAL_RAST4 NO-ZERO CURRENCY T001-WAERS, SY-VLINE,
    (14) TOTAL_RAST5 NO-ZERO CURRENCY T001-WAERS, SY-VLINE,
    (14) TOTAL_RAST6 NO-ZERO CURRENCY T001-WAERS, SY-VLINE.
    ULINE.
    ENDIF. "tonyc issue #3047 end
    ELSE.
    IF P_CONV = 'X'.
    FORMAT COLOR OFF.
    FORMAT COLOR COL_HEADING INTENSIFIED OFF.
    WRITE: SY-VLINE,
    6 'TOTAL ', SY-VLINE.
    ULINE.
    FORMAT COLOR OFF.
    WRITE: / SY-VLINE.
    FORMAT COLOR COL_HEADING INTENSIFIED OFF.
    WRITE: 13 TOTAL_RAST1 NO-ZERO CURRENCY T001-WAERS, SY-VLINE,
    (14) TOTAL_RAST7 NO-ZERO CURRENCY T001-WAERS, SY-VLINE,
    (14) TOTAL_RAST2 NO-ZERO CURRENCY T001-WAERS, SY-VLINE,
    (14) TOTAL_RAST3 NO-ZERO CURRENCY T001-WAERS, SY-VLINE,
    (14) TOTAL_RAST4 NO-ZERO CURRENCY T001-WAERS, SY-VLINE,
    (14) TOTAL_RAST5 NO-ZERO CURRENCY T001-WAERS, SY-VLINE,
    (14) TOTAL_RAST6 NO-ZERO CURRENCY T001-WAERS, SY-VLINE.
    ULINE.
    ENDIF.
    ENDIF.
    SKIP 1. "DEVK939546
    ENDFORM. "DEVK939546
    *& Form GET_KNKK_INFO
    text
    --> p1 text
    <-- p2 text
    FORM GET_KNKK_INFO.
    CLEAR: G_WAERS,
    G_KLIMK_TXT,
    KNKK-KLIMK.
    get credit control area (KKBER) for comp code (BUKRS)
    SELECT SINGLE KLIMK
    INTO KNKK-KLIMK
    FROM KNKK
    WHERE KUNNR = KNA1-KUNNR AND
    KKBER = T001-KKBER.
    IF SY-SUBRC = 0.
    get currency for cred ctrl area
    CLEAR IT_T014.
    READ TABLE IT_T014 WITH KEY KKBER = T001-KKBER BINARY SEARCH.
    G_WAERS = IT_T014-WAERS.
    WRITE KNKK-KLIMK TO G_KLIMK_TXT CURRENCY G_WAERS.
    ENDIF.
    ENDFORM. " GET_KNKK_INFO
    *& Form SELECT_KNKK
    text
    -->P_KKBER Credit Limit Controlling Area
    <--P_FOUND_KNKK Indicates if record found
    FORM SELECT_KNKK USING P_KKBER
    CHANGING P_FOUND_KNKK.
    CLEAR: G_WAERS,
    G_KLIMK_TXT,
    KNKK-KLIMK.
    SELECT SINGLE KLIMK
    INTO KNKK-KLIMK
    FROM KNKK
    WHERE KUNNR = KNA1-KUNNR AND
    KKBER = P_KKBER.
    IF SY-SUBRC = 0.
    P_FOUND_KNKK = C_TRUE.
    get currency for cred ctrl area
    CLEAR IT_T014.
    READ TABLE IT_T014 WITH KEY KKBER = P_KKBER BINARY SEARCH.
    G_WAERS = IT_T014-WAERS.
    WRITE KNKK-KLIMK TO G_KLIMK_TXT CURRENCY G_WAERS.
    ELSE.
    P_FOUND_KNKK = C_FALSE.
    ENDIF.
    ENDFORM. " SELECT_KNKK
    *& Form GET_CUST_CONTACT & PHONE NUMBER
    FORM GET_CUST_CONTACT.
    CLEAR KNVK.
    C_CREDIT_ABTNR = '0003'. "look for contact in credit dept
    SELECT NAME1
    NAMEV
    TELF1
    INTO (KNVK-NAME1,
    KNVK-NAMEV,
    KNVK-TELF1)
    FROM KNVK
    WHERE KUNNR = KNA1-KUNNR AND
    ABTNR = C_CREDIT_ABTNR.
    ENDSELECT.
    If there wasn't a contact person for the credit dept, then just
    pull up the first contact info we find regardless of dept
    IF SY-SUBRC <> 0.
    CLEAR KNVK.
    SELECT NAME1
    NAMEV
    TELF1
    INTO (KNVK-NAME1,
    KNVK-NAMEV,
    KNVK-TELF1)
    FROM KNVK
    WHERE KUNNR = KNA1-KUNNR.
    IF SY-SUBRC = 0.
    EXIT.
    ENDIF.
    ENDSELECT.
    ELSE.
    EXIT.
    ENDIF. "not contact found in credit dept.
    ENDFORM. " GET_CUST_CONTACT
    *& Form LOAD_T014
    FORM LOAD_T014.
    SELECT *
    INTO TABLE IT_T014
    FROM T014.
    SORT IT_T014.
    ENDFORM. " LOAD_T014
    *& Form WRITE_CUST_INFO "TONYC
    text moved code and created a form. for cleaner code "TONYC
    --> p1 text
    <-- p2 text
    FORM WRITE_CUST_INFO.
    IF NOT REPORT_TYPE = 'super rep'.
    IF SY-TABIX > 1.
    ULINE.
    ENDIF.
    ENDIF.
    CONCATENATE GTAB-NAMEV "JAM
    GTAB-CONT_NAME1
    INTO G_CONT_NAME
    SEPARATED BY SPACE.
    FORMAT COLOR COL_TOTAL INTENSIFIED OFF.
    IF REPORT_TYPE = 'super rep'.
    IF GTAB-T_IND NE 'X'.
    WRITE: / GTAB-KUNNR, GTAB-NAME1, GTAB-ORT01, GTAB-REGIO, GTAB-LAND1,
    "g_cont_name,
    132 ONEBYTE.
    ELSE.
    WRITE: / GTAB_LINES-KUNNR, GTAB_LINES-NAME1, GTAB_LINES-ORT01, GTAB_LINES-REGIO, GTAB_LINES-LAND1,
    "g_cont_name,
    132 ONEBYTE.
    ENDIF.
    WRITE: /21 onebyte, 12 gtab-name2, 45 gtab-ort01,
    gtab-telf1, "gtab-klimk_txt, gtab-waers.
    132 onebyte.
    ELSE.
    WRITE: / GTAB-KUNNR, GTAB-NAME1, GTAB-ORT01, GTAB-REGIO, GTAB-LAND1,
    "g_cont_name, "JAM
    132 ONEBYTE.
    WRITE: /11 onebyte, 12 gtab-name2, 45 gtab-ort01,
    gtab-telf1, "gtab-klimk_txt, gtab-waers, "JAM
    132 onebyte.
    ENDIF.
    ENDFORM. " WRITE_CUST_INFO
    *& Form GET_AND_WRITE_SUPERINFO
    text
    --> p1 text
    <-- p2 text
    FORM GET_AND_WRITE_SUPERINFO.
    ULINE.
    IF GTAB-T_IND NE 'X'.
    SELECT SINGLE NAME1 FROM KNA1 INTO SUPER_NAME "TONYC
    WHERE KUNNR = GTAB-SUPER. "TONYC
    SELECT SINGLE NAME1 FROM KNA1 INTO REP_NAME "TONYC
    WHERE KUNNR = GTAB-REP. "TONYC
    CONCATENATE SUPER_NAME REP_NAME INTO REPS_INFO "TONYC
    SEPARATED BY BACKSLASH. "TONYC
    FORMAT COLOR COL_TOTAL INTENSIFIED. "TONYC
    WRITE:/ GTAB-SUPER, '/', "TONYC
    GTAB-REP, "TONYC
    25 REPS_INFO, 132 ONEBYTE. "TONYC
    ELSE.
    SELECT SINGLE NAME1 FROM KNA1 INTO SUPER_NAME
    WHERE KUNNR = GTAB_LINES-SUPER.
    SELECT SINGLE NAME1 FROM KNA1 INTO REP_NAME
    WHERE KUNNR = GTAB_LINES-REP.
    CONCATENATE SUPER_NAME REP_NAME INTO REPS_INFO
    SEPARATED BY BACKSLASH.
    FORMAT COLOR COL_TOTAL INTENSIFIED.
    WRITE:/ GTAB_LINES-SUPER, '/',
    GTAB_LINES-REP,
    25 REPS_INFO, 132 ONEBYTE.
    ENDIF.
    ENDFORM. " GET_AND_WRITE_SUPERINFO
    *& Form GET_AND_WRITE_REPINFO
    text
    --> p1 text
    <-- p2 text
    FORM GET_AND_WRITE_REPINFO.
    ULINE.
    SELECT SINGLE NAME1 FROM KNA1 INTO REP_NAME
    WHERE KUNNR = GTAB-REP.
    FORMAT COLOR COL_TOTAL INTENSIFIED.
    WRITE:/ GTAB-REP,
    25 REP_NAME, 132 ONEBYTE.
    ENDFORM. " GET_AND_WRITE_REPINFO
    *& Form WRITE_DETAIL
    text
    --> p1 text
    <-- p2 text
    FORM WRITE_DETAIL.
    clear z_description. "TONYC #2216
    move GTAB-KLIMK_TXT to z_hold_limit.
    IF z_hold_limit = 400.
    z_description = 'COD/Check'.
    elseif z_hold_limit = 500.
    z_description = 'COD/Cash'.
    elseif z_hold_limit = 600.
    z_description = 'Need Dealer Agree'.
    elseif z_hold_limit = 700.
    z_description = 'Need PDCs'.
    elseif z_hold_limit = 800.
    z_description = 'Need Fin Statements'.
    elseif z_hold_limit = 900.
    z_description = 'Past Due Balance'.
    elseif z_hold_limit = 1000.
    z_description = 'Miracle?'.
    endif. "TONYC #2216
    MOVE GTAB-GSBER TO T001-WAERS.
    FORMAT COLOR COL_TOTAL INTENSIFIED OFF.
    IF HOLD_KUNNR2 <> GTAB-KUNNR. "TONYC
    IF REPORT_TYPE = 'super rep'.
    WRITE: /3 ONEBYTE, GTAB-BUKRS.
    WRITE: 92 gtab-klimk_txt, gtab-waers, 132 onebyte. "TONYC
    WRITE: 92 gtab-klimk_txt, z_description,132 onebyte."TONYC #2500
    ELSE.
    WRITE: / ONEBYTE, GTAB-BUKRS.
    WRITE: 92 gtab-klimk_txt, z_description,132 onebyte."TONYC #2500
    WRITE: 92 gtab-klimk_txt, gtab-waers, 132 onebyte. "TONYC
    ENDIF.
    ENDIF.
    FORMAT COLOR COL_TOTAL INTENSIFIED OFF.
    IF P_KKBER = 'X'. "TONYC ISSUE# 2500
    CLEAR HOLD_KKBER_DESC.
    SELECT SINGLE KKBTX INTO HOLD_KKBER_DESC FROM T014T
    WHERE KKBER = GTAB-KKBER AND
    SPRAS = 'E'.
    IF SY-SUBRC <> '0'.
    HOLD_KKBER_DESC = 'Undetermined'.
    ENDIF.
    SELECT SINGLE KLIMK CTLPC
    INTO (HOLD_KLIMK, HOLD-CTLPC)
    FROM KNKK
    WHERE KUNNR = GTAB-KUNNR AND
    KKBER = GTAB-KKBER.
    SELECT SINGLE RTEXT INTO HOLD-CTLPC-TEXT FROM T691T
    WHERE SPRAS = 'EN' AND
    CTLPC = HOLD-CTLPC AND
    KKBER = GTAB-KKBER.
    WRITE HOLD_KLIMK TO HOLD_KLIMK2 CURRENCY GTAB-WAERS.
    WRITE: /7 GTAB-KKBER,
    12 HOLD_KKBER_DESC,
    80 HOLD_KLIMK2,
    103 GTAB-GSBER,
    108 HOLD-CTLPC-TEXT.
    ENDIF. "TONYC ISSUE# 2500
    FORMAT COLOR COL_NORMAL INTENSIFIED ON. "TONYC
    MOVE STAB-GSBER TO T001-WAERS.
    CLEAR HOLD_NAME.
    SELECT SINGLE NAME1 FROM KNA1 INTO HOLD_NAME
    WHERE KUNNR = GTAB-FILKD.
    WRITE: /15 GTAB-FILKD,
    30 HOLD_NAME.
    IF GTAB-T_IND NE 'X'.
    WRITE: /15(14) GTAB-RAST1 NO-ZERO CURRENCY T001-WAERS, ONEBYTE,
    (14) GTAB-RAST7 NO-ZERO CURRENCY T001-WAERS, ONEBYTE,
    (14) GTAB-RAST2 NO-ZERO CURRENCY T001-WAERS, ONEBYTE,
    (14) GTAB-RAST3 NO-ZERO CURRENCY T001-WAERS, ONEBYTE,
    (14) GTAB-RAST4 NO-ZERO CURRENCY T001-WAERS, ONEBYTE,
    (14) GTAB-RAST5 NO-ZERO CURRENCY T001-WAERS, ONEBYTE,
    (14) GTAB-RAST6 NO-ZERO CURRENCY T001-WAERS, ONEBYTE,
    132 ONEBYTE.
    ELSE.
    IF REPORT_TYPE NE 'super rep'.
    LOOP AT GTAB_LINES WHERE KUNNR = GTAB-KUNNR.
    WRITE: / GTAB_LINES-SUPER, ONEBYTE,
    15(14) GTAB_LINES-RAST1 NO-ZERO CURRENCY T001-WAERS, ONEBYTE,
    (14) GTAB_LINES-RAST7 NO-ZERO CURRENCY T001-WAERS, ONEBYTE,
    (14) GTAB_LINES-RAST2 NO-ZERO CURRENCY T001-WAERS, ONEBYTE,
    (14) GTAB_LINES-RAST3 NO-ZERO CURRENCY T001-WAERS, ONEBYTE,
    (14) GTAB_LINES-RAST4 NO-ZERO CURRENCY T001-WAERS, ONEBYTE,
    (14) GTAB_LINES-RAST5 NO-ZERO CURRENCY T001-WAERS, ONEBYTE,
    (14) GTAB_LINES-RAST6 NO-ZERO CURRENCY T001-WAERS, ONEBYTE,
    132 ONEBYTE.
    ENDLOOP.
    ELSE.
    WRITE: / GTAB_LINES-SUPER, ONEBYTE,
    15(14) GTAB_LINES-RAST1 NO-ZERO CURRENCY T001-WAERS, ONEBYTE,
    (14) GTAB_LINES-RAST7 NO-ZERO CURRENCY T001-WAERS, ONEBYTE,
    (14) GTAB_LINES-RAST2 NO-ZERO CURRENCY T001-WAERS, ONEBYTE,
    (14) GTAB_LINES-RAST3 NO-ZERO CURRENCY T001-WAERS, ONEBYTE,
    (14) GTAB_LINES-RAST4 NO-ZERO CURRENCY T001-WAERS, ONEBYTE,
    (14) GTAB_LINES-RAST5 NO-ZERO CURRENCY T001-WAERS, ONEBYTE,
    (14) GTAB_LINES-RAST6 NO-ZERO CURRENCY T001-WAERS, ONEBYTE,
    132 ONEBYTE.
    ENDIF.
    ENDIF.
    HOLD_BUKRS = GTAB-BUKRS. "Tonyc
    HOLD_KUNNR2 = GTAB-KUNNR. "TONYC
    HOLD_KKBER = GTAB-KKBER. "TONYC ISSUE #2500
    IF REPORT_TYPE = 'super rep' OR REPORT_TYPE = 'rep'. "DEVK939546
    IF GTAB-T_IND NE 'X'.
    MOVE-CORRESPONDING GTAB TO RTOT. "DEVK939546
    COLLECT RTOT. "DEVK939546
    ELSE.
    MOVE-CORRESPONDING GTAB_LINES TO RTOT.
    COLLECT RTOT.
    ENDIF.
    IF REPORT_TYPE = 'super rep'. "DEVK939546
    IF GTAB-T_IND NE 'X'.
    MOVE-CORRESPONDING GTAB TO STOT. "DEVK939546
    COLLECT STOT. "DEVK939546
    ELSE.
    MOVE-CORRESPONDING GTAB_LINES TO STOT.
    COLLECT STOT.
    ENDIF.
    ENDIF. "DEVK939546
    ENDIF. "DEVK939546
    ENDFORM. " WRITE_DETAIL
    *& Form convert_values
    text
    -->P_STAB_RAST1 text
    -->P_STAB_GSBER text
    FORM CONVERT_VALUES USING P_STAB_RAST1 "tonyc issue #3047 begin
    P_STAB-GSBER.
    CALL FUNCTION 'CONVERT_TO_LOCAL_CURRENCY'
    EXPORTING
    CLIENT = SY-MANDT
    DATE = SY-DATUM
    FOREIGN_AMOUNT = P_STAB_RAST1
    FOREIGN_CURRENCY = P_STAB-GSBER
    LOCAL_CURRENCY = 'USD'
    RATE = 0
    TYPE_OF_RATE = 'M'
    READ_TCURR = 'X'
    IMPORTING
    EXCHANGE_RATE =
    FOREIGN_FACTOR =
    LOCAL_AMOUNT = P_STAB_RAST1
    LOCAL_FACTOR =
    EXCHANGE_RATEX =
    FIXED_RATE =
    DERIVED_RATE_TYPE =
    EXCEPTIONS
    NO_RATE_FOUND = 1
    OVERFLOW = 2
    NO_FACTORS_FOUND = 3
    NO_SPREAD_FOUND = 4
    DERIVED_2_TIMES = 5
    OTHERS = 6 .
    IF SY-SUBRC <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
    WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.
    ENDFORM. " convert_values

    solved

  • 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

  • Regarding Customer ageing report logic in R/3.

    Dear
    Experts
    i  have requirement to develop customer ageing  report logic for input 30,60,90,180,360
    i  don' t have any idea hw can i take these values  in input& hw can i caluclate the   values
    i  searched in  sdn, i did n't get any  suitable answer..
    Regards
    Spandana

    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

  • F-32 residual payment is affecting my ageing report.

    When I am doing the residual payment using f-32 then we are getting two document generated out this, one for the incoming payment and the other for the balance amount as new invoice with new posting date, this is affecting my ageing report.
    For Example: My old invoice is 01.01.2010 with 1000 USD, when I am applying the residual payment method on 08.03.2010 with 500 USD then two documents are generated out this, one for the incoming payment i.e. for 500 USD and the other for the balance amount as new invoice with new posting date i.e. 500 USD on 08.03.2010.
    My original invoice ageing is under over 81 days, but when we applied the residual payment method then it got changed to less than 21 days, which is incorrect. When we analysis the issue and found that due the residual payment method we are getting this problem i.e. during this process new invoice which is generated ahs replaced my original invoice with the new invoice with new posting date, system is taking that as base and doing the ageing analysis. Which is incorrect?
    We just want to have the original invoice date 01.01.2010 in the new document which is generated on 08.03.2010, so that this may not affect my ageing report.
    Thanks a lot in advance.
    Rajesh Kumar Mantri.

    When you post a residual payment, SAP creates 1 document with 2 line items for the customer.  One line item clears the original invoice and the other posts the difference (residual) as a new open item on the customer.  With the settings in OBA3, you can transfer the baseline date and payment terms from the original invoice to the residual item.  The baseline date is normally used for aging, so with the baseline date and payment terms transfer, the residual will have the same aging as the original invoice.  Also, since the original invoice is cleared when a residual payment is created, it will not show on the aging.
    If you want the original invoice to remain open, not cleared, after the payment, then you need to do a partial payment instead of a residual payment.  With a partial payment, the original invoice and the payment will both be open items on the customer.  The payment will reference the original invoice so that when the remaining payment is made, the two items will be cleared together.
    Regards,
    Shannon

  • Not able to pick Opening Balance in Ageing Report

    Hi
    I have made an query for customer ageing report based on our requirement, but am not able to fetch the OB (Opening Balance) in that.  If i generate Customer ageing report from B1, its showing the OB in the first line, then it showing the open invoices on the corresponding ageing days.
    Can anyone help me to fetch the opening balance in ageing report.  Below is the query i have given for ageing.
    SELECT     NNM1.Remark AS Branch, OINV.DocNum, OINV.NumAtCard AS VendorRef, OINV.DocType AS Type, OINV.DocStatus AS Status, OINV.DocDate,
                          OINV.DocDueDate, OINV.CardCode, OINV.CardName, OINV.DocTotal, OINV.PaidToDate AS [Paid/Credited],
                          OINV.DocTotal - OINV.PaidToDate AS [Balance Due], (CASE WHEN DateDiff(dd, OINV.DocDate, getdate()) BETWEEN - 120 AND
                          0 THEN (OINV.DocTotal - OINV.PaidToDate) END) AS 'Less then Due Date', (CASE WHEN DateDiff(dd, OINV.DocDate, getdate()) BETWEEN 0 AND
                          30 THEN (OINV.DocTotal - OINV.PaidToDate) END) AS '0 - 30', (CASE WHEN DateDiff(dd, OINV.DocDate, getdate()) BETWEEN 31 AND
                          45 THEN (OINV.DocTotal - OINV.PaidToDate) END) AS '30 - 45', (CASE WHEN DateDiff(dd, OINV.DocDate, getdate()) BETWEEN 46 AND
                          60 THEN (OINV.DocTotal - OINV.PaidToDate) END) AS '45 - 60', (CASE WHEN DateDiff(dd, OINV.DocDate, getdate()) BETWEEN 61 AND
                          90 THEN (OINV.DocTotal - OINV.PaidToDate) END) AS '60-90', (CASE WHEN DateDiff(dd, OINV.DocDate, getdate()) BETWEEN 91 AND
                          120 THEN (OINV.DocTotal - OINV.PaidToDate) END) AS '90-120', (CASE WHEN DateDiff(dd, OINV.DocDate, getdate())
                          > 120 THEN (OINV.DocTotal - OINV.PaidToDate) END) AS '120 +', OSLP.SlpName, OUBR.Name
    FROM         OINV AS OINV INNER JOIN
                          NNM1 AS NNM1 ON OINV.Series = NNM1.Series INNER JOIN
                          OSLP ON OINV.SlpCode = OSLP.SlpCode INNER JOIN
                          OHEM ON OSLP.SlpCode = OHEM.salesPrson INNER JOIN
                          OUBR ON OHEM.branch = OUBR.Code
    WHERE     (OINV.DocStatus = 'O') AND (OUBR.Code IN (@Branch)) AND (OSLP.SlpCode IN (@SalesEmployee))
    ORDER BY OINV.CardName, OSLP.SlpName
    How to add the OB in the above query.

    Check note 1023083 and for information about the expected release date of the patch please view note 578944.this problem is related to the new  SAP GUI 7 patch-level 0. There is something wrong with  the GUI function to get information from the local registry (CL_GUI_FRONTEND_SERVICES=>REGISTRY_GET_VALUE).
    We had the same issue sometime back and we applied the patch. I have the patch but it will be a huge file to send over internet. See the above notes and you should be able to apply the required patch.
    Also check Note
    Note 696069 below:
    Summary
    Symptom
    No Data is displayed when View is changed from ALV to Excel Inplace on
    ALV Grid. This Happens with Office XP/2003/2007.
    Other terms
    Excel inplace, Excel, ALV, Office 2003, Office XP, office 2007
    Reason and Prerequisites
    With newer release of MS Office (XP/2003/2007) Microsoft added new security settings/options for Visual Basic project and Macros. Excel Inplace uses Visual Basic Project and macro functionality of MS Office. If the setting for Macro security is High (which automatically disables macro or if access to Visual Basic Project is suppressed then Excel Inplace doesn't show any Data in Excel.
    Solution
    Required settings in MS office XP and MS Office 2003:
    To use the Excel Inplace functionality make sure the security settings for Macro is set to Medium and the option "Trust access to Visual Basic Project" must be checked on Tools->Macro->Security->Trusted Sources tab.
    Required settings in Office 2007:
    Please see the video file in attachments of this note.
    This is required with MS Office XP, MS Office 2003, MS Office 2007.
    Header Data
    Release Status: Released for Customer
    Released on: 22.12.2006  14:47:01
    Priority: Recommendations/additional info
    Category: Consulting
    Primary Component: BC-FES-OFFI SAP Desktop Office Integration
    Secondary Components: BC-FES-XXL XXL List Viewer/Lotus Connections
    Reward points if this help
    Sanghamitra
    Message was edited by:
            Sanghamitra11

Maybe you are looking for

  • Can not refresh server manager Error:0x8007045b

    OS: Windows 2012 R2 Core Services: Hyper V I was trying to remote reboot and the session hung. No worries I decided I could just reboot the next morning. So I rebooted the next day but when I go into server manager I get an errror can not refresh ser

  • I donnt why my iphone is not working. I can not turn on my phone.

    I do not why my iphone 4 is not working.  also I can not turn on it. please help me. Thank you

  • Default Parental Controls blocks FaceBook

    I just updated my family G4 iMac to Leopard. On the kids' accounts, under Parental Controls -> Content, I chose the "Try to limit access to adult websites automatically" My older son logged in and hollered that he could not get to his FaceBook page.

  • Automatic acknowledgement of sent email ?

    We have an imac OS10.6.8 ( I know, an old OS) and apple mail 4.6 A microsoft user friend said that she could get her email to send an acknowledgement back when the email was received at the other end. Can apple mail do the same, get a 'received' mess

  • Extended syntax check

    In ECC 6.0, I have two errors in my extended syntax check 1).   Char. strings w/o text elements will not be translated: 'Store%' (The message can be hidden with "#EC NOTEXT) with below coding SELECT  kunnr name2 j_3astcu     FROM kna1     INTO TABLE