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

ALV Reports using Abap Objects ?

Former Member
0 Likes
720

<b>Hi All,

I am trying to print the values in my internal table using ALV, using ABAP classes and objects. Here i am able to get the total succesfully. but i need to get subtotals also, like based on the carrid in table sflight i need subtotal of price for every carrid like 'LH' , 'SQ'.

here is my code:</b>

REPORT znav_report.

DATA: alv TYPE REF TO cl_salv_table,

value1 TYPE REF TO cl_salv_aggregations,

value2 TYPE REF TO cl_salv_aggregation.

DATA: BEGIN OF itab_flight OCCURS 0,

carrid LIKE sflight-carrid,

connid LIKE sflight-connid,

fldate LIKE sflight-fldate,

price LIKE sflight-price,

paymentsum LIKE sflight-paymentsum,

currency LIKE sflight-currency,

END OF itab_flight.

SELECT carrid

connid

fldate

price

paymentsum

currency

FROM sflight INTO TABLE itab_flight

WHERE carrid = 'LH' OR carrid = 'SQ'.

cl_salv_table=>factory( IMPORTING r_salv_table = alv

CHANGING t_table = itab_flight[] ).

CALL METHOD alv->get_aggregations

RECEIVING

value = value1.

CALL METHOD value1->add_aggregation

EXPORTING

columnname = 'PAYMENTSUM'

aggregation = if_salv_c_aggregation=>total

RECEIVING

value = value2.

alv->display( ).

<b>here how to get subtotals for every different carrid.

regards,

Navneeth.K</b>

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
674

Hi Navaneeth,

Here i modify your program for explanation .

here i am giving the code part Please go through it .

i think it will answer your question.

DATA: alv TYPE REF TO cl_salv_table,

value1 TYPE REF TO cl_salv_aggregations.

data: itab_flight type table of sflight.

data: gr_sorts type ref to cl_salv_sorts.

data: gr_agg type ref to cl_salv_aggregations.

start-of-selection.

select * into table itab_flight from sflight.

cl_salv_table=>factory( IMPORTING r_salv_table = alv

CHANGING t_table = itab_flight[] ).

CALL METHOD alv->get_aggregations

RECEIVING

value = value1.

gr_sorts = alv->get_sorts( ).

gr_sorts->add_sort( columnname = 'CARRID' subtotal = abap_true ).

value1->add_aggregation( 'PAYMENTSUM' ).

alv->display( ).

Let me know .

Thanks.

Uma.

4 REPLIES 4
Read only

Former Member
0 Likes
675

Hi Navaneeth,

Here i modify your program for explanation .

here i am giving the code part Please go through it .

i think it will answer your question.

DATA: alv TYPE REF TO cl_salv_table,

value1 TYPE REF TO cl_salv_aggregations.

data: itab_flight type table of sflight.

data: gr_sorts type ref to cl_salv_sorts.

data: gr_agg type ref to cl_salv_aggregations.

start-of-selection.

select * into table itab_flight from sflight.

cl_salv_table=>factory( IMPORTING r_salv_table = alv

CHANGING t_table = itab_flight[] ).

CALL METHOD alv->get_aggregations

RECEIVING

value = value1.

gr_sorts = alv->get_sorts( ).

gr_sorts->add_sort( columnname = 'CARRID' subtotal = abap_true ).

value1->add_aggregation( 'PAYMENTSUM' ).

alv->display( ).

Let me know .

Thanks.

Uma.

Read only

0 Likes
674

Hi Uma,

There is one place in your code where I am getting stuck up.

If in your code I change the structure of the table to be comprisinf some fields say:

data : begin of itab_flight occurs 0,

carrid type sflight-carrid,

connid type sflight-connid,

fldate type sflight-fldate,

price type sflight-price,

currency type sflight-currency,

planetype type sflight-planetype,

end of itab_flight.

Then, when I perform a select query, say as below,

select carrid connid fldate price currency planetype into corresponding fields of table itab_flight from sflight.

It gives me a dump.

Can you figure this out?

Read only

0 Likes
674

Hi,

Make use of one of these statement,,,,

<b>Either</b>

<b>(a)</b> select carrid connid fldate price currency planetype into table itab_flight from sflight.

<b>or</b>

<b>(b)</b> select * into corresponding fields of table itab_flight from sflight.

<b>(a)</b> is better in performace than<b> (b)</b>

<b>But before that, please note some performance related issues with OO Context...</b>

1. When defining an Internal table, avoid occurs specification, It is Obsolete,Make use of Initial Size n.

2. Declare Workarea separately,since Internal table defined along with header line is Obsolete in OO Context.Its better and more robust to fill the itab and fetch the values from itab using a separate Workarea rather than the header line... So avoid header lines...

3. When defining an internal table, follow this way ....

Define a Linetype (Field String) using the TYPES Statement

TYPES: begin of ty_line,

f1 type i,

f2 type i,

end of ty_line.

Then define a Table type using TYPES Statement...

TYPES: ty_lines type standard table of ty_line with default key.

"there is differnnce between line and lines..... make it clear..."

Then after, define the internal table and its work area using DATA statement... as shown below..

DATA: i_lines type ty_lines,

wa_lines like line of i_lines

<b>This is the standard way of defining the internal table under OO Context.,,..

Your definition is creating a default header line....that should be avoided...</b>

Thanks for ur patience,

Regards..

Mohammed Anwar..

Read only

Former Member
0 Likes
674