‎2009 Jan 13 5:14 AM
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??
‎2009 Jan 13 5:16 AM
U can do one thing.
take all the dmbtr in one internal table and then loop into that internal table and calculate the SUM.
‎2009 Jan 13 5:22 AM
hi anurodh and ranjit
i do agree what u r saying . i just want to know what s the problem with that query..
‎2009 Jan 13 5:20 AM
Hi,
Instead of doing sum inside the query within loop. First fetch your query
then loop and add up dmbtr.
Thanks & Regards
‎2009 Jan 13 5:22 AM
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
‎2009 Jan 13 5:36 AM
the sy-subrc always shows zero bcoz of that sum .even the wrbtr is 0 .
solved the problem
‎2009 Jan 13 5:24 AM
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.
‎2009 Jan 13 5:34 AM
Hi Rakesh,
I think this sy-subrc problem comes because of the SUM function which u used in the select statement.
Thanks.
‎2009 Jan 13 5:42 AM
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