Application Development and Automation 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: 
Read only

OOPs ABAP question (2)

Former Member
0 Likes
679

Hi all.

In this simple code example. I would like to know why this line of code generates an error.  CL_SALV_TABLE->DISPLAY( ).

************************************************

DATA : IT_MARA TYPE TABLE OF MARA.

DATA : LR_ALV  TYPE REF TO CL_SALV_TABLE.

SELECT * FROM MARA INTO TABLE IT_MARA UP TO 50 ROWS.

   CALL METHOD CL_SALV_TABLE=>FACTORY

     IMPORTING

       R_SALV_TABLE = LR_ALV

     CHANGING

       T_TABLE      = IT_MARA.

****  LR_ALV->DISPLAY( ).                "correct


   CL_SALV_TABLE->DISPLAY( ).      "error


********************************

Q : Isn't  the last statement similar to this one : CALL METHOD CL_SALV_TABLE->DISPLAY( )


which is similar to CALL METHOD CL_SALV_TABLE=>FACTORY ?


FACTORY & DISPALY are both methods of the class CL_SALV_TABLE, except that DISPLAY has no import or export parameters. why calling it,  is causing an issue ?


Thank you.






3 REPLIES 3
Read only

JK
Contributor
0 Likes
632

hi sami

the difference is:

CL_SALV_TABLE=>FACTORY is a STATIC Method, where

CL_SALV_TABLE->DISPLAY is a INSTANCE Method, so you cannot Access it over the Classname but you can use a REF TO variable (LR_ALV)

Read only

rosenberg_eitan
Active Contributor
0 Likes
632

Hi,

You are missing basic OO knowledge.

See here http://help.sap.com/abapdocu_740/en/abenabap_objects_oview.htm

Regards.

Read only

thokane
Explorer
632

Hi,

FACTORY is static method.

DISPLAY is instance method.

check the syntax for method call

http://help.sap.com/saphelp_nw70/helpdata/en/08/d27c03b81011d194f60000e8353423/content.htm