ABAP Objects Case Study – Usage for More Design Flexibility

By | February 13, 2013 | ABAP Objects, Case Study | 3,018 | 22

How object oriented designs was beneficial to me as well as my clients while enhancing development created in Object Oriented ABAP.

I have been fan of object oriented design and trying to use them where ever I can for a long time now. Today I will walk you through one of development which I initially developed in OO ABAP and let on was able to extend that very easily.

Initial Requirements

I developed a shop floor cockpit. This involved few screens and functionality of issuing components for serialized build and for non serialized build as well. Cockpit also allowed to confirm the operations. At last when all operations are confirmed, good receipt should take place.

Shop floor is integral part of Production Planning where raw materials are consumed (e.g. circuit boards, screens, software) to build a finished goods (iPhone, iPad, Cell Phone, Laptop, etc.). Operator on Shop floor performs operations in the sequence. Raw components are consumed based on the operations. Once FG is built, checked (QA) and tested ok, it would be issued to a different location (e.g. warehouse) to ship to Customers.

Initial Design

To implement this requirement, I created basically four classes:

  • Static class with all methods for BAPI calls
  • Order details class
  • Operation class
  • Serial number class

Order class would have many serial numbers and serial number would have many operations. Serial number is the inital class which would get instantiated. Based on this fact I have created my classes which are designed as per this UML:

Initial UML design for the OO ABAP development

When ever a SN is entered a new object for order and serial number would be instantiated. Based on completed Operations and current operation to be performed, SN would have Operation objects.

New Requirements

After this the new requirement came in to create another version of cockpit which would be used by SME to correct components, cancel operations, display all operations and so on.

The new version of the UML looks something similar to this:

Redesigned UML for new requirement in OO ABAP

Example operation cancellation

To achieve this it was so easy. I inherited a sub class for all of my existing classes. This gave me default access to all attributes of those classes. I had used Singleton Design Pattern. I changed the method GET_DATA to give me instance of the object based on the transaction type.

I added another method in the class operation to do the cancellation. I left the blank implementation. I redefined this method in the class for SME. This allowed me the flexibility to call this method without thinking which transaction is running.

Conclusion

When I started building the design blocks for this it was definitely challenging. I could have used FM based approach but I decided to use OO ABAP as I have been doing always. This gave me great degree of flexibility as well as I was able to minimize the impact on existing design.

I would always suggest you to leverage OO ABAP where ever you can. You never know what is in future for that development. Whoever would be touching that again would definitely appreciate all your efforts. I guarantee :)

More from Case Studies

Learn more from the Case Studies on OO ABAP and other technique usage:

Like It? Share!!

Don't miss an Update

Naimesh Patel{244 articles}

I'm SAP ABAP Consultant for more than a decade. I like to experiment with ABAP especially OO. I have been SDN Top Contributor.
Follow :

Explore all of his 244 articles.

Load comments

22 Comments

  • Hi Naimesh,
    I am just doing exactly the same. An Interface with one base and a derivation for each subsidiary. Special checks and anomalies for some countries can be coded in their derivation. Very neat structure… ;)
    This programming construct might be difficult if you do not start with tweo or more derivations at once. If the design is quite complex you will need some checks or “hooks” where you did not think of at the beginning.
    Changing the base structure afterwards can be dangerous as this will influence the productive coding.
    Nevertheless a great possibility of ABAP OO.

  • Steve Oldner

    I am having to add buttons to a POWL screen. One SAP employee guy suggested (there is no direct way to add custom buttons) I subclass CL_IBO_INBOX_FEEDER_WI and override certain methods, or create my own feeder class.

    What does subclass mean?

    Keep up the good work! Old dogs must learn new tricks so they can eat…
    .

  • Krishna

    Hi Naimesh,

    I always follow your blogs on regular basis
    Thanks .
    KB
    @ Steve
    We can add custom button in the POWL .Did it in SNC .
    Check the link.
    http://scn.sap.com/people/naveen.bathini/blog/2011/05/09/adding-a-custom-button-and-custom-functionality-in-po-worklist-screen-of-supply-network-collaboration#comment-318893

  • Hello Enno,

    Yes, that’s the way to go. Its a basic step while designing the application itself. If we follow design patterns and principles, the maintenance would be lot easier. I know there is only one Design Principle on Zevolving so far and I need to cover more :)

    I agree with you that it would be easy design such an application when you have more than one deviation in your requirement. But, if you don’t have any deviation, you should still try to assume a deviation and implement the OO ABAP as much as possible with flexibility. One can assume a arbitrary scenario alongwith the requirements to try to give enough hooks and methods which can be redefined / implemented.

    Regards,
    Naimesh Patel

  • Hello Steve,

    That is what Subclass is supposed to do. To provide specific functionality than the Super does.

    Regards,
    Naimesh Patel

  • Hello Krishna,

    I’m glad that you like following my posts. Keep visiting & spreading the word.

    Regards,
    Naimesh Patel

  • Steve Oldner

    @ Krishna – thanks for the link. I saw that before, which gave me hope we can do it in HR.

    @ Naimesh – I have followed you for several years, but not had to do any OO coding, or rather, my QC reviewers suggested not to. Last few months I’ve been coding using OO just to get the feel of it. I think I’m at the level to start to understand what you all are talking about! Thank you for the blog!

  • Hello Steve,

    Its so nice of you that you’re sticking with me from a long time.

    Why your QA reviewers don’t like to use OO ABAP? Is there any specific reason? I want to understand what is point of view here on not to use OO ABAP.

    For my current client, I do the QA reviews and I encourage everyone to leverage as much as of OO ABAP as it has many more advantages over the procedural ABAP.

    Regards,
    Naimesh Patel

  • Steve Oldner

    Hi Naimesh,

    They say is adds another layer on top of the ABAP and is hard for the other coders to modify or to follow. Most of our ABAPPERs came from COBOL, so this is a issue.

    Regards,

    Steve

  • Nabheet

    Awesome blog…Well done Naimesh..your blogs have been the source of motivation for me to switch to objects from procedural…pls keep up the good work.

    Nabheet

  • Hello Nabheet,

    I’m glad that you move towards using ABAP Objects from Procedural ABAP.

    Regards,
    Naimesh Patel

  • steve oldner

    I have been building and using functional method calls for many of the ‘text’ we using in the ALVs. Example, Cost center text from cskt.

    alv_rec-ltext = gr_get_txt->for_kostl( i_kostl = alv_rec-kostl i_date = l_date ). These little functions are read handy and beats the traditional function module or form call.

  • Hello Steve,

    That’s way to go : All those objects are already being reused – one of the basic advantage of using ABAP Objects. Keep it up.

    Regards,
    Naimesh Patel

  • Wouter

    I’m very fond of creating ‘utility’ classes for everything. For email functionality, sd specific actions, … . But I’m having trouble deciding when to use instance oo and static oo. I always use static oo aka utility classes.

  • steve oldner

    @Wouter

    Good question – I enjoy creating and using my utility classes also! Maybe this can be a topic for another blog post.

  • Hello Wouter / Steve,

    While using the Static methods, we may lose some of the basic OO ABAP advantages like Polymorphism.

    Indeed this is the food for an article. I already started putting it together, it should be out soon.

    Thanks,
    Naimesh Patel

  • steve oldner

    Just doing one now.

    Naimesh, for the article, would you opine on whether parameters should pass value or not? I seem to remember where pass by value was recommended but not as to why or if that is still true.

    I’m looking forward to the articel!

  • Wouter

    Correct about Polymorphism, exactly my issue.

    Imagine the business wants to keep records in a Z table and maintain these from all sorts of places:
    - Create 1 static utility class with a create method, an update method for each status ( approved, not approved, waiting ), some other methods which retrieve statusses of SAP documents or do some sort of flows.

    In my opinion I would create an utility class for this, but what if the business decides, that for some sort of scenario (other country or whatever ) they need a create somewhat different, the description is retrieved from another sales order item, or whatever. This would resort (in my eyes) into either:
    - Duplicating the application into a seperate one specifically for that country
    - Forking the application

    But, to take this possibility in mind, is it worth creating an instance class for this?
    There is not advantage in creating an instance class and doing
    lo_instance->create( )
    these kind of methods while not keeping any data in the instance attributes?

    I would think if you use an instance class, you need to keep everything in instance attributes for it to make sence.

  • @Wouter:
    In this case a dynamically call different methods within the tools class.
    For example: Different plant determination for different sales organizations:
    GET_PLANT( 1000 ) =>
    call GET_PLANT_1000 and so on.

  • Wouter

    I see, agreed this is a good option. But not as clean as an instance class with a factory method, and let the factory decide which class to create, for example according to the companycode or country
    - ZCL_FLOW
    – ZCL_FLOW_BELGIUM
    – ZCL_FLOW_USA

    lo_flow->do_something( ).

    And redefine methods where nescecary. Which is sooo clean

  • Hello Wouter,

    But, to take this possibility in mind, is it worth creating an instance class for this?
    - I say, yes. We should go for Instance methods for the scenario which you have mentioned.

    One more advantage is: You can have more than one instance of objects which would have there own attributes. E.g. An Application Log generator utility – If you design it with Static, you can only use ONE time in your application. If you have to generate another Application log in the same session to track a different event or something, you wont be able to use it. I faced the very same issue when earlier designer designed it with static.

    I would capture this in the upcoming article on Static.

    @Enno
    Yes, we can use the technique, but as Wouter suggested, it wont be clean anymore. Abstract Factory would be the answer to that case.

    Thanks much guys for the discussion.

    Regards,
    Naimesh Patel

  • Hello Enno, Wouter & Steve,

    I know you guys would already know about the post on Static Vs Instance – Which to use When? , but just wanted to track it here for others benefit.

    Thanks,
    Naimesh Patel

Comments on this Post are now closed. If you have something important to share, you can always contact me.