ABAP Objects-attribute accessability issue
Hi,
Let me introduce the problem.
I have a class c1 which has a public attribute a1.
a1 is of table type which refers to a class c2. c2 has an attribute a2 which is public.
With the object o1 of class c1 I need to access a2.
Please help me solve the problem.
Regards,
Ravi
Message was edited by: Ravi Prasad Reddy L
HI,
Check the below code....
Hope it solves your purpose.
class b definition deferred.
class a definition.
public section.
data : obj2 type ref to b.
methods : write_data.
endclass.
class b definition.
public section.
data : v_num type i.
methods : assign_value.
endclass.
class a implementation.
method write_data.
create object obj2.
call method obj2->assign_value.
write:/1 'Hello Everybody'.
endmethod.
endclass.
class b implementation.
method assign_value.
v_num = 100.
endmethod.
endclass.
data : obj1 type ref to a.
start-of-selection.
create object obj1.
call method obj1->write_data.
write:/1 obj1->obj2->v_num.
Regards,
Vara
Similar Messages
-
ABAP Objects Design/Organization Issues
Hi,
I'm trying to design and implement reusable components using ABAP Objects. I'm familliar with OO concepts and have developed a few applications using C++ and Java.
I'm trying to organize my classes into separate source files (include program in ABAP).
ie.
<b>include program a</b>
CLASS a DEFINITION.
ENDCLASS.
<b>include program b</b>
INCLUDE a.
CLASS b DEFINITION.
data x TYPE REF TO a.
ENDCLASS.
Lets say I want to write a report that uses both objects a and b. That means I have to include both programs. but since program b includes program a. including both programs a and b in my report would produce redeclarations of class a.
<b>executable program c</b>
REPORT c.
INCLUDE a.
INCLUDE b. " error: redeclaration of class a
DATA: x TYPE REF TO a.
y TYPE REF TO b.
This bothers me. Although it would be possible to <b>just include program b</b>, it would be a bit awkward since, i dont care if class a was used in the implementation of class b. Implementation should be abstracted from the user. Besides, everything should be explicit.
Is there a way to organize things as such? Would importing these classes globally would solve the problem.
Thanks.Emir,
The way we do OO Programming in ABAP and other languages differ.
In your case, it might be a better option to create these classes as global classes, so that you will not have this issue. You can SE24 to do the same.
Regards,
Ravi -
How to Implement Abap Object and Access Key for se24 developers.
Hi every One,
This is Abdul Rahman, Started Learning Abap Objects i want a simple program to be executed i.e. in Local class (Abap program)and as well in global class(class builder).
Also i would like to know When ,Were and Why Abap Object should be used.
prob to Me :- When i wanted execute F8 a Class in se24 Class Builder it is asking me AcessKey , plz if this is required plz any one send Me.
I have this key 36687663221261278694 it is already used in Abap editor , it is not accepting in se24 .
plz help Me , waiting for response ..
thankyou so much
Abdul Rahman.Hello Abdul
Here are my answers to your questions:
(1) <b>Local classes</b>: <i>Do not use them.</i>
- As long as your class is rather small (few attributes and methods), local classes are ok yet as soon as they become larger you will loose the overview
(2) <b>Global classes</b>: <i>Do use them.</i>
- Make use of global classes even if they are only used for your training. The big advantage over local classes is that you will get used to the classe builder (SE24) which has a plethora of functions.
(3) <b>Executing global classes</b>: <i>Can be done if you have defined an OO-transaction.</i>
- An OO-transaction has a class and one of its public methods as parameters (similar like report transactions). When you all the OO-transaction an instance of you class is created and the public method is called.
(4) <b>Where and Why use ABAP Objects?</b> <i>Everywhere. Anytime.</i>
- ABAP objects is about stability, maintainability and re-usability of coding. These developer aims can be much more fulfilled using ABAP OO means than in classical programming.
Regards
Uwe
PS: There are situations where local classes are quite appropriate and, using ABAP Unit testing, are obligatory. -
How to synchronize concurrent access to static data in ABAP Objects
Hi,
1) First of all I mwould like to know the scope of static (class-data) data of an ABAP Objects Class: If changing a static data variable is that change visible to all concurrent processes in the same Application Server?
2) If that is the case. How can concurrent access to such data (that can be shared between many processes) be controlled. In C one could use semaphores and in Java Synchronized methods and the monitor concept. But what controls are available in ABAP for controlling concurrent access to in-memory data?
Many thanks for your help!
Regards,
ChristianHello Christian
Here is an example that shows that the static attributes of a class are not shared between two reports that are linked via SUBMIT statement.
*& Report ZUS_SDN_OO_STATIC_ATTRIBUTES
REPORT zus_sdn_oo_static_attributes.
DATA:
gt_list TYPE STANDARD TABLE OF abaplist,
go_static TYPE REF TO zcl_sdn_static_attributes.
<i>* CONSTRUCTOR method of class ZCL_SDN_STATIC_ATTRIBUTES:
**METHOD constructor.
*** define local data
** DATA:
** ld_msg TYPE bapi_msg.
** ADD id_count TO md_count.
**ENDMETHOD.
* Static public attribute MD_COUNT (type i), initial value = 1</i>
PARAMETERS:
p_called(1) TYPE c DEFAULT ' ' NO-DISPLAY.
START-OF-SELECTION.
<b>* Initial state of static attribute:
* zcl_sdn_static_attributes=>md_count = 0</b>
syst-index = 0.
WRITE: / syst-index, '. object: static counter=',
zcl_sdn_static_attributes=>md_count.
DO 5 TIMES.
<b>* Every time sy-index is added to md_count</b>
CREATE OBJECT go_static
EXPORTING
id_count = syst-index.
WRITE: / syst-index, '. object: static counter=',
zcl_sdn_static_attributes=>md_count.
<b>* After the 3rd round we start the report again (via SUBMIT)
* and return the result via list memory.
* If the value of the static attribute is not reset we would
* start with initial value of md_count = 7 (1+1+2+3).</b>
IF ( p_called = ' ' AND
syst-index = 3 ).
SUBMIT zus_sdn_oo_static_attributes EXPORTING LIST TO MEMORY
WITH p_called = 'X'
AND RETURN.
CALL FUNCTION 'LIST_FROM_MEMORY'
TABLES
listobject = gt_list
EXCEPTIONS
not_found = 1
OTHERS = 2.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
CALL FUNCTION 'DISPLAY_LIST'
* EXPORTING
* FULLSCREEN =
* CALLER_HANDLES_EVENTS =
* STARTING_X = 10
* STARTING_Y = 10
* ENDING_X = 60
* ENDING_Y = 20
* IMPORTING
* USER_COMMAND =
TABLES
listobject = gt_list
EXCEPTIONS
empty_list = 1
OTHERS = 2.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
ENDIF.
ENDDO.
<b>* Result: in the 2nd run of the report (via SUBMIT) we get
* the same values for the static counter.</b>
END-OF-SELECTION.
Regards
Uwe -
Overriding attributes in ABAP objects
Hello,
I currently want know if it is possible to override attributes in ABAP objects. i know it is possible with methods. I have extend a previous class functionality and want to change the refrence type of an attribute from the parent class, but only on the child. Is this possible in ABAP object or even in normal object oriented techniques.
Thanks
BrendanHi,
ususally you can achive this with other technics. You can e.g. use the class hierarchy for this:
The attribute is of type REF_SUPERCLASS. Within the superclass it should be working when you set subclasses of REF_SUPERCLASS as attribute.
Another way is to use interfaces as reference type for your attribute.
Please refer to [ABAP Objects|http://help.sap.com/saphelp_nw70/helpdata/EN/ce/b518b6513611d194a50000e8353423/frameset.htm]. Especially the chapters about Inheritance and Interfaces.
Regards Rudi -
Is there a table type ATTRIBUTE that can be defined in an ABAP object?
Hi. Within SE24 on the Attributes tab, is there a way to define an attribute of type TABLE? If you put in STANDARD TABLE as the reference type, it does not allow a generic table type.
What I want to do is pass in a standard table type to my constructor, and then assign it to a private table attribute in the object.
I do not want to assign the table to a local variable of the constructor. I want to store the table in a private object attribute. I don't mind if the attribute type is a specific table type (such as KNA1), I just want to be able to assign the constructor's table parameter to some type of private object attribute.
Thanks.
BrendanHi Brendan,
No they are not same. A modelled class or method or an attribute will not have any realtime appliaction. Say for example you want to provide a method or Attribute which may be used in future or expected to be used in future, then you declare that method as Modelled. YOu can execute such a method or access such an attribute.
Abstract Class is an executable class...but it will have some methods with no implementation. The implementation of such methods will upto the user who is accessing that class.A class defined as ABSTRACT cannot be instantiated, that is, you cannot use CREATE OBJECT with reference to the class. Instead, you can only address the class using its static components or its subclasses. The major purpose of an abstract class is to serve as a template for subclasses.
If a class contains abstract methods, that is, method declarations with the ABSTRACT addition, the whole class must also be abstract (that is, have the ABSTRACT addition), since a class may not be instantiated if it has unimplemented methods. Equally, if a subclass does not implement all of the abstract methods of its superclasses, it must itself declare them abstract.
Regards,
Vara -
Access object attributes using other object JNI native method
Hi. I'm trying to change an attribute of object O1 from another object O2 without invoking a O1 method and without making the attribute as public or protected.
The only possibility that comes to my mind for doing so is writting a JNI native method
public class O1 {
static public native changeAttribute (Object O2, Object newAttributeValue) ;
that change the attribute memory reference, but all I've found about accesing attributes in JNI is about accessing the invoker attributes (in this case, O1).
�Does any one know if it's possible to do so? Thanks.I know that is not a good practice but I cannot figure out another way.
I'll try to explain the whole problem so you see the reason. I'm working with transactions, using objects as the data. An object can be opened for write by several transactions because the granularity for conflicts is not the object, is each of its attributes. As long as two transaction don't write the same attribute, they both can write. For writing, each transactions uses a private copy of the object. At committing, the actual copy of the object must be replaced by the committer one, but as far as the granularity is the object attributes, only each written attribute must be replaced (if not, only the last commit would be visible).
This attribute replace must be done by the transaction manager as far as the transactional object is provided by the client. So what i was thinking was to use JNI or some trick like that to replace the object attributes transparently to the object.
I hope the explain is clear, my english is a little asleep :-(.
How to do it with reflection? I thought that was only for method calling. Anyway, there wouldn't be problems if the attributes are private?
Thanks for answering.
EDIT: I've been able to change a public field using reflection, but not the private one
import java.lang.reflect.*;
class Caca {
public static void main(String[] args) {
Integer r = new Integer(0);
System.out.println("original: " + r.toString());
modifyWidth(r, 300);
System.out.println("modified: " + r.toString());
static void modifyWidth(Integer r, int newValue ) {
Field valueField; Class c = r.getClass();
try {
valueField = c.getField("value");
valueField.set(r, newValue);
} catch (Exception e) { System.out.println(e); }
Message was edited by:
dfasdfsdafsadfasdf -
Problem to access the object attribute in a code
Hi guys,
I need to pass the attribute of a business object to class.Below is the code but its throwing an error 'There is no component ZYBTT in l_bus2000116'.Since the business object conatins the attribute but its throwing an error.Could any one throw some light on the below code -
data: l_BUS2000116 type swc_object,
Z_BRF_Function_name TYPE FDT_UUID.
swc_get_element ac_container 'Z_Quotation' l_BUS2000116.
swc_get_element ac_container 'Z_BRF_Function_name' Z_BRF_Function_name.
CALL METHOD ZYCLOTO_AGENTDTMT_BRF=>ZYOTOM_GET_AGENT_IDS_SING_LEV
EXPORTING
IM_FUNCTION_ID = Z_BRF_Function_name
IM_BTT = l_BUS2000116-ZYBTT
IM_COMPL_CAT =
IM_COUNTRY_CODE = ZYCOUNTRY
IM_LEAD_BRAND = l_BUS2000116-leadbrand
IM_RISK_LEVEL = l_BUS2000116-ZYRISKLEVEL
IM_SALES_ORG = l_BUS2000116-ZYsalesorg
IM_TCV = l_BUS2000116-ZYTCV.
IMPORTING
EX_FULL_NAME =
EX_RETURN =Hi,
Is ZYBTT a new attribute? Have you changed the status of the attribute to implemented or released (in SWO1: Edit -> Change release status)?
And actually I think that your syntax is wrong too (BOR world is different compared to classes). If you want to use an attribute, I think that the syntax should be something like this:
SWC_GET_PROPERTY <Object> <Attribute> <AttributeValue>.
Read more here:
http://help.sap.com/saphelp_nw04/helpdata/en/c5/e4acef453d11d189430000e829fbbd/content.htm
Regards,
Karri -
when calling to method in abap objects we can write
CALL METHOD method_name
EXPORTING
param =: value1 , value2 , .... ,valuen .
but how can i call method if it get 2 parameters ?
means like
CALL METHOD method_name
EXPORTING
param1 =: ???????
param2 =: ??????? .Example
CALL METHOD object=>method
EXPORTING
param1 = 'PARAM1'
param2 = 'PARAM2'.
Another example:
CALL METHOD cl_gui_frontend_services=>file_open_dialog
CHANGING
file_table = filetable
rc = rc
EXCEPTIONS
file_open_dialog_failed = 1
cntl_error = 2
error_no_gui = 3
not_supported_by_gui = 4
OTHERS = 5.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
Please give points if it helps.
Message was edited by: Fuat Ulugay -
Logical Database in Abap Objects
Hi to All
I want do it a program report using a Logical Database.
Is this possible ??? But when I make a GET <node>, occurs the following error:
"" Statement "ENDMETHOD" missing. ""
I'm doing the following:
CLASS MONFIN IMPLEMENTATION.
METHOD TRAER_DATOS.
GET VBRK.
ENDMETHOD.
ENDCLASS.
Please, somebody tell me how I use the logical database in Abap Objects.
Thank you very much
Regards
Dario R.Hi there
Logical databases whilst of "some use" are not really part of OO.
If you want to use a logical database in an abap OO program I would create a special class which just does the get data from your DB and pass this either at record or table level.
Techniques such as GET XXXX LATE aren't really part of any OO type of application since at Object Instantiation time you should be able to access ALL the attributes of that object.
As far as OO is concerned Logical databases are a throwback to "Dinosaur Technology".
Since however modules such as SD and FI are still heavily reliant on relational structures (i.e linked tables etc) then there is still some limited life in this stuff but for OO try and solve it by another method.
If you really must use this stuff in OO then do it via a FMOD call and save the data in a table which your method will pass back to your application program.
You can't issue a GET command directly in a method.
Cheers
Jimbo -
Use of 'ME' keyword in ABAP Objects?
Hi all,
Can any one please use of 'ME' keyword in ABAP Objects?
Thanks,
Vijay.
Moderator message: next time, please search for available information before asking.
Edited by: Thomas Zloch on Sep 16, 2010 5:33 PMHi,
Please find the description about the ME keyword as per the SAP documentation and help.sap.com.
Within the implementation of every instance method, an implicitly created local reference variable called me is available, which points to the instance in which the method is currently being executed. The static type of me is the class in which the instance method is implemented.
Each class implicitly contains the reference variable me. In objects, the reference variable mealways contains a reference to the respective object itself and is therefore also referred to as the self-reference. Within a class, you can use the self-reference me to access the individual class components:
-To access an attribute attr of your class: me->attr
-To call a method meth of your class: CALL METHOD me->meth
When you work with attributes of your own class in methods, you do not need to specify a reference variable. The self-reference me is implicitly set by the system. Self-references allow an object to give other objects a reference to it. You can also access attributes in methods from within an object even if they are obscured by local attributes of the method.
Regards,
Sagar -
Hi Experts.
Plz give me some details for the following questions.
1. what is abstract class.
2. give me some example program using inheritance.
3. Some sample programs using events.
4. Narrow casting & wide casting.. And describe the use of it.
5. How to declare internal table in ABAP OOPS.
6. What is the use of table type.?
7. What is instance.?
8. Explain friend class.
Thank in advance.
Points will be given for the answers.
regards,
J.JoeHI
<b>1. what is abstract class.</b>
Abstract classes are normally used as an incomplete blueprint for concrete (that is, non-abstract) subclasses, for example to define a uniform interface.
Classes with at least one abstract method are themselves abstract.
Static methods and constructors cannot be abstract.
You can specify the class of the instance to be created explicitly: CREATE OBJECT <RefToAbstractClass> TYPE <NonAbstractSubclassName>.
Abstarct classes themselves cant be instantiated ( althrough their subclasses can)
Reference to abstract classes can refer to instance of subclass
Abstract (instance) methods are difined in the class , but not implemented
They must be redefined in subclasses
CLASS LC1 DEFINAITION ABSTARCT
PUBLIC SECTION
METHODS ESTIMATE ABSTARCT IMPORTING
ENDCLASS.
<b>2. give me some example program using inheritance.</b>
The following simple example shows the principle of inheritance within ABAP Objects. It is based on the Simple Introduction to Classes. A new class counter_ten inherits from the existing class counter.
REPORT demo_inheritance.
CLASS counter DEFINITION.
PUBLIC SECTION.
METHODS: set IMPORTING value(set_value) TYPE i,
increment,
get EXPORTING value(get_value) TYPE i.
PROTECTED SECTION .
DATA count TYPE i.
ENDCLASS.
CLASS counter IMPLEMENTATION.
METHOD set.
count = set_value.
ENDMETHOD.
METHOD increment.
ADD 1 TO count.
ENDMETHOD.
METHOD get.
get_value = count.
ENDMETHOD.
ENDCLASS.
CLASS counter_ten DEFINITION INHERITING FROM counter.
PUBLIC SECTION.
METHODS increment REDEFINITION .
DATA count_ten.
ENDCLASS.
CLASS counter_ten IMPLEMENTATION.
METHOD increment.
DATA modulo TYPE I.
CALL METHOD super->increment .
write / count.
modulo = count mod 10.
IF modulo = 0.
count_ten = count_ten + 1.
write count_ten.
ENDIF.
ENDMETHOD.
ENDCLASS.
DATA: count TYPE REF TO counter,
number TYPE i VALUE 5.
START-OF-SELECTION.
CREATE OBJECT count TYPE counter_ten .
CALL METHOD count->set EXPORTING set_value = number.
DO 20 TIMES.
CALL METHOD count->increment.
ENDDO.
The class COUNTER_TEN is derived from COUNTER. It redefines the method INCREMENT. To do this, you must change the visibility of the COUNT attribute from PRIVATE to PROTECTED. The redefined method calls the obscured method of the superclass using the pseudoreference SUPER->. The redefined method is a specialization of the inherited method.
The example instantiates the subclass. The reference variable pointing to it has the type of the superclass. When the INCREMENT method is called using the superclass reference, the system executes the redefined method from the subclass.
<b>3. Some sample programs using events.</b>
Events in ABAP Objects - Example
The following example shows how to declare, call, and handle events in ABAP Objects.
Overview
This object works with the interactive list displayed below. Each user interaction triggers an event in ABAP Objects. The list and its data is created in the class C_LIST. There is a class STATUS for processing user actions. It triggers an event BUTTON_CLICKED in the AT USER-COMMAND event. The event is handled in the class C_LIST. It contains an object of the class C_SHIP or C_TRUCK for each line of the list. Both of these classes implement the interface I_VEHICLE. Whenever the speed of one of these objects changes, the event SPEED_CHANGE is triggered. The class C_LIST reacts to this and updates the list.
Constraints
The ABAP statements used for list processing are not yet fully available in ABAP Objects. However, to produce a simple test output, you can use the following statements:
WRITE [AT] /<offset>(<length>) <f>
ULINE
SKIP
NEW-LINE
Note: The behavior of formatting and interactive list functions in their current state are not guaranteed. Incompatible changes could occur in a future release.
Declarations
This example is implemented using local interfaces and classes. Below are the declarations of the interfaces and classes:
Interface and Class declarations
INTERFACE I_VEHICLE.
DATA MAX_SPEED TYPE I.
EVENTS SPEED_CHANGE EXPORTING VALUE(NEW_SPEED) TYPE I.
METHODS: DRIVE,
STOP.
ENDINTERFACE.
CLASS C_SHIP DEFINITION.
PUBLIC SECTION.
METHODS CONSTRUCTOR.
INTERFACES I_VEHICLE.
PRIVATE SECTION.
ALIASES MAX FOR I_VEHICLE~MAX_SPEED.
DATA SHIP_SPEED TYPE I.
ENDCLASS.
CLASS C_TRUCK DEFINITION.
PUBLIC SECTION.
METHODS CONSTRUCTOR.
INTERFACES I_VEHICLE.
PRIVATE SECTION.
ALIASES MAX FOR I_VEHICLE~MAX_SPEED.
DATA TRUCK_SPEED TYPE I.
ENDCLASS.
CLASS STATUS DEFINITION.
PUBLIC SECTION.
CLASS-EVENTS BUTTON_CLICKED EXPORTING VALUE(FCODE) LIKE SY-UCOMM.
CLASS-METHODS: CLASS_CONSTRUCTOR,
USER_ACTION.
ENDCLASS.
CLASS C_LIST DEFINITION.
PUBLIC SECTION.
METHODS: FCODE_HANDLER FOR EVENT BUTTON_CLICKED OF STATUS
IMPORTING FCODE,
LIST_CHANGE FOR EVENT SPEED_CHANGE OF I_VEHICLE
IMPORTING NEW_SPEED,
LIST_OUTPUT.
PRIVATE SECTION.
DATA: ID TYPE I,
REF_SHIP TYPE REF TO C_SHIP,
REF_TRUCK TYPE REF TO C_TRUCK,
BEGIN OF LINE,
ID TYPE I,
FLAG,
IREF TYPE REF TO I_VEHICLE,
SPEED TYPE I,
END OF LINE,
LIST LIKE SORTED TABLE OF LINE WITH UNIQUE KEY ID.
ENDCLASS.
The following events are declared in the example:
The instance event SPEED_CHANGE in the interface I_VEHICLE
The static event BUTTON_CLICKED in the class STATUS.
The class C_LIST contains event handler methods for both events.
Note that the class STATUS does not have any attributes, and therefore only works with static methods and events.
Implementations
Below are the implementations of the methods of the above classes:
Implementations
CLASS C_SHIP IMPLEMENTATION.
METHOD CONSTRUCTOR.
MAX = 30.
ENDMETHOD.
METHOD I_VEHICLE~DRIVE.
CHECK SHIP_SPEED < MAX.
SHIP_SPEED = SHIP_SPEED + 10.
RAISE EVENT I_VEHICLE~SPEED_CHANGE
EXPORTING NEW_SPEED = SHIP_SPEED.
ENDMETHOD.
METHOD I_VEHICLE~STOP.
CHECK SHIP_SPEED > 0.
SHIP_SPEED = 0.
RAISE EVENT I_VEHICLE~SPEED_CHANGE
EXPORTING NEW_SPEED = SHIP_SPEED.
ENDMETHOD.
ENDCLASS.
CLASS C_TRUCK IMPLEMENTATION.
METHOD CONSTRUCTOR.
MAX = 150.
ENDMETHOD.
METHOD I_VEHICLE~DRIVE.
CHECK TRUCK_SPEED < MAX.
TRUCK_SPEED = TRUCK_SPEED + 50.
RAISE EVENT I_VEHICLE~SPEED_CHANGE
EXPORTING NEW_SPEED = TRUCK_SPEED.
ENDMETHOD.
METHOD I_VEHICLE~STOP.
CHECK TRUCK_SPEED > 0.
TRUCK_SPEED = 0.
RAISE EVENT I_VEHICLE~SPEED_CHANGE
EXPORTING NEW_SPEED = TRUCK_SPEED.
ENDMETHOD.
ENDCLASS.
CLASS STATUS IMPLEMENTATION.
METHOD CLASS_CONSTRUCTOR.
SET PF-STATUS 'VEHICLE'.
WRITE 'Click a button!'.
ENDMETHOD.
METHOD USER_ACTION.
RAISE EVENT BUTTON_CLICKED EXPORTING FCODE = SY-UCOMM.
ENDMETHOD.
ENDCLASS.
CLASS C_LIST IMPLEMENTATION.
METHOD FCODE_HANDLER .
CLEAR LINE.
CASE FCODE.
WHEN 'CREA_SHIP'.
ID = ID + 1.
CREATE OBJECT REF_SHIP.
LINE-ID = ID.
LINE-FLAG = 'C'.
LINE-IREF = REF_SHIP.
APPEND LINE TO LIST.
WHEN 'CREA_TRUCK'.
ID = ID + 1.
CREATE OBJECT REF_TRUCK.
LINE-ID = ID.
LINE-FLAG = 'T'.
LINE-IREF = REF_TRUCK.
APPEND LINE TO LIST.
WHEN 'DRIVE'.
CHECK SY-LILLI > 0.
READ TABLE LIST INDEX SY-LILLI INTO LINE.
CALL METHOD LINE-IREF->DRIVE.
WHEN 'STOP'.
LOOP AT LIST INTO LINE.
CALL METHOD LINE-IREF->STOP.
ENDLOOP.
WHEN 'CANCEL'.
LEAVE PROGRAM.
ENDCASE.
CALL METHOD LIST_OUTPUT.
ENDMETHOD.
METHOD LIST_CHANGE .
LINE-SPEED = NEW_SPEED.
MODIFY TABLE LIST FROM LINE.
ENDMETHOD.
METHOD LIST_OUTPUT.
SY-LSIND = 0.
SET TITLEBAR 'TIT'.
LOOP AT LIST INTO LINE.
IF LINE-FLAG = 'C'.
WRITE / ICON_WS_SHIP AS ICON.
ELSEIF LINE-FLAG = 'T'.
WRITE / ICON_WS_TRUCK AS ICON.
ENDIF.
WRITE: 'Speed = ', LINE-SPEED.
ENDLOOP.
ENDMETHOD.
ENDCLASS.
The static method USER_ACTION of the class STATUS triggers the static event BUTTON_CLICKED. The instance methods I_VEHICLEDRIVE and I_VEHICLESTOP trigger the instance event I_VEHICLE~SPEED_CHANGE in the classes C_SHIP and C_TRUCK.
Using the Classes in a Program
The following program uses the above classes:
REPORT OO_EVENTS_DEMO NO STANDARD PAGE HEADING.
Global data of program
DATA LIST TYPE REF TO C_LIST.
Program events
START-OF-SELECTION.
CREATE OBJECT LIST.
SET HANDLER: LIST->FCODE_HANDLER,
LIST->LIST_CHANGE FOR ALL INSTANCES.
AT USER-COMMAND.
CALL METHOD STATUS=>USER_ACTION.
The program creates an object of the class C_LIST and registers the event handler method FCODE_HANDLER of the object for the class event BUTTON_CLICKED, and the event handler method LIST_CHANGE for the event SPEED_CHANGE of all instances that implement the interface I_VEHICLE.
<b>4. Narrow casting & wide casting.. And describe the use of it.</b>
<b>Narrowing Cast</b>
The assignment of a subclass instance to a reference variable of the type "reference to superclass" is described as a narrowing cast, because you are switching from a more detailed view to a one with less detail.
Description up-cast is also used.
<b>use</b>
A user who is not interested in the finer points of cars, trucks, and busses (but only, for example, in the fuel consumption and tank gauge) does not need to know about them. This user only wants and needs to work with (references to) the lcl_vehicle class. However, in order to allow the user to work with cars, busses, or trucks, you generally need a narrowing cast.
<b>Widening cast</b>
The widening cast logically represents the opposite of the narrowing cast. The widening cast cannot be checked statically, only at runtime. The Cast Operator ?= (or the equivalent MOVE ... ?TO ) must be used to make this visible.
It changes from a less detailed view to one with more detail.
<b>use</b>
The client, the car rental company wants to execute a function for specific vehicles form the list (vehicle_list). For example, the client wants to ascertain the truck with the largest cargo capacity. However, not all vehicles are in the trucks list, it also includes references to cars and busses.
<b>5. How to declare internal table in ABAP OOPS.</b>
BEGIN OF LINE,
ID TYPE I,
FLAG,
IREF TYPE REF TO I_VEHICLE,
SPEED TYPE I,
END OF LINE,
<b>6. What is the use of table type.?</b>
Please check the SAP help , as all these things are provided in detail in it .
In case you find it difficult to find it or search for it here is the link
http://help.sap.com/saphelp_nw04/helpdata/en/90/8d7304b1af11d194f600a0c929b3c3/frameset.htm
<b>7. What is instance.?</b>
Instance methods are called using CALL METHOD <reference>-><instance_method>.
Static methods (also referred to as class methods) are called using CALL METHOD <classname>=><class_method>.
If you are calling a static method from within the class, you can omit the class name.
You access instance attributes using <instance>-><instance_attribute>
<b>8. Explain friend class.</b>
In rare cases, classes have to work together so closely that they need access to their protected and private components. To avoid making these components available to all users, there is the concept of friendship between classes.
To do this you use the FRIENDS additions to the CLASS statement, in which all classes and interfaces that are to be provided friendship are listed
In principle, providing friendship is one-sided: A class providing friendship is not automatically a friend of its friends. If a class providing friendship wants to access the non-public components of a friend, this friend has to explicitly provide friendship to it.
Classes that inherit from friends and interfaces that contain a friend as a component interface also become friends. However, providing friendship, unlike the attribute of being a friend, is not inherited. A friend of a superclass is therefore not automatically a friend of its subclasses.
<b>Reward if usefull</b> -
ABAP Object Exception handling
Hi all,
I would very much like some links to learn how to create Exception objects, and how to use them in my ABAP Object apps.
Thanks in advance!hi,
Object Services classes work exclusively with Class-Based Exceptions. The exception classes are predefined in the system. They always start with CX_OS_.
Exceptions of the CX_DYNAMIC_CHECK category are passed to the caller using the RAISING clauses of interface methods; class-specific methods of the class actor; attribute access methods of persistent classes; in the transaction object; and the system actors. Such exceptions must be handled here by the user, (in contrast to the general rule that exceptions should be handled within a procedure, not passed along the hierarchy). Thus semantically, the above exceptions of the CX_DYNAMIC_CHECK category belong more to the CX_STATIC_CHECK category. However, they could not be defined as such, due to their incompatibility with existing Object Services applications.
Check out the link.
http://help.sap.com/saphelp_erp2005vp/helpdata/en/66/bc7aec43c211d182b30000e829fbfe/frameset.htm
http://help.sap.com/saphelp_nw04/helpdata/en/fb/35c62bc12711d4b2e80050dadfb92b/content.htm
http://help.sap.com/saphelp_erp2005vp/helpdata/en/17/f9f44295bae2499e8c56ca4f5106fb/frameset.htm
Regards,
Richa. -
Help regarding ABAP and ABAP Objects
Dear all,
I am very new in abap and abap objects. But i have some expr. in other language..specialy development. Right now i am working for srm module...So i want to move my self into abap object and specialy in workflow...Please provide me help regarding this...along with the starting point for this.
Best Regards
Vijay Patilhi
Object Oriented prg
A programming technique in which solutions reflect real world objects
What are objects ?
An object is an instantiation of a class. E.g. If Animal is a class, A cat
can be an object of that class .
With respect to code, Object refers to a set of services ( methods /
attributes ) and can contain data
What are classes ?
A class defines the properties of an object. A class can be instantiated
as many number of times
Advantages of Object Orientated approach
Easier to understand when the system is complex
Easy to make changes
Encapsulation - Can restrict the visibility of the data ( Restrict the access to the data )
Polymorphism - Identically named methods behave differently in different classes
Inheritance - You can use an existing class to define a new class
Polymorphism and inheritance lead to code reuse
Have a look at these good links for OO ABAP-
http://www.sapgenie.com/abap/OO/
http://www.sapgenie.com/abap/OO/index.htm
http://help.sap.com/saphelp_nw04/helpdata/en/c3/225b5654f411d194a60000e8353423/content.htm
http://www.esnips.com/doc/375fff1b-5a62-444d-8ec1-55508c308b17/prefinalppt.ppt
http://www.esnips.com/doc/2c76dc57-e74a-4539-a20e-29383317e804/OO-abap.pdf
http://www.esnips.com/doc/5c65b0dd-eddf-4512-8e32-ecd26735f0f2/prefinalppt.ppt
http://www.allsaplinks.com/
http://www.sap-img.com/
http://www.sapgenie.com/
http://help.sap.com
http://www.sapgenie.com/abap/OO/
http://www.sapgenie.com.
http://www.sapgenie.com/abap/OO/index.htm
http://www.sapgenie.com/abap/controls/index.htm
http://www.esnips.com/doc/2c76dc57-e74a-4539-a20e-29383317e804/OO-abap.pdf
http://www.esnips.com/doc/0ef39d4b-586a-4637-abbb-e4f69d2d9307/SAP-CONTROLS-WORKSHOP.pdf
http://www.sapgenie.com/abap/OO/index.htm
http://help.sap.com/saphelp_erp2005/helpdata/en/ce/b518b6513611d194a50000e8353423/frameset.htm
http://www.sapgenie.com/abap/OO/
check the below links lot of info and examples r there
http://www.sapgenie.com/abap/OO/index.htm
http://www.geocities.com/victorav15/sapr3/abap_ood.html
http://www.brabandt.de/html/abap_oo.html
Check this cool weblog:
/people/thomas.jung3/blog/2004/12/08/abap-persistent-classes-coding-without-sql
/people/thomas.jung3/blog/2004/12/08/abap-persistent-classes-coding-without-sql
http://help.sap.com/saphelp_nw04/helpdata/en/c3/225b6254f411d194a60000e8353423/frameset.htm
http://www.sapgenie.com/abap/OO/
http://www.sapgenie.com/abap/OO/index.htm
http://help.sap.com/saphelp_nw04/helpdata/en/c3/225b5654f411d194a60000e8353423/content.htm
http://www.esnips.com/doc/375fff1b-5a62-444d-8ec1-55508c308b17/prefinalppt.ppt
http://www.esnips.com/doc/2c76dc57-e74a-4539-a20e-29383317e804/OO-abap.pdf
http://www.esnips.com/doc/5c65b0dd-eddf-4512-8e32-ecd26735f0f2/prefinalppt.ppt
http://www.allsaplinks.com/
http://www.sap-img.com/
http://www.sapgenie.com/
http://help.sap.com
http://www.sapgenie.com/abap/OO/
http://www.sapgenie.com/abap/OO/index.htm
http://www.sapgenie.com/abap/controls/index.htm
http://www.esnips.com/doc/2c76dc57-e74a-4539-a20e-29383317e804/OO-abap.pdf
http://www.esnips.com/doc/0ef39d4b-586a-4637-abbb-e4f69d2d9307/SAP-CONTROLS-WORKSHOP.pdf
http://www.sapgenie.com/abap/OO/index.htm
http://help.sap.com/saphelp_erp2005/helpdata/en/ce/b518b6513611d194a50000e8353423/frameset.htm
http://www.sapgenie.com/abap/OO/
these links
http://help.sap.com/saphelp_47x200/helpdata/en/ce/b518b6513611d194a50000e8353423/content.htm
For funtion module to class
http://help.sap.com/saphelp_47x200/helpdata/en/c3/225b5954f411d194a60000e8353423/content.htm
for classes
http://help.sap.com/saphelp_47x200/helpdata/en/c3/225b5c54f411d194a60000e8353423/content.htm
for methods
http://help.sap.com/saphelp_47x200/helpdata/en/08/d27c03b81011d194f60000e8353423/content.htm
for inheritance
http://help.sap.com/saphelp_47x200/helpdata/en/dd/4049c40f4611d3b9380000e8353423/content.htm
for interfaces
http://help.sap.com/saphelp_47x200/helpdata/en/c3/225b6254f411d194a60000e8353423/content.htm
For Materials:
1) http://help.sap.com/printdocu/core/Print46c/en/data/pdf/BCABA/BCABA.pdf -- Page no: 1291
2) http://esnips.com/doc/5c65b0dd-eddf-4512-8e32-ecd26735f0f2/prefinalppt.ppt
3) http://esnips.com/doc/2c76dc57-e74a-4539-a20e-29383317e804/OO-abap.pdf
4) http://esnips.com/doc/0ef39d4b-586a-4637-abbb-e4f69d2d9307/SAP-CONTROLS-WORKSHOP.pdf
5) http://esnips.com/doc/92be4457-1b6e-4061-92e5-8e4b3a6e3239/Object-Oriented-ABAP.ppt
6) http://esnips.com/doc/448e8302-68b1-4046-9fef-8fa8808caee0/abap-objects-by-helen.pdf
7) http://esnips.com/doc/39fdc647-1aed-4b40-a476-4d3042b6ec28/class_builder.ppt
8) http://www.amazon.com/gp/explorer/0201750805/2/ref=pd_lpo_ase/102-9378020-8749710?ie=UTF8
1) http://www.erpgenie.com/sap/abap/OO/index.htm
2) http://help.sap.com/saphelp_nw04/helpdata/en/ce/b518b6513611d194a50000e8353423/frameset.htm
Hope this helps
if it helped, you can acknowledge the same by rewarding
regards
ankit -
Need to learn abap objects plz help me
hi to all sdners ,
i need to learn oops in abap plz send me material and tutorials for learning it. please help me .you can send all the materials to my mail id [email protected] will rewarded.hi
Object Oriented prg
A programming technique in which solutions reflect real world objects
What are objects ?
An object is an instantiation of a class. E.g. If Animal is a class, A cat
can be an object of that class .
With respect to code, Object refers to a set of services ( methods /
attributes ) and can contain data
What are classes ?
A class defines the properties of an object. A class can be instantiated
as many number of times
Advantages of Object Orientated approach
Easier to understand when the system is complex
Easy to make changes
Encapsulation - Can restrict the visibility of the data ( Restrict the access to the data )
Polymorphism - Identically named methods behave differently in different classes
Inheritance - You can use an existing class to define a new class
Polymorphism and inheritance lead to code reuse
Have a look at these good links for OO ABAP-
http://www.sapgenie.com/abap/OO/
http://www.sapgenie.com/abap/OO/index.htm
http://help.sap.com/saphelp_nw04/helpdata/en/c3/225b5654f411d194a60000e8353423/content.htm
http://www.esnips.com/doc/375fff1b-5a62-444d-8ec1-55508c308b17/prefinalppt.ppt
http://www.esnips.com/doc/2c76dc57-e74a-4539-a20e-29383317e804/OO-abap.pdf
http://www.esnips.com/doc/5c65b0dd-eddf-4512-8e32-ecd26735f0f2/prefinalppt.ppt
http://www.allsaplinks.com/
http://www.sap-img.com/
http://www.sapgenie.com/
http://help.sap.com
http://www.sapgenie.com/abap/OO/
http://www.sapgenie.com.
http://www.sapgenie.com/abap/OO/index.htm
http://www.sapgenie.com/abap/controls/index.htm
http://www.esnips.com/doc/2c76dc57-e74a-4539-a20e-29383317e804/OO-abap.pdf
http://www.esnips.com/doc/0ef39d4b-586a-4637-abbb-e4f69d2d9307/SAP-CONTROLS-WORKSHOP.pdf
http://www.sapgenie.com/abap/OO/index.htm
http://help.sap.com/saphelp_erp2005/helpdata/en/ce/b518b6513611d194a50000e8353423/frameset.htm
http://www.sapgenie.com/abap/OO/
/people/dirk.feeken/blog/2007/07/06/abap-trial-version-for-newbies-part-17--your-first-abap-object
https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.km.cm.docs/library/events/sap-teched-03/why%20use%20abap%20objects
Hope this helps
if it helped, you can acknowledge the same by rewarding
regards
ankit
Maybe you are looking for
-
SHC not appearing in Buyeru2019s worklist
Hi SRM Gurus,, In SRM Web, after the creation and apporval of shopping cart, the buyer checked the items in carry out sourcing (professional purchaser- Sourcing- carry out sourcing). In find tab, seacrh using extended seacrh and then filling out the
-
Examples for SAP Memory and ABAP Memory
Hi all, can u give me one example of sap memory and abap memory. Ranjith
-
Variable Refresh button in WAD
Hi All, I would like to add a button to a web template so that after I execute the report I would like to click on the button and the variable screen pops up enabling the user to select alternative values. I am working in BI 7 and would like to know
-
Receiving js error when inserting Flash content
When I try to insert a standard SWF file into a web page i receive this error (screenshot below). http://www.atvbid.com/001.gif Then when I click OK I receive this error http://www.atvbid.com/002.gif Any help in this problem? Thanks, Casey
-
I have had a Mac in the past and had no problem with downloading adobe flash but for some reason my laptop will not let me get flash. What should I do?