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: 

OOP for abap

Former Member
0 Kudos

good morning to all sap experts,

i have a question for any OOP programmers in abap. i have been working in abap for over 12 years, but have not yet transitioned to oop. but, since we have been upgrading to ecc 6.0, i am constantly working with oop classes, and objects. maybe someone can answer these questions, and also point me in the right direction online, to educate myself.

i have a class that is called CL_WTY_CLAIM and it is running a method called get_direct_references. within get_direct_references, this line of code is running.

co_ltext ?= co_ext_objects->get_ext_buffered_object(

co_ltext_class_id ).

firstly, what does "?=" mean?

secondly, if i go to get_ext_buffered_object, i find the following code.

ro_object = co_ext_objects->get_ext_buffered_object( io_id ).

how/where is the code running to fill the initial co_ltext field?

please and thank you.

1 ACCEPTED SOLUTION

naimesh_patel
Active Contributor
0 Kudos

"?=" is the Narrowing Cast or Down Cast

When your target object is more specific than the Source object than you need to do the Down Cast. E.g. You want to assign the CAR object (less Specific) to the RACER_CAR(More Specific) object.

Check this glossary on Down Cast.

http://help.sap.com/abapdocu/en/ABENDOWN_CAST_GLOSRY.htm

In your code example, the returning type of the method "co_ext_objects->get_ext_buffered_object" is the less specific one and the target "co_ltext" is the more specific. You can try to debug and find out what's going on in that method call.

Regards,

Naimesh Patel

5 REPLIES 5

naimesh_patel
Active Contributor
0 Kudos

"?=" is the Narrowing Cast or Down Cast

When your target object is more specific than the Source object than you need to do the Down Cast. E.g. You want to assign the CAR object (less Specific) to the RACER_CAR(More Specific) object.

Check this glossary on Down Cast.

http://help.sap.com/abapdocu/en/ABENDOWN_CAST_GLOSRY.htm

In your code example, the returning type of the method "co_ext_objects->get_ext_buffered_object" is the less specific one and the target "co_ltext" is the more specific. You can try to debug and find out what's going on in that method call.

Regards,

Naimesh Patel

0 Kudos

thanks for the quick reply. i think i understand the down cast function.

when i debug the code at the point of the following:

co_ltext ?= co_ext_objects->get_ext_buffered_object(

co_ltext_class_id ).

it goes to the get_ext_buffered_object method, and i see the following:

data:

ls_ext_object type t_ext_object.

read table ct_external_objects into ls_ext_object

with table key id = io_id.

ro_object = ls_ext_object-object.

can you easily tell me how the ct_external_objects table is populated? i know that the table is in another class "CL_WTY_BUFFER_EXT_CNTL" and it is a attribute of that class, but i do not know how it is populated. do you have another link to show me a easy way to determine how a table is populated?

the issue i am having is that this table does not always have the text info i am looking for. i would like to review their code to see if it is a data problem, or a code problem.

thanks again.

0 Kudos

The returning parameter RO_OBJECT of the method GET_EXT_BUFFERED_OBJECT is type ref to CL_WTY_EXT_BUFFERED_OBJECT, where as we are receiving it in the object reference CO_LTEXT which is type of CL_WTY_LONG_TEXT.

Now, if you see the superclass of the CL_WTY_LONG_TEXT is the CL_WTY_EXT_BUFFERED_OBJECT. So, the method's returning type is less generic (CL_WTY_EXT_BUFFERED_OBJECT) where as we try to get it into the more specific type (CL_WTY_LONG_TEXT). That's we need to use the ?= operator. Because of this operator, system will not give any error in Syntax Check and it will handle the casting at run time.

Regards,

Naimesh Patel

0 Kudos

thank you naimesh patel.

the missing piece, which you pointed out, was the connection to the class CL_WTY_LONG_TEXT. i should have know this, but thanks again for the specific reference.

i found the method DB_READ and realized that this is a simple call to a function module READ_TEXT.

if you have any more info for senior abapers who are trying to learn OOP for abap, please pass it along.

once again thanks for your help.

ET.

Former Member
0 Kudos

'?=' is just an assignment operator between two reference variables.

co_ltext ?= co_ext_objects->get_ext_buffered_object(

co_ltext_class_id ).

co_ltext is getting its value from the method defined in co_ext_objects by passing value co_ltext_class_id

destination {=|?=} source.

Effect

Variants with the addition ?TO or the assignment operator ?= (casting operator) must be used if the source and destination are reference variables and the static type of source is more general than the static type of destination (down cast). For assignments between operands that are not reference variables, use of the question mark ? is not permitted.