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: 

What about ?=

Former Member
0 Kudos

Hi,

Can anyone explain the ?= in :

lr_column ?= lr_columns->get_column( 'BUKRS' ).

In what kind of situations must i use this. Is there mabye a document about this ?

Thanks,

Rob Makelaar.

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi Rob,

The ?= operator is called the "cast" operator. It is used in widening cast where a check is carried out at runtime to ensure that the content of the source variable coppesponds to the type of requirements to the target variables and if there is a mismatch, the catchable runtime error "MOVE_CAST_ERROR" occurs which can be caught with "CATCH...ENDCATCH" and the original value of the target variable remains the same.

Example usage:

Class A is the super class of class B.

DATA: OBJ_A TYPE REF TO A,

OBJ_B1 TYPE REF TO B,

OBJ_B2 TYPE REF TO B.

CREATE OBJECT OBJ_B1.

OBJ_A = OBJ_B1.

OBJ_B2 ?= OBJ_A. "widening cast or down casting using the cast operator

Reward points if helpful.

Regards,

Renuka

5 REPLIES 5

Peter_Inotai
Active Contributor
0 Kudos

Hi Rob,

It's called casting, you can find some example here:

http://help.sap.com/saphelp_webas630/helpdata/en/86/8280d812d511d5991b00508b6b8b11/frameset.htm

Actually lr_column and lr_columns has a different reference class, however these classes inherited one from the other, so moving data is possible between them this way.

Best regards,

Peter

RichHeilman
Developer Advocate
Developer Advocate
0 Kudos

Sure, that is actually a casting mechisum, in this case the returning paramter of the GET_COLUMN method, is not of the same type as the object LR_COLUMN, which is why you need the casting operator.

I can try to explain, but it would just sound confusing, so here is the help on the subject.

<i>Casting

Whenever a static type check is not possible or when the type checks are to be performed at program runtime, you must use the statement

MOVE ... ?TO ...

or the casting operator (?=). The casting assignment replaces the assignment operator (=). In the MOVE... ? TO statement, or when you use the casting assignment, there is no static type check. Instead, the system checks at runtime whether the object reference in the source variable points to an object to which the object reference in the target variable can also point. If the assignment is possible, the system makes it, otherwise, the catchable runtime error MOVE_CAST_ERROR occurs.

Syntax rules force you to use casting whenever a static type check is not possible, for example:

cref1 ?= iref1.

Here, an interface reference is assigned to a class reference. For the casting to be successful, the object to which irefrpoints must be an object of the same class as the class of the class variable cref1 or one of its subclasses..</i>

Regards,

Rich Heilman

Former Member
0 Kudos

Hi Rob,

The ?= operator is called the "cast" operator. It is used in widening cast where a check is carried out at runtime to ensure that the content of the source variable coppesponds to the type of requirements to the target variables and if there is a mismatch, the catchable runtime error "MOVE_CAST_ERROR" occurs which can be caught with "CATCH...ENDCATCH" and the original value of the target variable remains the same.

Example usage:

Class A is the super class of class B.

DATA: OBJ_A TYPE REF TO A,

OBJ_B1 TYPE REF TO B,

OBJ_B2 TYPE REF TO B.

CREATE OBJECT OBJ_B1.

OBJ_A = OBJ_B1.

OBJ_B2 ?= OBJ_A. "widening cast or down casting using the cast operator

Reward points if helpful.

Regards,

Renuka

Former Member
0 Kudos

more then 10 years ABAP exp. can't help me out here.

cl_salv_column_table ?= cl_salv_columns_table->get_column( 'BUKRS' ).

From my point of view : in class CL_SALV_COLUMN_TABLE there's a method GET_COLUMNS with as importing parameter COLUMNNAME, value of this is the field BUKRS. OK, this is clear to me but ...

cl_salv_column_table ?=

This is (only) a class (without mentioning a method to call). Is there input on CLASS level (which receives the value 'BUKRS') ?. Can anyone explain this to me ?

Thanks,

Rob Makelaar.

If you check GET_COLUMN in CL_SALV_COLUMNS_TABLE, you can see that the returning parameter VALUE is reference to CL_SALV_COLUMN.

It means, that when this method called, it returns with an object.

Peter