Skip to Content

Dos and Don’ts in ABAP Webdynpro

  • Where to Store business logic?
  • How to simplify context reading / writing?
  • Use structure vs fields
  • Handle dropdown by key
  • Delete unwanted components

Where to Store business logic?

  • As beginners we do coding inside the respective controllers. We should be aware that it is wrong practice of coding . Webdynpro framework is based on  MVC (Model View Controller) architecture.
  • Model is the area to store the business logic which indicates separation of business logic and user view.
  • Assistance class represents the best example for model. We can put our business logic inside the assistance class and by attaching the assistance class , we can access those methods.
  • One more advantage would be reusability.

     WD1.jpg

  • This way we can use business routines again or even change / copy assistance class for another purpose.

  

•  Instead of specifying the methods in view as shown below,

   WD2.jpg

we could implement the assistance class and deploy methods through assistance class.

WD3.jpg

  • How to simplify context reading / writing?

      

  • About 60% or more of software costs is maintenance. The more code lines we have, the more maintenance costs are. Henceforth we need to reduce the lines of coding.
  • Mostly developers ignores the above fact by following standard way of generating code through code wizard.

         WD4.jpg

  • In real time applications, we need to build multiple views and each view has to read ‘n’ number of context and nodes. Rather using 14 lines of code to read the context and nodes, we can achieve the same in 2 lines of code as given below.

        WD5.jpg

  • This is achieved by integrating a helper class and using it to read the context.
  • We need to initialize the helper class in WDDOINIT method as given below.

        WD6.jpg

  •   Use structure vs fields

        

  • It is simpler to use complex structure instead of using individual fields.

        

   WD7.jpg

 

  • Without Structure, it took 15 lines and with structure the same will take only 3 lines as shown below.

       WD8.jpg

 

  • Handle dropdown by key

      

  • Experts advice not to use drop down by key. In unavoidable scenarios, we can handle the dropdown by key through optimization.
  • WD4A engines fills automatically the dropdown by key fields whose domain values are directly associated.
  • If domain values are not directly associated with the field, then WD4A does not fill dropdown by key field values automatically.
  • We have to call set_attribute_value_set of if_wd_context_node_info what we find by calling get_node_info

    WD9.jpg

  • We can further optimize the code by using helper class as given below.

     

WD10.jpg

  • Delete unwanted components

   

  • Delete the webdynpro components which are no longer required.
  • IF_wd_component_usage=>delete_component.
  • Unwanted nodes can be deactivated by using <node_name>->invalidate().

   

To report this post you need to login first.

1 Comment

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

Leave a Reply