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.

Enhancing Custom Reports with ABAP2XLSX 11.2

DATA: ls_iconset3 TYPE zexcel_conditional_iconset,

ld_number_as_string TYPE string.

"Green if below 7 days

ls_iconset3-cfvo1_type = zcl_excel_style_conditional=>c_cfvo_type_

number.

ls_iconset3-cfvo1_value = '-9999'.”What on Earth???

"Red if above 14 days

ls_iconset3-cfvo2_type = zcl_excel_style_conditional=>c_cfvo_type_

number.

ld_number_as_string = 14.

ld_number_as_string = '-' && ld_number_as_string.

CONDENSE ld_number_as_string.

ls_iconset3-cfvo2_value = ld_number_as_string.

"Yellow otherwise

ls_iconset3-cfvo3_type = zcl_excel_style_conditional=>c_cfvo_type_

number.

ld_number_as_string = 7.

ld_number_as_string = '-' && ld_number_as_string.

CONDENSE ld_number_as_string.

ls_iconset3-cfvo3_value = ld_number_as_string.

"Show the value as well as the ICON

ls_iconset3-showvalue = zcl_excel_style_conditional=>c_showvalue_

true.

lo_style_conditional = lo_worksheet->add_new_conditional_style( ).

"We are going to show ICONS

lo_style_conditional->rule = zcl_excel_style_conditional=>c_rule_

iconset.

lo_style_conditional->priority = 1.

"The ICONS are going to look like Traffic Lights

ls_iconset3-iconset = zcl_excel_style_conditional=>c_iconset_

3trafficlights.

lo_style_conditional->mode_iconset = ls_iconset3.

lo_style_conditional->set_range(

ip_start_column = lc_age_column

ip_start_row = ld_first_data_row

ip_stop_column = lc_age_column

ip_stop_row = ld_last_data_row ).

Listing 11.20 Conditional Formatting with Traffic Lights

When looking at Listing 11.20, which c overs the conditional formatting for the

traffic lights, you may well be puzzled as to what the -9999 value is doing. The

problem is that in standard Excel the green traffic light always relates to the highest

value. If a high value is bad, then you have to multiply all your values by

minus one. However, you do not want th e value to appear as negative on the

spreadsheet, so in your internal table you can multiply the value by minus one

just before converting it to an Excel object and then change the formatting (Listing

11.21) so that the negative figure looks positive.

481

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

Saved successfully!

Ooh no, something went wrong!