How to fetch the customer debit balances form the KNC1 database table

Hi Experts,
I am creating a ABAP report which would dispaly the customer credit balances for the currenct fiscal year.
I am fetching the values form KNC1 database table.....But in this table values are stored year wise.
But I want to display for the current fiscal year that means if teh user selects the 07/2011 as the month on the sleection screen then the debit balances from 072010 to 062011 should be dispalyed.
Could anyone please help me out to fetch this the debit balaces form KNC1 database table in the above format.
Or is there any other way to solve this problem?
Awating your urgent reply.
Many Thanks,
Komal.

Hi Komal,
First, you have to compute the initial period and the final period.
Next, you must read table KNC1 for the years comprised between these two periods.
Last, you must read the fields of table KNC1. For that, you should compose dynamically the name of the field, and then ASSIGN it to a FIELD-SYMBOL.
Now, just add up the values!
Please try the following code:
FIELD-SYMBOLS: <fs>.
DATA: t_knc1 TYPE TABLE OF knc1 WITH HEADER LINE.
DATA: d_debits LIKE knc1-um01s.
PARAMETERS: p_kunnr LIKE knc1-kunnr,
            p_bukrs LIKE knc1-bukrs,
            p_spmon TYPE spmon.
DATA: l_fieldname(20) TYPE c.
DATA: l_date LIKE sy-datum,
      l_date_from LIKE sy-datum,
      l_date_to LIKE sy-datum.
DATA: l_period(2) TYPE n.
DATA: l_num_times TYPE i.
START-OF-SELECTION.
"Compute the initial and final periods
  CONCATENATE p_spmon '01' INTO l_date.
  CALL FUNCTION 'RE_ADD_MONTH_TO_DATE'
    EXPORTING
      months  = '-1'
      olddate = l_date
    IMPORTING
      newdate = l_date_to.
  CALL FUNCTION 'RE_ADD_MONTH_TO_DATE'
    EXPORTING
      months  = '-12'
      olddate = l_date
    IMPORTING
      newdate = l_date_from.
"Read table KNC1
  SELECT *
    INTO CORRESPONDING FIELDS OF TABLE t_knc1
    FROM knc1
    WHERE kunnr = p_kunnr
      AND bukrs = p_bukrs
      AND gjahr BETWEEN l_date_from(4) AND l_date_to(4).
"this will yield at most 2 records, one for present year, and another one for the previous year.
"but if you select i.e. period '01.2012', initial_date = '01.01.2011' and final_date = '31.12.2011'
" --> thus only one year --> one record
  CLEAR: d_debits.
  LOOP AT t_knc1.
" If there's no year change
    IF l_date_from(4) = l_date_to(4).
      DO 16 TIMES.
        l_period = sy-index.
        CONCATENATE 'UM'      "compute dynamically the field name
                    l_period
                    'S'
          INTO l_fieldname.
        ASSIGN COMPONENT l_fieldname OF STRUCTURE t_knc1 TO <fs>.   "assign
        ADD <fs> TO d_debits.                  "and add up
      ENDDO.
    ELSE.
" If there IS a year change
      IF t_knc1-gjahr = l_date_from+0(4).
        l_num_times = 16 - l_date_from+4(2) + 1.    "you must loop 16 - initial_period + 1 times for the first year
        DO l_num_times TIMES.
          l_period = sy-index + l_date_from+4(2) - 1.
          CONCATENATE 'UM'                "compute dynamically the field name
                      l_period
                      'S'
            INTO l_fieldname.
          ASSIGN COMPONENT l_fieldname OF STRUCTURE t_knc1 TO <fs>.    "assign
          ADD <fs> TO d_debits.              "and add up
        ENDDO.
      ELSE.
        l_num_times = l_date_to+4(2).            "you must loop final_period times for the second year
        DO l_num_times TIMES.
          l_period = sy-index.
          CONCATENATE 'UM'               "compute dynamically the field name
                      l_period
                      'S'
            INTO l_fieldname.
          ASSIGN COMPONENT l_fieldname OF STRUCTURE t_knc1 TO <fs>.     "assign
          ADD <fs> TO d_debits.        "and add up
        ENDDO.
      ENDIF.
    ENDIF.
  ENDLOOP.
You'll have the result on variable 'd_debits'.
I hope this helps. Kind regards,
Alvaro

Similar Messages

  • [HTML DB] How to use the existing database table?

    [HTML DB] How to use the existing database table?
    I installed Oracle 10g database in Computer A(Windows 2000), and I already create all the tables with data and the data size is about 300MB.
    In Computer B(Windows 2000), I installed HTML DB 1.6.
    How can I use /get the existing database table (in computer A) for HTML DB?
    Could anyone help me on this? I am newbie and I need some detail instructions. or Where can I find the examples.....
    Thanks

    Well I guess if you wish to retain that architecture, i.e. HTMLDB on one machine and your data on another, you will have to establish database links to access the data. Oracle documentation will describe how to achieve that.

  • Please help..it's Urgent..How to fetch the value from table row from Page

    Hi,
    I have created a table with 2 LOV's , LOV2 is dependent on LOV2.
    Here I can not use the general Dependent LOV concept, as these values are coming from 2 different LookUps.
    I am not able to fetch the user input for LOV1 (from page) .that is why not able to set the where cluse fro 2nd LOVVO.
    I have used this code:
    if ("ViolationCat".equals(lovInputSourceId)) {
    OAMessageLovInputBean msglov =
    (OAMessageLovInputBean)webBean.findChildRecursive("ViolationCat");
    // String p_violation_category = "'"+(String)msglov.getValue(pageContext)+"'";
    String p_violation_category =
    (String)msglov.getValue(pageContext);
    // System.out.println(" p_violation_category =" +
    // p_violation_category);
    String v_violation_category = "";
    //System.out.println("vcat=" + vCat);
    OAViewObject violationVO =
    (OAViewObject)am.findViewObject("SNI_Violation_DtlsVO2");
    Number vcatViolationIdnum =
    (Number)violationVO.getCurrentRow().getAttribute("ViolationId");
    String vcatViolationId = "" + vcatViolationIdnum;
    pageContext.putTransactionValue("vcatViolationId",
    vcatViolationId);
    pageContext.putTransactionValue("p_violation_category",
    p_violation_category);
    String query =
    " SELECT LOOKUP_CODE, \n" + " MEANING, \n" +
    " LOOKUP_TYPE \n" +
    " FROM apps.fnd_lookup_values \n" +
    " WHERE LOOKUP_TYPE ='SNI_VIOLATION_CATEGORY' AND MEANING=?";
    PreparedStatement ps = txn.createPreparedStatement(query, 1);
    try {
    ps.setString(1, p_violation_category);
    ResultSet rs = ps.executeQuery();
    //System.out.println("before while,");
    // rs.next();
    // v_violation_category = rs.getString("LOOKUP_CODE");
    // System.out.println("v_violation_category="+v_violation_category);
    while (rs.next()) {
    //System.out.println("inside while");
    v_violation_category = rs.getString("LOOKUP_CODE");
    // System.out.println("v_violation_category=" +
    // v_violation_category);
    ps.close();
    } //try ends
    catch (Exception e) {
    e.getMessage();
    //System.out.println("in catch.." + e.getMessage());
    OAViewObject subCatVO =
    (OAViewObject)am.findViewObject("SNI_ViolationSubCategoryVO1");
    //System.out.println("get VO before where clause: subCatVO::"+subCatVO.getQuery());
    subCatVO.setWhereClause("LOOKUP_TYPE like '%SNI_VIOL_SUB_CAT_" +
    v_violation_category + "'");
    System.out.println("after set where clause VO: subCat VO::" +
    subCatVO.getQuery());
    subCatVO.executeQuery();
    // System.out.println("query of subCat VO::" +
    // subCatVO.getQuery());
    //End of sub category Validation
    It is working fine only for the 1st row of teh table.
    I have tried to fetch the value using :
    String violationCategory = (String)violationVO.getCurrentRow().getAttribute("ViolationCategory");
    String violationSubcategory = (String)violationVO.getCurrentRow().getAttribute("ViolationSubcategory");
    But it is fetching null value.
    Please tell me how can I able to fetch the values.

    Hi
    in your scenarion,first u have to identify the particular row of table where the changes is being made ,u have to use this code .when u select the lov ,first it will give the row refernce and then u have to catch the lov event
    OAApplicationModule am =
    (OAApplicationModule)pageContext.getApplicationModule(webBean);
    String event = pageContext.getParameter("event");
    if ("<ItemPPREventName>").equals(event))
    // Get the identifier of the PPR event source row
    String rowReference =
    262
    pageContext.getParameter(OAWebBeanConstants.EVENT_SOURCE_ROW_REFERENCE);
    Serializable[] parameters = { rowReference };
    // Pass the rowReference to a "handler" method in the application module.
    am.invokeMethod("<handleSomeEvent>", parameters);
    In your application module's "handler" method, add the following code to access the source row:
    OARow row = (OARow)findRowByRef(rowReference);
    if (row != null)
    thanx
    Pratap

  • Pls let me know how to fetch the data from tables bdcp or bdcps

    Hi guru's!!!!
    I want to post the changed master data to the legacy.
    I am npt using IDOC. I want to go ahead by using the change doc. I want to know how we can filer the change doc. data for my equirement. & also how to send the data
    transaction wise. I am using the FMs "change_pointers_read.
    it is very urgent..
    Thanks in advance!!!!!

    Hi,
    1. You will have to activate the change pointers for the master data you are looking for.
    2. You can do the configuration so that whenever master data is changed, a IDOC is triggered for that master data.
    3. You can configure the IDOC's to be transmitted to your legacy system in the form of files or to your middleware system.
    <b>You don't have to read the CHANGE POINTERS yourself.</b>
    Regards,
    Ravi
    Note : Please mark all the helpful answers
    Message was edited by: Ravikumar Allampallam

  • How to Delete the Standard Database table KONV which is Related to ME47

    Hi Experts,
                   i am having the Query that i want to delete some condition types in ME47 Transaction which is related to MM in my requirement. that i have checked that all data is storing in KONV Cluster table but deleting data for standard table we should not delete it directly.so i searched for BAPI and Functional Module i did not get it . can you prefer and BAPI OR Functional Module through that we can delete Record in the KONV Table for this Issuse.

    WHY would you want to do that directly with a function?  Why don't you just fix the pricing issue in the RFQ's in question?

  • How to fetch the Table Control data to Customer Table(Z-Table) ?

    How to fetch the Table Control data to Customer Table(Z-Table) ?

    Hi Krishna,
    Check this sample programs
    http://www.planetsap.com/online_pgm_main_page.htm
    http://sap.niraj.tripod.com/id29.html
    http://www.sapdevelopment.co.uk/dialog/tabcontrol/tc_basic.htm
    Have a look at below links. It will help you.
    http://help.sap.com/saphelp_nw04/helpdata/en/9f/dbac5135c111d1829f0000e829fbfe/content.htm
    http://help.sap.com/saphelp_nw04/helpdata/en/9f/dbac1d35c111d1829f0000e829fbfe/content.htm
    Thanks,
    Reward If helpful.

  • How to fetch the VAT registration number of the ship to party from billing

    Dear SDN Team
    How to fetch the VAT registration number of the ship to party from the billing document.  Can you proide some information for fetching the VAT registration number of the ship to party.
    Normally only the payer VAT registration number will be displayed in the Invoice.  But in my case the Ship to party VAT number is displayed. 
    I have resolved this problem by doing the customizing setting in order to have the payer vat registration number.  But for the Old Billing documents it is more than 30,000 documents where it was printed with the ship to party VAT number.  So i need to identify those documents.
    Can you please help to resolve this problem.
    With Regards,
    Jai

    Hi,
    To get VAT from the ship to from Billing, You have to first fetch the BILLING NUMBER from the VBRK and then goto the Document flow in VBFA to get the SALES DOCUMENT NUMBER and with sales document you will get the SHIP TO number from the VBPA with the PARVW = SH
    Once you got the SHIP TO , then goto the KNA1 and get the VAT ID in the field STCEG
    so the logic will be as follows
    VBRK---VBELN and then
    VBFA--VBELN with the document Category as C
    VBPA-VBELN and get the  KUNNR with PARVW =SH
    Now with KUNNR ( ship to ) get the VAT ID from KNA1-STCEG
    regards,
    santosh

  • Customer Debit balance is reclassified

    Hi, all:
         My issue is: customer debit balance is reclassified (tcode: FAGLF101) ? Why?
        My configuration as follows:

    Dear Sreebha,
    You can check the settings as mentioned by Ankur.
    If the credit check is required in sales order level , check in OVAK whether the credit group and D(dynamic credit check ) is assigned to your sales order type.
    If the credit check is required for delivery/PGI in SPRO.IMGSALES & DISTRIBUTION> BASIC SETTINGS> CREDIT MANAGEMENT--> Credit limit check for delivery types
    Check whether the sales area you are making the sales order have a credit control area in ovfl.
    After this configuration checks, you can check in FD32 whether the credit exposure is 0 and also the the
    risk category is assigned.
    If the configurations and master data are perfect, then run RVKRED88/RVKRED77/F.28 for the customer code .
    Please check and revert back.
    Also please go through the forum and be sure you have not missed any credit control configuration settings.
    Thanks & Regards,
    Hegal K Charles

  • How to fetch the data & display the data if fields got the same name in alv

    hi frnds, i need ur help.
    how to fetch the data & display the data if fields got the same name in alv grid format.
    thanks in advance,
    Regards,
    mahesh
    9321043028

    Refer the url :
    http://abapexpert.blogspot.com/2007/07/sap-list-viewer-alv.html
    Go thru the guide for OOPs based ALV.
    Use SET_TABLE_FOR_FIRST_DISPLAY to display the table:
    CALL METHOD grid->set_table_for_first_display
     EXPORTING
    I_STRUCTURE_NAME = 'SFLIGHT'     “Structure data
    CHANGING
    IT_OUTTAB = gt_sflight.          “ Output table
    You can also implement
    Full Screen ALV, its quite easy. Just pass the output table to FM REUSE_ALV_GRID_DISPLAY. 
    For controlling and implementing the FS-ALV we have to concentrate on few of the components as follows :
    1. Selection of data.
    2. Prepare Layout of display list.
    3. Event handling.
    4. Export all the prepared data to REUSE_ALV_GRID_DISPLAY.
    Regd,
    Vishal

  • How to fetch the payment details in to report

    Hi,
    I have the MIRo number, How to find the payment document number and check number so and so.
    What are the transactions like: F053,FB03.
    Let me know the process of payment after MIRO.
    What are the documents we need to raise, how to find those documents, what is the link.
    How to find the accounting document for payment and check details (from which tables).
    What are the table names and field names. What we can get from PAYR table.
    I want to create a report for MIRO with payment details.
    How to fetch the business area field value in to report.
    What is the table name. I verified it is storing in structure. Which is the right table for fetching that value with reference to MIRO.
    With regards
    Lakki
    With regards
    Lakki

    Hi,
    For Creating MIRO Document,
    We have to create PO Me21n,
    then Do GR - MIGO using PO Reference,
    then we have to do MIRO Using then same PO. so the link is basically the PO. Then the Payment for the MIRO document is done in F-53/F-58 refering the MIRO  document. the check number will be generated once we do the Check  Print in
    FBZ5.
    You can  assign the check number to the F-53 document either in Assignment Field or the Reference field Using FCHU.
    Once you do this you can view all the Vendor Bill using Doc Type RE, KR & Vendor Payments Doc Type KZ.
    You can use the Std Report FBL1N / FK110N
    Hope its useful. Assign points if found use ful
    Regards,
    R.Ramakrishnaraj

  • How to specify the type of table in the form parameters

    How to specify the type of table in the form parameters. for example, how to specify the type of table "vacancies".
    FORM getcertainday
                       USING
                       vacancies TYPE STANDARD TABLE
                       efirstday LIKE hrp9200-zfirst_day
                       lfristday LIKE hrp9200-zfirst_day.

    Hi
    Are you asking about subroutine program to declare a variable for perform statement etc
    if it so check this coding
    DATA: NUM1 TYPE I,
    NUM2 TYPE I,
    SUM TYPE I.
    NUM1 = 2. NUM2 = 4.
    PERFORM ADDIT USING NUM1 NUM2 CHANGING SUM.
    NUM1 = 7. NUM2 = 11.
    PERFORM ADDIT USING NUM1 NUM2 CHANGING SUM.
    FORM ADDIT
           USING ADD_NUM1
                 ADD_NUM2
           CHANGING ADD_SUM.
      ADD_SUM = ADD_NUM1 + ADD_NUM2.
      PERFORM OUT USING ADD_NUM1 ADD_NUM2 ADD_SUM.
    ENDFORM.
    FORM OUT
           USING OUT_NUM1
                 OUT_NUM2
                 OUT_SUM.
      WRITE: / 'Sum of', OUT_NUM1, 'and', OUT_NUM2, 'is', OUT_SUM.
    ENDFORM.
    If your issue is some other can u explain me clearly
    Regards
    Pavan

  • How to fetch the query string in BW?

    Hi Gurus,
    How can fetch the query string from BW Server to implement  Bex web application Iview.
    *Now to get the information "BEx Web Application Query String". open the SAP Log on and open the BW Browser, double click any of the queries available, this will open a window and select the Query String ( it should be between & to end &).*
    Explain the above point with more detail like how will open the bw browser what is the step for that?where the query string will available in BW browser.
    Higher points will be rewarded for valuable inputs.
    Thanks in Advance,
    Dharani

    hi ,
    What krishna suggested is right ... Another method can be like :
    &CMD=LDOC&infocube=0D_DECU&query=SALES_DEMO_2
    Get this information from your BI consultant.
    Please close thread if you got ur answer!!!
    Regards
    Parth

  • How to fetch the query by a report

    Post Author: gionnyDeep
    CA Forum: Data Connectivity and SQL
    How to fetch the query by  a report.I need to manipulate it and pass it again to the report.
    Any idea?

    Post Author: gionnyDeep
    CA Forum: Data Connectivity and SQL
    I just need to get the query of a report.
    You know that a report is buld up on a sql query.I just want to know how to get that query starting by  a java ReportClientDocument.
    And I found reportClientDoc.getDatabaseController().getDatabase() to fetch DataBase object .After that I do not know the exact sequence of methods for fetch the query
    Sorry for my english

  • How to fetch the SAP Standard Prog. built internal table into my_z_prog.?

    Hi Experts,
    Pls. let me know that,
    How to fetch the SAP Standard Prog. built internal table into my_z_prog.?
    For more explannation, pls. see my other thread with name of yestrday,
    SUBMIT RFGLBALANCE WITH selection criteria, then How to get resulted itab?
    thanq

    Hi
    Suppose RFGLBALANCE is your standard program and you have an internal table named I_RFGLBALANCE.
    And lets say your Z program name is Z_SRINIVAS.
    First find out the type of the internal table you want in your Z-program in the standard program. And declare an internal table of similar type in your Z-program.
    I hope you can do this much.
    Later wherever you are putting the below mentioned code.
    SUBMIT RFGLBALANCE WITH selection criteria
    Write the code which i have written.Obviously modify it to suit your requirement.
    Please show what is not working fine so that even anyone else can help you with the problem you are facing.
    Regards,
    Mayank

  • How to fetch the Business area field value from MIRo into report

    Hi,
    I want to create a report for MIRO with payment details.
    How to fetch the business area field value in to report.
    What is the table name. I verified it is storing in structure. Which is the right table for fetching that value with reference to MIRO.
    After that, how to find the accounting document for payment and check details.
    What are the table names and field names. What we can get from PAYR table.
    With regards
    Lakki

    Dear,
    For Bussiness area
    RKPF-GSBER

Maybe you are looking for