6678 Readings
ABAP
SAP for 12 years
Posted by Yann MORINEAU
7 years ago
Modified 7 years ago


Licence Creative Commons Attribution - Pas d'Utilisation Commerciale - Pas de Modification 4.0 International.

Partager — copier, distribuer et communiquer le matériel par tous moyens et sous tous formats

Dynamic method call

The following code allows you to dynamically call a class method.

Class content

img

METHOD1 method is composed of a parameter PARAM1.

 

Selection screen

img

In this example, I want to call METHODE1 and pass it "la valeur de mon paramètre".

 

The BREAK-POINT

img

 

Parameter content

img

PARAM1 does contain the value of the parameter P_TEXT.

 

The parameters table content

img

 

The code

DATA : t_params        TYPE abap_parmbind_tab,
       l_params        TYPE abap_parmbind.

SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME.

  PARAMETERS p_method  TYPE text40.
  PARAMETERS p_text    TYPE string.

SELECTION-SCREEN END OF BLOCK b1.


INITIALIZATION.

  CLEAR : t_params, l_params.


START-OF-SELECTION.

* Inserting the parameters expected by the method

  l_params-name = 'PARAM1'.
  l_params-kind = cl_abap_objectdescr=>exporting.
  GET REFERENCE OF p_text INTO l_params-value.
  INSERT l_params INTO TABLE t_params.

* Method call

  CALL METHOD ZCL_MA_CLASS=>(p_method) PARAMETER-TABLE t_params.

 

From this simple code you can write more complex algorithms.

Have a good dev!

 

Advantages

  • You can easily debug the code by placing BREAK-POINT,
  • You can easily generate a local or server log file using logical files.

Pub

Sign in or Sign up to ask questions.

Latest tutorials from the same author

imgBPC

Déboguer un package

Astuce pour déboguer un package ...

Posted 6 years ago
Modified 6 years ago
6157
imgBPC

BPC BI and Source system

BPC Overview ...

Posted 6 years ago
Modified 6 years ago
6923
imgBPC

Vider le cache BPC

Vider le cache BPC avec UJA_REFRESH_DIM_CACHE ...

Posted 6 years ago
Modified 6 years ago
5277
imgBPC

BPC, BI et Système source

Vue d'ensemble de BPC ...

Posted 6 years ago
Modified 6 years ago
5966