Skip to content

Instantly share code, notes, and snippets.

@furlan
Created June 24, 2012 12:51
Show Gist options
  • Save furlan/2983147 to your computer and use it in GitHub Desktop.
Save furlan/2983147 to your computer and use it in GitHub Desktop.
ZABAP101_RECURSION - with error
*&---------------------------------------------------------------------*
*& Report ZABAP101_RECURSION
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT zabap101_recursion.
*----------------------------------------------------------------------*
* CLASS lcl_math DEFINITION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS lcl_math DEFINITION.
PUBLIC SECTION.
METHODS execute_exponentiation
IMPORTING
base TYPE i
expoent TYPE i
RETURNING value(re_power) TYPE i.
PRIVATE SECTION.
DATA: interaction TYPE i.
ENDCLASS. "lcl_math DEFINITION
*----------------------------------------------------------------------*
* CLASS lcl_math IMPLEMENTATION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS lcl_math IMPLEMENTATION.
METHOD execute_exponentiation.
ADD 1 TO interaction.
IF interaction <= expoent.
re_power = re_power * me->execute_exponentiation( base = base
expoent = expoent ).
ELSE.
CLEAR interaction.
ENDIF.
ENDMETHOD. "execute_exponentiation
ENDCLASS. "lcl_math IMPLEMENTATION
DATA: r_exp TYPE REF TO lcl_math,
v_power TYPE i.
PARAMETERS: p_base TYPE i DEFAULT 2,
p_exp TYPE i DEFAULT 3.
INITIALIZATION.
CREATE OBJECT r_exp.
START-OF-SELECTION.
v_power = r_exp->execute_exponentiation( base = p_base
expoent = p_exp ).
WRITE: / 'Power: ', v_power.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment