Problem in Logic for Customer Ageing Report

Hi,
I am developing a Customer Ageing Report in which i am facing a problem i.e. i am taking tables BSID,BSAD in which i ham taking the open items first and then i am using for all entries in it on the open items and i had debugged it and data picking is correct .
But the MAJOR problem comes when the data is stored in the respective coloumns i.e. 0-30 ,31-60-61-90 etc.. Currently i am comparing the code with the Standard Report i.e.S_ALR_87012126 it is not coming accurate...
Is there any way to solve this problem ....
Edited by: nav009 on Jan 8, 2010 11:39 AM

Hi,
First you need to calculate the Due date of the Transaction with the help of FM 'NET_DUE_DATE_GET'.
Once you get the Due date calculate the value wf_nod  as wf_nod = p_budat - wf_due_date where p_budat is the date on which you want to run the ageing report and wf_due_date  is due date of the transaction.
once you get this wf_nod write the following logic :
      IF wf_nod < 0.
        wa_tab-ndue = wa_data-dmbtr.
      ELSE.
        IF wf_nod <= pnod1.
          wa_tab-amt1 = wa_data-dmbtr.
        ELSE.
          IF wf_nod > pnod1 AND wf_nod <= pnod2.
            wa_tab-amt2 = wa_data-dmbtr.
          ELSE.
            IF wf_nod > pnod2 AND wf_nod <= pnod3.
              wa_tab-amt3 = wa_data-dmbtr.
            ELSE.
              IF wf_nod > pnod3 AND wf_nod <= pnod4.
                wa_tab-amt4 = wa_data-dmbtr.
              ELSE.
                IF wf_nod > pnod4 AND wf_nod <= pnod5.
                  wa_tab-amt5 = wa_data-dmbtr.
                ELSE.
                  IF wf_nod > pnod5.
                    wa_tab-amt6 = wa_data-dmbtr.
                  ENDIF.
                ENDIF.
              ENDIF.
            ENDIF.
          ENDIF.
        ENDIF.
      ENDIF.
    ENDIF.
Collect wa_tab into it_tab.
where pnod1.......pnod5 are the aging period as 30,60,90,180,365 etc.
by this you will get correct results.
Please get back to me if you need some more help on this.
Regards,
Nikhil

Similar Messages

  • Problem in making logic for customer balance report

    Hi,
    I am working on a customer balance report in which i am picking the data from BSAD and BSID tables. I am facing a problem that i am able to calculate the opening balance in it but not able to calculate  closing balance. I am comparing the data with tcode FBL5N for opening and closing  balances for a given date range.  Kindly help me out where i am getting wrong:-
    Here the link to the code :-
    http://docs.google.com/View?id=dfxswwff_11fdktr7ct
    Edited by: nav009 on Feb 6, 2010 9:30 AM

    Hi Nikhil,
    Thanks for you response but i had developed the report and  i am able to pick the correct data but i am facing the problem in displaying the NETAMT which is displaying the data using this formula :-
    1.) NETAMT = NETAMT +  W_TAB1-DR + W_TAB1-CR.
    so that the last value matches with the closing balance.
    When i am using this formula i am not able to display the correct data of deducting or addition of the opening balance in it but the value matches with closing balance .
    2.) NETAMT = NETAMT + W_OPBAL-OPBAL +  W_TAB1-DR + W_TAB1-CR.
    When i am using this formula it is showing the first value correctly but not the last one which will be displayed in the closing balance.
    I want to have desired output to display the first value to be displayed as it is showing in the (2) and last value to be displayed as  it is showing in (1) last value.
    How can i achieve this  functionality? i really want to know...
    Edited by: nav009 on Feb 10, 2010 6:29 AM

  • Logic for stock aging report

    I am trying to create a stockaging report using 0IC_C03.
    I am see that the tables actually stores the qty recieved and issued of an article on a particular day/period.
    Can some one explain how it is being used in aging?
    How is it used to compute against the current SOH of article for aged QTY?
    Thanks
    Bye

    Hi,
    Create a Formula variable with Replacement Path for Batch, and replace with Attribute and attribute is Date OF Manufacturing, so using this you get Date Of manufacture. And next create a Formula variable with Custome Exit and select Dimenstion ID = Date.
    And write the following code to get Current day.
    WHEN 'ZVCURDAY'.
          CLEAR: l_s_range.
          l_s_range-low = sy-datum.
          l_s_range-sign = 'I'.
          l_s_range-opt = 'EQ'.
          APPEND l_s_range TO e_t_range.
    so by using you get current date. So create Formula and do Substraction, i.e. Curday-Dateof Manufacture (above Replcement variable), so you get number of days from Manufacturing.
    Then you csan create conditions, i.e. <30 days, <60 days like that.
    Thanks
    Reddy

  • 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

  • Customer aging report-needs the line items behind it

    We have created a Z report for customer aging report,is it feasible to get the drilldown against each aging bucket.I.e to call the FBL5n report to be displayed to see the line items behind each aging bucket.
    Regards
    Rekha

    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.
    From there you can put the cursor on customer number and from the menu goto -> line items then it will go for each line item wise..
    Regards,
    Nauma

  • 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

  • Customer ageing report for fbl5n

    hi all,
    I want to develop an customer Ageing Report in abap  to calculate the net due date  which is similar to the Tcode fbl5n but the problem is functional consultant told me about this tcode  and there is no such information regarding the specified tables which are to be used. I had searched in SDN also but i did not got the desired information.
    regards,
    karthik
    Edited by: k.vinu.karthik on Jul 23, 2010 7:21 AM

    Use the development tools available to you - the transaction and a sample account is all you need.  Debug, ST05, SE30, etc....

  • Customer Aging Report Query (without invoices offset by incoming payment)

    Hi All Experts,
    May I know is there any field from JDT1 mention which invoices is already offset by the Incoming payment or AR Credit note? Because I do not want those invoices that already offset by incoming payment appear at the Customer Aging Report. Meaning, the data appear in the Customer Aging Report is only show those invoices that yet to pay by the customer. Kindly give some advise on it. Thanks a lot.
    Thanks and regards,
    Angie Ng

    Hi David,
    Thanks for your suggestion. I have try it, but all of my JDT1.IntrnMatch is in 0 value. Meaning in my situation it is none of any reconcilliation making. But from my SBO window, i manage to see that actually this incoming payment is pay for which invoices. Problem is it is difficult for me to do the possiblity logic that might be happen in my Customer Aging Report Query. Please give some advise that how to show only those invoices yet to pay? The current query will show all the data no matter the invoices or credit memo has been offset.
    select OCRD.cardcode 'Supplier Code',OCRD.cardname 'Name',sysdeb  'Debit GBP',syscred 'Credit GBP',
    case JDT1.transtype
    when '13' then 'INV'
    when '14' then 'AR CN'
    when '24' then 'INCOMING'
    else 'Other'
    end 'Type',
    Ref1,
    fccurrency 'BP Currency',
    CONVERT(VARCHAR(10), refdate, 103)'Posting Date' ,
    CONVERT(VARCHAR(10), duedate, 103) 'Due Date',
    CONVERT(VARCHAR(10), taxdate, 103) 'Doc Date' ,
    CASE
    when (DATEDIFF(dd,refdate,current_timestamp))+1 < 31
    then
    case
    when syscred <> 0 then syscred * - 1
    else sysdeb
    end
    end "0-30 days",
    case when ((datediff(dd,refdate,current_timestamp))+1 > 30
    and (datediff(dd,refdate,current_timestamp))+1< 61)
    then
    case
    when syscred <> 0 then syscred * - 1
    else sysdeb
    end
    end "31 to 60 days",
    case when ((datediff(dd,refdate,current_timestamp))+1 > 60
    and (datediff(dd,refdate,current_timestamp))+1< 91)
    then
    case
    when syscred <> 0 then syscred * - 1
    else sysdeb
    end
    end "61 to 90 days",
    CASE
    when (DATEDIFF(dd,refdate,current_timestamp))+1 > 90
    then
    case
    when syscred= 0 then sysdeb
    when sysdeb= 0 then syscred * - 1
    end
    end "90 + days"
    from JDT1,OCRD where JDT1.shortname = OCRD.cardcode and cardtype = 'c' and intrnmatch = '0'
    ORDER BY OCRD.CARDCODE, taxdate

  • Opening Balance in Customer Aging report

    Hi Gurus,
    I am making the Customer aging report am facing a problem in the calculation of 'opening balance'.
    If the opening balance has to done by using routines how to do it.
    I am using the 0FI_AR_4 datasource.
    I am getting Debit amount , Credit amount , and Balance. They can be seen in R/3 in the
    Tcode: FD10N.
    the balance must be calculated with the previous balance.
    How to write the routine / what logic must be used . If you have the code please paste it
    here or send to:   [email protected]
    regards
    Edited by: man man on Jan 16, 2008 11:04 AM

    Hi,
    I am making a report for the Customer Aging.
    using the keyfigures 'Debit'(Collections), 'Credit'(Sales), 'Balance'
    and the characteristics 'G/L Account', 'Customer'.
    I want all the above infoobjects in the report.
    regards,
    man

  • 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.

  • SGD Exchange Rate Difference JE appears in Customer Aging Report

    Dear Experts,
    SAP Version: 8.81
    Local Currency: SGD
    We perform Exchange Rate Difference for a USD BP to calculate the unrealized gain/loss during month-end, JE created successfully.
    Next, we go to Customer Aging Report and select this USD BP.
    When i choose to view the Aging Report in Local Currency, the USD Invoice will appear in SGD + Exchange Rate Difference JE in SGD, the total balance can appear in SGD with no problem.
    When i choose to view the Aging Report in BP Currency, the USD Invoice will appear in USD + Exchange Rate Difference JE in SGD, i can't see the total balance as it is appeared as xxxxx.
    Above is the behaviour in 881.
    Last time in SAP 2005, when i choose to view the Aging Report in BP Currency, the Exchange Rate Difference JE in SGD will not appear, therefore i can see the total balance in USD.
    What is your opinion about the behavior in 881? Will you consider it as design or issue?
    Thanks.
    Regards,
    Lay Chin

    Dear all,
    This problem is no longer there when upgrade to 881 Patch 08.
    Regards,
    Lay Chin

  • Asking Exchange rate at the time of Customer aging report

    Dear All,
    I am facing one problem, when I am asking customer aging report the system is asking to enter exchange rate.but at the time of vendor aging is working fine does not asking any exchange rate,this problem happens only one specific  user, not for other users.
    In other users it is working fine.Do we need to do any configuration for that user for working this customer aging report.
    Please give solution as soon as possible
    Thanks advance.
    Regards
    Komanduri.

    We faced the same problem today.
    Finally, we found out the user accidentally selected the currency which we didn't set the exchange rate in the aging report.
    After the aging report is generated, we can change the currency in the upper left corner.
    If we didn't set the rate of that currency, it will keep asking.
    Even if we close the aging report and open again, it  will still ask for that currency before it could generate the report
    When we set the rate of that currency, it will not ask exchange rate again

  • Customer Aging Report. Pl help me in this issue.

    Problem in Customer Aging Report.
    1. No concrete solution given to take project wise, bill wise. 2. Opening dues break up - project wise. Bill wise. 3. Aging days not able to select the required interval. Only standard intervals are available. 4. How to find the exact payment payable/ receivable for an vendor/customer.

    Hi Arun...........
    You can get the invoice wise aging. Once you run aging report you have to only double click on the sequence no grid.
    Hope this will solve the issue........
    Regards,
    Rahul

  • Need standrad program for vendor aging report

    Hi
      Need standrad program for vendor aging report.
    Please reply me only standrad programs.
    Point are sure.
    Regards,
    kumar

    Hi Pankaj
       sorry to say that this is not my required program.
    I need vendor aging report like s_alr_87012178 tc leads to customer aging report.
    Thanks for your effort.
    points are awarded.
    Regards,
    kumar

  • Customer Aging Report(without reconciled transaction)-what types of documents are considered?

    Hi Friends,
    As per my knowledge,Customer Aging Report consider only those documents(ar invoice,ar downpayment,incoming payment-payment on a/c,ar credit memo) which are open and showing balance due and standalone JE against Customer.
    As I cross checked,I found those standalone JE where Customer and round off account are considered as debit,credit are not considered by 'Customer Aging report'.
    So,I just want to know what are all the logic based on which SAP B1 standard report 'Customer Aging ' (without reconciled transaction ) consider the documents????

    Which SAP B1 Version and Patch is under use at your end ?
    There were issues in SAP B1 regarding reconcilliations in versions prior to 2007 series.
    Samir Gandhi

Maybe you are looking for

  • How to change the default Real-Time Collaboration page?

    Who can tell me how to change the default Real-Time Collaboration page? If I want to add my corporation logo in the top of the default page.How to do? Thanks!

  • How Do I add Bonjour printer to groups of Macs

    I have a few HP 2600n (running with bonjour over network) I want to add all of these to 40 iMacs in one hit, I cannot do this via Server admin can I? If not then is it possible to send out a command to add the printer with its designated name to all

  • Best options for decent quality output?

    Hi all, I'm using a Canon HG10 shooting HD AVCHD. I am pretty pleased with the new archive facility as it's helping save space, and I'm debating whether to edit in 960x540 or 1920x1080. The 1080 footage looks way better onscreen (to my eye at least)

  • Handling RAW data types (from SAP) in Adobe forms - Illegal Arg Exception

    Hi,       I have a scenario where I have to get data of type RAW in SAP to Adobe Forms using web dynpro java. What is the corresponding type in Web Dynpro / Adobe Forms. I am using Adaptive RFC and when I get the model from SAP function module, the R

  • How to chage the info email change

    i am trying to chenge the email address thtat sends RESET info to??