Application Development 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: 

Is this ABAP statement correct ?

Former Member
0 Kudos

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

1 ACCEPTED SOLUTION

Former Member
0 Kudos

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

11 REPLIES 11

arindam_m
Active Contributor
0 Kudos

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

Former Member
0 Kudos

Hi, that anytime i can do that. But what i am doing is that correct or not ?

Regards,

Ravi

Former Member
0 Kudos

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

former_member186077
Active Participant
0 Kudos

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.

Venkat_Sesha
Advisor
Advisor
0 Kudos

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.

former_member209920
Active Participant
0 Kudos

Hi

INTO CORRESPONDING FIELDS OF TABLE

IT will ask for exact field name in you internal table.

therefore your query is incorrect.

0 Kudos

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

Former Member
0 Kudos

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..

dirk_wittenberg
Contributor
0 Kudos

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

Former Member
0 Kudos

Thank you, Xiang Li.

0 Kudos

You are most welcome. Thanks for the LIKE and point given.