Application Development and Automation 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: 
Read only

Reading internal table with references to objects

Former Member
0 Likes
1,335

Hello all,

I came across a thought. Imagine example of object oriented design of a car garage. As we know, in garage, cars are parked.

Garage would be represented as object of class Garage. Cars as objects of class Car. In Garage I would have an internal table type table of ref to Car. So far, everything good.

But what if I need to retrieve a car with ID 45 I would need to loop through all objects in internal table and check ID until I find 45.

My question is: Is there any chance not to do that with loop but with read? Thanks

3 REPLIES 3
Read only

Former Member
0 Likes
936

How about having a field called CAR ID in the internal table apart from the ref object? This way you can read the internal table with the field CAR ID and the second variable in the internal table would give you the instance of the car class?

Something like:

TYPES: BEGIN OF car,

               car_id          TYPE car_id,

               car_instance TYPE REF TO class_name,

            END OF car.

DATA: car_it TYPE TABLE OF car.

Thanks,

Vikram.M

Read only

0 Likes
936

I'm aware of that solution, I was thinking about more generic approach to read by any attribute, but that's something for functional programming

Read only

Former Member
0 Likes
936

>>I came across a thought<<

Ouch.  Did it hurt ??

I agree with Vikram.

And technically,  a Garage is a Collection of Cars.....

Rich