Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

[ABAP-OO] How to create dynamically a Method for a class?

Hello everyone,

I would like to know, how to create a method dynamically for a class (in SE24) from a program?

I have checked this one out, but not working on SAP 7.40...

Thank you.


Former Member
Former Member replied

Hi Ibrahim,

you're welcome, thank for your help too.

"All in once" is the best, yes! But time-consuming. I have also seen that if you want to create a simple method very quickly, juste:

1) Create a ZCL_TEST1 Class and put that code in your CONSTRUCTOR:

METHOD constructor.

     DATA i_clsname    TYPE  seoclsname                          .

     DATA i_methodname TYPE  seocpdname                          .

     DATA i_tab_code   TYPE  siw_tab_code                        .

     DATA i_str_code   TYPE  siw_dte_code                        .

     DATA lv_uzeit     TYPE  syuzeit                             .

     i_clsname     = 'ZCL_TEST1'                                 . "An Existing Persistance Class!

     CONCATENATE 'METHOD_' sy-uzeit          INTO  i_methodname  .

* Implementation

     CONCATENATE 'METHOD ' i_methodname '.'  INTO  i_str_code

                                             SEPARATED BY space  .

     APPEND        i_str_code                TO    i_tab_code    .

     i_str_code    = 'WRITE ''Implementation TEST'' .'           .

     APPEND        i_str_code                TO    i_tab_code    .

     i_str_code    = 'ENDMETHOD.'                                .

     APPEND        i_str_code                TO    i_tab_code    .



         i_clsname    = i_clsname

         i_methodname = i_methodname

         I_TAB_CODE   = I_TAB_CODE.


2) Execute your class directly with F8 and make sure before, that you are in display mode. Get out of SE24 and go in again (to refresh ALV)...

This snippet creates quick methods without any parameters ...

Have a great day!


0 View this answer in context
Not what you were looking for? View more on this topic or Ask a question