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: 

ALV OOPS - simple class vs super class

divsmart
Participant
0 Kudos

Hi Guys,

I am new to ABAP OOPS , i wrote an sample code which need to display an employee details.

Here i need to display the method 'display_no_of_employees' ie., (if we display 2 emplyee 'Number of emplye = 2' and so on).

But i am unable to display the method as an output. what mistake as i doing?

Coding:

  • source.txt
  • 11 REPLIES 11

    FredericGirod
    Active Contributor

    You will have litle clearing to do at first.

    1. CLASS-METHODS <-- NO ! only for SingleTon design pattern

    2. CLASS-DATA <-- Why ?!

    3. CALL METHOD my_class->my-method <-- NO! my_class->my_method( ).

    4. WRITE in CLASS <-- No, for test you could use CL_DEMO_OUTPUT (https://blogs.sap.com/2016/05/10/cldemooutput-part-1-of-2-usage/)

    5. CREATE OBJECT my_object <-- No my_object = new #( ... ).

    michael_piesche
    Active Contributor
    0 Kudos

    Currently you try to call your 'class-method' through an instance. Which works, but only if the object is also instantiated.

    CALL METHOD g_employee3->display_no_of_employees.

    The right way to call a class method would be to call it from the class lvl:

    CALL METHOD lvl=>display_no_of_employees.

    PS: I am not commenting on your style, just on the functionality you are trying to achieve.

    michael.piesche, I am so disapointed, I thought you follow Clean Code Best Practice ...

    😉

    frdric.girod, you got me ;)

    This time I just wanted to focus on the issue and tried not to overwhelm with other things that could be done better and stick with the users logic.

    But you actually hit the nail on the head. Even though I have „studied“ the "Clean ABAP Cheat Sheet" as well as the styleguides from https://github.com/SAP/styleguides, my coding still is very influenced by the Hungarian notation.

    I promise to do better in the future.

    Thanks for pointing that out!

    😉

    We are watching you. 😉

    0 Kudos

    matthew.billingham, you have been noticed too. I am happy to work with you as well ... well sort of work and somewhat with but still very well. 'Hats off.' 😉

    0 Kudos
    michael.piesche

    Thanks for your quick response, i have acccess the method as below...

    CALL METHOD g_employee2->display_no_of_employees. this is correct way.

    ---------------------------------------------------------------------------------------------------------------------------------

    Another way as below (Method was in static need to access through both object as well class).

    Yes, this way i got the O/P * CALL METHOD lvl=>display_no_of_employees*.

    0 Kudos

    divsmart, so is your problem solved or can you be more specific on your issue? Can you show what is wrongly or not happening and what instead should be correctly happening?

    >> But i am unable to display the method as an output. what mistake as i doing?

    matt
    Active Contributor

    This is nothing to do with super classes. Nor ALV. Your question title should accurately reflect what your question is actually about.

    divsmart
    Participant
    0 Kudos

    frdric.girod

    i now the concept of instance method as well static method using (constructor). Here i was struugged on output..

    FredericGirod
    Active Contributor
    0 Kudos
    divsmart CL_DEMO_OUTPUT->display( ... ).