Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_014aUaQeLnwbb1zTpN7kHeat
52 lines
1.3 KiB
ABAP
52 lines
1.3 KiB
ABAP
FUNCTION {{p}}energy_bill
|
|
IMPORTING
|
|
iv_consumption TYPE decfloat34
|
|
iv_tariff TYPE string
|
|
iv_direct_debit TYPE abap_bool
|
|
EXPORTING
|
|
ev_bill TYPE decfloat34
|
|
EXCEPTIONS
|
|
invalid_consumption
|
|
invalid_tariff.
|
|
|
|
CONSTANTS lc_base_fee TYPE decfloat34 VALUE '12.00'.
|
|
CONSTANTS lc_tier_limit TYPE decfloat34 VALUE '300'.
|
|
CONSTANTS lc_tier_factor TYPE decfloat34 VALUE '0.8'.
|
|
CONSTANTS lc_debit_factor TYPE decfloat34 VALUE '0.98'.
|
|
|
|
IF iv_consumption < 0.
|
|
RAISE invalid_consumption.
|
|
ENDIF.
|
|
|
|
DATA lv_rate TYPE decfloat34.
|
|
CASE iv_tariff.
|
|
WHEN 'BASIC'.
|
|
lv_rate = '0.32'.
|
|
WHEN 'GREEN'.
|
|
lv_rate = '0.38'.
|
|
WHEN 'NIGHT'.
|
|
lv_rate = '0.24'.
|
|
WHEN OTHERS.
|
|
RAISE invalid_tariff.
|
|
ENDCASE.
|
|
|
|
DATA lv_standard_qty TYPE decfloat34.
|
|
DATA lv_reduced_qty TYPE decfloat34.
|
|
IF iv_consumption > lc_tier_limit.
|
|
lv_standard_qty = lc_tier_limit.
|
|
lv_reduced_qty = iv_consumption - lc_tier_limit.
|
|
ELSE.
|
|
lv_standard_qty = iv_consumption.
|
|
lv_reduced_qty = 0.
|
|
ENDIF.
|
|
|
|
DATA lv_bill TYPE decfloat34.
|
|
lv_bill = lc_base_fee + lv_standard_qty * lv_rate
|
|
+ lv_reduced_qty * lv_rate * lc_tier_factor.
|
|
IF iv_direct_debit = abap_true.
|
|
lv_bill = lv_bill * lc_debit_factor.
|
|
ENDIF.
|
|
|
|
ev_bill = round( val = lv_bill dec = 2 mode = cl_abap_math=>round_half_up ).
|
|
ENDFUNCTION.
|