05-14-2013 10:07 AM
Hello Colleague,
I am trying to sum number of seats available in a flight of same carrier type and putting in internal table.
I wrote this statement but sum is coming as 0.
DATA: t_sflight TYPE TABLE OF sflight.
SELECT carrid SUM( seatsmax ) FROM sflight INTO CORRESPONDING FIELDS OF TABLE t_sflight GROUP BY carrid.
If i do the same thing by creatting structure with only these two fields carrid seatsmax then it works fine.
Please let me know is above mentioned statement is correct or not ?
Regards,
Ravi
05-14-2013 10:21 AM
Hi Ravi,
For aggregate operation/field, by default there is no field name for it, and in your case system would not knwo which correspond field to go into.
Try this.
SELECT carrid SUM( seatsmax ) as seatsmax FROM
sflight INTO CORRESPONDING FIELDS OF TABLE t_sflightGROUP BY carrid.
I guess, it works for 2 fields only structure because you use INTO TABLE instead of
INTO CORRESPONDING FIELDS OF TABLE right?
Hope this helps.
regards,
Xiang Li
05-14-2013 10:16 AM
Hi,
Put this in two work variable like LV_CARRID and LV_SUM then transfer that to the table and do SELECT.. END SELECT.
Cheers,
Arindam
05-14-2013 10:18 AM
Hi, that anytime i can do that. But what i am doing is that correct or not ?
Regards,
Ravi
05-14-2013 10:21 AM
Hi Ravi,
For aggregate operation/field, by default there is no field name for it, and in your case system would not knwo which correspond field to go into.
Try this.
SELECT carrid SUM( seatsmax ) as seatsmax FROM
sflight INTO CORRESPONDING FIELDS OF TABLE t_sflightGROUP BY carrid.
I guess, it works for 2 fields only structure because you use INTO TABLE instead of
INTO CORRESPONDING FIELDS OF TABLE right?
Hope this helps.
regards,
Xiang Li
05-14-2013 10:22 AM
Hi Ravi,
The query is not correct as INTO corresponding fields of table looks for the exact field name to which the fetched data needs to be passed.
The query worked in the other case because you have specified the exact fields to which the fetched data should return.
Hope this explanation helps.
Thanks and Regards,
Sriranjani Chimkaurthy.
05-14-2013 10:25 AM
Hi Ravi,
May be nothing wrong your statement. The problem is with the Data at table level.
Even I too get the same sum 0. and a number when created with TYPES.
So check the data in the database table.
You may know other ways to write the same Logic, i dont any comments on those things.
But the above mentioned select should work.
Hope this helps.
05-14-2013 10:27 AM
Hi
INTO CORRESPONDING FIELDS OF TABLE
IT will ask for exact field name in you internal table.
therefore your query is incorrect.
05-14-2013 10:31 AM
Hi,
Problem is with corresponding fields of table.Please create appropriate structure and try it.
I tried the below code and it was working.
TYPES : BEGIN OF ty_sflight ,
carrid TYPE sflight-carrid,
seatsmax TYPE sflight-seatsmax,
END OF ty_sflight.
DATA: t_sflight TYPE TABLE OF ty_sflight,
l_sflight TYPE ty_sflight.
SELECT carrid SUM( seatsmax ) FROM sflight INTO TABLE t_sflight GROUP BY carrid.
LOOP AT t_sflight INTO l_sflight.
WRITE :/ l_sflight-carrid, l_sflight-seatsmax.
ENDLOOP.
Regards,
Peri
05-14-2013 10:35 AM
corresponding fields of table means i will search for the fields which is present in internal table if its was there then i will get that field info.. so i think statement wt u propose is incorrect..
05-14-2013 10:47 AM
Hi,
as Xiang Li already wrote all that's missing is "as seatsmax" behing the "sum(seatsmax)".
With this it should work as it provides the fieldname for the "corresponding" clause.
Regards,
Dirk
05-14-2013 11:25 AM
05-14-2013 12:38 PM