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

SOLVE THIS QUERY

Former Member
0 Likes
748

HI SAP GURUS,

SELECT SUM( dmbtr ) INTO w_dmbtr10

FROM bsis

WHERE belnr = it_input-belnr

AND hkont = it_input-racct

AND gjahr = it_input-gjahr

AND bukrs = 'BP01'

AND shkzg = 'S'.

I HAVE GIVEN THAT IN A LOOP.

SY-SUBRC ALWAYS EQUALS ZERO. WHAT S WRONG WITH THAT QUERY??

8 REPLIES 8
Read only

Former Member
0 Likes
722

U can do one thing.

take all the dmbtr in one internal table and then loop into that internal table and calculate the SUM.

Read only

0 Likes
722

hi anurodh and ranjit

i do agree what u r saying . i just want to know what s the problem with that query..

Read only

Former Member
0 Likes
722

Hi,

Instead of doing sum inside the query within loop. First fetch your query

then loop and add up dmbtr.

Thanks & Regards

Read only

Former Member
0 Likes
722

Hi Rakesh,

Even if the select query does not fetch any entries SUM is calculated as zero, so that only its

giving sy-subrc as zero (Not sure).

So

SELECT  dmbtr INTO TABLE it_dmbtr10 
FROM bsis 
WHERE belnr = it_input-belnr 
AND hkont = it_input-racct
AND gjahr = it_input-gjahr 
AND bukrs = 'BP01'
AND shkzg = 'S'.

IF sy-subrc EQ 0.
LOOP AT it_dmbtr10.
   "Calculate the sum
ENDLOOP.
ENDIF.

Try like this.

Hope this helps you.

Regards,

Manoj Kumar P

Edited by: Manoj Kumar on Jan 13, 2009 6:23 AM

Read only

0 Likes
722

the sy-subrc always shows zero bcoz of that sum .even the wrbtr is 0 .

solved the problem

Read only

Former Member
0 Likes
722

Hi,

First select all the dmbtr values into one internal table with all your requirements and then u can find the SUM. and avoid select statement inside the loop statement.

Thanks.

Read only

Former Member
0 Likes
722

Hi Rakesh,

I think this sy-subrc problem comes because of the SUM function which u used in the select statement.

Thanks.

Read only

I355602
Product and Topic Expert
Product and Topic Expert
0 Likes
722

Hi,

Try it this way, it will work:-


DATA : v_dmbtr TYPE bsis-dmbtr.

START-OF-SELECTION.
  SELECT SUM( dmbtr ) INTO (v_dmbtr) 
  FROM bsis 
  WHERE belnr = it_input-belnr 
  AND hkont = it_input-racct
  AND gjahr = it_input-gjahr 
  AND bukrs = 'BP01'
  AND shkzg = 'S'.

END-OF-SELECTION.
WRITE : / v_dmbtr.

Hope this solves your problem.

Thanks & Regards,

Tarun Gambhir