Google Search - Blog...........

ABAP - Use Of Export & Changing Parameters Of A Method - OOPS Concept.

REPORT YSUBDEL .

DATA : w_tax type p decimals 2 ,
w_salary type p decimals 2 .

CLASS CTAX DEFINITION.
PUBLIC SECTION.
METHODS : TAX_CALC IMPORTING grade TYPE C
EXPORTING itax TYPE P
CHANGING salary TYPE P .
ENDCLASS.

CLASS CTAX IMPLEMENTATION.
METHOD : TAX_CALC.
CASE grade.
WHEN 'A01'.
itax = salary * '0.2'.
WHEN 'A02'.
itax = salary * '0.1'.
WHEN OTHERS.
itax = salary * '0.15'.
ENDCASE.
salary = salary - itax.
ENDMETHOD.
ENDCLASS.


START-OF-SELECTION.
DATA : OREF1 TYPE REF TO CTAX.
CREATE OBJECT : OREF1.
w_salary = 30000.
w_tax = 0 .
write:/5 'Before method call, salary and tax are' ,
w_salary ,
w_tax .
CALL METHOD OREF1->TAX_CALC EXPORTING grade = 'A01'
IMPORTING itax = w_tax
CHANGING salary = w_salary.
write:/5 'After method call, salary and tax are' ,
w_salary ,
w_tax .


Output Before method call, salary and tax are 30,000.00 0.00
After method call, salary and tax are 24,000.00 6,000.00

No comments:

Post a Comment