cancel
Showing results for 
Search instead for 
Did you mean: 

group by ODS table

Former Member
0 Kudos

Hi experts,

Some doubts, please advice.

I am trying to send aggregate value of one column in ODS table into an internal table. I am using the following code.

select carrid connid AVG( seatsocc ) as seatsocc

from /BIC/ODSTable

into corresponding fields of table itab

where fldate = sy-datum group by carrid connid

But either because there is no header line in ODS table, or because I did use right column names in the internal table itab, I got "0" in all rows. Could anyone please tell me which is the reason of my error?

I tried to skip "corresponding fields of table itab ", and using internal table, however, i got an syntax error.

I saw some ABAP book using working area. Is it the only solution? I am not familiar with working area and someone told me I should be very careful of working area. what's the deal with working area? Can I append working area to an internal table?

Any suggestion will be really appreciated.

Jenny

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hello JennY,

how r u ?

The statements should be in the loop, if u want to use Internal Table automatically the Work Area and body will be created.

Work Area will hold only one record at a time, so u have to append the Internal Table after every record selection.

Loop at itab.

(your statements).

.....

Append itab.

Endloop.

Try with this....

Best Regards....

Sankar Kumar

+91 98403 47141

Answers (2)

Answers (2)

Former Member
0 Kudos

Hi,

It is not necessary that the field names of your internal table should be same as that of the ODS. But the data type of the internal table fields should be same as that of the ODS fields.

And in the select query you have to specify the field name of the ODS and not the field name of internal table.

Sample:

Data: Begin of itab occurs 0,

CARRID type /BIC/ODSTABLE-/BIC/ZCARRID,

CONNID type /BIC/ODSTABLE-/BIC/ZCONNID,

SEATSOC type /BIC/ODSTABLE-/BIC/ZSEATSOC,

End of itab.

Select /BIC/ZCARRID /BIC/ZCONNID AVG(SEATSOC)

From /BIC/ODSTABLE

Into table itab

Where fldate = sy-datum group by /BIC/ZCARRID /BIC/ZCONNID.

Hope you would be able to get it solved.

Regards,

Prema

Former Member
0 Kudos

Hi,

If your Internal table itab has someother fields other than these 3 fields that you are updating then you need to specify ‘into corresponding fields of itab’. Whereas if your itab contains only these three fields then ‘into table itab’ will work.

Work Area is a data object that should be compatible with the line type of the Internal table. It is an interface to the entries in the Internal table.

When you write data to internal table, the data is first written to the work Area and then transferred to appropriate entries in the table.

When you read data from an internal table to work Area, the record is over written to the work Area and it is used in the program.

You can also access an internal table using field symbols. In this case you do not need to copy the data into a work area. You can assign a line of an internal table to a field symbol. Ideally, the field symbol will have the same type as the line type of the internal table. Once you have assigned the entry to the field symbol, working with the field symbol has exactly the same effect as accessing the corresponding line directly.

Regards,

Prema

Former Member
0 Kudos

Hi, thank for replying.

"Whereas if your itab contains only these three fields then ‘into table itab’ will work"

My isuues is --

the itab table only have 3 colomns, but their header line names are not the same as ODS table. So I still cannot send data to itab. Do you know their names?

Jenny.