14.01.2020 Views

ABAP_to_the_Future

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

10

ALV SALV Reporting Framework

or average—but in 14 years I’ve never needed any of those in a report, so I’ve left

my method set to use the default total va lue. (Now that I’ve said this, tomorrow

a business user will come to me and say he really needs a column with the minimum

value at the bottom.)

METHOD set_subtotal.

mo_aggregations = mo_alv_grid->get_aggregations( ).

TRY.

mo_aggregations->add_aggregation( columnname = id_field_name ).

CATCH cx_salv_not_found

cx_salv_data_error

cx_salv_existing.

"Raise Fatal Exception

ENDTRY.

ENDMETHOD.

Listing 10.15 SET_SUBTOTAL Method

You can also, of course, change the headin gs at the top of each column in the

report. You may find that when you do change the name of the column, you end

up changing the long, medium, and short texts to exactly the same string. You can

define separate methods for changing th e long, medium, and short texts in case

they need to be different, but if the value is constant (i.e., short), you can just pass

it in to the SET_LONG_TEXT method, and it changes all three values.

In Listing 10.16, you ‘ll see that if the string length is short enough, then the SET_

LONG_TEXT method copies the value to the medium text and to the short text

method, if it can. (The medium text and short text methods are not shown here,

but they follow the same principle.)

METHOD set_long_text.

* Local Variables

DATA: ld_medium_text TYPE scrtext_m,

ld_short_text TYPE scrtext_s.

TRY.

mo_column ?= mo_columns->get_column( id_field_name ).

mo_column->set_long_text( id_long_text ).

IF strlen( id_long_text ) LE 20.

ld_medium_text = id_long_text.

mo_column->set_medium_text( ld_medium_text ).

ENDIF.

432

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!