06-03-2011 8:56 PM
data: g_dock type ref to cl_gui_docking_container,
g_split type ref to cl_gui_easy_splitting_container,
g_cont type ref to cl_gui_container.
create object g_dock " this is a constructor
exporting
*side = cl_gui_docking_container=>dock_at_top* ..... "pls explain this syntax in general
extension = 200.
'dock_at_top' is a constant in the attributes component of the class 'cl_gui_docking_container'.
1.) we are already creating an instance of this class as 'g_dock'.
so instead of writing 'g_dock -> dock_at_top', why are we using ' clgui_docking_container=>dock_at_top_ '. pls explain this.
2.) pls clarify 1 thing ....the syntax ...
"create object g_dock
exporting
......... "
it is a constructor method, so why are we writing 'cl_gui_docking_container=>dock_at_top' instead of writing only 'dock_at_top'
pls help.
detailed answers will be appreciated, thnks in adv
06-06-2011 11:05 AM
Clarification,
By saying
CREATE OBJECT <object_name>
EXPORTING
<par1> = <val>
<par2> = <val>
What we are doing here is instanciate an object and send the constructor values that it is expecting on the constructor's import section, if we did not have paramaters expected on the constructor of class
cl_gui_docking_container
,
we would just say
CREATE OBJECT <object_name>
*as for *
cl_gui_docking_container=>dock_at_top
You could just have
DOCK_AT_TOP
alone if you want, but, yes there is a but!
It will come back to bite you, why,
class components are defined in terms of a given class
and most probably donu2019t have a lot of meaning outside of their defining classu2019s context. To avoid this kind of confusion, it is recommended that you always address class components by applying the class component selector to the defining
classu2019s name. Therefore,
cl_gui_docking_container=>dock_at_top
instead of just
dock_at_top
That way, your intentions are always clear.
I hope this makes sence.
06-03-2011 10:01 PM
Hello
Within an instance of the docking container class itself the constant DOCK_AT_TOP is known.
The piece of coding is presumably within the CONSTRUCTOR method of a (any) Z-class. Therefore, the constant DOCK_AT_TOP must be references as part of its class, i.e. CL_GUI_DOCKING_CONTAINER=>DOCK_AT_TOP.
Regards
Uwe
06-03-2011 11:24 PM
i am new to oo abap, so kindly elaborate pls....
constructors are called by the system whenever an object instance to a class is created, so why are we needing this class reference ( side = cl_gui_docking_container => dock_at_top ) here ?
06-04-2011 7:41 AM
cl_gui_docking_container => dock_at_top is a constant. It has a value. It doesn't matter what the value is, but lets say that, for the sake of example, it's 3. Now, which is more meaningful?
create object g_dock " this is a constructor
exporting
side = 3
or
create object g_dock " this is a constructor
exporting
side = cl_gui_docking_container=>dock_at_top
06-04-2011 7:43 AM
This is beacuse your object reference g_dock will be instantiated (in client program) only AFTER exection of CREATE OBJECT statement, not during this statement. So later on you will indeed be able to access this constant the way you are trying, but BEFORE that this is not possible as object reference at that time is "pointing" to nothing. That's why you need to use class name in order to address constants.
One more reason and I think good practise is that all static or constant attributes should be accessed in this manner. This uniform notation provides a clear view for someone who doesn't know your code what are you in fact addressing. By using object reference it is ambigous whether underneath you access an instance/static/constant one.
Regards
Marcin
06-04-2011 7:46 AM
Because it is a must have property for the instance. However it could be optional since you give a default value for the property.
06-05-2011 6:57 AM
THNK U ALL..
pls clear this doubt..
when i create the object instance for the very first time..the constant appears as 'dock_at_left' by default.
data: g_dock type ref to cl_gui_docking_container,
g_split type ref to cl_gui_easy_splitting_container,
g_cont type ref to cl_gui_container.
create object g_dock " this is a constructor
exporting
*side = dock_at_left* ..."this comes as default
extension = 200.
but since i know that its a constant i write it as
side = cl_gui_docking_container=>dock_at_top
but since i am new to oo abap, i am unfamiliar to most of the class and its components, then how will i come to know dat where the coding will get changed similarly .
06-05-2011 9:33 AM
but since i am new to oo abap, i am unfamiliar to most of the class and its components, then how will i come to know dat where the coding will get changed similarly .
- by reading papers, articles, blogs
- by searching the forum
- by reviewing sources of SAP tutorial programs
- by reviewing different classes
- by gaining experience
Regards
Marcin
06-06-2011 12:23 PM
Hi Akash,
The replies to your question are good, in case you are not clear, let me try my bit
1.) we are already creating an instance of this class as 'g_dock'.
so instead of writing 'g_dock -> dock_at_top', why are we using ' clgui_docking_container=>dock_at_top_ '. pls explain this.
You mean to say something like this,
data: g_dock type ref to cl_gui_docking_container,
g_split type ref to cl_gui_easy_splitting_container,
g_cont type ref to cl_gui_container.
create object g_dock " this is a constructor
exporting
*side = g_dock=>dock_at_top* ..... "pls explain this syntax in general
extension = 200.
Well, as Marcin said object G_DOCK is not yet created at this point, so it is not possible to get a reference to any of it's attributes(constant/static/instance), when you try to compile the above code it will throw a compile error that g_dock=>dock_at_top is not known. Now if your question is how "cl_gui_docking_container=>dock_at_top" is valid syntax, the compiler checks if the global class "cl_gui_docking_container" exists and if yes, then checks for a constant attribute "DOCK_AT_TOP" within it.
2.) pls clarify 1 thing ....the syntax ...
"create object g_dock
exporting
......... "
it is a constructor method, so why are we writing 'cl_gui_docking_container=>dock_at_top' instead of writing only 'dock_at_top'
Again, "DOCK_AT_TOP" doesn't have any existence on its own, an attribute irrespective of whether it is constant/static/instance...will always be accessed via it's class reference, and again you cannot use g_dock until it's instance has been created already, not while creating it's instance.
Not sure if i understood your doubt in the above post, the parameter SIDE of the constructor let's you choose where do you want the container to show up top, left, bottom etc...by default it will be left, so if you do not pass anything to the parameter side, it will be created on the left. Now if you want it to be in any other place other than left then you have to specify the same by passing the corresponding value.
@TREASURE - My understanding is that the below is incorrect, and would hold good only within the class and not outside of it.
You could just have
DOCK_AT_TOP
Regards,
Chen
Edited by: Chen K V on Jun 6, 2011 4:54 PM
Edited by: Chen K V on Jun 6, 2011 4:56 PM
06-06-2011 11:05 AM
Clarification,
By saying
CREATE OBJECT <object_name>
EXPORTING
<par1> = <val>
<par2> = <val>
What we are doing here is instanciate an object and send the constructor values that it is expecting on the constructor's import section, if we did not have paramaters expected on the constructor of class
cl_gui_docking_container
,
we would just say
CREATE OBJECT <object_name>
*as for *
cl_gui_docking_container=>dock_at_top
You could just have
DOCK_AT_TOP
alone if you want, but, yes there is a but!
It will come back to bite you, why,
class components are defined in terms of a given class
and most probably donu2019t have a lot of meaning outside of their defining classu2019s context. To avoid this kind of confusion, it is recommended that you always address class components by applying the class component selector to the defining
classu2019s name. Therefore,
cl_gui_docking_container=>dock_at_top
instead of just
dock_at_top
That way, your intentions are always clear.
I hope this makes sence.