CLASS {{p}}shred_pricer DEFINITION PUBLIC FINAL CREATE PUBLIC. PUBLIC SECTION. TYPES ty_size TYPE i. TYPES ty_service TYPE c LENGTH 1. TYPES ty_price TYPE p LENGTH 8 DECIMALS 2. CONSTANTS: BEGIN OF c_size, small TYPE ty_size VALUE 60, large TYPE ty_size VALUE 240, END OF c_size. CONSTANTS: BEGIN OF c_service, plant TYPE ty_service VALUE 'P', onsite TYPE ty_service VALUE 'O', END OF c_service. METHODS calculate_price IMPORTING iv_boxes TYPE i iv_size TYPE ty_size iv_service TYPE ty_service iv_express TYPE abap_bool iv_contract TYPE abap_bool RETURNING VALUE(rv_price) TYPE ty_price. ENDCLASS. CLASS {{p}}shred_pricer IMPLEMENTATION. METHOD calculate_price. DATA: lv_base TYPE ty_price, lv_total TYPE ty_price, lv_min TYPE ty_price, lv_factor TYPE ty_price. rv_price = 0. * no boxes, no price IF iv_boxes <= 0. RETURN. ENDIF. * price of one box IF iv_size = 60. lv_base = '8.00'. ELSE. IF iv_size = 120. lv_base = '12.00'. ELSE. IF iv_size = 240. lv_base = '18.00'. ELSE. lv_base = '12.00'. ENDIF. ENDIF. ENDIF. * on site shredding costs more IF iv_service = 'O'. lv_base = lv_base + '3.50'. ENDIF. * add one box after the other lv_total = 0. DO iv_boxes TIMES. lv_total = lv_total + lv_base. ENDDO. * discount for many boxes IF iv_boxes >= 25. lv_factor = '0.90'. ELSE. IF iv_boxes >= 10. lv_factor = '0.95'. ELSE. lv_factor = '1.00'. ENDIF. ENDIF. lv_total = lv_total * lv_factor. * contract customers get a discount IF iv_contract = 'X'. lv_total = lv_total * '0.90'. ENDIF. * express service costs more IF iv_express = 'X'. lv_total = lv_total * '1.20'. ENDIF. * minimum charge IF iv_service = 'O'. lv_min = '60.00'. ELSE. lv_min = '35.00'. ENDIF. IF lv_total < lv_min. lv_total = lv_min. ENDIF. rv_price = lv_total. ENDMETHOD. ENDCLASS.