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: 

Why we need casting in OO Concept

0 Kudos

Hi Gurus,

  I am new to OO ABAP. Recently I learnt about casting concept in OO-ABAP. I was curious to know what is the use of casting, what is the need to use or know casting in OO concept.

  I searched for this topic in SDN but didn't got use full answers.

Thanks you

Sreeni

1 ACCEPTED SOLUTION

rodrigo_paisante3
Active Contributor
0 Kudos

Hi,

OO is a reusable code concept.

Look for IF_PURCHASE_ORDER_MM interface and cl_po_header_handle_mm  class.

The class was designed with this interface (and others too).

Then, the class has the interface (methods and attributes).

When you code:

  o_purchase_order ?= im_header.

*(o_purchase_order type class and im_header type interface)

You will initialize the object o_purchase_order, passing all the attributes and values from interface object im_header.

Note that o_purchase_order has other interfaces, and to initialize theirs values you will need to do the same with their respective interfaces.

Using casting command you will reduce effort, creating clean and quality code.

2 REPLIES 2

rodrigo_paisante3
Active Contributor
0 Kudos

Hi,

OO is a reusable code concept.

Look for IF_PURCHASE_ORDER_MM interface and cl_po_header_handle_mm  class.

The class was designed with this interface (and others too).

Then, the class has the interface (methods and attributes).

When you code:

  o_purchase_order ?= im_header.

*(o_purchase_order type class and im_header type interface)

You will initialize the object o_purchase_order, passing all the attributes and values from interface object im_header.

Note that o_purchase_order has other interfaces, and to initialize theirs values you will need to do the same with their respective interfaces.

Using casting command you will reduce effort, creating clean and quality code.

Former Member
0 Kudos

Hi,

Please try to search a bit harder, I have just found over 800 results on SCN for "ABAP OBJECT CASTING" including numerous blogs, discussions, wiki entries, etc.

Casting is an OO paradigm, not specific to ABAP so you could also try using Google to find out about casting.

As a starter for 10, try reading this blog post about but please search harder in future.

Cheers,

G.