Application Development and Automation 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: 
Read only

Count and Other fields - VBAK

Former Member
0 Likes
1,439

Hi All,

I want to find the count the no of Orders from VBAK for a combination of VBTYP and AUART.

Select Count(*) from vbak into table t_vbak where vbeln in s_vbeln

and vkorg eq p_vkorg

group by vbtyp auart.

This will only give the count.

I also need other data like erdat ernam and a bunch of other fields for this combination.

Do I need to select again from VBAK??

Any ideas.

Meghna

6 REPLIES 6
Read only

Former Member
0 Likes
1,171

yes you have to select again from VBAK.

program code would look like this:

select count(*) from vbak where.....

select field1

field2

from vbak

where ....

Read only

Former Member
0 Likes
1,171

Hi Meghna,

The statement you written above, Is it correct, Is it working,,,

I will not work as in count(*) it will not allow to select the data into a table and instead you need to write like this.


DATA : i_vbak type i.
Select Count(*) from vbak into i_vbak where vbeln in s_vbeln

Then you will get the no. of records,,,

It give No difference again to count Erdat or Ernam...! As it will be the same count.

If you need the Maximum then it will give you ethe maximum date but for time it give maximum time in 24 Hours but it may be different from the latest date time....

lets say you ha two record in April & May,, May you created time at 1 PM.. In April you created at 3 PM..

for max time,,,, you will get April,

And for max date you will get May,,,

remember that.

Count is for No. of records,,, & Max is for maximum no. or date or version,,,

Thanks & regards,

Dileep .C

Read only

Former Member
0 Likes
1,171

Hi,

You have to select the fields again... Select count will just return a number i.e. the count of the conditions specified in the where condition... To fetch the individual field values you have to write a separate select statement to fetch it... You can put an initial check before going for the next database hit, so that if no records are found in the database for those selection criteria it will not hit the database again to fetch blank data...

Read only

Former Member
0 Likes
1,171

Hi,

In this case you don't have to select Count(*) first, Directly select the necessary fields into the itab and after the select use Sy-dbcnt or Describe table to find the number of records returned.

Regards

Karthik D

Read only

Former Member
0 Likes
1,171

Hi,

first u dont count the data,always u first select the data and split the data for your requirement and then use :

AT END OF FIELD NAME.

SUM.

ENDAT.

hope this will help u.

Regards,

K.Karthikeyan.

Read only

Former Member
0 Likes
1,171

Hi Meghna,

its not possible to combine the query to get the count of a certain table or its fields and at the same time get some of its fields.

You would need to create two separate select statements: one SELECT statement to get the count and another SELECT statement to get the table fields and store it in an internal table.

Hope it helps!