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: 

Get additions throu Select

Former Member
0 Kudos

Hi All

I have a doubt in retrieving the data from database.

Please assume we have the table as below

Sales doc no Date Value customer No

1 10/05/2005 10000 1

2 10/02/2005 20000 1

3 05/05/2004 10000 1

4 05/10/2005 30000 2

5 12/12/2004 15000 2

6 14/10/2005 20000 2

If I want to get sales values during the year 2005. Is there any possibility sum-up the sales value in a single field into internal table. It means I want to see in the internal table structure like below during the year 2005

customer No Sales Value

1 30000

2 50000

Please help me ASAP. I am very beginner in ABAP.

Regards

Praveen

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Praveen - this doesn't answer the specific question you're asking, but you can sum amounts from tables like:

REPORT ztest.
TABLES bsis.
DATA tot LIKE bsis-dmbtr.
SELECT SUM( dmbtr )
  FROM bsis
  INTO tot
  WHERE gjahr = '2006'.

Rob

3 REPLIES 3

Former Member
0 Kudos

Praveen - this doesn't answer the specific question you're asking, but you can sum amounts from tables like:

REPORT ztest.
TABLES bsis.
DATA tot LIKE bsis-dmbtr.
SELECT SUM( dmbtr )
  FROM bsis
  INTO tot
  WHERE gjahr = '2006'.

Rob

0 Kudos

More specifically:


REPORT ztest.

TABLES vbap.

SELECT-OPTIONS: s_dat FOR vbap-erdat.

DATA tot LIKE vbap-netwr.

SELECT matnr SUM( netwr )
  FROM vbap
  INTO (vbap-matnr, tot)
  WHERE erdat IN s_dat
  GROUP BY MATNR.

ENDSELECT.

This is very inefficiant because the select is done without using an index.

Rob

Former Member
0 Kudos

Hello Praveen,

For this you have to use control level events.

Select all the fields you want from the database tables into an internal table.

Then loop thru that internal table and check for new customer using AT NEW control statement and the use COLLECT statement for summing up the values.

Do F1 on AT NEW and COLLECT.

look at the following example code.

TYPES: BEGIN OF COMPANIES_TYPE,

NAME(30),

PRODUCT(20),

SALES TYPE I,

END OF COMPANIES_TYPE.

DATA: COMPANIES TYPE STANDARD TABLE OF COMPANIES_TYPE WITH

NON-UNIQUE DEFAULT KEY INITIAL SIZE 20,

WA_COMPANIES TYPE COMPANIES_TYPE.

...

LOOP AT COMPANIES INTO WA_COMPANIES.

AT NEW NAME.

NEW-PAGE.

WRITE / WA_COMPANIES-NAME.

ENDAT.

WRITE: / WA_COMPANIES-PRODUCT, WA_COMPANIES-SALES.

AT END OF NAME.

SUM.

WRITE: / WA_COMPANIES-NAME, WA_COMPANIES-SALES.

ENDAT.

ENDLOOP.

Regards,

Message was edited by: Naren Somen