Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Help required for COUNT in select with INTO Clause

Former Member
0 Kudos

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

7 REPLIES 7

Former Member
0 Kudos

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

Former Member
0 Kudos

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

Former Member
0 Kudos

Raghu,

what are you trying to count?

Former Member
0 Kudos

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!

former_member195402
Active Contributor
0 Kudos

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

Former Member
0 Kudos

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.

Former Member
0 Kudos

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