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

Get additions throu Select

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

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

2 Answers

  • Best Answer
    author's profile photo Former Member
    Former Member
    Posted on Oct 05, 2005 at 09:03 PM

    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

    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member

      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

  • author's profile photo Former Member
    Former Member
    Posted on Oct 05, 2005 at 09:06 PM

    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

    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.