Video Preview:
Click here to download the source code and presentation for this video.
Learn the difference between narrowing (upcast) and widening (downcast) cast in ABAP.
This video will teach you how to implement both, and when to use them in a real case scenario.
Narrowing Cast
Variables of the type “reference to superclass” can also refer to subclass instances at runtime.
For example:
*superclass
DATA lv_vehicle TYPE REF TO zcl_vehicle.
*subclass
DATA lv_truck TYPE REF TO zcl_truck.
*narrowing cast
lv_vehicle = lv_truck.
- The term upcast is also common.
- The subclass always contains at least the same components as the superclass.
- The user can therefore address the subclass instance in the same way as the superclass instance.
- However, it is restricted to using only the inherited components.
- The view is thus generally narrowed. That is why we describe this type of assignment of reference variables as narrowing cast.
- There is a switch from a view of several components to a view of a few components.
Practical Example
- A typical use for narrowing cast assignments is to prepare for generic access.
- A user, who is not at all interested in the finer points of the instances of the subclasses but who simply wants to address the shared components, could use a superclass reference for this access.
- For example, a travel agency needs to manage all imaginable kinds of vehicles in one list.
- This leads to the question of what type should be assigned to the internal table for the references of the different types of vehicles.
Purchase a Premium Pass with an access link to watch the full video:
After completion of purchase , download the Premium Pass file where you will find the access link to the video.
You will also receive an email, shortly after the purchase, from Mendoza Learning Hub that will contain the Premium Pass and instructions for your video.
Or, become a Premium Member... - click here to become one
As a Premium member you get access to all of the videos, including this one. Log in to your Premium Account by clicking on 'Sign Up/Log In'. Visit your 'Member Profile' page where you will find access to all the Premium content. Alternately, you can visit the course's main page where you can access the premium videos.
If you didn't receive an email:
Check your spam folder. Many internet providers have spam filters that block emails that contain links. If you’re unable to find the confirmation email, then please contact us.
If you have problems with this video visit Help & Support, or contact us at info@carlosmdubon.com .
If you want a video on a particular topic, fill the form below.
[contact-form][contact-field label='Name' type='name' required='1'/][contact-field label='Email' type='email' required='1'/][contact-field label='Video Topic' type='text' required='1'/][contact-field label='Description' type='textarea' required='1'/][/contact-form]