Application Development and Automation 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: 
Read only

How can i create a function

Former Member
0 Likes
1,187

Hi, i know my question seems weird but what i am asking about is NOT how to create function modules i know how to do that, the functions i mean are the ones like STRLEN() and TRUNC() functions that can be called directly without "CALL FUNCTION EXPORTING  something" can somebody tell me how to create functions like that in SAP?

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,152

An alternative could be to create static functional methods in a class, like z=>strlen( ).

6 REPLIES 6
Read only

former_member192854
Active Participant
0 Likes
1,152

You might consider using macro's?

But if things fail, you might add up with lot's of code which you can't debug.

So next best thing is to make a class with methods containing the commong functions you need. Or you might apply to SAP Labs to develop some new functionality :-).

Good luck!

Read only

former_member192854
Active Participant
0 Likes
1,152

Before I forget, you can also create global macro's within table TRMAC. But this is very very very dangerous, since it's able to mess up existing code which might change in how it works when regenerate (variables which contain parts of the global macros when activating them etc. etc.) If you have a real good idea for such a function, you better contact SAP.

As well as in the source code of a program, you can also store macros in the database table TRMAC, where they can be used by any program. The system first searches in the current program for a macro, and then in the table TRMAC. Do not define your own macros in TRMAC. One example of a macro in TRMAC is break, which sets a breakpoint in the system field sy-uname, depending on the current user name. 

Read only

Former Member
0 Likes
1,153

An alternative could be to create static functional methods in a class, like z=>strlen( ).

Read only

0 Likes
1,152

Manish,

Can you perhaps provide an example link?

Neal

Read only

0 Likes
1,152

This is what I meant to say:

Create global class with a short name, like Z.

Create functional method, that has receiving parameter. Something like cl_abap_typedescr=>describe_by_data( ).

If your class named Z has static function method named strlen( ) that accepts string and returns length, it can be invoked using lv_len = z=>strlen( lv_str ). This is close to

lv_len = strlen( lv_str ).

Read only

0 Likes
1,152

Its not exactly what i was looking for but it is as close as it gets and its much more code friendly than full function module calls specially if it is being used multiple times throughout the code, Thanks.