SAP Query - Count(*)

Hi,
i have a table with records
abc
abc
def
fgt
def
abc
fgt
abc
def
jkh
i want the SAP query to display as
abc - 4
def - 3
jkh - 1
fgt - 2
when i wrote a query ( select count(*) ) in infoset and added an additional field count, it is giving me the right count but it is repeated as many times as the record, like below
abc 4
abc 4
abc 4
abc 4
def 3
def 3
def 3
jkh 1
fgt 2
fgt 2
Can you please tell me how to avoid this multiple lines?
Regards,
Sharadha

Hi,
I think LTAP is a field group and not an internal table...
You can create your own internal table in the DATA section...and add the entries during the RECORD_PROCESSING event..
Ex..
****DATA Section
TYPES: BEGIN OF type_data,
               value TYPE char10,
             END OF type_data.
DATA: MY_ITAB TYPE STANDARD TABLE OF type_data,
           MY_WA   TYPE type_data.
****In RECORD_PROCESSING section.
READ TABLE MY_ITAB TRANSPORTING NO FIELDS
                     WITH KEY value = LTAP-value.
IF sy-subrc = 0.
  CHECK 1 = 0.        " Don't proceed with the record as it is already added.
ELSE.   " REcord not added.
  MY_WA-value = LTAP-value.
  APPEND MY_WA TO MY_ITAB.
ENDIF.
Hope this is clear.
Thanks
Naren

Similar Messages

  • Sap query sq02

    Dear all,
    since TWO days Iam working on this .... SAP Query without succes. Now I wanted to ask you here.
    I want to make a select-option in the SAP Query. Ok, this is easy! now the customer want to have F4-Help. Iam now in SQ02 where the data coming IN. I  crated a Z-Structur. In this Structur I have my field KLART. This field has a domain. In SQ02 I can say take the value from references. This mean  its takes the data from TCLA-KLART. But I see in the reference field. It takes data from TCLAT-ARTXT. So my question are:
    1) Why does it take the field from TCLAT-ARTXT?
    2) I dont see any information in the screen. This mean I dont get an option for this field KLART
    Thank u very much

    Hi,
    1)Data Source is  direct read of  table Mara
    2)
    you've to place the follow. code in
    SQ02-Goto-Code-Record processing:
    select count( * ) from mchb into sy-dbcnt
                     where matnr = mara-matnr.
    check sy-dbcnt = 0.
    regards Andreas

  • Number of records in SAP Query

    Hi There,
    I have created a SAP Query. Instead of rows in the output I would like to display number of rows fetched in my list output. How can I do this? Please advice.
    Thanks in advance,
    Rams.

    Hi rams,
    1. simple
    2. we have to use Count(*) in select query.
    3. just copy paste
    4.
    report abc.
    data : mycount type i.
    select count(*) from t001
    into mycount.
    write :/ mycount.
    regards,
    amit m.

  • Is it possible to use aggregation function in SQ Sap query?

    I need to create a sap query like using SELECT MAX(begda) statement.
    Please teach me how...
    Thank u in advance..

    Hi Ella,
    You can very well use the aggregate functions in sql which is usually a performance tuning technique.
    A calculation that is made on several records or cells of data. SUM, AVG, MAX, MIN and COUNT are examples of aggregate functions that are used in spreadsheets and database programs.
    SELECT ( ( ] ...
    MAX: returns the maximum value of the column
    MIN: returns the minimum value of the column
    AVG: returns the average value of the column
    SUM: returns the sum value of the column
    COUNT: counts values or lines as follows:
    · COUNT( DISTINCT ) returns the number of different values in the column.
    · COUNT( * ) returns the total number of lines in the selection.
    Ex:    DATA: fldate LIKE sbook-fldate,
          count  TYPE i,
          avg    TYPE p DECIMALS 2,
          max    TYPE p DECIMALS 2.
    SELECT fldate COUNT( * ) AVG( luggweight ) MAX( luggweight )
           FROM sbook
           INTO (fldate, count, avg, max)
           WHERE carrid = 'LH' AND
                 connid = '0400'
           GROUP BY fldate.
      WRITE: / fldate, count, avg, max.
    ENDSELECT.
    For further info:
    http://help.sap.com/saphelp_nw04/helpdata/EN/fc/eb3990358411d1829f0000e829fbfe/content.htm
    http://help.sap.com/abapdocu/en/ABAPSELECT_AGGREGATE.htm
    Thanks and Regards
    Srikant.P
    Edited by: SRIKANTH P on May 27, 2009 9:41 AM

  • SAP Query- Is summation possible

    Dear All,
    Pls let me know if we can do summation in SAP Query to get a count on positions for example.
    Eg. If i ve say 25 positions in the system pulled out by through Query, can i be able to sum them up saying the count is "25" in SAP Query.
    Points would be awarded.
    Thanks.

    will put up the example as below:
    the query pulls out a report on the existing positons as below:
    Object Type    Start Date       End Date         Object Name
       S                01.01.2005     31.12.9999         HR
       S                01.01.2005     31.12.9999         Marketing
       S                01.01.2005     31.12.9999         Finance
       S                01.01.2005     31.12.9999         ABC
    Now, I want the report to diplay the count of the position as "4" somewhere above.
    Is this possible in to get this count in standard report or query?

  • SAP Query - SQVI or SQ01 -- Implementing Group By

    Hi,
    Please advice on whether we can use GROUP BY and HAVING clauses in SAP Query.
    For ex. I need to find all the customers in the system who have been defined for multiple company codes. In ABAP, I could do it using
    Select kunnr count(*) from knb1
    group by lifnr
    having count(*) > 1
    Is this possible to do this in SAP query?
    Thanks,
    Ani

    Ani P,
       IN  ABAP Query you can  write this in  under  START-OF-SELECTION  event.
    There are 2 options for out put
    1. Out in ALV format in System itself
      This can be possible in RECORD PROCESSING.Here you don't have command on "main selection statement ".System will write this.
       If you want to do some validations OR want to delete some records you have write logic for this here. Process will be record by record.
    2.Output in Excel format.
       If you want "GROUP BY or Having"  write code in START-OF-SELECTION event.
    Extract all the data in one final internal table.
    use Function Module WS_EXCEL.
    3.Output in file format in application server.
       This is also you can do in START-OF-SELECTION  by using
    OPEN DATASETS.
    For your requirement better use " START-OF-SELECTION ".
    Pls. reward if useful

  • Serial Number in SAP Query !!!

    Hi Gurus
    How can we add Serial Number in SAP Query? There is a field named Counter which gives Total number of count. But i need numbers to be displayed with each line item.

    OK,
    So you need to create a Number Range Object (tr SNRO), this create a object like ZNUM.
    then, each time you need insert a new record to table only call this FM:
    CALL FUNCTION 'NUMBER_GET_NEXT'
        EXPORTING
          nr_range_nr             = '01'
          object                  = 'ZNUM'
        IMPORTING
          number                  = itab-field
        EXCEPTIONS
          interval_not_found      = 1
          number_range_not_intern = 2
          object_not_found        = 3
          quantity_is_0           = 4
          quantity_is_not_1       = 5
          interval_overflow       = 6
          buffer_overflow         = 7
          OTHERS                  = 8.
    at this point, ITAB-FIELD contains the next number in the range ZNUM.
    I hope this help,
    X.S.

  • Max Query Count setting

    Hello colleagues,
    Probably you many know there is Max Query Count setting in MII.
    Does any of you experience performance concerns by dealing with large number of query count?  or does any of you have a recommendation for how to set max query count, e.g. not exceeding memory size to avoid memory swapping? 
    my customer want to increase this max count due to fluctuating record count.  but they have concerns on such disadvantage in performance.
    any of your experiences are welcome.  Thank you,
    Shiroh Kinoshita, SAP Japan

    Shiroh,
    Good to hear from you.
    All queries have the RowCount setting, but we typically discourage people from just setting it to a high number.  In some cases the data servers will limit this number to a max (something like 250000) but that doesn't mean that from a memory standpoint, or a customer patience level (especially in the browser) would ever get to that number of records.
    Where is it that you are seeing the record count fluctuate, applets in the browser, query actions in a transaction?
    What is it that makes the customer want to increase this to a high number?
    Regards,
    Jeremy

  • How i can keep my code after %dba standard table in sap query

    hi expert,
    how i can keep my code after %dba standard table in sap query..
      add 1 to %count-VBRP.
      %linr-VBRP = '01'.
      extract %fg01.
      %linr-VBRP = '02'.
      extract %fg02.
      %linr-VBRP = '04'.
      extract %fg04.
      %linr-VBRP = '05'.
      extract %fg05.
      %ext-VBRP05 = 'X'.
        extract %fgwrVBRP05.
    endselect.
    i want keep my code after filling the standard table generated by sap abap query
    Thanks & regards
    Sajad Ahmad

    Hi,
    the above code is excuted succesfully, but if i have
    return "Navigation" ;
    it is not working
    any idea why??????????

  • Creation of SAP Query in SQ02 with Single Table With Condition

    Hi All,
    I want to Create SAP Query in SQ02 using single Table MCHA.
    ii) I dont want all entries of MCHA Table I mean , I have to apply some Condition on this Table.
    i.e  Suppose I am having actual data in MCHA table is like this for Material M1.
    Plant    Material   Batch   BatchCreationdate
    P1          M1         B1       20.06.2007
    P2          M1         B1       04.05.2009
    P3          M1         B1       04.05.2009
    But I want the Output of SAP Query is like this:
       Material   Batch   BatchCreationdate
          M1         B1       20.06.2007
    That is irrespective of Plant if Material & Batch are equal ---> 1st record with Lowest date shoud get at the output.
    Please help me How write the code on single table in the SAP Query.
    Thanks,
    Kiran Manyam

    Hi,
    Your query should be like this:
    Select MATNR CHARG HSDAT
    from MCHA
    into table t_mcha
    where matnr = Materlal number from selection screen.
    The structure of t_mcha should contain the fields that you select.
    Then sort the table by date ascending
    Sort t_mcha by HSDAT.
    Hope this solves your problem.
    Thanks,
    Sowmya

  • SAP query

    Hello ABAP Guru
    I need a help here. trying to create SAP query joining three table VBAK VBAP KONV since KONV being cluster table I am not able to do that
    thpough I am suceesfully establishe dthe link
    VBAK-VBELN=VBAP-VBELN
    VBAK-KNUMV=KONV-KNUMV & VBAP-POSNR=KONV-KPOSN
    OSS msg says we have to write routine in sap query
    but I never used that option
    anyone has any clue on how to use cluster table in SAP query?
    Thx
    Praveen

    Hi,
         Inner Join can't be  used for cluster tables.
         Write a routine in SAP query as follows.
          do inner join on vbak,vbap into internal table  
          itab.
           select for konv for all entries itab .           
    Regards
    Amole

  • How to call SAP query in a program

    Hi experts
      I have created a query in SQVI its gives a result. Now i want this query to be used in my program. Is there any FM which gets the quary name and populates the result in iternal table. So that i can use that result.
       I know without query you can write using the tables you can fetch the records but i just want to explore a new way to do things. If any body done such type let me know and also give some sample code or process how to achieve it.
    Regards
    Vijay

    Hi Siva
      My final option is that only. That you can do any how. But my intension is to learn something new way. How to do copy the query and where to inject the code is there any example in wiki or artical for that. I want to something new. Old way of creating a report program is possible i want to do this way. If some body could help me out.
    @ karthik
       I have generated the SAP query and i got the program but when i view the code i dont find any select statment or where storing my input data. How to identity that i did in debug mode but am not sure where it pulls the data and where it put in internal table. Can you throw some light with example code or an article.
    Regards
    Vijay

  • SAP QUERY report for vendor line items

    Hi
    I have created a SAP QUERY report for vendor line items with fields vendor no.,vendor name,amount,company code and period.But there is one line item i donot know from wher system is getting it picked with is not in that vedor account,when i compare with fbl1n.I checked the document number too...the same doc number is twice in my query report.One with correct amount and another with wrong one.How do i chk.Where did i go wrong in creating query.I used logical database KDF.
    Please advise.

    i chked...how do we get the amount displayed in query...it just displays amount no debit credit symbol... i have selected BSEG-DMBTR field but no -/+ sign,how is it done in query,please suggest.

  • SAP Query- Reporting on SOD

    Hello everyone,
    I need some help in creating a report in SAP Query based on user's processing Vendor Invoices and also Vendor Payments?
    I would like to have the following columns to report on:
    USNAM u2013 User Name (from BKPF)
    BLDAT u2013 Document Date (from BKPF)
    BELNR u2013 Document Number (from BKPF)
    BUKRS u2013 Company Code (from BKPF)
    BLART u2013 Document Type (from BKPF)
    LIFNR u2013 Vendor Number (from BSEG)
    NAME1 u2013 Vendor Name (from LFA1)
    WRBTR u2013 Amount (from BSEG)
    Vendor Invoice- I would like to restrict to only document type fields that are KA,KR,RC,RE,RN and ZE
    Vendor Payment- I would like to restrict to only document type fields that are ZV,ZS,ZP,ZH and KZ
    I have a few questions:
    First is i am using a logical database (BRM as BSEG cannot be joined) to select my columns however i do not know how to pull the 'Vendor Name' from LFA1. I understand that this table is not in BRM but is there a way to add any extra tables to work along side the logical database?
    Secondly, i have managed to report on all columns except the vendor name (from LFA1) and although i can restrict my output data based on document type fields, i need the report to only show the user's that have process vendor invoices & vendor payments only?
    At the moment i have a list of restricted document type but cannot seem to jsut show only those users who have processed both in both processes. For example User A has processed a vendor invoice (which is shown) and the same user may have processed vendor payment (after searching through the long output list!)
    I want all users who have doen one of the other process and only interested in those that have done both?
    Any feedback is much appreciated and pelase let me know if i have not explained this problem properly (as i am a newbie in this area)
    Many thanks
    Amar

    Hi Pascal,
    Since the IT2501 is a "Simulated Time Infotype" you cannot look at the data in it, but you can confirm the data from the ZL cluster and the data from the employee.  Since it is only this employee or a few employees, it is probably not the configuration of the time buckets for the IT2501, but you may want to make sure all time times are captured as you want.  Then look at the time entries for this individual or individuals.  Did they enter a time type that was not expected or configured?  Is all their time approved and passed through Time Evaluation?  Finally check the Master Data for the employee - is the Planned Working Time (IT0007) infotype correct or has it been recently changed?  Is he in a special Cost Center (IT0027) or Project that is captured differently for time purposes? 
    Since it just one or a few individuals, I would suspect the Master Data and some inconsistant entry that affects the time cummulation for the IT2501.
    Paul

  • How can I define Double Click Processing in SAP Query ?

    The first question is : How Can I define drill-down for SAP Query report ?
    The second one :  How can I program Double Click in SAP Query report for Different columns like ALV Grid processing ?

    you can attach a repot or at tcode etc in an SAP query using report assignment in SQ01 but as far as i remember you cannot attach multiple reports.
    regards,
    khusro habib

Maybe you are looking for