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

hi

Former Member
0 Likes
865

SELECT SINGLE SUM(ERFMG) FROM MSEG INTO ITAB-ERFMG WHERE MBLNR = ITAB-MBLNR AND LGORT = 'FGS' AND BWART = '101'.

this stmt is not working why?

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
843

Hi,

In your code ...

********************

SELECT SINGLE SUM(ERFMG) FROM MSEG INTO ITAB-ERFMG WHERE MBLNR = ITAB-MBLNR AND LGORT = 'FGS' AND BWART = '101'.

Change it like this.....

SELECT SINGLE SUM( ERFMG ) FROM MSEG INTO ITAB-ERFMG WHERE MBLNR = '10032333' AND LGORT = 'FGS' AND BWART = '101'.

*********************************

So in your the mistakes is the way you gave Sum(ERFMG) it shopuld be like Sum( ERFMG ) and in the where clause you cant use a field of itab as it is still initial...

Reward if helpful.

Regards,

Syed

10 REPLIES 10
Read only

Former Member
0 Likes
843

hi

you need spaces Abap is very sensitive with that

try


SUM( ERFMG )

or what was the exact error ?

regards

Read only

Former Member
0 Likes
843

i have given space but stil not giving output. Its saying Sum un known coloumn name

Read only

prasanth_kasturi
Active Contributor
0 Likes
843

HI,

I THINK YOU HAVE GIVEN SPACE BETWEEN SUM AND THE BRACKET.

GIVE THE FOLLOWING WAY

SUM( ERFMG ).

REWARD IF HELPFUL

PRASANTH

Read only

Former Member
0 Likes
843

Hi Anuradha,

try this code

SELECT  SUM(ERFMG) 
        INTO ITAB-ERFMG
         FROM MSEG 
          WHERE MBLNR = ITAB-MBLNR 
          AND LGORT = 'FGS'
         AND BWART = '101'.

IF Found Helpfull DO Reward.

Regards.

Eshwar.

Read only

Former Member
0 Likes
843

hi there....

i think the error is here

MBLNR = ITAB-MBLNR

u cannot apply this as itab currently is empty....

here itab is not the internal table but the work area which is empty when the query is called. u need to put this inside a loop at itab to get the query working.

do reward if helpful.

Read only

Former Member
0 Likes
843

Hi,

Actually sum you should't use in select querys why becuase it is a performance issue.

anyhow, your select query is in loop or not. if it is in loop ok. but it is not in loop

itab-mblnr is empty so it won't work. then you have to read that table itab.

if it is one time requirement you can use read statement.

or it is required for all entries in itab then you have use loop.

below 2 eg are there 1st one is for read table and 2nd one is looping table

Eg: read table itab with key mblnr = mblnr.

Eg:

loop at itab.

select query.

endloop.

Regard

Ganesh

Read only

Former Member
0 Likes
843

Hi Anuradha,

I have checked this query now and its working 100% correctly.

 
SELECT sum( erfmg )
        INTO lv_erfmg
         FROM mseg
          WHERE mblnr = '4900000010'
          AND lgort = '1020'
         AND bwart = '561'.

Check: There is no gap between sum and starting bracket also check your doc number in debug mode.. if its not in compatible format thats in table no data will be fetched. You will have to apeend zeros or something.

Please award points to all correct answers in this thread and mark question as answered.

Thanks,

Ags..

Read only

Former Member
0 Likes
843

y thr is necessary to SUM

ur using select single ,only one value will come .

use either select single erfmg

or select sum( erfmg )

as per ur requirement.

Read only

former_member787646
Contributor
0 Likes
843

Hi,

Try this.

IF NOT ITAB-MBLNR IS INITIAL.

SELECT SUM( ERFMG ) FROM MSEG INTO

ITAB-ERFMG WHERE MBLNR = ITAB-MBLNR

AND LGORT = 'FGS' AND BWART = '101'.

ENDIF.

Hope it helps you.

Murthy.

Read only

Former Member
0 Likes
844

Hi,

In your code ...

********************

SELECT SINGLE SUM(ERFMG) FROM MSEG INTO ITAB-ERFMG WHERE MBLNR = ITAB-MBLNR AND LGORT = 'FGS' AND BWART = '101'.

Change it like this.....

SELECT SINGLE SUM( ERFMG ) FROM MSEG INTO ITAB-ERFMG WHERE MBLNR = '10032333' AND LGORT = 'FGS' AND BWART = '101'.

*********************************

So in your the mistakes is the way you gave Sum(ERFMG) it shopuld be like Sum( ERFMG ) and in the where clause you cant use a field of itab as it is still initial...

Reward if helpful.

Regards,

Syed