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

Is this ABAP statement correct ?

Former Member
0 Likes
1,558

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
Read only

Former Member
0 Likes
1,505

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
Read only

arindam_m
Active Contributor
0 Likes
1,505

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

Read only

Former Member
0 Likes
1,505

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

Regards,

Ravi

Read only

Former Member
0 Likes
1,506

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

Read only

Former Member
0 Likes
1,505

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.

Read only

Venkat_Sesha
Product and Topic Expert
Product and Topic Expert
0 Likes
1,505

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.

Read only

former_member209920
Active Participant
0 Likes
1,505

Hi

INTO CORRESPONDING FIELDS OF TABLE

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

therefore your query is incorrect.

Read only

Former Member
0 Likes
1,505

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

Read only

Former Member
0 Likes
1,505

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

Read only

dirk_wittenberg
Contributor
0 Likes
1,505

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

Read only

Former Member
0 Likes
1,505

Thank you, Xiang Li.

Read only

0 Likes
1,505

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