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 Programmatically Create and Activate an ABAP Class

shreevathsa_s
Explorer
0 Kudos

Hi,

I have a requirement to programmatically create and activate an ABAP class that implements a 'pre-defined' interface.

Do you have any ideas how this can be done?

Thanks,

Shreevathsa S

1 REPLY 1

0 Kudos

Hi,

Try if GENRATE SUBROUTINE POOL keyword can be of your help.

See the below example,

DATA itab  TYPE TABLE OF string. 
DATA prog  TYPE string. 
DATA class TYPE string. 

APPEND `program.`                     TO itab. 
APPEND `class main definition.`       TO itab. 
APPEND `  public section.`            TO itab. 
APPEND `    class-methods meth.`      TO itab. 
APPEND `endclass.`                    TO itab. 
APPEND `class main implementation.`   TO itab. 
APPEND `  method meth.`               TO itab. 
APPEND `    message 'Test' type 'I'.` TO itab. 
APPEND `  endmethod.`                 TO itab. 
APPEND `endclass.`                    TO itab. 

GENERATE SUBROUTINE POOL itab NAME prog. 

CONCATENATE `\PROGRAM=` prog `\CLASS=MAIN` INTO class. 

CALL METHOD (class)=>meth.

Regards,

Sesh