1. Report with static and class method execution
REPORT TEST_CALC.
TYPES:
RES TYPE P DECIMALS 4.
*Class definition
CLASS CCALC DEFINITION.
PUBLIC SECTION.
*Class methods
METHODS ADD IMPORTING VALUE(CI1) TYPE I VALUE(CI2) TYPE I RETURNING VALUE(CRESULT) TYPE RES.
METHODS SUBSTRACT IMPORTING VALUE(CI1) TYPE I VALUE(CI2) TYPE I RETURNING VALUE(CRESULT) TYPE RES.
*Static methods
CLASS-METHODS POWER IMPORTING VALUE(CI1) TYPE I VALUE(CTO2) TYPE I RETURNING VALUE(CRESULT) TYPE RES.
PRIVATE SECTION.
ENDCLASS.
*Class implementation
CLASS CCALC IMPLEMENTATION.
METHOD ADD.
CRESULT = CI1 + CI2.
ENDMETHOD.
METHOD SUBSTRACT.
CRESULT = CI1 - CI2.
ENDMETHOD.
METHOD POWER.
CRESULT = 1.
DO CTO2 TIMES.
CRESULT = CRESULT * CI1.
ENDDO.
ENDMETHOD.
ENDCLASS.
PARAMETERS:
I1 TYPE I,
I2 TYPE I.
DATA:
RESULT TYPE P DECIMALS 4,
OCALC TYPE REF TO CCALC.
START-OF-SELECTION.
*Static method execution example
RESULT = CCALC=>POWER( EXPORTING CI1 = I1 CTO2 = I2 ).
WRITE: 'POWER result: ' , RESULT.
* Class method execution example with object creation
CREATE OBJECT OCALC.
RESULT = OCALC->ADD( EXPORTING CI1 = I1 CI2 = I2 ).
WRITE: 'ADD result: ' , RESULT.
RESULT = OCALC->SUBSTRACT( EXPORTING CI1 = I1 CI2 = I2 ).
WRITE : 'SUBSTRACT result: ' , RESULT.
2. Selection screen
3. In order to add description to parameters I1 and I2 go to: Go to->Text element->Selection text4. Result screen
No comments:
Post a Comment