09-11-2007 5:46 AM
Hi abapers,
I am working object oriented abap and i need a small example of ,how to use
export and changing parameter of a method.
Can anyone help me regarding this
sanjay
09-11-2007 5:51 AM
Hi,
Check standard program <b>demo_abap_objects_methods</b>.
Regards,
Sesh
09-11-2007 6:05 AM
See the below code. Hope it will be helpful.
<code>
REPORT zexp1 .
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 .
</code>
The program contains a method TAX_CALC belonging to the class CTAX. It receives GRADE as IMPORTING parameter and SALARY as CHANGING parameter. Based on the grade, the EXPORTING parameter ITAX is calculated and the CHANGING parameter , SALARY is modified by deducting tax from it.
reward if you find it helpful.
Thanks & Regards,
Rajesh