Vendor variance report

vendor variance report and vendor performance report both are same . pls tell in detail . points will be rewarded  definitely.

Hi
Both are same
Before purchasing some thing from Vendor We ask for quotations from different vendors
After receiving them all will be compared in terms of the Prices, different Taxes and other conditions and a single vendor is shortlisted asking him to supply the goods. We will issue a PO for that vendor.
Reward points if useful
Regards
Anji

Similar Messages

  • Vendor rating report

    Hello all,
    Vendor rating report with respect to PO Delivery date Vs. actual delivery date required.
    The actual delevery date incase of domestic PO is the GoddsReciep Number date, and incase of importPO, this is the invoice date of the vendor.
    thanks &regards,
    Obulesu

    Hi,
    T code MC$6 will be useful for you.
    There you can get the delivery date variance in days.
    Regards
    KK

  • Vendor Spend Report

    Hi Gurus,
    I am working on developing a quaterly vendor spend report with some additional custom fields to narrow down the custom report. I am looking at table LFC1. I want to know if that is the right table for payment information for quaterly purpose. Also, please throw in your logic to calculate the quaterly amount .
    Also, suggest me if there are any other tables i should be taking into picture for vendor quarterly spend report .
    Thank you for reading this message and will really appreciate if you can send your views.
    Sri

    Hi
    The table you are looking into is the perfect table.
    The only problem in this table is it will be the transaaction figure total table, which will take your invoice booked, credit memo booked & the payment made also.
    So i feel that this table will not solve your requirement.
    Better take the table BSIK & check with your FI team & exclude the document types that are used for the payment to the vendor
    To arrive at the quarterly spend check the fiscal year variant attached to the company code & map the no of the periods to the quarter (Posting period in BSIK - MONAT)
    Hope this will fulfill your requirement
    Let me know if you need further clarification on this front.
    Regards
    R.Karthigayan

  • Vendor Aging Report

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

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

  • Vendor performance report

    hai
    how to create an vendor performance report which display purchase order issued to a vendor, material supplied delivery times, payment terms, prices during a period of time.
        for this report what are the tables and fields we have to use pls give me sample report..
                  thank you..

    Hi,
    Against the RFQ's vendor submit quotations and the Based on the RFQ's data we have to compare the different Vendors with the respective data like terms and prices
    Fetch the data of all RFQ's from EKKO and EKPO tables
    and take the EKKO-KNUMV field and pass to KONV table and fetch the different prices based on the Condition types  for each RFQ and put it in a tabular format  and compare.
    see the sample code
    *& Report  ZRFQ_COMP
    *& Quotation Comparison Report
    REPORT  ZRFQ_COMP no standard page heading line-size 187 line-count 35.
    *&Tables
    Tables : ekko,
             ekpo,
             konp,
             a016.
    *&Data Decleration
    Data : v_pos type i value 19.
    Data : begin of it_rfq occurs 0,
            ebeln type ekko-ebeln,
            ekorg type ekko-ekorg,
            lifnr type ekko-lifnr,
            matnr type ekpo-matnr,
            WERKS type ekpo-WERKS,
           end of it_rfq.
    Data : begin of it_a016 occurs 0,
            ebeln type ekko-ebeln,
            knumh type knumh,
           end of it_a016.
    Data : begin of it_a363 occurs 0,
            werks type werks,
            lifnr type lifnr,
            matnr type matnr,
            knumh type knumh,
           end of it_a363.
    Data : begin of it_pr_details occurs 0,
            knumh type knumh,
            kschl type kschl,
            kbetr type kwert,
           end of it_pr_details.
    Data : begin of it_final occurs 0,
            ebeln type ebeln,
            lifnr type lifnr,
            name1 type lfa1-name1,
            pb00  type kbetr,
            zpac  type kbetr,
            zb00  type kbetr,
            ZIN1  type kbetr,
            JEC1  type kbetr,
            JHX1  type kbetr,
            JMOP  type kbetr,
            JMX1  type kbetr,
            JMX3  type kbetr,
            JSEP  TYPE KBETR,
            JVRD  type kbetr,
           end of it_final.
    Data : begin of it_vendorname occurs 0,
            lifnr type lifnr,
            name1 type lfa1-name1,
           end of it_vendorname.
    *&Selection Screen
    Selection-screen: begin of block blk1 with frame title text-001.
      parameters     : p_matnr like ekpo-matnr obligatory.
      select-options : s_ebeln for ekko-ebeln,
                       s_ekorg for ekko-ekorg,
                       s_lifnr for ekko-lifnr.
    Selection-screen: end of block blk1.
    *&Start-of-Selection.
    Start-of-selection.
      Select ekko~ebeln
             ekko~ekorg
             ekko~lifnr
             ekpo~matnr
             ekpo~werks
        into table it_rfq
        from ekko
       inner join ekpo
          on ekkoebeln eq ekpoebeln
        where ekko~ebeln in s_ebeln
          and ekko~ekorg in s_ekorg
          and ekko~lifnr in s_lifnr
          and ekpo~matnr eq p_matnr
          and ekko~bstyp eq 'A'.
      if sy-subrc eq 0.
    *--> Condition number from A tables.
      Perform get_connum.
    *--> Getting the Pricing Details from Konp Table.
      Perform get_prices.
    *--> Populate Vendor Name.
      Perform pop_vendor_name.
    *--> Populating the Final Internal table for Report.
      Perform pop_final_tab.
      else.
       message 'Purchase Document does not exist' type 'E'.
      endif.
    *&End-of-Selection.
    End-of-Selection.
    write :/ sy-vline,
           2 'Vendor Number',
           19 sy-vline.
    v_pos = 19.
    loop at it_final.
      write at v_pos sy-vline.
      v_pos = v_pos + 1.
      write at v_pos it_final-lifnr.
      v_pos = v_pos + 35.
    endloop.
    write at: v_pos sy-vline,
              /(v_pos) sy-uline.
    write :/ sy-vline,
           2 'Gross Price',
           19 sy-vline.
    v_pos = 19.
    loop at it_final.
      write at v_pos sy-vline.
      v_pos = v_pos + 20.
      write at v_pos it_final-pb00.
      v_pos = v_pos + 16.
    endloop.
    write at: v_pos sy-vline,
              /(v_pos) sy-uline.
    write :/ sy-vline,
           2 'Packing & Forward',
           19 sy-vline.
    v_pos = 19.
    loop at it_final.
      write at v_pos sy-vline.
      v_pos = v_pos + 20.
      write at v_pos it_final-zpac.
      v_pos = v_pos + 16.
    endloop.
    write at: v_pos sy-vline,
              /(v_pos) sy-uline.
    write :/ sy-vline,
           2 'Surcharge',
           19 sy-vline.
    v_pos = 19.
    loop at it_final.
      write at v_pos sy-vline.
      v_pos = v_pos + 20.
      write at v_pos it_final-zb00.
      v_pos = v_pos + 16.
    endloop.
    write at: v_pos sy-vline,
              /(v_pos) sy-uline.
    write :/ sy-vline,
           2 'Installation',
           19 sy-vline.
    v_pos = 19.
    loop at it_final.
      write at v_pos sy-vline.
      v_pos = v_pos + 20.
      write at v_pos it_final-zin1.
      v_pos = v_pos + 16.
    endloop.
    write at: v_pos sy-vline,
              /(v_pos) sy-uline.
    write :/ sy-vline,
           2 'Ed cess on BED%',
           19 sy-vline.
    v_pos = 19.
    loop at it_final.
      write at v_pos sy-vline.
      v_pos = v_pos + 20.
      write at v_pos it_final-jec1.
      v_pos = v_pos + 16.
    endloop.
    write at: v_pos sy-vline,
              /(v_pos) sy-uline.
    write :/ sy-vline,
           2 'A/P Secess set off',
           19 sy-vline.
    v_pos = 19.
    loop at it_final.
      write at v_pos sy-vline.
      v_pos = v_pos + 20.
      write at v_pos it_final-jhx1.
      v_pos = v_pos + 16.
    endloop.
    write at: v_pos sy-vline,
              /(v_pos) sy-uline.
    write :/ sy-vline,
           2 'Basic Excise Duty',
           19 sy-vline.
    v_pos = 19.
    loop at it_final.
      write at v_pos sy-vline.
      v_pos = v_pos + 20.
      write at v_pos it_final-zpac.
      v_pos = v_pos + 16.
    endloop.
    write at: v_pos sy-vline,
              /(v_pos) sy-uline.
    write :/ sy-vline,
           2 'A/P BED set off',
           19 sy-vline.
    v_pos = 19.
    loop at it_final.
      write at v_pos sy-vline.
      v_pos = v_pos + 20.
      write at v_pos it_final-jmx1.
      v_pos = v_pos + 16.
    endloop.
    write at: v_pos sy-vline,
              /(v_pos) sy-uline.
    write :/ sy-vline,
           2 'Ecess % set off',
           19 sy-vline.
    v_pos = 19.
    loop at it_final.
      write at v_pos sy-vline.
      v_pos = v_pos + 20.
      write at v_pos it_final-jmx3.
      v_pos = v_pos + 16.
    endloop.
    write at: v_pos sy-vline,
              /(v_pos) sy-uline.
    write :/ sy-vline,
           2 'Sec ED Cess on BED',
           19 sy-vline.
    v_pos = 19.
    loop at it_final.
      write at v_pos sy-vline.
      v_pos = v_pos + 20.
      write at v_pos it_final-jsep.
      v_pos = v_pos + 16.
    endloop.
    write at: v_pos sy-vline,
              /(v_pos) sy-uline.
    write :/ sy-vline,
           2 'VAT%',
           19 sy-vline.
    v_pos = 19.
    loop at it_final.
      write at v_pos sy-vline.
      v_pos = v_pos + 20.
      write at v_pos it_final-jvrd.
      v_pos = v_pos + 16.
    endloop.
    write at: v_pos sy-vline,
              /(v_pos) sy-uline.
    *&Top-of-Page.
    Top-of-Page.
    format color 1.
    Write: 'Material Number :' color 1, p_matnr color 1.
    loop at it_final.
      v_pos = v_pos + 1.
      v_pos = v_pos + 35.
    endloop.
    write at: /(v_pos) sy-uline,/ sy-vline,2 'Vendor Name'.
    v_pos = 19.
    loop at it_final.
      write at v_pos sy-vline.
      v_pos = v_pos + 1.
      write at v_pos it_final-name1.
      v_pos = v_pos + 35.
    endloop.
    write at: v_pos sy-vline,
              /(v_pos) sy-uline.
    *&      Form  get_connum
          Condition number from A tables
    form get_connum .
        Select EVRTN
               knumh
          from a016
          into table it_a016
           for all entries in it_rfq
         where EVRTN eq it_rfq-ebeln.
        Select werks
               lifnr
               matnr
               knumh
          from a363
          into table it_a363
           for all entries in it_rfq
         where werks eq it_rfq-werks
           and lifnr eq it_rfq-lifnr
           and matnr eq it_rfq-matnr.
    endform.                    " get_connum
    *&      Form  get_prices
          Getting the Pricing Details from Konp Table.
    form get_prices .
      if not it_a016[] is initial.
        select knumh
               kschl
               kbetr
          from konp
          into table it_pr_details
           for all entries in it_a016
         where knumh eq it_a016-knumh.
      endif.
      if not it_a363[] is initial.
        select knumh
               kschl
               kbetr
          from konp
    appending table it_pr_details
           for all entries in it_a016
         where knumh eq it_a016-knumh.
      endif.
    endform.                    " get_prices
    *&      Form  pop_final_tab
          Populating the Final Internal table for Report
    form pop_final_tab .
    data : l_subrc like sy-subrc.
      sort it_a016 by ebeln.
      loop at it_rfq.
        clear l_subrc.
        read table it_a016 with key ebeln = it_rfq-ebeln
        binary search.
        if sy-subrc eq 0.
          loop at it_pr_details where knumh eq it_a016-knumh.
            it_final-ebeln = it_rfq-ebeln.
            it_final-lifnr = it_rfq-lifnr.
            read table it_vendorname with
            key lifnr = it_rfq-lifnr.
            it_final-name1 = it_vendorname-name1.
            case it_pr_details-kschl.
            when 'PBOO'.
              it_final-pb00 = it_pr_details-kbetr.
              if it_pr_details-kbetr eq 0.
               clear it_final.
               continue.
              endif.
            when 'ZPAC'.
              it_final-zpac = it_pr_details-kbetr.
            when 'ZB00'.
              it_final-ZB00 = it_pr_details-kbetr.
            when 'ZIN1'.
              it_final-ZIN1 = it_pr_details-kbetr.
            endcase.
          endloop.
        else.
          l_subrc = sy-subrc.
        endif.
        read table it_a363 with key lifnr = it_rfq-lifnr
                                    werks = it_rfq-werks
                                    matnr = it_rfq-matnr.
        if sy-subrc eq 0.
          loop at it_pr_details where knumh eq it_a016-knumh.
            it_final-ebeln = it_rfq-ebeln.
            it_final-lifnr = it_rfq-lifnr.
            read table it_vendorname with
            key lifnr = it_rfq-lifnr.
            it_final-name1 = it_vendorname-name1.
            case it_pr_details-kschl.
            when 'JEC1'.
              it_final-JEC1 = it_pr_details-kbetr.
            when 'JHX1'.
              it_final-JHX1 = it_pr_details-kbetr.
            when 'JMOP'.
              it_final-JMOP = it_pr_details-kbetr.
            when 'JMX1'.
              it_final-JMX1 = it_pr_details-kbetr.
            when 'JMX3'.
              it_final-JMX3 = it_pr_details-kbetr.
            when 'JSEP'.
              it_final-JSEP = it_pr_details-kbetr.
            when 'JVRD'.
              it_final-JVRD = it_pr_details-kbetr.
            endcase.
          endloop.
        elseif l_subrc ne 0.
       continue.
        endif.
        append it_final.
        clear  it_final.
      endloop.
    endform.                    " pop_final_tab
    *&      Form  pop_vendor_name
          Populate Vendor Name
    form pop_vendor_name .
      if not it_rfq[] is initial.
      Select lifnr
             name1
        from lfa1
        into table it_vendorname
       where lifnr eq it_rfq-lifnr.
      endif.
    endform.                    " pop_vendor_name
    Reward points if useful
    Regards
    Anji

  • Vendor ageing report(urgent)

    in vendor ageing report i am getting the data for the vendors with open item only means those vendors who have to pay depending on the parameter date which we r passing
    in selection screen.
    but i  want all those records with cleared item also depending on that date.
    means suppose there r 2 vendors
    1.sanjeev-he has to pay 1000 but he has paid 500 and left
    with 500 due.
    2. amit -he has to pay 1000 and he had not paid anything till now.
    so when i am executing my report it is showing only
    sanjeev 500
    amit 1000
    but i need
    sanjeev 1000
    amit 1000
    to be displayed but as sanjeev has already paid 500
    so it is not showing the output as above.
    so how it could be achieved

    hi sanjeev,
    anver here.
    do like this.
    if has_paid < has_to_pay.
    write has_to_pay.
    endif.
    rgds
    anver

  • Vendor Payments Report with WBS Elements

    Dear Expert,
    I am looking a report for Vendor outgoing payment against WBS Elements.
    Is there any Vendor Payments report with WBS Elements in SAP? I have seen FBL1N but WBS Elements field is blank.
    Thanks
    Samiee.

    Hi,
    You mentioned WBS Element is blank; so please check in any one sample payment documnet whetehr WBS is maintained and if yes find which field it is populated. For eg; sometimes people populate this information in the text or assignment field. If that is the case then change the layout accordingly in FBL1N.
    Regards
    Sreekanth

  • Vendor Aging Report to show zero balance does not show all vendors

    Hi all,
    I would like to see a list of all my vendors in the Vendor Aging Report. I clicked on show vendors with zero balance, however, I still only get a partial list of the vendors. Is there a setting I need to set to show all the vendors? Any advice would be appreciated.
    Thank you!
    Jane

    Hi,
    I think your requirement is you want all vendors displayed irrespective of the transactions entered for that Business Partner.
    The Aging Report will display only those BPs which have transactions posted to them.
    The function of 'Display Vendors with zero balance' checkbox is that it behaves like a selection creteria and leads to inclusion
    of all those Business Partners who do not have a balance as of the current date but had a balance on the selected backdate.
    example :
    If a vendor has a balance as on 01.08.08 and is paid on 10.08.08, then the vendor will not be included in aging report (when run on 01.08.08) unless "Include Vendors with zero balance" is checked.
    This checkbox does not allow you to display all the vendors created in the database.
    Regards,
    Jitin
    SAP Business One Forum Team

  • Please update the functional specifications for Vendor Balance Report

    Dear All,
    Please update the functional specifications for Vendor Balance Report with
    proper descriptions.
    Please include
    1. How your selection screen should look like..
    2. Output format ( in an excel sheet)
    3. Logic for every field in the output format (viz. .. how do link the
    vendors from the selection screen to the BKPf and BSEG tables, how do you
    find open and closed items in BSEG , etc.)
    Please avoid statements like 'The total value of all the break-up should
    tally with the balance as shown in FBL1N for a given vendor for the given
    day.'
    You need to give the logic for the FBL1N, in that case.
    Regards
    Rama Mohan

    Hello again,
    Regarding having them update the specs, one can dream. Dreams are free. LOL. Hopefully the memory makers will update their specs as more makers start supporting a large memory configuration.
    The 4GB sticks I am using are http://shop.kingston.com/partsinfo.asp?ktcpartno=KTL-TP667/4G
    I did not do an extended test of the sticks in my MBP. Their home is in the ThinkPad I have because it is running Windows Server 2008 with Hyper-V.
    As you can see from the link above, these little suckers are pricey. But consider the price of 2GB SoDIMMs were $950 when they entered the market a couple of years ago. The price will drop.
    I asked the Kingston rep that sent these to me if online sites like newegg.com would have them soon. She indicated no, but the corporate buying sites like CDW and Zone would. So check around. They just started shipped a couple of weeks ago so be patient.
    If you have any other questions, please stop by http://blogs.technet.com/keithcombs/archive/2008/07/05/testing-my-apple-macbook- pro-with-8gb-of-ram.aspx and ask there. I'll see them much more quickly.
    Cheers,
    Keith Combs
    Microsoft

  • Problem in dynamic selection in vendor balance report  tcode S_ALR_87012082

    Hello Friends,
    After upgrading from 4.7 to ecc 6.0 we are facing the below mentioned problem.
    In a Vendor Balances report, the document selection is not available in the dynamic selections and hence i am not able to select the business area to suit the requirement. We have only, vendor master and company code in the dynamic selections.
    Is there any customization tht needs to be set???
    Thanks,
    Sunny

    Hi Vas,
    I am not sure..... but you can view the details in "S_ALR_87012079", you need to chnage the layout....
    If the hint is useful… Say thanks by reward….
    Regards,
    Prabhu Rajesh

  • Statistical Posting seen in Vendor balance report

    Hi,
    I have posted a bank guarantee through statistical posting (F-55). As per my knowledge, statistical posting does not update GL.
    Statistical Entry Passed:
    Vendor A/c... Dr (Special GL - G)
       TO BG cleaing
    But when i take a report for Vendor report along with special GL, the statistical posting is also considered. How to take a report for the same.
    I know one option through dynamic selection in FBL1N.
    What is TCode if i want Vendor Balance Report without statistical posting directly.

    select the noted items check box at the time of report execution, if u want to see the only splecial gl -G, give the G in spl. gl field at dynamic selection

  • Vendor order report

    explain me the vendor order report.its urgent.

    Hi,
    Following standard reports are  used for vendor related information giving reports provide by SAP.
    RFKOPR10 is the program for vendor ageing
    Try this transaction S_ALR_87012078
    RFKRRANZ - Vendor Information System
    Please follow this path in the main SAP menu to find vendor-related reports:
    SAP menu --> Information Systems --> Accounting --> Financial Accounting --> Accounts Payable --> Report for Accounts Payable Accounting
    Check in the Master Data folder, the Vendor Balances folder, and the Vendors: Items folder. I hope this helps.
    Please try standard program RM06IL00 (transaction ME1L).
    There are SAP Standard reports like ME2L ,ME2M,just look at souce code.
    you will find more information on Tables and fields.
    FBL1N is a stanradr transaction and has accesses only transaction data, no master data of the vendor.
    Thanks,
    Sankar M

  • Vendor Spending Report

    We have a requirement to report vendor spending per a specified period, per material group.  The standard MCE5 report works great, however consignment costs are not accurately reported due to the PO price being 0.  The Vendor Business report S_ALR_87012093 is another great report and includes consignment, however it cannot be drilled down per material group. 
    At this time we are not able to develop a BW report.  Is there another transaction that could provide this information, or could a query be written?  If a query could be written what tables would be used?
    Thanks.

    Hi Harris,
    As far as I know, A/P is a subledger and contains detailed info on purchasing. To G/L is transferred rather aggregated info. So, I doubt that you'll have all info you need from BSEG only. Check it out.
    Best regards,
    Eugene

  • Vendor ageing report

    Hi all,
    i have to prepare vendor ageing report.In that there is one exception that is if "no. of overdue days > 7 " color should be red.But here no. of overdue days can be calculated with the following formula as shown below.
    no. of overdue days = query date(today's date) - orginal confirmation date.
    but my query is there is no orginal confirmation date present in the infocube 0pur_c01 . how to get that ?
    plz help me in this regards,
    Thanx & Regards,
    RaviChandra

    Hi suman,
    thanx for ur reply , but my question is how to get the orginal confirmation date from the cube 0pur_c01 , my requirement is to find the no. of overdue days.
    no. of overdue day = today's date - orginal confirmation date.
    Here we can get the today's date , but how to  get the orginal confirmation date from the cube 0pur_c01 ,
    I hope u understand the question.
    Thanx & Regards,
    RaviChandra
    Edited by: Ravichandra.bi on Sep 18, 2011 7:32 AM

  • I need a code for VENDOR AGEING REPORT

    plz help me i am in urgent need of source code of
    VENDOR AGEING REPORT.
    if any body help me regarding this above report i will be
    great ful to him/her.
    bcoz deadline is today.
    i  need ur urgent help, i treid very much but i failed,
    so hope help from anybody there.

    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.

Maybe you are looking for