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: 

ABAP OO: how to pass a internal table with objects as a method parameter

wim_verschueren
Explorer
0 Kudos

Hello all,

I have a class "ZCL_VEHICLE", this class contains the attribute WHEELS.

This attribute contains objects of the class ZCL_WHEEL.

(definition: data WHEELS TYPE TABLE OF REF TO zcl_wheel.).

I now need a method that gives this table back (as return or export parameter). How can I define a parameter for this method that will contain this table?

Thanks for the help.

Best regards,

Wim

1 ACCEPTED SOLUTION

Former Member
0 Kudos

hi, you can define a table type, assume named as ZWHEELTB.

From se11, you can create a table type,

in the LineType tab, you choose 'Reference type' and choose the class ZCL_WHEEL as the line type.

Then in the method, you just need to define an o/p, type ZWHEELTB.

My suggestion is base on WAS 6.4.

Hope it will be helpful

Thanks

7 REPLIES 7

Former Member
0 Kudos

hi, you can define a table type, assume named as ZWHEELTB.

From se11, you can create a table type,

in the LineType tab, you choose 'Reference type' and choose the class ZCL_WHEEL as the line type.

Then in the method, you just need to define an o/p, type ZWHEELTB.

My suggestion is base on WAS 6.4.

Hope it will be helpful

Thanks

Former Member
0 Kudos

Hi

You can use the same statamen used to define attribute WHEELS:

DATA: MY_WHEELS TYPE TABLE OF REF TO ZCL_VEHICLE.

But remember: this statament defines a table without header line, so you need to define it.

Max

Message was edited by: max bianchi

0 Kudos

About the solution of Max:

I use transaction SE80 for developing my classes. There I can choose only between the types "TYPE REF TO", "TYPE" or "LIKE". Not "TYPE TABLE OF REF TO".

For defining the attribute I used the option in the menu: "Goto > Protected section". There I could code the attribute definition myself.

For method definition (it is a public method) I try to use the option in the menu: "Goto > Public section". But it is read-only, and the change button is disabled...

Does anybody now how I can jump to the changeable code view of the public method definitions? If that would succeed, I think my problem would be solved.

About the solution of Zhenglin:

I'm going to wait a bit to see of I can use Max his solution before I try yours, because it's not optimal that a table type should be created in the data dictionary for every internal table I want to pass using parameters. Or do I see something wrong here?

Thanks for the quick responses!

Wim

0 Kudos

Hi Wim

Excuse me! I understood you wanted to define it in a program, not in a class.

You can define your type into CLASS (use the same statament: go to TYPES (there's a pushbotton on status gui).

TYPES: MY_WHEELS TYPE TABLE OF REF TO .....

Now you can use this type to create a parameter like that, but you can use that type for an object of class defined as PRIVATE.

Infact if your object is public, you'll use it in a your program, so you'll probably have to define a variable like the type defined in the class.

It shouldn't make sense to define the same type for two times or more (one in the class, the others in each program uses your class). So you should define your type in dictionary (all abap object could use it).

If you think to have to use your class in few program (perhaps in olny one), you shuold consider to create your class as local class.

Max

Message was edited by: max bianchi

0 Kudos

Hello all,

Thx for the tips. I am going to try the proposed solution of the data dictionary this evening. I will let you now how it turned out.

Wim

Former Member
0 Kudos

Check the method GUI_DOWNLOAD of Class CL_GUI_FRONTEND_SERVICES . The parameter DATA_TAB is capable of accepting any type of standard table. You can define similarly .

Cheers.

Former Member
0 Kudos

hi, Wim Verschueren

you mentioned:

'There I can choose only between the types "TYPE REF TO", "TYPE" or "LIKE". Not "TYPE TABLE OF REF TO".'

yeah, that's right. That's also why I suggested you to create a table type yourself, and through it you can specify a class as a line type in your table type. Then the target achieve.

you also mentioned

'Does anybody now how I can jump to the changeable code view of the public method definitions? If that would succeed, I think my problem would be solved.'

it's simple. just into se24, open you class, and go 'method' tab, double click the method name. then you can turn to the method edit mode.

by the way, creat a table type is not a strange thing, SAP create many table type for their table.

Hope it will be helpful

thanks

Message was edited by: zhenglin gu