This topic is the first one of a serie of articles coming soon, concerning a global approach of abap oriented-object in order to capitalize your development in a long term.

To introduce basically, often when we code a custom OO framework, this framework is only used for the current project. What do you think, if your framework can be more global, can grow up without any direct action by you and finally, can be usable for several projects and several clients?


That is why, it could be relevant to know that the creation of some methods dynamically is possible, in order to give more flexibility, more factorization, better evolution and artificial intelligence design of your framework. Let’s it begin…

After some investigations resulting in successful tests and obsolete codes found, I would like to share with you regarding my point of view, the best way to improve dynamically a class during the runtime, This snippet is based on the framework used by SAP for the version 740, including security and a minimum of lines of code.

Well, for this example, I will create a CLASS “ZCL_TEST1” that will create a method into the class “ZCL_TEST2” dynamically. The process is below:


1) Call a MF to create a method into the target class

2) Call a MF to include the implementation of the fresh method

3) Call a MF to regenerate the sections of the target class

4) Call the dynamic method of the target class


Here we go… 🙂


1) In SE24, create the class “ZCL_TEST2“. This class will see their own methods created through the “ZCL_TEST1“.


/wp-content/uploads/2015/08/2_766208.jpg

2) In SE24, create the class “ZCL_TEST1” and create a CONSTRUCTOR to simplify our example. This class will create method into the “ZCL_TEST2” class during the instantiation.


/wp-content/uploads/2015/08/2_766208.jpg


3) In the CONSTRUCTOR, you have to call 3 MF (complete source code in attachment) succinctly:

    1. ‘SEO_METHOD_CREATE’
    2. ‘SEO_METHOD_GENERATE_INCLUDE’
    3. ‘SEO_CLASS_GENERATE_SECTIONS’



3.1) Variables initialization


/wp-content/uploads/2015/08/2_766208.jpg


3.2) Call the right MF to create a method in the target class

/wp-content/uploads/2015/08/2_766208.jpg



3.2) Init & Call the right MF to create an implementation into the target class

/wp-content/uploads/2015/08/2_766208.jpg



3.3) Call the right MF to regenerate the sections of the target class (Private,Protected & Public Section)

/wp-content/uploads/2015/08/2_766208.jpg


(source code in attachment)


At this time, your class ZCL_TEST1 is able to interact onto the class ZCL_TEST2.


Finally, execute many times ZCL_TEST1 class locally with F8 and check out the result in ZCL_TEST2.


/wp-content/uploads/2015/08/2_766208.jpg

/wp-content/uploads/2015/08/2_766208.jpg



That is done!



For the next topic, I will enjoy to share with you in which context this kind of development can be useful and how is it exciting to enhance your custom framework including several design patterns, in order to improve dynamically your architectural layers during the runtime.

The final goal will be to decrease your lines code, increase the reusability, be able to call generic methods that do not exist yet during your writing code and at the same time, thinking about how can you grow up your custom framework by adding these generic methods freshly created throughout your miscellanous projects.



To report this post you need to login first.

2 Comments

You must be Logged on to comment or reply to a post.

  1. Ebrahim Hatem

    Hi,

    thank you for sharing, it is really interesting. 

    I  have  in the beginning tried this one SEO_METHOD_CREATE_F_DATA, and other FMs, but I could not create a dynamic method on SAP 740.

    Anyhow, thank you 🙂

    (0) 
  2. Steve Mo

    Hi Rachid,

    Really great posting.

    I am also looking for dynamic programming to generate the code which generating code… 😉

    And do you have considered that adding the created object to transport request? This should also be a mandatory requirement if you want to transport code from D to P system, right?

    Looking forward to your great remaining posting of this series 🙂 .

    BR,

    Steve

    (0) 

Leave a Reply