Skip to Content
author's profile photo Former Member
Former Member

Help required for COUNT in select with INTO Clause

HI All,

I have worte the belwo select statement to get the records from 2 tables and counting ans summing based some paraaters.

Internal table structure

------------------------------------------------------------------
*         bukrs          TYPE dfkkinvdoc_i-bukrs,
*         budat          TYPE dfkkinvdoc_h-budat,
*         waers          TYPE dfkkinvdoc_i-waers,
*         count          TYPE i,
*         menge         TYPE dfkkinvdoc_i-menge,
*         betrw          TYPE dfkkinvdoc_i-betrw,
--------------------------------------------------------------------

Select statement

SELECT a~budat 
               b~bukrs
               b~waers 
               COUNT(*)
               SUM( b~menge ) AS menge
               SUM( b~betrw ) AS betrw
           INTO CORRESPONDING FIELDS OF TABLE lt_data
           FROM dfkkinvdoc_h AS a
           INNER JOIN dfkkinvdoc_i AS b
           ON a~invdocno = b~invdocno
           WHERE a~invdocno IN s_invno
           AND   a~inv_process IN r_proce
           AND   a~inv_type IN r_type
           AND   a~inv_category IN r_cate
           AND   a~budat IN r_crdate
           AND   b~itemtype = 'ZXXXXX' GROUP BY b~bukrs a~budat b~waers.

but the count field in internal table is not getting filled, except that i got every thing is fine. could you please let me know you thoughts on the below.

Thanks,

Raghu.

Edited by: Raghu on Dec 13, 2011 7:14 AM

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

7 Answers

  • author's profile photo Former Member
    Former Member
    Posted on Dec 13, 2011 at 04:20 AM

    Hi,

    For This You Need to Maintain Particular Field For Count Function Then Only You Will Get The Count Value

    i.e,The Syntax Of Count() is,

    SELECT COUNT(*) FROM table_name.

    For Your Issue You need to maintain Count(*) and Then Provide Table Name.

    I Think This will Give Some Idea To you.

    Warm Regards,

    PavanKumar.G

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Dec 13, 2011 at 04:21 AM

    Hi Raghu,

    To count internal table entries use this statement

    data : count type i.

    Describe table internaltablename lines count.

    The above statement counts the internal table contents and place it in the count variable.

    Note : Here count is a variable you need to declare .

    Regards,

    G.Aditya

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Dec 13, 2011 at 04:41 AM

    Raghu,

    what are you trying to count?

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Dec 13, 2011 at 04:52 AM

    what i have observed that many times aggregate function( count,sum,min,max) does not able to identify the corresponding fields of internal table.

    instead of using into correspinding fields try into table itab.

    try:

    select a

    b

    count( * )

    from ztable into itab where..... group by a b. keep internal table structure same as in select statement.

    i m not sure whether this works but give it atleast a single try!

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Dec 13, 2011 at 05:51 AM

    Hi,

    please have a look at this sample:

    REPORT  zsmarcbabl                              .
                                                                                    TYPES: BEGIN OF x_mara,
             matnr TYPE matnr,
             count TYPE sytfill,
             werks TYPE werks_d,
           END   OF x_mara.
                                                                            
    DATA: xs_mara TYPE x_mara.
    DATA: xt_mara TYPE TABLE OF x_mara.
                                                                            
    SELECT-OPTIONS: xp_matnr FOR xs_mara-matnr.
                                                                            
    START-OF-SELECTION.
                                                                            
      SELECT a~matnr        AS matnr
             COUNT( * )     AS count
             MAX( c~werks ) AS werks  FROM  mara AS a
                               INNER  JOIN  marc AS c
                                        ON  c~matnr = a~matnr
                                      INTO  CORRESPONDING FIELDS
                                        OF  TABLE xt_mara
      WHERE  a~matnr                    IN  xp_matnr
      GROUP                             BY  a~matnr.
                                                                            
      loop                              at  xt_mara
                                      into  xs_mara.
        write: /1                           xs_mara-matnr,
                                            xs_mara-count,
                                            xs_mara-werks.
      endloop.                             "xt_mara

    Regards,

    Klaus

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Dec 13, 2011 at 03:54 PM

    Hi All,

    Its been solved by using select and endselect, earlier i thougt of avioding this loop.

    Anyway thanks for all your promot responses.

    Thanks,

    Raghu.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Dec 15, 2011 at 08:42 AM

    Hi,

    For This You Need to Maintain Particular Field For Count Function Then Only You Will Get The Count Value

    i.e,The Syntax Of Count() is,

    SELECT COUNT(*) FROM table_name.

    For Your Issue You need to maintain Count(*) and Then Provide Table Name.

    I Think This will Give Some Idea To you.

    Warm Regards,

    PavanKumar.G

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.