Could anybody give me the logic in sales report

Hi All,
I have a sales report on multprovider. In this sales report, I want to find out how many customers had done the transactions in day.
<b>Two transactions for one customer in a day can be counted as one transaction</b>.
Could anybody give me the logic to how to find the total number of customers made transaction in a day.
Thanks in advance
Narendra

Hi Anil,
Thanks alot for your answer.
I am not sure, how the user is going to excute the report.however there is a <b>user entry Characterstic variable on 0CALDAY with selection options.</b>
For example :
If the user run the sales report  from Calander Day from 01-06-2007 to 06.06.2007.
that means 4 business days (1st, 4th, 5th and 6th June). He wants to see the total number of customer done the transaction in a day separately, means 1st June how many customers, 4th June how many customers, 5th June how many customers, and 6th June how many customers.
Based on the user selections,how many customers per day made the transactions. could you please send me the logic.
My email Id is : [email protected]
<b>Note : Query <---- multiprovider <---- Infocube <---- ODS</b>
Thanks in advance
Narendra

Similar Messages

  • Can anyone please give me the logic for this....

    I have a database table and in it i have a field department code. now, that department code might have '00' or '   ' (blank) or anyother value. now i want to add up all the currency amounts with department code '00'  and '  ' (blank) which have same company code and currency type. I called all the entries with '00' into one internal table and enrties with '  ' (blank) to other internal table.
    can anyone give me the logic for adding all the entries at a time.
    thanks in advance.....

    HI Srinivas
    i have a solution for this question.
    Use At control break statement for this.
    Loop the internal table.
    Use at Event AT LAST. In that use SUM Statement. U will get sum of all the numeric fields.
    Or else u can use ON CHANGE OF Currency type
    then find the total amount by adding previouse value with ur current value.
    Like itab1-amount = total + itab1-amount.
    Appent this into ur internal or write it into ur report.
    Reward me if its useful.
    Regards
    Ravi

  • Can anybody give me the table with tcode and its development class

    can anybody give me the table with tcode and its development class

    Hi phani,
    1) First retrieve program name from tstc table I.e field pgmna.
      2) Using pgmna retrieve from tadir table by using the following criteria from tadir table
       pgmid    = 'R3TR'
      AND object   = 'PROG'
      AND obj_name = tstc-pgmna.
    We will get development class or package in tadir i.e
    tadir-devclass 
    Thanks,
    Naveen Kumar.

  • Plz, could anybody send me the driver for VF0010 webcam for xp 64 bit?

    Plz, could anybody send me the driver for VF000 webcam ? iam using xp 64 bit
    my email is [email protected]
    thanks in advance

    yeah exactly
    3000 N100-0768DKU
    XP Home 5.01.2600 SP2
    Ubuntu 8.04(hardy)

  • ANYBODY GIVE ME THE TABLE/TABLES THAT CONTAIN TCODE AND DEVELOPMENT CLASS

    ANYBODY GIVE ME THE TABLE/TABLES THAT CONTAIN TCODE AND DEVELOPMENT CLASS

    Hi phani,
                 The table TSTC contains the transaction codes.
    Also the below links provides a lot of info on the Standard SAP Tables.
    http://www.sapdev.co.uk/tables/tables.htm
    Pls reward if useful..
    Thanks,
    Sirisha.

  • Can anybody give me in logical standby

    give me the link and obe of logical standby which book is refer to me for dataguard.

    http://download.oracle.com/docs/cd/B19306_01/server.102/b14220/high_av.htm#sthref2556
    http://download.oracle.com/docs/cd/B19306_01/server.102/b14239/toc.htm
    http://download.oracle.com/docs/cd/B19306_01/server.102/b14239/concepts.htm#sthref41
    http://download.oracle.com/docs/cd/B19306_01/server.102/b14230/toc.htm

  • Can anybody give me the jdbc code for postgres database.

    Hello all,
    I tried to search for sample jdbc code for postgres. But I couldn't find working sample. Can anybody please post the sample jdbc code for connecting to postgres database.
    I have already added the jar file, "postgresql-8.0-312.jdbc3.jar" to the build path.
    Thanks.
    Srinivas

    Hi,
    Thanks for your reply!
    I wrote the following code, but the insert doesn't add a row.
    try {
              Class.forName("org.postgresql.Driver");
              //Preparing Conenction String     
              Connection con = DriverManager.getConnection("jdbc:postgresql://<name>:5432/sales_office_test", "sales_office_data","sales_office_data");
              PreparedStatement prepSt =  con.prepareStatement(
                                  "INSERT INTO office_personnel (office_id, salutation, firstname, lastname, email_address,"
                                  + " cellphone, phonenumber, extension, password, username) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
                             prepSt.setString(1, newOfficeIds);
                             prepSt.setString(2, whopperUserSalutation);
                             //Close statement
                             prepSt.close();
         } catch (ClassNotFoundException e1) {
              // TODO Auto-generated catch block
              e1.printStackTrace();
         } catch (SQLException e1) {
              // TODO Auto-generated catch block
              e1.printStackTrace();
         }If I print the connection object I get
    Sql connection value: org.postgresql.jdbc3.Jdbc3Connection@10965c3 I double checked the same query by directly executing it on the web interface to the postgres, works fine there and creates the row...
    What could be wrong.
    Thanks
    Srinivas

  • Can anybody give me the difference between Catt and Ecatt

    Hi gurus,
    Can any body give me the difference between catt and ecatt.

    Hi,
    I think this is new technology in sap.
    I know little bit of this can u go through this.
    eCATT (extended Computer Aided Test Tool)
    What is eCATT?
    eCATT is an SAP Testing Tool used to automate & test business scenarios in R/3. Each test generates a detailed log that documents the test process and results. If the testing is smooth without any errors, this means that the business scenarios mapped in R/3 are correct. If the test results in error then the problem can be analyzed using the error log that is generated. 
    eCATT enables automatic testing in SAP GUI for Windows and SAP GUI for Java.
    Features of eCATT:
    Following functions can be performed using eCATT:
    Test transactions, reports and scenarios.
    Call BAPIs and function modules.
    Test remote systems.
    Check authorizations (user profiles).
    Test updates (database, applications, GUI).
    Set up customizing tables.
    Test the effect of changes to customizing settings.
    Perform load testing.
    Check system messages.
    Integrated with Test Workbench, so allows proper management of scripts using SCAT transaction.
    Supports CATT migration to eCATT.
    All eCATT Objects are Repository Objects. Therefore one can take advantage of Standard SAP Transport Tools.
    eCATT Objects can easily download & upload in XML with XSD format.
    There can be several versions of Test Scripts, which allows different implementations with different releases.
    The separation of Test Scripts, Test Data & System Data allows for a considerable degree of reuse.
    Why eCATT?
    CATT is no longer supported by SAP for the creation of new developments. Hence all the test scripts developed in CATT are now need to migrate/Update to eCATT. Comparative to manual testing, the following are advantages of using eCATT:
    Due to automation, testing time is reduced to a large extent.
    Due to automation, less manpower is required for testing. This helps financially.
    Due to automation, manual errors are reduced to large extent. Hence results in error free testing. This helps, as no further problems will occur while the usage of R/3 system by end users and hence increases the efficiency.
    Proved to be extremely useful in implementation projects.
    In regression testing, automated test scripts are an ideal method of quickly detecting errors. Automatic test logs make it easy to reproduce test results, enabling fast analysis and planning of further activities, leading to cost savings for the customer.
    Differences between CATT and eCATT?
    Till date, CATT could only be used with the R/3 system. eCATT (which is available with SAP Web Application Server 6.20) covers the automatic testing in SAPGUI for Windows and SAP GUI for Java. For other GUIs and Applications, eCATT provides an interface for external tools. This allows companies to perform automated tests from an SAP system in a complete IT solution landscape across system boundaries. These new options enable complete automation of solution landscapes under standard Windows and Web-based user interfaces- resulting in low-cost operation of an IT Solution.
    eCATT (extended Computer Aided Test Tool)
    eCATT requisites
    Web Application Server (WAS) 6.20 or more.
    SAPGUI 6.20 or more.
    R/3 4.6C or more. (Target system must have sufficient support package level (Details available in SAP Note 519858) or SAP R/3 Enterprise Release 4.7).
    Before creating Test Scripts using eCATT, some system settings need to be done: 
    Maintain table T000.
    1.      Go to transaction SM31
    2.      Enter T000 and chose MAINTAIN.
    3.      In the Change View “Clients”: Overview screen, select the relevant client and choose “Details”
    4.      In the “CATT and eCATT Restrictions” field, select “CATT and eCATT allowed”.
    5.      Click on SAVE. 
    Enabling scripting at the Front-end
    1.      On any SAP GUI screen, choose “Customizing of Local Layout”.
    2.      Choose Options
    3.      Choose “Scripting Tab”
    4.      Select “Enable Scripting”
    5.      Click Apply and then OK. 
    Enabling Scripting on the Application Server
    1.      Go to transaction RZ11.
    2.      On the Maintain Profile Parameters screen, enter sapgui/user_scripting.
    3.       Choose Display.
    4.      If the Current Value is not set to TRUE, then click on Change Value:
    5.      Enter TRUE in the “New Value”.
    6.      Click on SAVE.
    eCATT is an SAP Testing Tool used to automate & test business scenarios in R/3. Each test generates a detailed log that documents the test process and results. If the testing is smooth without any errors, this means that the business scenarios mapped in R/3 are correct. If the test results in error then the problem can be analyzed using the error log that is generated. 
    eCATT enables automatic testing in SAP GUI for Windows and SAP GUI for Java.
    Features of eCATT:
    Following functions can be performed using eCATT:
    Test transactions, reports and scenarios.
    Call BAPIs and function modules.
    Test remote systems.
    Check authorizations (user profiles).
    Test updates (database, applications, GUI).
    Set up customizing tables.
    Test the effect of changes to customizing settings.
    Perform load testing.
    Check system messages.
    Integrated with Test Workbench, so allows proper management of scripts using SCAT transaction.
    Supports CATT migration to eCATT.
    All eCATT Objects are Repository Objects. Therefore one can take advantage of Standard SAP Transport Tools.
    eCATT Objects can easily download & upload in XML with XSD format.
    There can be several versions of Test Scripts, which allows different implementations with different releases.
    The separation of Test Scripts, Test Data & System Data allows for a considerable degree of reuse.
    Why eCATT?
    CATT is no longer supported by SAP for the creation of new developments. Hence all the test scripts developed in CATT are now need to migrate/Update to eCATT. Comparative to manual testing, the following are advantages of using eCATT:
    Due to automation, testing time is reduced to a large extent.
    Due to automation, less manpower is required for testing. This helps financially.
    Due to automation, manual errors are reduced to large extent. Hence results in error free testing. This helps, as no further problems will occur while the usage of R/3 system by end users and hence increases the efficiency.
    Proved to be extremely useful in implementation projects.
    In regression testing, automated test scripts are an ideal method of quickly detecting errors. Automatic test logs make it easy to reproduce test results, enabling fast analysis and planning of further activities, leading to cost savings for the customer.
    Reward points if it is helpful.
    Rgds,
    P.Nag

  • Could anybody post here the Symbian Anna Email Wid...

    Hi, could anybody tell me how can I get the Email Widget for Symbian Anna?
    I have a Nokia N8 Belle and I don't like the big widget for email, so I would like install the old email widget for Symbian Anna for my N8 Belle.
    How can I get the wgz file, please?
    Thank you very much,
    Luis.
    Attachments:
    widget.png ‏91 KB

    The widget is part of the mail application, and as such you cannot have the updated mail application with the old style widget. Unfortunately as the mail application is built into the ROM it's not possible to replace.
    Sorry.
    If I have helped you, please hit the star at the bottom of my posts - it's appreciated!
    Don't forget if your problem is solved to press the "Accept as Solution" button.

  • Can anyone pls..  give me the material for sales information system?

    hi,
    good evening to all gurus,
    this is arunteja vasan
    pls.. if anybody have material for SIS, u will send me.
    thanks to all.

    Hi,
    1.create information structure by selecting the key figures and characteristics. After creating the information structure u must activate and generate.
    2.include updating rule for information structure. After including the updating rule the information structure u must activate and generate
    3.select the updating rule is whether for day, week, month, or year by double clicking on the information structure.
    4.Maintaining all seetings ie; customer statistics group, materialstatistics group, sales document, sales item, billing document, and assign all these to sales document type, sales item, billing type,
    5.Assign sales area to updating rule.
    6.check the sales area whether all settings are maintained or not.
    7.maintained customer statistics group in the customer master record, and material statistics group in the material master record.
    8.After all the settings use T.c. MCSI enter the sales area customer material and see the results, now u get the report or sales of a particular customer or organization.
    Note: Before doing the last step create a sales order, delivery, AND billing.
    Award points if useful.
    Regards,
    Amrish Purohit

  • Can anybody give me the formula for Database capacity planning for 10gR2?

    Hi ,
    I want to learn how to make database capacity planning for production in 10gR2. Here i need any formula to plan the capacity.
    Can anybody help me?
    Regards
    Rajesh

    hi,
    There is no perfect world. There is no perfect application. If I am permitted to say, there is no perfect CAPACITY PLANNING. In this world, we strive hard to achieve near PERFECTION
    DISK SPACE ESTIMATED FOR THE DATABASE(RDBMS) ONLY
    ESTIMATES ARE BASED ON ASSUMPTIONS, SAMPLING, STATISTICS
    ESTIMATES CAN NOT QUANTIFY DISK SPACE REQUIREMENTS IN REAL TIME
    ACTUALS ALWAYS VARY FROM ESTIMATES.
    so ther is no particular formula to plan capacity planning.
    or post your rquirements for the DB and wait for some reply
    regards,
    Deepak

  • Could anybody pls provide the solution for test condition for ceating deliv

    Hi,
    I am working one function module but I want some functional input (SD).
    1. Create a domestic delivery. 
    2. Create ICB direct to customer delivery.
    3. Create ICB PO replenishment delivery 
    4. Create ICB Atlas to Non Atlas.
    5. Repeat the steps for gateout enabled and not enabled locations and perform billing. Check the billing log.
    6. Repeat the tests with delivery with and without gateout info.
    7. Create a POD adjustment document for over delivery scenario. Perform billing.
    8. Perform billing using VF01 and VF04
    So anbody can help me for functional input.
    Waiting for quick response.
    Best Regards,
    BDP

    Hi Reneta
    For your requirement , Bonus Buy concept should  be used. But the best way to meet your requirement is to go with a
    new subroutine and assign to the discount condition type in your pricing procedure.But if there are several combination's of materials which can vary the reduction of the price then in the subroutine only you have to write the subroutine with the help of ABAPer that if any vary comes then system should check the prices and vary the prices  also. So give your requirement to the ABAPer then he will fulfill your requirement.
    Regards
    Srinath

  • Can anybody give me the solutions for these

    In the definition of Item Catogory vov7, thers is a field " Relevent for Delivery", The same field is there in the definition of Scheduleline catagory vov6.
    1. Y the same field is there in both definitions?
    2. If I didnt check the field in item catagory definition, then item cannot be deliver?
    3.Y should we check in itemcatagory and scheduline catagory definition the field " relevent for delivery"
        If i check in Item catagory , if i didnt check in scheduline catagory any problem occurs at the time of delivery
    Plz reply me for these questions
    Thanks in Advance
    Venkat Ramana

    Dear Venkata Ramana
    - In VOV7, if you select the field "Relevant for Delivery", then you are defining that the item category is relevant for creating delivery and posting goods issue.
    - Similarly, in VOV6, by selecting the field Relevant for Delivery, you are defining that the schedule line is relevant for delivery
    As you would be aware, you can create invoice referencing order and delivery as well.  So in order to differentiate the item category and schedule line category from this, you have to maintain different item categories and schedule line categories.
    thanks
    G. Lakshmipathi

  • Can anybody give me the list of variables can pass in the requestPlatform

    hi all,
    I am very curious about knowing the list of variables that can be passed to requestPlatform().
    as i know we can pass tel,url and fax.Is there any variables that can be passed.
    I want to know the Operating System variables...
    My objective was to get the location name..
    thanks in advance

    hi ,
    thanks for your help,
    I want to get the location name (which will display on your mobile when you moving from one region to another region),is there is any way to capture that information...
    one more question is this possible to get the information in the mobile device with the help of the requestPlatform(),like we have initiatng the phone call something like that
    thanks in advance
    lakshman

  • Please help---give me the logic(very-2 urgent)

    Hi Experts,,
    i am struck in a very difficult situation.
    actually its a ageing report,the problem is that when i run this report for a single customer it shows the correct output.
    but when i run it for a range suppose for 0610000021 to 0610000024 it starts showing me the the wrong report although i have debugged it and found the problem that instead of picking data for a single customer at a time it picks for all customer in the loop.but i was not able to find out to exit it wen it it encounters a different customer and starts the outer loop again with different customer.please help as this has made my life hell..........plz help. i am attaching the code where the problem is please suggest.......
    loop at ctab into wa_ctab. (for customer)
    loop at itab_bb where shkzg <> 'C' and augdt > key_date and budat <= key_date and kunnr = wa_ctab-kunnr.
    if itab_bb-budat between cc AND d.
    amount214 = amount214 + itab_bb-wrbtr + itab_bb-bbb.
    endif.
    if itab_bb-budat between a AND b.
    amount216 = amount216 + itab_bb-wrbtr + itab_bb-bbb.
    endif.
    if itab_bb-budat between e AND f.
    amount210 = amount210 + itab_bb-wrbtr + itab_bb-bbb.
    endif.
    if itab_bb-budat between g AND h.
    amount218 = amount218 + itab_bb-wrbtr + itab_bb-bbb.
    endif.
    if itab_bb-budat  BETWEEN gg AND hh.
    amount212 = amount212 + itab_bb-wrbtr + itab_bb-bbb.
    endif.
    if itab_bb-budat <= j.
    amt212 = amt212 + itab_bb-wrbtr + itab_bb-bbb.
    endif.
    endloop.
    (wen i use exit here it only run onece and shows the right data for the first customer encounter)
    endloop.

    attaching u the whole code please tell wht changes should i make
    *& Report  ZAGING1
    REPORT  zage  NO STANDARD PAGE HEADING LINE-SIZE 250.
    TABLES : bseg, kna1 ,bsad, bsid, vbrk.
    SELECT-OPTIONS: s_kunnr FOR kna1-kunnr OBLIGATORY.
    PARAMETERS : key_date TYPE bldat OBLIGATORY.
    PARAMETERS : ccode    TYPE bukrs OBLIGATORY.
    SELECTION-SCREEN BEGIN OF LINE.
    SELECTION-SCREEN COMMENT 01(30) text-001 FOR FIELD int1.
    SELECTION-SCREEN POSITION POS_LOW.
    PARAMETERS: int1(3) TYPE n DEFAULT '030'.
    PARAMETERS: int2(3) TYPE n DEFAULT '060'.
    PARAMETERS: int3(3) TYPE n DEFAULT '090'.
    PARAMETERS: int4(3) TYPE n DEFAULT '120'.
    PARAMETERS: int5(3) TYPE n DEFAULT '150'.
    SELECTION-SCREEN END OF LINE.
    DATA : onacc LIKE bsid-wrbtr,
    ind TYPE i.
    TYPES: BEGIN OF cust,
            kunnr TYPE kna1-kunnr,
            adrnr TYPE kna1-adrnr,
            name1 TYPE kna1-name1,
            wrbtr TYPE bseg-wrbtr,
            bzirk TYPE knvv-bzirk,
            zterm TYPE knvv-zterm,
            ztag1 TYPE t052-ztag1,
           END OF cust.
    data : amount208 like bsad-wrbtr.
    TYPES: BEGIN OF invt,
            kunnr TYPE kna1-kunnr,
            kunrg TYPE kna1-kunnr,
            wrbtr TYPE bseg-wrbtr,
            invamt TYPE bseg-wrbtr,
            name1 TYPE kna1-name1,
            vbeln TYPE vbrk-vbeln,
            belnr TYPE bseg-belnr,
           END OF invt.
    TYPES : BEGIN OF ytab,
              kunnr TYPE bsid-kunnr,
              wrbtr TYPE bsid-wrbtr,
              sinv_amt TYPE bsid-wrbtr,
              paid_amt TYPE bsid-wrbtr,
              adj_amt   TYPE bsid-wrbtr,
              cncl_amt TYPE bsid-wrbtr,
              baln_amt TYPE bsid-wrbtr,
              onac_amt TYPE bsid-wrbtr,
              ac_amt   TYPE bsid-wrbtr,
              age_amt TYPE bsid-wrbtr,
              wrbtr_rvh TYPE bsid-wrbtr,
              wrbtr_rvs TYPE bsid-wrbtr,
              wrbtr_obh TYPE bsid-wrbtr,
              wrbtr_obs TYPE bsid-wrbtr,
              wrbtr_dg TYPE bsid-wrbtr,
              wrbtr_dr TYPE bsid-wrbtr,
              wrbtr_dzs TYPE bsid-wrbtr,
              wrbtr_dzh TYPE bsid-wrbtr,
              wrbtr_sas TYPE bsid-wrbtr,
              wrbtr_sah TYPE bsid-wrbtr,
              wrbtr_abs TYPE bsid-wrbtr,
              wrbtr_abh TYPE bsid-wrbtr,
              wrbtr_DAs TYPE bsid-wrbtr,
              wrbtr_DAh TYPE bsid-wrbtr,
              UMSKZ TYPE BSID-UMSKZ,
              baln1 TYPE bsid-wrbtr,
              baln2 TYPE bsid-wrbtr,
              baln3 TYPE bsid-wrbtr,
              baln4 TYPE bsid-wrbtr,
              baln5 TYPE bsid-wrbtr,
              baln6 TYPE bsid-wrbtr,
              blart TYPE bsid-blart,
              vbeln TYPE bsid-vbeln,
              fkdat TYPE vbrk-fkdat,
              belnr TYPE bsid-belnr,
              rebzg TYPE bsid-rebzg,
              shkzg TYPE bsid-shkzg,
              zuonr TYPE bsid-zuonr,
              od_days(4) TYPE n,
            END OF ytab.
    DATA :  aa(3) TYPE n,
            bb(3) TYPE n,
            dd(3) TYPE n,
            ee(3) TYPE n,
           ind TYPE i,
            it TYPE i.
    TYPES : BEGIN OF ftab,
              kunnr TYPE bsid-kunnr,
              name1 TYPE kna1-name1,
             WRBTR TYPE BSID-WRBTR,
              sinv_amt TYPE bsid-wrbtr,
              paid_amt TYPE bsid-wrbtr,
              adj_amt   TYPE bsid-wrbtr,
              cncl_amt TYPE bsid-wrbtr,
              baln_amt TYPE bsid-wrbtr,
              ac_amt   TYPE bsid-wrbtr,
              onac_amt TYPE bsid-wrbtr,
              outs_amt TYPE bsid-wrbtr,
              age_amt TYPE bsid-wrbtr,
              wrbtr_rvh TYPE bsid-wrbtr,
              wrbtr_rvs TYPE bsid-wrbtr,
              wrbtr_obh TYPE bsid-wrbtr,
              wrbtr_obs TYPE bsid-wrbtr,
              wrbtr_dg TYPE bsid-wrbtr,
              wrbtr_dr TYPE bsid-wrbtr,
              wrbtr_dzs TYPE bsid-wrbtr,
              wrbtr_dzh TYPE bsid-wrbtr,
              wrbtr_sas TYPE bsid-wrbtr,
              wrbtr_sah TYPE bsid-wrbtr,
              wrbtr_abs TYPE bsid-wrbtr,
              wrbtr_abh TYPE bsid-wrbtr,
              wrbtr_DAs TYPE bsid-wrbtr,
              wrbtr_DAh TYPE bsid-wrbtr,
              UMSKZ TYPE BSID-UMSKZ,
              baln1 TYPE bsid-wrbtr,
              baln2 TYPE bsid-wrbtr,
              baln3 TYPE bsid-wrbtr,
              baln4 TYPE bsid-wrbtr,
              baln5 TYPE bsid-wrbtr,
              baln6 TYPE bsid-wrbtr,
              blart TYPE bsid-blart,
              vbeln TYPE bsid-vbeln,
              belnr TYPE bsid-belnr,
              rebzg TYPE bsid-rebzg,
              shkzg TYPE bsid-shkzg,
              bzirk TYPE knvv-bzirk,
              zterm TYPE knvv-zterm,
              ztag1 TYPE t052-ztag1,
              zuonr TYPE bsid-zuonr,
              od_days(4) TYPE n,
              sno(3) TYPE n,
            END OF ftab.
    data : wrbtr_note like bsid-wrbtr.
            DATA : BEGIN OF itab1 OCCURS 0,
            hkont LIKE bsid-hkont,   " General Ledger Account
            kunnr LIKE bsid-kunnr,   " Customer Number 1
            dmbtr LIKE bsid-dmbtr,  " Amount
            shkzg LIKE bsid-shkzg,  " Debit/Credit Indication
            budat LIKE bsid-budat,  " Posting date
            kostl LIKE bsid-kostl,  " Cost center
            opnbl LIKE bsid-dmbtr,  " Opening Balance Amount
            clsbl LIKE bsid-dmbtr,  " Closing balnce Amount
            vbeln LIKE bsid-vbeln,
            blart LIKE bsid-blart,
            wrbtr LIKE bsid-wrbtr,
            bukrs LIKE bsid-bukrs,
            belnr LIKE bsid-belnr,
            xblnr LIKE bsid-xblnr,
            abc LIKE bsid-wrbtr,
            aaa LIKE bsid-wrbtr,
            sgtxt LIKE bsid-sgtxt,
            bcd LIKE bsid-wrbtr,
            bbb LIKE bsid-wrbtr,
            flag TYPE c,
            flag1(3) TYPE c,
            flag2(15) TYPE c,
            bldat like bsid-bldat,
            zuonr like bsid-zuonr,
            umskz like bsid-umskz,
            END OF itab1.
            DATA : BEGIN OF itab2 OCCURS 0,
            hkont LIKE bsid-hkont,   " General Ledger Account
            kunnr LIKE bsid-kunnr,   " Customer Number 1
           txt50 LIKE skat-txt50,  " GL A/C TEXT
            dmbtr LIKE bsid-dmbtr,  " Amount
            shkzg LIKE bsid-shkzg,  " Debit/Credit Indication
            budat LIKE bsid-budat,  " Posting date
            kostl LIKE bsid-kostl,  " Cost center
            opnbl LIKE bsid-dmbtr,  " Opening Balance Amount
            clsbl LIKE bsid-dmbtr,  " Closing balnce Amount
            vbeln LIKE bsid-vbeln,
            blart LIKE bsid-blart,
            wrbtr LIKE bsid-wrbtr,
            bukrs LIKE bsid-bukrs,
            belnr LIKE bsid-belnr,
            xblnr LIKE bsid-xblnr,
            sgtxt LIKE bsid-sgtxt,
            abc LIKE bsid-wrbtr,
            aaa LIKE bsid-wrbtr,
            bcd LIKE bsid-wrbtr,
            bbb LIKE bsid-wrbtr,
            flag TYPE c,
            flag1(3) TYPE c,
            flag2(15) TYPE c,
            bldat like bsid-bldat,
            GJAHR like bsid-GJAHR,
            zuonr like bsid-zuonr,
            umskz like bsid-umskz,
            END OF itab2.
    DATA : BEGIN OF itab3 OCCURS 0,
            hkont LIKE bsid-hkont,   " General Ledger Account
            kunnr LIKE bsid-kunnr,   " Customer Number 1
            dmbtr LIKE bsid-dmbtr,  " Amount
            shkzg LIKE bsid-shkzg,  " Debit/Credit Indication
            budat LIKE bsid-budat,  " Posting date
            kostl LIKE bsid-kostl,  " Cost center
            opnbl LIKE bsid-dmbtr,  " Opening Balance Amount
            clsbl LIKE bsid-dmbtr,  " Closing balnce Amount
            vbeln LIKE bsid-vbeln,
            blart LIKE bsid-blart,
            wrbtr LIKE bsid-wrbtr,
            bukrs LIKE bsid-bukrs,
            belnr LIKE bsid-belnr,
            xblnr LIKE bsid-xblnr,
            abc LIKE bsid-wrbtr,
            aaa LIKE bsid-wrbtr,
            bcd LIKE bsid-wrbtr,
            bbb LIKE bsid-wrbtr,
            flag TYPE c,
            flag1(3) TYPE c,
            flag2(15) TYPE c,
            sgtxt LIKE bsid-sgtxt,
            bldat like bsid-bldat,
                    zuonr like bsid-zuonr,
                    umskz like bsid-umskz,
            END OF itab3.
    DATA : BEGIN OF itab4 OCCURS 0,
            hkont LIKE bsid-hkont,   " General Ledger Account
            kunnr LIKE bsid-kunnr,   " Customer Number 1
           txt50 LIKE skat-txt50,  " GL A/C TEXT
            dmbtr LIKE bsid-dmbtr,  " Amount
            shkzg LIKE bsid-shkzg,  " Debit/Credit Indication
            budat LIKE bsid-budat,  " Posting date
            kostl LIKE bsid-kostl,  " Cost center
            opnbl LIKE bsid-dmbtr,  " Opening Balance Amount
            clsbl LIKE bsid-dmbtr,  " Closing balnce Amount
            vbeln LIKE bsid-vbeln,
            blart LIKE bsid-blart,
            wrbtr LIKE bsid-wrbtr,
            bukrs LIKE bsid-bukrs,
            belnr LIKE bsid-belnr,
            xblnr LIKE bsid-xblnr,
            aaa LIKE bsid-wrbtr,
            abc LIKE bsid-wrbtr,
            bbb LIKE bsid-wrbtr,
            bcd LIKE bsid-wrbtr,
            flag TYPE c,
            flag1(3) TYPE c,
            flag2(15) TYPE c,
            sgtxt LIKE bsid-sgtxt,
            bldat like bsid-bldat,
                    zuonr like bsid-zuonr,
                    umskz like bsid-umskz,
            END OF itab4.
    DATA : BEGIN OF itab5 OCCURS 0,
            hkont LIKE bsid-hkont,   " General Ledger Account
            kunnr LIKE bsid-kunnr,   " Customer Number 1
           txt50 LIKE skat-txt50,  " GL A/C TEXT
            dmbtr LIKE bsid-dmbtr,  " Amount
            shkzg LIKE bsid-shkzg,  " Debit/Credit Indication
            budat LIKE bsid-budat,  " Posting date
            kostl LIKE bsid-kostl,  " Cost center
            opnbl LIKE bsid-dmbtr,  " Opening Balance Amount
            clsbl LIKE bsid-dmbtr,  " Closing balnce Amount
            vbeln LIKE bsid-vbeln,
            blart LIKE bsid-blart,
            wrbtr LIKE bsid-wrbtr,
            bukrs LIKE bsid-bukrs,
            belnr LIKE bsid-belnr,
            xblnr LIKE bsid-xblnr,
            abc LIKE bsid-wrbtr,
            aaa LIKE bsid-wrbtr,
            bcd LIKE bsid-wrbtr,
            bbb LIKE bsid-wrbtr,
            flag TYPE c,
            flag1(3) TYPE c,
            flag2(15) TYPE c,
            sgtxt LIKE bsid-sgtxt,
            bldat like bsid-bldat,
                    zuonr like bsid-zuonr,
                    umskz like bsid-umskz,
            END OF itab5.
    data : amount207 like bsad-wrbtr,
            amount210 like bsad-wrbtr,
            amount212 like bsad-wrbtr,
            amount213 like bsad-wrbtr,
            amount214 like bsad-wrbtr,
            amount215 like bsad-wrbtr,
            amount216 like bsad-wrbtr,
            amount217 like bsad-wrbtr,
            amount218 like bsad-wrbtr,
            amt like bsad-wrbtr,
            amt1 like bsad-wrbtr,
            amt212 like bsad-wrbtr,
            amt213 like bsad-wrbtr,
            amount219 like bsad-wrbtr.
    DATA : BEGIN OF itab6 OCCURS 0,
            hkont LIKE bsid-hkont,   " General Ledger Account
            kunnr LIKE bsid-kunnr,   " Customer Number 1
           txt50 LIKE skat-txt50,  " GL A/C TEXT
            dmbtr LIKE bsid-dmbtr,  " Amount
            shkzg LIKE bsid-shkzg,  " Debit/Credit Indication
            budat LIKE bsid-budat,  " Posting date
            kostl LIKE bsid-kostl,  " Cost center
            opnbl LIKE bsid-dmbtr,  " Opening Balance Amount
            clsbl LIKE bsid-dmbtr,  " Closing balnce Amount
            vbeln LIKE bsid-vbeln,
            blart LIKE bsid-blart,
            wrbtr LIKE bsid-wrbtr,
            bukrs LIKE bsid-bukrs,
            belnr LIKE bsid-belnr,
            xblnr LIKE bsid-xblnr,
            sgtxt LIKE bsid-sgtxt,
            bldat like bsid-bldat,
            umskz like bsid-umskz,
            abc LIKE bsid-wrbtr,
            aaa LIKE bsid-wrbtr,
            bcd LIKE bsid-wrbtr,
            bbb LIKE bsid-wrbtr,
            flag TYPE c,
            flag1(3) TYPE c,
            flag2(15) TYPE c,
            xzahl like bsid-xzahl,
            rebzg like bsid-rebzg,
    zuonr like bsid-zuonr,
            END OF itab6.
    data : dr_deduct like bsid-wrbtr.
    DATA : a TYPE sy-datum,
           b TYPE sy-datum,
           cc TYPE sy-datum,
           d TYPE sy-datum,
           e TYPE sy-datum,
           f TYPE sy-datum,
           g TYPE sy-datum,
           h TYPE sy-datum,
           i TYPE sy-datum,
           gg TYPE sy-datum,
           hh TYPE sy-datum,
           j TYPE sy-datum.
    DATA : BEGIN OF itab7 OCCURS 0,
            hkont LIKE bsid-hkont,   " General Ledger Account
            kunnr LIKE bsid-kunnr,   " Customer Number 1
           txt50 LIKE skat-txt50,  " GL A/C TEXT
            dmbtr LIKE bsid-dmbtr,  " Amount
            shkzg LIKE bsid-shkzg,  " Debit/Credit Indication
            budat LIKE bsid-budat,  " Posting date
            kostl LIKE bsid-kostl,  " Cost center
            opnbl LIKE bsid-dmbtr,  " Opening Balance Amount
            clsbl LIKE bsid-dmbtr,  " Closing balnce Amount
            vbeln LIKE bsid-vbeln,
            blart LIKE bsid-blart,
            wrbtr LIKE bsid-wrbtr,
            bukrs LIKE bsid-bukrs,
            belnr LIKE bsid-belnr,
            xblnr LIKE bsid-xblnr,
            sgtxt LIKE bsid-sgtxt,
            bldat like bsid-bldat,
            umskz like bsid-umskz,
            END OF itab7.
    DATA : BEGIN OF itab8 OCCURS 0,
            hkont LIKE bsid-hkont,   " General Ledger Account
            kunnr LIKE bsid-kunnr,   " Customer Number 1
           txt50 LIKE skat-txt50,  " GL A/C TEXT
            dmbtr LIKE bsid-dmbtr,  " Amount
            shkzg LIKE bsid-shkzg,  " Debit/Credit Indication
            budat LIKE bsid-budat,  " Posting date
            kostl LIKE bsid-kostl,  " Cost center
            opnbl LIKE bsid-dmbtr,  " Opening Balance Amount
            clsbl LIKE bsid-dmbtr,  " Closing balnce Amount
            vbeln LIKE bsid-vbeln,
            blart LIKE bsid-blart,
            wrbtr LIKE bsid-wrbtr,
            bukrs LIKE bsid-bukrs,
            belnr LIKE bsid-belnr,
            xblnr LIKE bsid-xblnr,
            abc LIKE bsid-wrbtr,
            aaa LIKE bsid-wrbtr,
            bcd LIKE bsid-wrbtr,
            bbb LIKE bsid-wrbtr,
            flag TYPE c,
            flag1(3) TYPE c,
            flag2(15) TYPE c,
            sgtxt LIKE bsid-sgtxt,
            bldat like bsid-bldat,
            zuonr like bsid-zuonr,
            umskz like bsid-umskz,
            END OF itab8.
    DATA : BEGIN OF itab_b OCCURS 0,
           bukrs like bsad-bukrs,
           kunnr like bsad-kunnr,
           wrbtr like bsad-wrbtr,
           belnr like bsad-belnr,
           AUGDT like bsad-AUGDT,
           AUGBL like bsad-AUGBL,
           budat like bsad-budat,
           shkzg like bsad-shkzg,
           blart like bsad-blart,
           vbeln like bsad-vbeln,
           bldat like bsad-bldat,
           abc LIKE bsad-wrbtr,
           aaa LIKE bsad-wrbtr,
           bcd LIKE bsad-wrbtr,
           bbb LIKE bsad-wrbtr,
           flag TYPE c,
           flag1(3) TYPE c,
           flag2(15) TYPE c,
           END OF itab_b.
    DATA : BEGIN OF itab_bb OCCURS 0,
           bukrs like bsad-bukrs,
           kunnr like bsad-kunnr,
           wrbtr like bsad-wrbtr,
           belnr like bsad-belnr,
           AUGDT like bsad-AUGDT,
           AUGBL like bsad-AUGBL,
           budat like bsad-budat,
           shkzg like bsad-shkzg,
           blart like bsad-blart,
           vbeln like bsad-vbeln,
           bldat like bsad-bldat,
           abc LIKE bsad-wrbtr,
           aaa LIKE bsad-wrbtr,
           bcd LIKE bsad-wrbtr,
           bbb LIKE bsad-wrbtr,
           flag TYPE c,
           flag1(3) TYPE c,
           flag2(15) TYPE c,
           END OF itab_bb.
    DATA : BEGIN OF itab_rv OCCURS 0,
           bukrs like bsid-bukrs,
           kunnr like bsid-kunnr,
           wrbtr like bsid-wrbtr,
           belnr like bsid-belnr,
           budat like bsid-budat,
           shkzg like bsid-shkzg,
           blart like bsid-blart,
           vbeln like bsid-vbeln,
           bldat like bsid-bldat,
           abc LIKE bsid-wrbtr,
           aaa LIKE bsid-wrbtr,
           bcd LIKE bsid-wrbtr,
           bbb LIKE bsid-wrbtr,
           flag TYPE c,
           flag1(3) TYPE c,
           flag2(15) TYPE c,
           END OF itab_rv.
    DATA : BEGIN OF itab_da OCCURS 0,
           bukrs like bsid-bukrs,
           kunnr like bsid-kunnr,
           wrbtr like bsid-wrbtr,
           belnr like bsid-belnr,
           budat like bsid-budat,
           shkzg like bsid-shkzg,
           blart like bsid-blart,
           vbeln like bsid-vbeln,
           bldat like bsid-bldat,
           abc LIKE bsid-wrbtr,
           aaa LIKE bsid-wrbtr,
           bcd LIKE bsid-wrbtr,
           bbb LIKE bsid-wrbtr,
           flag TYPE c,
           flag1(3) TYPE c,
           flag2(15) TYPE c,
           END OF itab_da.
    DATA : wa_ctab TYPE cust.
    DATA : wa_btab TYPE invt.
    DATA : wa_bsid type bsid.
    DATA : wai_bsid TYPE ytab.
    DATA : wac_bsid TYPE ytab.        " CREDIT - INVOICE
    DATA : wad_bsid TYPE ytab.        " DEBIT  - PAYMENT
    DATA : wao_bsid TYPE ytab.        " ON ACCOUNT
    DATA : wa_itab  TYPE ftab.
    DATA : ctab TYPE cust OCCURS 0.
    DATA : btab TYPE invt OCCURS 0.
    DATA : it_bsid type bsid OCCURS 0.
    DATA : iti_bsid TYPE ytab OCCURS 0.        " CANCELLED INVOICES
    DATA : itc_bsid TYPE ytab OCCURS 0.        " CREDIT - INVOICE
    DATA : itd_bsid TYPE ytab OCCURS 0.        " DEBIT  - PAYMENT
    DATA : ito_bsid TYPE ytab OCCURS 0.        " ON ACCOUNT
    DATA : itab     TYPE ftab OCCURS 0 with header line.        " OUTPUT
    DATA : inv_amt LIKE bseg-wrbtr.
    DATA : paid_amt LIKE bseg-wrbtr.
    DATA : cncl_amt LIKE bseg-wrbtr.
    DATA : adj_amt LIKE bseg-wrbtr.
    DATA : billing_date LIKE sy-datum.
    DATA : overdue_date LIKE sy-datum.
    DATA : overdue_days LIKE rfposx-verzn.
    DATA : credit_days(4) TYPE n.
    DATA : int1s(3) TYPE n VALUE 0,
           int1e(3) TYPE n VALUE 0,
           int2s(3) TYPE n VALUE 0,
           int2e(3) TYPE n VALUE 0,
           int3s(3) TYPE n VALUE 0,
           int3e(3) TYPE n VALUE 0,
           int4s(3) TYPE n VALUE 0,
           int4e(3) TYPE n VALUE 0,
           int5s(3) TYPE n VALUE 0,
           int5e(3) TYPE n VALUE 0,
           int TYPE i,
           slno(5)  TYPE n VALUE 0.
    CLEAR : INV_AMT, CTAB, BTAB, WA_ITAB, WAC_BSID, WAD_BSID, WAO_BSID, itab_bb , amount210 , amount212 ,amount214 , amount216 , amount218.
    REFRESH : CTAB, BTAB,ITAB, ITC_BSID, ITD_BSID, ITO_BSID , itab_bb .
    START-OF-SELECTION.
    cc = key_date - int1.
    d = key_date.
    aa = int1 + 1.
    a = key_date - int2.
    b = cc - 1.
    bb = int2 + 1.
    e = key_date - int3.
    f = a - 1.
    dd = int3 + 1.
    g = key_date - int4.
    h = e - 1.
    dd = int4 + 1.
    gg = key_date - int5.
    hh = g - 1.
    ee = int5 + 1.
    j = key_date - ee.
    SELECT KUNNR NAME1 ADRNR FROM KNA1 INTO CORRESPONDING FIELDS OF WA_CTAB WHERE KUNNR IN S_KUNNR.
      SELECT SINGLE BZIRK ZTERM FROM KNVV INTO (WA_CTAB-BZIRK, WA_CTAB-ZTERM) WHERE KUNNR = WA_CTAB-KUNNR.
      SELECT SINGLE ZTAG1 FROM T052 INTO WA_CTAB-ZTAG1 WHERE ZTERM = WA_CTAB-ZTERM.
    APPEND WA_CTAB TO CTAB.
    ENDSELECT.
    hide wa_ctab.
    select bukrs kunnr wrbtr belnr AUGDT AUGBL budat shkzg blart vbeln bldat from bsad into
    corresponding fields of table itab_bb where kunnr in s_kunnr and augdt > key_date and budat <= key_date.
    *if sy-subrc = 0.
    *loop at itab_bb.
    *write : / 'yes' , itab_bb-wrbtr , itab_bb-kunnr.
    *endloop.
    *else.
    *write : / 'no'.
    *endif.
    loop at itab_bb.
         IF itab_bb-blart = 'RV'.
                itab_bb-flag2 = 'INVOICE'.
                MODIFY itab_bb.
          ELSEIF itab_bb-blart = 'DR'.
                itab_bb-flag2 = 'DR-NOTE'.
                MODIFY itab_bb.
          ELSEIF itab_bb-blart = 'OB'.
                itab_bb-flag2 = 'OPN-BAL'.
                MODIFY itab_bb.
          ELSEIF itab_bb-blart = 'DG'.
                itab_bb-flag2 = 'CR-NOTE'.
                MODIFY itab_bb.
          ELSEIF itab_bb-blart = 'DZ'.
                itab_bb-flag2 = 'RECEIPTS'.
                MODIFY itab_bb.
          ELSEIF itab_bb-blart = 'SA'.
                itab_bb-flag2 = 'JOURNAL'.
                MODIFY itab_bb.
          ELSEIF itab_bb-blart = 'DA'.
                itab_bb-flag2 = 'CREDIT'.
                MODIFY itab_bb.
          ELSEIF itab_bb-blart = 'AB'.
                itab_bb-flag2 = 'ADJUSTMENTS'.
                MODIFY itab_bb.
          ENDIF.
                IF itab_bb-shkzg = 'S'.
                itab_bb-shkzg = 'D'.
                MODIFY itab_bb.
                else.
                itab_bb-shkzg = 'C'.
                MODIFY itab_bb.
                ENDIF.
                endloop.
                loop at itab_bb.
                ind  = sy-tabix.
      IF itab_bb-vbeln IS NOT INITIAL.
    SELECT   wrbtr FROM bsad INTO itab_bb-abc WHERE vbeln = itab_bb-vbeln and augdt > key_date and budat <= key_date and kunnr = itab_bb-kunnr.
    itab_bb-aaa = itab_bb-aaa + itab_bb-abc.
    ENDSELECT.
      ENDIF.
          IF itab_bb-vbeln IS NOT INITIAL.
    SELECT   wrbtr FROM bsid INTO itab_bb-abc WHERE vbeln = itab_bb-vbeln  and budat <= key_date  and kunnr = itab_bb-kunnr and blart = 'DZ' .
    itab_bb-aaa = itab_bb-aaa + itab_bb-abc.
    ENDSELECT.
    endif.
      IF itab_bb-vbeln IS NOT INITIAL.
    SELECT SINGLE  wrbtr FROM bsad INTO itab_bb-bcd WHERE vbeln = itab_bb-vbeln and augdt > key_date and budat <= key_date and kunnr = itab_bb-kunnr.
    itab_bb-bbb = itab_bb-bcd - itab_bb-aaa.
    ENDIF.
       IF itab_bb-vbeln IS INITIAL.
    SELECT SINGLE  wrbtr FROM bsad INTO itab_bb-bcd WHERE belnr = itab_bb-belnr and augdt > key_date and budat <= key_date and kunnr = itab_bb-kunnr.
    itab_bb-bbb = itab_bb-bcd - itab_bb-aaa.
    ENDIF.
    MODIFY itab_bb INDEX ind.
    endloop.
    *loop at ctab into wa_ctab.
    sort itab_bb by kunnr.
    data xyz like kna1-kunnr.
    loop at itab_bb where shkzg <> 'C' and augdt > key_date and budat <= key_date.
    amt = amt + itab_bb-bbb.
    endloop.
    loop at itab_bb where shkzg = 'C'. " ON ACCOUNT
    amount207 = amount207 + itab_bb-wrbtr.
    endloop.
    loop at ctab into wa_ctab.
    loop at itab_bb where shkzg <> 'C' and augdt > key_date and budat <= key_date and kunnr = wa_ctab-kunnr.
    if itab_bb-budat between cc AND d.
    amount214 = amount214 + itab_bb-wrbtr + itab_bb-bbb.
    endif.
    if itab_bb-budat between a AND b.
    amount216 = amount216 + itab_bb-wrbtr + itab_bb-bbb.
    endif.
    if itab_bb-budat between e AND f.
    amount210 = amount210 + itab_bb-wrbtr + itab_bb-bbb.
    endif.
    if itab_bb-budat between g AND h.
    amount218 = amount218 + itab_bb-wrbtr + itab_bb-bbb.
    endif.
    if itab_bb-budat  BETWEEN gg AND hh.
    amount212 = amount212 + itab_bb-wrbtr + itab_bb-bbb.
    endif.
    if itab_bb-budat <= j.
    amt212 = amt212 + itab_bb-wrbtr + itab_bb-bbb.
    endif.
    endloop.
    endloop.
    SELECT * FROM BSID INTO TABLE IT_BSID FOR ALL ENTRIES IN CTAB WHERE KUNNR = CTAB-KUNNR
                                                                  AND   BuDAT =< KEY_DATE
                                                                 AND   BUKRS = CCODE.
    SORT IT_BSID BY KUNNR.
    LOOP AT IT_BSID INTO WA_BSID.
      IF  WA_BSID-BLART = 'RV' AND WA_BSID-SHKZG = 'S' OR
          WA_BSID-BLART = 'OB' AND WA_BSID-SHKZG = 'S' or
          wa_bsid-blart = 'DR'.
          WAC_BSID-KUNNR = WA_BSID-KUNNR.
          WAC_BSID-BLART = WA_BSID-BLART.
          WAC_BSID-VBELN = WA_BSID-VBELN.
          WAC_BSID-BELNR = WA_BSID-BELNR.
          WAC_BSID-REBZG = WA_BSID-REBZG.
          WAC_BSID-WRBTR = WA_BSID-WRBTR.
          WAC_BSID-ZUONR = WA_BSID-ZUONR.
          WAC_BSID-SHKZG = WA_BSID-SHKZG.
    *write : / WAC_BSID-WRBTR , wac_bsid-blart ,WAC_BSID-VBELN.
          IF WAC_BSID-VBELN IS NOT INITIAL.
             SELECT SINGLE FKDAT FROM VBRK INTO WAC_BSID-FKDAT WHERE VBELN = WAC_BSID-VBELN.
          ELSEIF WAC_BSID-VBELN IS INITIAL.
            IF WAC_BSID-BELNR IS NOT INITIAL.
             SELECT SINGLE BuDAT FROM BSID INTO WAC_BSID-FKDAT WHERE BELNR = WAC_BSID-BELNR.
            ENDIF.
          ENDIF.
       WAC_BSID = WA_BSID.
        APPEND WAC_BSID TO ITC_BSID.
    ELSEIF  WA_BSID-BLART = 'DZ' AND WA_BSID-VBELN <> ' '.
      ELSEIF  WA_BSID-BLART = 'DZ' .
       WAD_BSID = WA_BSID.
        WAD_BSID-KUNNR = WA_BSID-KUNNR.
        WAD_BSID-BLART = WA_BSID-BLART.
        WAD_BSID-VBELN = WA_BSID-VBELN.
        WAD_BSID-BELNR = WA_BSID-BELNR.
        WAD_BSID-REBZG = WA_BSID-REBZG.
        WAD_BSID-WRBTR = WA_BSID-WRBTR.
        WAD_BSID-ZUONR = WA_BSID-ZUONR.
        WAD_BSID-SHKZG = WA_BSID-SHKZG.
        APPEND WAD_BSID TO ITD_BSID.
      ELSEIF  WA_BSID-BLART = 'RV' AND WA_BSID-SHKZG = 'H' AND WA_BSID-ZUONR <> ' '.
        WAI_BSID-KUNNR = WA_BSID-KUNNR.
        WAI_BSID-BLART = WA_BSID-BLART.
        WAI_BSID-VBELN = WA_BSID-VBELN.
        WAI_BSID-BELNR = WA_BSID-BELNR.
        WAI_BSID-REBZG = WA_BSID-REBZG.
        WAI_BSID-WRBTR = WA_BSID-WRBTR.
        WAI_BSID-ZUONR = WA_BSID-ZUONR.
        WAI_BSID-SHKZG = WA_BSID-SHKZG.
       write : / 'rv-h ' , WAI_BSID-WRBTR.
        APPEND WAI_BSID TO ITI_BSID.
      ENDIF.
        MODIFY IT_BSID FROM WA_BSID.
    ENDLOOP.
    CLEAR : WAC_BSID.
    LOOP AT ITC_BSID INTO WAC_BSID.
      CLEAR : WAD_BSID, INV_AMT, PAID_AMT, CNCL_AMT, ADJ_AMT.
      IF WAC_BSID-BLART = 'RV' AND WAC_BSID-SHKZG = 'S'.
          WAC_BSID-SINV_AMT = WAC_BSID-WRBTR.
          INV_AMT = WAC_BSID-SINV_AMT.
    *WRITE : / WAC_BSID-SINV_AMT.
        READ TABLE ITD_BSID INTO WAD_BSID WITH KEY KUNNR = WAC_BSID-KUNNR VBELN = WAC_BSID-VBELN.
        LOOP AT ITD_BSID INTO WAD_BSID WHERE KUNNR = WAC_BSID-KUNNR AND VBELN = WAC_BSID-VBELN.
         IF SY-SUBRC = 0.
           WAC_BSID-PAID_AMT = WAD_BSID-WRBTR.
            PAID_AMT = PAID_AMT + WAD_BSID-WRBTR.
         ENDIF.
        WRITE : / PAID_AMT.
        ENDLOOP.
         IF PAID_AMT IS NOT INITIAL.
           WAC_BSID-BALN_AMT = WAC_BSID-SINV_AMT - WAC_BSID-PAID_AMT.
            WAC_BSID-PAID_AMT = PAID_AMT.
            WAC_BSID-BALN_AMT = WAC_BSID-SINV_AMT - PAID_AMT.
            WAC_BSID-AGE_AMT  = WAC_BSID-BALN_AMT.
         ELSE.
            WAC_BSID-PAID_AMT = 0.
            WAC_BSID-BALN_AMT = WAC_BSID-SINV_AMT.
           WRITE : / WAC_BSID-BALN_AMT.
            WAC_BSID-AGE_AMT  = WAC_BSID-BALN_AMT.
         ENDIF.
        LOOP AT ITI_BSID INTO WAI_BSID WHERE KUNNR = WAC_BSID-KUNNR AND ZUONR = WAC_BSID-VBELN.
        IF SY-SUBRC = 0.
           WAC_BSID-PAID_AMT = WAD_BSID-WRBTR.
            CNCL_AMT = CNCL_AMT + WAI_BSID-WRBTR.
           write :/ 'cancelled' , cncl_amt.
        ENDIF.
        ENDLOOP.
         IF CNCL_AMT IS NOT INITIAL.
           WAC_BSID-BALN_AMT = WAC_BSID-SINV_AMT - WAC_BSID-PAID_AMT.
            WAC_BSID-CNCL_AMT = CNCL_AMT.
            WAC_BSID-BALN_AMT = WAC_BSID-BALN_AMT." - CNCL_AMT.
            WAC_BSID-AGE_AMT  = WAC_BSID-BALN_AMT.
         ELSE.
            WAC_BSID-BALN_AMT = WAC_BSID-BALN_AMT.
            WAC_BSID-AGE_AMT  = WAC_BSID-BALN_AMT.
         ENDIF.
      ELSEIF WAC_BSID-BLART = 'DR'.
          IF WAC_BSID-ZUONR <> ' '.
             LOOP AT ITD_BSID INTO WAD_BSID WHERE KUNNR = WAC_BSID-KUNNR AND VBELN = ' ' AND ZUONR = WAC_BSID-ZUONR.
               IF SY-SUBRC = 0.
                  ADJ_AMT = ADJ_AMT + WAD_BSID-WRBTR.
               ENDIF.
             ENDLOOP.
             WAC_BSID-ADJ_AMT  = ADJ_AMT.
             WAC_BSID-BALN_AMT = WAC_BSID-WRBTR - ADJ_AMT.
             WAC_BSID-AGE_AMT  = WAC_BSID-BALN_AMT.
          ELSEIF WAC_BSID-ZUONR = ' '.
            WAC_BSID-BALN_AMT = WAC_BSID-WRBTR.
            WAC_BSID-AGE_AMT  = WAC_BSID-BALN_AMT.
          ENDIF.
      ELSEIF WAC_BSID-BLART = 'OB' AND WAC_BSID-SHKZG = 'S'.
          IF WAC_BSID-ZUONR <> ' '.
             LOOP AT ITD_BSID INTO WAD_BSID WHERE KUNNR = WAC_BSID-KUNNR AND VBELN = ' ' AND ZUONR = WAC_BSID-ZUONR.
               IF SY-SUBRC = 0.
                  ADJ_AMT = ADJ_AMT + WAD_BSID-WRBTR.
               ENDIF.
             ENDLOOP.
             WAC_BSID-ADJ_AMT  = ADJ_AMT.
             WAC_BSID-BALN_AMT = WAC_BSID-WRBTR - ADJ_AMT.
             WAC_BSID-AGE_AMT  = WAC_BSID-BALN_AMT.
          ELSEIF WAC_BSID-ZUONR = ' '.
            WAC_BSID-BALN_AMT = WAC_BSID-WRBTR.
            WAC_BSID-AGE_AMT  = WAC_BSID-BALN_AMT.
          ENDIF.
      ENDIF.
        PERFORM AGING_CALCULATION.
        WA_ITAB-KUNNR = WAC_BSID-KUNNR.
        WA_ITAB-SINV_AMT = WAC_BSID-SINV_AMT.
        WA_ITAB-PAID_AMT = WAC_BSID-PAID_AMT.
        WA_ITAB-CNCL_AMT = WAC_BSID-CNCL_AMT.
        WA_ITAB-BALN_AMT = WAC_BSID-BALN_AMT.
       WA_ITAB-OD_DAYS  = WAC_BSID-OD_DAYS.
        WA_ITAB-BALN1 = WAC_BSID-BALN1.
        WA_ITAB-BALN2 = WAC_BSID-BALN2.
        WA_ITAB-BALN3 = WAC_BSID-BALN3.
        WA_ITAB-BALN4 = WAC_BSID-BALN4.
        WA_ITAB-BALN5 = WAC_BSID-BALN5.
        WA_ITAB-BALN6 = WAC_BSID-BALN6.
        COLLECT WA_ITAB INTO ITAB.
      MODIFY ITC_BSID FROM WAC_BSID.
    COLLECT WAC_BSID.
    ENDLOOP.
    CLEAR : WA_ITAB, WA_CTAB.
    LOOP AT CTAB INTO WA_CTAB.
    CLEAR : WAO_BSID.
    LOOP AT IT_BSID INTO WA_BSID WHERE KUNNR = WA_CTAB-KUNNR.
      IF WA_BSID-BLART = 'RV' OR
         WA_BSID-BLART = 'OB' OR
         WA_BSID-BLART = 'DG' OR
         WA_BSID-BLART = 'DR' OR
         WA_BSID-BLART = 'DZ' OR
         WA_BSID-BLART = 'DA' OR
         WA_BSID-BLART = 'SA' OR
         WA_BSID-BLART = 'AB'.
         WAO_BSID-KUNNR = WA_BSID-KUNNR.
         WAO_BSID-BLART = WA_BSID-BLART.
         WAO_BSID-VBELN = WA_BSID-VBELN.
         WAO_BSID-BELNR = WA_BSID-BELNR.
         WAO_BSID-REBZG = WA_BSID-REBZG.
         WAO_BSID-WRBTR = WA_BSID-WRBTR.
         WAO_BSID-SHKZG = WA_BSID-SHKZG.
         WAO_BSID-ZUONR = WA_BSID-ZUONR.
         WAO_BSID-SHKZG = WA_BSID-SHKZG.
         WAO_BSID-UMSKZ = WA_BSID-UMSKZ.
         APPEND WAO_BSID TO ITO_BSID.
       ENDIF.
    ENDLOOP.
    CLEAR : WAO_BSID.
    LOOP AT ITO_BSID INTO WAO_BSID WHERE KUNNR = WA_CTAB-KUNNR.
      IF WAO_BSID-BLART = 'OB' AND WAO_BSID-SHKZG = 'H'.
        WAO_BSID-ONAC_AMT = WAO_BSID-ONAC_AMT - WAO_BSID-WRBTR.
          WAO_BSID-WRBTR_OBH = WAO_BSID-WRBTR.
      ELSEIF WAO_BSID-BLART = 'OB' AND WAO_BSID-SHKZG = 'S'.
        WAO_BSID-ONAC_AMT = WAO_BSID-ONAC_AMT - WAO_BSID-WRBTR.
          WAO_BSID-WRBTR_OBS = WAO_BSID-WRBTR.
      ELSEIF WAO_BSID-BLART = 'DG'.
        WAO_BSID-ONAC_AMT = WAO_BSID-ONAC_AMT - WAO_BSID-WRBTR.
          WAO_BSID-WRBTR_DG = WAO_BSID-WRBTR.
      ELSEIF WAO_BSID-BLART = 'DZ' AND WAO_BSID-SHKZG = 'H'.
        WAO_BSID-ONAC_AMT = WAO_BSID-ONAC_AMT - WAO_BSID-WRBTR.
         WAO_BSID-WRBTR_DZH = WAO_BSID-WRBTR.
      ELSEIF WAO_BSID-BLART = 'DZ' AND WAO_BSID-SHKZG = 'S'.
        WAO_BSID-ONAC_AMT = WAO_BSID-ONAC_AMT - WAO_BSID-WRBTR.
         WAO_BSID-WRBTR_DZS = WAO_BSID-WRBTR.
         ELSEIF WAO_BSID-BLART = 'DR'.
        WAO_BSID-ONAC_AMT = WAO_BSID-ONAC_AMT + WAO_BSID-WRBTR.
         WAO_BSID-WRBTR_DR = WAO_BSID-WRBTR.
      ELSEIF WAO_BSID-BLART = 'SA' AND WAO_BSID-SHKZG = 'S'.
        WAO_BSID-ONAC_AMT = WAO_BSID-ONAC_AMT + WAO_BSID-WRBTR.
          WAO_BSID-WRBTR_SAS = WAO_BSID-WRBTR.
      ELSEIF WAO_BSID-BLART = 'SA' AND WAO_BSID-SHKZG = 'H'.
        WAO_BSID-ONAC_AMT = WAO_BSID-ONAC_AMT - WAO_BSID-WRBTR.
         WAO_BSID-WRBTR_SAH = WAO_BSID-WRBTR.
      ELSEIF WAO_BSID-BLART = 'AB' AND WAO_BSID-SHKZG = 'S'.
        WAO_BSID-ONAC_AMT = WAO_BSID-ONAC_AMT + WAO_BSID-WRBTR.
          WAO_BSID-WRBTR_ABS = WAO_BSID-WRBTR.
      ELSEIF WAO_BSID-BLART = 'AB' AND WAO_BSID-SHKZG = 'H'.
        WAO_BSID-ONAC_AMT = WAO_BSID-ONAC_AMT - WAO_BSID-WRBTR.
         WAO_BSID-WRBTR_ABH = WAO_BSID-WRBTR.
    ELSEIF WAO_BSID-BLART = 'RV' AND WAO_BSID-SHKZG = 'H' AND WAO_BSID-ZUONR = ' '.
      ELSEIF WAO_BSID-BLART = 'RV' AND WAO_BSID-SHKZG = 'H'.
         WAO_BSID-WRBTR_RVH = WAO_BSID-WRBTR.
        WRITE : / WAO_BSID-WRBTR_RVH .
      ELSEIF WAO_BSID-BLART = 'RV' AND WAO_BSID-SHKZG = 'S'.
         WAO_BSID-WRBTR_RVS = WAO_BSID-WRBTR.
      ELSEIF WAO_BSID-BLART = 'DA' AND WAO_BSID-SHKZG = 'H' AND WAO_BSID-UMSKZ <> 'G'.
         WAO_BSID-WRBTR_DAH = WAO_BSID-WRBTR.
      ENDIF.
        WA_ITAB-KUNNR    = WAO_BSID-KUNNR.
        WA_ITAB-WRBTR_DG = WAO_BSID-WRBTR_DG.
        WA_ITAB-WRBTR_DR = WAO_BSID-WRBTR_DR.
        WA_ITAB-WRBTR_DZS = WAO_BSID-WRBTR_DZS.
        WA_ITAB-WRBTR_DZH = WAO_BSID-WRBTR_DZH.
        WA_ITAB-WRBTR_OBH = WAO_BSID-WRBTR_OBH.
        WA_ITAB-WRBTR_OBS = WAO_BSID-WRBTR_OBS.
        WA_ITAB-WRBTR_SAH = WAO_BSID-WRBTR_SAH.
        WA_ITAB-WRBTR_SAS = WAO_BSID-WRBTR_SAS.
        WA_ITAB-WRBTR_RVH = WAO_BSID-WRBTR_RVH.
        WA_ITAB-WRBTR_RVS = WAO_BSID-WRBTR_RVS.
        WA_ITAB-WRBTR_ABH = WAO_BSID-WRBTR_ABH.
        WA_ITAB-WRBTR_ABS = WAO_BSID-WRBTR_ABS.
        WA_ITAB-WRBTR_DAH = WAO_BSID-WRBTR_DAH.
        WA_ITAB-WRBTR_DAS = WAO_BSID-WRBTR_DAS.
       WA_ITAB-AC_AMT    = WAO_BSID-AC_AMT.
        COLLECT WA_ITAB INTO ITAB.
      MODIFY ITO_BSID FROM WAO_BSID.
    ENDLOOP.
    ENDLOOP.
    CLEAR : SLNO.
    clear : wa_itab.
    SORT ITAB BY KUNNR.
    LOOP AT ITAB INTO WA_ITAB.
    SLNO = SLNO + 1.
    WA_ITAB-SNO = SLNO.
    READ TABLE CTAB INTO WA_CTAB WITH KEY KUNNR = WA_ITAB-KUNNR.
         WA_ITAB-NAME1 = WA_CTAB-NAME1.
         WA_ITAB-BZIRK = WA_CTAB-BZIRK.
         WA_ITAB-ZTAG1 = WA_CTAB-ZTAG1.
        WA_ITAB-AC_AMT =     WA_ITAB-WRBTR_SAS
                           - WA_ITAB-WRBTR_SAH
                           - WA_ITAB-WRBTR_OBH
                           + WA_ITAB-WRBTR_OBS
                           + WA_ITAB-WRBTR_RVS
                           - WA_ITAB-WRBTR_RVH
                           - WA_ITAB-WRBTR_ABH
                           + WA_ITAB-WRBTR_ABS
                           - WA_ITAB-WRBTR_DAH
                           - WA_ITAB-WRBTR_DG
                           + WA_ITAB-WRBTR_DR
                           - WA_ITAB-WRBTR_DZH
                           + WA_ITAB-WRBTR_DZS.
    data : amount211 like bsad-wrbtr,
    amount_t like bsad-wrbtr.
                           data : aaaa type p decimals 2,
                           bbbb type p decimals 2,
                           cccc type p decimals 2,
                           wrbtr_shkzg like bsid-shkzg.
    SELECT      shkzg wrbtr
                FROM bsid
                INTO (wrbtr_shkzg , wrbtr_note )
                WHERE kunnr = wa_itab-kunnr
                AND UMSKZ = 'G'.
                if wrbtr_shkzg = 'S'.
      aaaa = wrbtr_note + aaaa.
      elseif wrbtr_shkzg = 'H'.
      bbbb = wrbtr_note + bbbb.
      endif.
    endselect.
    cccc = BBBB - AAAA.
    amount211 = wa_itab-baln3 + amount210.
    amount213 = wa_itab-baln5 + amount212.
    amount215 = wa_itab-baln1 + amount214.
    amount217 = wa_itab-baln2 + amount216.
    amount219 = wa_itab-baln4 + amount218.
    amt213    = amt212 + wa_itab-baln6.
    amount_t = amount215 + amount217 + amount211 + amount219 + amount213 + amt213.
    wa_itab-outs_amt = wa_itab-ac_amt.
    wa_itab-onac_amt = wa_itab-baln_amt - wa_itab-outs_amt + amount207 + amt.
    onacc = wa_itab-onac_amt.
    wa_itab-vbeln = wac_bsid-vbeln.
    wa_itab-outs_amt = wa_itab-ac_amt + amount210 + amount212 - amount207.
    amount_t = amount_t -  wa_itab-onac_amt.
    WRITE : /    wa_itab-sno,
             5   wa_itab-kunnr  LEFT-JUSTIFIED HOTSPOT ON,
             16  wa_itab-name1,
             50  wa_itab-bzirk,
             63  wa_itab-ztag1 RIGHT-JUSTIFIED,
             69  CCCC,
             85  amount_t,
             105 amount215,
             125 amount217,
             145 amount211,
             165 amount219,
             185 amount213,
             205 AMT213,
             225 wa_itab-onac_amt.
    MODIFY itab FROM wa_itab.
    clear  : aaaa, bbbb, cccc ,amount215, amount217, amount211, amount219 ,AMT212, AMT213,  amount213 ,AMOUNT210 , AMOUNT212 , AMOUNT214 ,AMOUNT216 ,AMOUNT218 , AMOUNT207 , amount_t, cc , d , aa ,
    a , b , bb , e , f , dd , g , h , dd, gg , hh , wa_itab-baln1 , wa_itab-baln2 , wa_itab-baln3 , wa_itab-baln4 , wa_itab-baln5 , wa_itab-baln6 ,wa_itab-onac_amt, amt.
    HIDE : wa_itab-kunnr , wa_itab-name1.
    ENDLOOP.
    WRITE : / sy-uline.
    TOP-OF-PAGE.
    WRITE : 'SAKATA INX INDIA LTD.',
            / 'Age wise analysis as on', key_date,
            / sy-uline.
    WRITE :  / 'SNo',
              5  'C-Code',
             16  'Customer Name',
             50  'Region',
             58  ' CR-DAYS',
             72  'SEC.AMOUNT',
             86  'Net O/S Amount',
             107  '0 to', int1, 'Days',
             125  int2s, 'to', int2e, 'Days',
             145 int3s, 'to', int3e, 'Days',
             165 int4s, 'to', int4e, 'Days',
             185 int5s, 'to', int5e, 'Days',
             210 '>',int5e, 'Days',
             230 'On Account',
             / sy-uline.
            'Invoice Amount',
            80  'Paid Amount',
            100 'Balance Amount',.
    FORM aging_calculation.
    CLEAR : billing_date, credit_days, wa_ctab.
    DATA : shiftdays TYPE tb_days_to_pos.
    CLEAR : shiftdays, overdue_days.
    READ TABLE ctab INTO wa_ctab WITH KEY kunnr = wac_bsid-kunnr.
      billing_date = wac_bsid-fkdat.
      credit_days  = wa_ctab-ztag1.
         overdue_date = billing_date.
      CALL FUNCTION 'FAGL_ITEM_OVERDUE_DAYS'
        EXPORTING
         key_date                =  key_date
        PAY_DATE                =
          due_date                = overdue_date
        CLEAR_DATE              =
       IMPORTING
        OVER_SKONTO1_DAYS       =
         overdue_days            =  overdue_days
        wac_bsid-od_days = overdue_days.
           IF int1 IS INITIAL.
            int1s = 0.
            int1e = 0.
           ELSEIF int1 IS NOT INITIAL.
            int1s = 0.
            int1e = int1.
           ENDIF.
           IF int2 IS INITIAL.
            int2s = 0.
            int2e = 0.
           ELSE.
            int2s = int1 + 1.
            int2e = int2.
           ENDIF.
           IF int3 IS INITIAL.
            int3s = 0.
            int3e = 0.
           ELSE.
            int3s = int2 + 1.
            int3e = int3.
           ENDIF.
           IF int4 IS INITIAL.
            int4s = 0.
            int4e = 0.
           ELSE.
            int4s = int3 + 1.
            int4e = int4.
           ENDIF.
           IF int5 IS INITIAL.
            int5s = 0.
            int5e = 0.
           ELSE.
            int5s = int4 + 1.
            int5e = int5.
           ENDIF.
          write : / WAO_BSID-WRBTR_DR.
          IF  wac_bsid-od_days BETWEEN int1s AND int1e.
            wac_bsid-baln1 =  wac_bsid-age_amt.
          ELSEIF  wac_bsid-od_days BETWEEN int2s AND int2e.
            wac_bsid-baln2 =  wac_bsid-age_amt .
          ELSEIF  wac_bsid-od_days BETWEEN int3s AND int3e.
            wac_bsid-baln3 =   wac_bsid-age_amt.
          ELSEIF  wac_bsid-od_days BETWEEN int4s AND int4e.
            wac_bsid-baln4 =  wac_bsid-age_amt .
          ELSEIF  wac_bsid-od_days BETWEEN int5s AND int5e.
            wac_bsid-baln5 =  wac_bsid-age_amt .
          ELSEIF  wac_bsid-od_days > int5e.
            wac_bsid-baln6 =  wac_bsid-age_amt .
          ENDIF.
    ENDFORM.
    AT LINE-SELECTION.
    CASE sy-lsind.
    WHEN ' 1'.
    WRITE : / sy-uline.
    WRITE : 'SAKATA INX INDIA LTD.',
            / 'Age wise analysis as on', key_date,
            / 'Customer-Code : ' , wa_itab-kunnr, 'Customer-Name : ' , wa_itab-name1,
            / sy-uline.
    DATA : amount1 LIKE bsid-dmbtr,
           amount2 LIKE bsid-dmbtr,
           amount3 LIKE bsid-dmbtr,
           amount4 LIKE bsid-dmbtr,
           amount5 LIKE bsid-dmbtr,
           amount6 LIKE bsid-dmbtr,
           amount7 LIKE bsid-dmbtr,
           amount8 LIKE bsid-dmbtr,
           amount9 LIKE bsid-dmbtr,
           amount10 LIKE bsid-dmbtr,
           amount11 LIKE bsid-dmbtr,
           amount12 LIKE bsid-dmbtr,
           amount13 LIKE bsid-dmbtr,
           amount14 LIKE bsid-dmbtr,
           amount15 LIKE bsid-dmbtr,
           amount17 LIKE bsid-dmbtr,
           amount16 LIKE bsid-dmbtr,
           amount19 LIKE bsid-dmbtr,
           amount22 LIKE bsid-dmbtr,
           amount23 LIKE bsid-dmbtr,
           amount200 LIKE bsid-dmbtr,
           amount201 LIKE bsid-dmbtr,
           amount202 LIKE bsid-dmbtr,
           amount203 LIKE bsid-dmbtr,
           amount204 LIKE bsid-dmbtr,
           amount205 LIKE bsid-dmbtr,
           amount206 LIKE bsid-dmbtr,
           amount233 LIKE bsid-dmbtr,
           amount234 LIKE bsid-dmbtr,
           amount235 LIKE bsid-dmbtr,
           amount550 LIKE bsid-dmbtr,
           amt202 LIKE bsid-dmbtr,
           amt205 LIKE bsid-dmbtr,
           amt13 LIKE bsid-dmbtr,
           amt111 LIKE bsid-dmbtr,
           amount236 LIKE bsid-dmbtr.
             select bukrs kunnr wrbtr belnr AUGDT AUGBL budat shkzg blart vbeln bldat from bsad into corresponding fields of table itab_b where bukrs = 'SAIL' and kunnr = wa_itab-kunnr and augdt > key_date and budat <= key_date.
    loop at itab_b.
         IF itab_b-blart = 'RV'.
                itab_b-flag2 = 'INVOICE'.
                MODIFY itab_b.
          ELSEIF itab_b-blart = 'DR'.
                itab_b-flag2 = 'DR-NOTE'.
                MODIFY itab2.
          ELSEIF itab_b-blart = 'OB'.
                itab_b-flag2 = 'OPN-BAL'.
                MODIFY itab_b.
          ELSEIF itab_b-blart = 'DG'.
                itab_b-flag2 = 'CR-NOTE'.
                MODIFY itab_b.
          ELSEIF itab_b-blart = 'DZ'.
                itab_b-flag2 = 'RECEIPTS'.
                MODIFY itab_b.
          ELSEIF itab_b-blart = 'SA'.
                itab_b-flag2 = 'JOURNAL'.
                MODIFY itab_b.
          ELSEIF itab_b-blart = 'DA'.
                itab_b-flag2 = 'CREDIT'.
                MODIFY itab_b.
          ELSEIF itab_b-blart = 'AB'.
                itab_b-flag2 = 'ADJUSTMENTS'.
                MODIFY itab_b.
          ENDIF.
                IF itab_b-shkzg = 'S'.
                itab_b-shkzg = 'D'.
                MODIFY itab_b.
                else.
                itab_b-shkzg = 'C'.
                MODIFY itab_b.
                ENDIF.
                endloop.
                loop at itab_b.
                ind  = sy-tabix.
          IF itab_b-vbeln IS NOT INITIAL.
    SELECT   wrbtr FROM bsad INTO itab_b-abc WHERE vbeln = itab_b-vbeln and augdt > key_date and budat <= key_date and blart = 'DZ' and kunnr = itab_b-kunnr.
    itab_b-aaa = itab_b-aaa + itab_b-abc.
    ENDSELECT.
      ENDIF.
          IF itab_b-vbeln IS NOT INITIAL.
    SELECT   wrbtr FROM bsid INTO itab_b-abc WHERE vbeln = itab_b-vbeln and budat <= key_date  and kunnr = itab_b-kunnr.
    itab_b-aaa = itab_b-aaa + itab_b-abc.
    ENDSELECT.
    endif.
      IF itab_b-vbeln IS NOT INITIAL.
    SELECT SINGLE  wrbtr FROM bsad INTO itab_b-bcd WHERE vbeln = itab_b-vbeln and augdt > key_date and budat <= key_date and kunnr = itab_b-kunnr.
    itab_b-bbb = itab_b-bcd - itab_b-aaa.
    ENDIF.
       IF itab_b-vbeln IS INITIAL.
    SELECT SINGLE  wrbtr FROM bsad INTO itab_b-bcd WHERE belnr = itab_b-belnr and augdt > key_date and budat <= key_date and kunnr = itab_b-kunnr.
    itab_b-bbb = itab_b-bcd - itab_b-aaa.
    ENDIF.
    MODIFY itab_b INDEX ind.
    *write : / itab_b-vbeln , itab_b-bbb.
    endloop.
    cc = key_date - int1.
    d = key_date.
    SELECT      hkont      " General Ledger Account
                kunnr      " Customer Number 1
               

Maybe you are looking for