Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

How to create a method with generic parameter?

0 Kudos

Hi, I would like to know if it is possible to create a method that accepts an importing parameter with a generic data type, the scenario is I need my method to accept a parameter with any "NUMERIC" data type be it integers, floats , quantities but no character types so that the developer doesnt have to create intermediate variables when calling my method he could just pass the variable from his program and the casting happens inside my method, is this possible? and if it is then how ?.

1 ACCEPTED SOLUTION

SuhaSaha
Advisor
Advisor
0 Kudos

the scenario is I need my method to accept a parameter with any "NUMERIC" data type be it integers, floats , quantities

ABAP has the generic type NUMERIC, you could have just typed NUMERIC.

Keep these points in mind while doing generic programming - http://help.sap.com/abapdocu_740/en/abentype_formal_param_guidl.htm.


iv_param TYPE REF TO data

So you think data reference will not accept character-like actual parameters.

BR,

Suhas

3 REPLIES 3

Former Member
0 Kudos

iv_param TYPE REF TO data

SuhaSaha
Advisor
Advisor
0 Kudos

the scenario is I need my method to accept a parameter with any "NUMERIC" data type be it integers, floats , quantities

ABAP has the generic type NUMERIC, you could have just typed NUMERIC.

Keep these points in mind while doing generic programming - http://help.sap.com/abapdocu_740/en/abentype_formal_param_guidl.htm.


iv_param TYPE REF TO data

So you think data reference will not accept character-like actual parameters.

BR,

Suhas

Abhijit74
Active Contributor
0 Kudos

Hello,

I think this is a good example for your requirement.

ABAP OO - Generic class for inserting, updating and deleting records.

Thanks & Regards,

Abhijit